-
Notifications
You must be signed in to change notification settings - Fork 11
/
SDO_DAS_Setting.cpp
508 lines (440 loc) · 13.8 KB
/
SDO_DAS_Setting.cpp
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
/*
+----------------------------------------------------------------------+
| (c) Copyright IBM Corporation 2005, 2006. |
| All Rights Reserved. |
+----------------------------------------------------------------------+
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you |
| may not use this file except in compliance with the License. You may |
| obtain a copy of the License at |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Author: Caroline Maynard |
+----------------------------------------------------------------------+
*/
static char rcs_id[] = "$Id: SDO_DAS_Setting.cpp 234945 2007-05-04 15:05:53Z mfp $";
#ifdef PHP_WIN32
#include <iostream>
#include <math.h>
#include "zend_config.w32.h"
#endif
#include "php.h"
#include "php_sdo_int.h"
#define CLASS_NAME "SDO_DAS_Setting"
/* {{{ sdo_das_setting_object
* The instance data for this class - extends the standard zend_object
*/
typedef struct {
zend_object zo; /* The standard zend_object */
Setting *setting;
} sdo_das_setting_object;
/* }}} */
static zend_object_handlers sdo_das_setting_object_handlers;
/* {{{ sdo_das_setting_get_instance
*/
static sdo_das_setting_object *sdo_das_setting_get_instance(zval *me TSRMLS_DC)
{
return (sdo_das_setting_object *)zend_object_store_get_object(me TSRMLS_CC);
}
/* }}} */
/* {{{ debug macro functions
*/
SDO_DEBUG_ADDREF(das_setting)
SDO_DEBUG_DELREF(das_setting)
SDO_DEBUG_DESTROY(das_setting)
/* }}} */
/* {{{ sdo_das_setting_object_free_storage
*/
static void sdo_das_setting_object_free_storage(void *object TSRMLS_DC)
{
sdo_das_setting_object *my_object;
SDO_DEBUG_FREE(object);
my_object = (sdo_das_setting_object *)object;
zend_hash_destroy(my_object->zo.properties);
FREE_HASHTABLE(my_object->zo.properties);
if (my_object->zo.guards) {
zend_hash_destroy(my_object->zo.guards);
FREE_HASHTABLE(my_object->zo.guards);
}
my_object->setting = NULL;
efree(object);
}
/* }}} */
/* {{{ sdo_das_setting_object_create
*/
static zend_object_value sdo_das_setting_object_create(zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
zval *tmp; /* this must be passed to hash_copy, but doesn't seem to be used */
sdo_das_setting_object *my_object;
my_object = (sdo_das_setting_object *)emalloc(sizeof(sdo_das_setting_object));
memset(my_object, 0, sizeof(sdo_das_setting_object));
my_object->zo.ce = ce;
my_object->zo.guards = NULL;
ALLOC_HASHTABLE(my_object->zo.properties);
zend_hash_init(my_object->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
// zend_hash_copy(my_object->zo.properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));
#if PHP_VERSION_ID < 50399
zend_hash_copy(my_object->zo.properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));
#else
object_properties_init(&my_object->zo, ce);
#endif
retval.handle = zend_objects_store_put(my_object, SDO_FUNC_DESTROY(das_setting), sdo_das_setting_object_free_storage, NULL TSRMLS_CC);
retval.handlers = &sdo_das_setting_object_handlers;
SDO_DEBUG_ALLOCATE(retval.handle, my_object);
return retval;
}
/* }}} */
/* {{{ sdo_das_setting_new
*/
void sdo_das_setting_new(zval *me, Setting *setting TSRMLS_DC)
{
sdo_das_setting_object *my_object;
// char *class_name, *space;
Z_TYPE_P(me) = IS_OBJECT;
if (object_init_ex(me, sdo_das_setting_class_entry) == FAILURE) {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
php_error(E_ERROR, "%s%s%s(): internal error (%i) - failed to instantiate %s object",
class_name, space, get_active_function_name(TSRMLS_C), __LINE__, CLASS_NAME);
return;
}
my_object = (sdo_das_setting_object *)zend_object_store_get_object(me TSRMLS_CC);
my_object->setting = setting;
}
/* }}} */
/* {{{ sdo_das_setting_read_value
*/
static zval *sdo_das_setting_read_value (sdo_das_setting_object *my_object TSRMLS_DC)
{
Setting *setting = my_object->setting;
uint bytes_len;
char *bytes_value;
char char_value;
wchar_t wchar_value;
DataObjectPtr doh_value;
zval *return_value;
// char *class_name, *space;
MAKE_STD_ZVAL(return_value);
try {
if ((!setting->isSet()) || setting->isNull()) {
RETVAL_NULL();
} else {
const Property& property = setting->getProperty();
switch(property.getTypeEnum()) {
case Type::OtherTypes: {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'OtherTypes'",
class_name, space, get_active_function_name(TSRMLS_C), __LINE__);
break;
}
case Type::BigDecimalType:
case Type::BigIntegerType: {
RETVAL_STRING((char *)setting->getCStringValue(), 1);
break;
}
case Type::BooleanType: {
RETVAL_BOOL(setting->getBooleanValue());
break;
}
case Type::ByteType: {
RETVAL_LONG(setting->getByteValue());
break;
}
case Type::BytesType: {
bytes_len = setting->getLength();
bytes_value = (char *)emalloc(1 + bytes_len);
bytes_len = setting->getBytesValue(bytes_value, bytes_len);
bytes_value[bytes_len] = '\0';
RETVAL_STRINGL(bytes_value, bytes_len, 0);
break;
}
case Type::CharacterType: {
wchar_value = setting->getCharacterValue();
if (wchar_value > INT_MAX) {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
php_error(E_WARNING, "%s%s%s(): wide character data lost for '%s'",
class_name, space, get_active_function_name(TSRMLS_C), property.getName());
}
char_value = setting->getByteValue();
RETVAL_STRINGL(&char_value, 1, 1);
break;
}
case Type::DateType: {
RETVAL_LONG(setting->getDateValue().getTime());
break;
}
case Type::DoubleType: {
RETVAL_DOUBLE(setting->getDoubleValue());
break;
}
case Type::FloatType: {
RETVAL_DOUBLE(setting->getFloatValue());
break;
}
case Type::IntegerType: {
RETVAL_LONG(setting->getIntegerValue());
break;
}
case Type::LongType: {
/* An SDO long (64 bits) may overflow a PHP int, so we return it as a string */
RETVAL_STRING((char *)setting->getCStringValue(), 1);
break;
}
case Type::ShortType: {
RETVAL_LONG(setting->getShortValue());
break;
}
case Type::StringType:
case Type::UriType: {
RETVAL_STRING((char *)setting->getCStringValue(), 1);
break;
}
case Type::DataObjectType:
case Type::OpenDataObjectType: {
doh_value = setting->getDataObjectValue();
if (!doh_value) {
/* An old value may legitimately be null */
RETVAL_NULL();
} else {
sdo_do_new(return_value, doh_value TSRMLS_CC);
}
break;
}
case Type::ChangeSummaryType: {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'ChangeSummaryType'",
class_name, space, get_active_function_name(TSRMLS_C), __LINE__);
break;
}
case Type::TextType: {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type 'TextType'",
class_name, space, get_active_function_name(TSRMLS_C), __LINE__);
break;
}
default: {
const char *space, *class_name = get_active_class_name(&space TSRMLS_CC);
php_error(E_ERROR, "%s%s%s(): internal error (%i) - unexpected DataObject type '%s' for property '%s'",
class_name, space, get_active_function_name(TSRMLS_C), __LINE__,
property.getType().getName(), property.getName());
}
}
}
} catch (SDORuntimeException e) {
sdo_throw_runtimeexception(&e TSRMLS_CC);
}
return return_value;
}
/* }}} */
/* {{{ sdo_das_setting_get_properties
*/
static HashTable *sdo_das_setting_get_properties(zval *object TSRMLS_DC)
{
sdo_das_setting_object *my_object;
zval *tmp;
Setting *setting;
const char *property_name;
my_object = sdo_das_setting_get_instance(object TSRMLS_CC);
zend_hash_clean(my_object->zo.properties);
try {
setting = my_object->setting;
property_name = setting->getProperty().getName();
/* TODO if the setting is for a list element, we should
* probably include the list index as part of the key
*/
tmp = sdo_das_setting_read_value(my_object TSRMLS_CC);
zval_add_ref(&tmp);
zend_hash_add(my_object->zo.properties, (char *)property_name, 1 + strlen(property_name),
&tmp, sizeof(zval *), NULL);
} catch (SDORuntimeException e) {
sdo_throw_runtimeexception(&e TSRMLS_CC);
}
return my_object->zo.properties;
}
/* }}} */
/* {{{ sdo_das_setting_cast_object
*/
#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1)
static int sdo_das_setting_cast_object(zval *readobj, zval *writeobj, int type TSRMLS_DC)
{
int should_free = 0;
#else
static int sdo_das_setting_cast_object(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC)
{
#endif
sdo_das_setting_object *my_object;
ostringstream print_buf;
zval free_obj;
int rc = SUCCESS;
Setting *setting;
if (should_free) {
free_obj = *writeobj;
}
my_object = sdo_das_setting_get_instance(readobj TSRMLS_CC);
setting = my_object->setting;
try {
const Property& property = setting->getProperty();
print_buf << "object(" << CLASS_NAME <<
")#" << readobj->value.obj.handle;
if (property.isMany()) {
print_buf << '[' << setting->getIndex() << ']';
}
if (setting->isSet() && property.getType().isDataType()) {
print_buf << "=>";
if (setting->isNull()) {
print_buf << "NULL";
} else {
print_buf << '\"' << setting->getCStringValue() << '\"';
}
}
print_buf << '}';
std::string print_string = print_buf.str()/*.substr(0, SDO_TOSTRING_MAX)*/;
ZVAL_STRINGL(writeobj, (char *)print_string.c_str(), print_string.length(), 1);
} catch (SDORuntimeException e) {
ZVAL_NULL(writeobj);
sdo_throw_runtimeexception(&e TSRMLS_CC);
rc = FAILURE;
}
switch(type) {
case IS_STRING: {
convert_to_string(writeobj);
break;
}
case IS_BOOL: {
convert_to_boolean(writeobj);
break;
}
case IS_LONG: {
convert_to_long(writeobj);
break;
}
case IS_DOUBLE: {
convert_to_double(writeobj);
break;
}
default: {
rc = FAILURE;
}
}
if (should_free) {
zval_dtor(&free_obj);
}
return rc;
}
/* }}} */
/* {{{ sdo_das_setting_minit
*/
void sdo_das_setting_minit(zend_class_entry *tmp_ce TSRMLS_DC)
{
tmp_ce->create_object = sdo_das_setting_object_create;
sdo_das_setting_class_entry = zend_register_internal_class(tmp_ce TSRMLS_CC);
memcpy(&sdo_das_setting_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
sdo_das_setting_object_handlers.add_ref = SDO_FUNC_ADDREF(das_setting);
sdo_das_setting_object_handlers.del_ref = SDO_FUNC_DELREF(das_setting);
sdo_das_setting_object_handlers.clone_obj = NULL;
sdo_das_setting_object_handlers.get_properties = sdo_das_setting_get_properties;
sdo_das_setting_object_handlers.cast_object = sdo_das_setting_cast_object;
}
/* }}} */
/* {{{ SDO_DAS_Setting::getPropertyIndex
*/
PHP_METHOD(SDO_DAS_Setting, getPropertyIndex)
{
sdo_das_setting_object *my_object;
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC);
try {
const Property& property = my_object->setting->getProperty();
RETVAL_LONG(property.getContainingType().getPropertyIndex(property.getName()));
} catch (SDORuntimeException e) {
sdo_throw_runtimeexception(&e TSRMLS_CC);
}
return;
}
/* }}} */
/* {{{ SDO_DAS_Setting::getPropertyName
*/
PHP_METHOD(SDO_DAS_Setting, getPropertyName)
{
sdo_das_setting_object *my_object;
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC);
try {
RETVAL_STRING((char *)my_object->setting->getProperty().getName(), 1);
} catch (SDORuntimeException e) {
sdo_throw_runtimeexception(&e TSRMLS_CC);
}
return;
}
/* }}} */
/* {{{ SDO_DAS_Setting::getValue
*/
PHP_METHOD(SDO_DAS_Setting, getValue)
{
zval *value;
sdo_das_setting_object *my_object;
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC);
value = sdo_das_setting_read_value(my_object TSRMLS_CC);
RETVAL_ZVAL(value, 1, 0);
return;
}
/* }}} */
/* {{{ SDO_DAS_Setting::getListIndex
*/
PHP_METHOD(SDO_DAS_Setting, getListIndex)
{
sdo_das_setting_object *my_object;
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC);
try {
if (my_object->setting->getProperty().isMany()) {
RETVAL_LONG(my_object->setting->getIndex());
} else {
RETVAL_LONG(-1);
}
} catch (SDORuntimeException e) {
sdo_throw_runtimeexception(&e TSRMLS_CC);
}
return;
}
/* }}} */
/* {{{ SDO_DAS_Setting::isSet
*/
PHP_METHOD(SDO_DAS_Setting, isSet)
{
sdo_das_setting_object *my_object;
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
my_object = sdo_das_setting_get_instance(getThis() TSRMLS_CC);
try {
RETVAL_BOOL(my_object->setting->isSet());
} catch (SDORuntimeException e) {
sdo_throw_runtimeexception(&e TSRMLS_CC);
}
return;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/