Project

Profile

Help

Download (113 KB) Statistics
| Branch: | Revision:

he / src / main / c / Saxon.C.API / php_saxon.cpp @ 7728ae0b

1 72bf04c6 Norman Walsh
#ifdef HAVE_CONFIG_H
2
    #include "config.h"
3
#endif
4
5
#include "php_saxon.h"
6
7
#ifdef COMPILE_DL_SAXON
8
    extern "C" {
9
        ZEND_GET_MODULE(saxon)
10
    }
11
#endif
12
13
JNINativeMethod phpMethods[] =
14
{
15
    {
16
         "_phpCall",
17
         "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;",
18
         (void *)&phpNativeCall
19
    }
20
};
21
22
zend_object_handlers saxonProcessor_object_handlers;
23
zend_object_handlers xsltProcessor_object_handlers;
24
zend_object_handlers xqueryProcessor_object_handlers;
25
zend_object_handlers xpathProcessor_object_handlers;
26
zend_object_handlers schemaValidator_object_handlers;
27
zend_object_handlers xdmValue_object_handlers;
28
zend_object_handlers xdmItem_object_handlers;
29
zend_object_handlers xdmNode_object_handlers;
30
zend_object_handlers xdmAtomicValue_object_handlers;
31
32
zend_class_entry *saxonProcessor_ce;
33
zend_class_entry *xsltProcessor_ce;
34
zend_class_entry *xqueryProcessor_ce;
35
zend_class_entry *xpathProcessor_ce;
36
zend_class_entry *schemaValidator_ce;
37
zend_class_entry *xdmValue_ce;
38
zend_class_entry *xdmItem_ce;
39
zend_class_entry *xdmNode_ce;
40
zend_class_entry *xdmAtomicValue_ce;
41
42
void SaxonProcessor_free_storage(void *object TSRMLS_DC)
43
{
44
 
45
    saxonProcessor_object *obj = (saxonProcessor_object *)object;
46
47
    zend_hash_destroy(obj->std.properties);
48
    FREE_HASHTABLE(obj->std.properties);
49
    efree(obj);
50
}
51
52
zend_object_value saxonProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
53
{
54
    zval *tmp;
55
    zend_object_value retval;
56
57
    saxonProcessor_object *obj = (saxonProcessor_object *)emalloc(sizeof(saxonProcessor_object));
58
    memset(obj, 0, sizeof(saxonProcessor_object));
59
    obj->std.ce = type;
60
61
    ALLOC_HASHTABLE(obj->std.properties);
62 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
63 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
64 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, SaxonProcessor_free_storage, nullptr TSRMLS_CC);
65 72bf04c6 Norman Walsh
    retval.handlers = &saxonProcessor_object_handlers;
66
67
    return retval;
68
}
69
70
PHP_METHOD(SaxonProcessor, __construct)
71
{
72
73
    if (ZEND_NUM_ARGS()>2) {
74
        WRONG_PARAM_COUNT;
75
    }
76
77 ead48a5d O'Neil Delpratt
    char * cwdi = nullptr;
78 72bf04c6 Norman Walsh
   bool license = false;
79
    int len1;
80
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &license) == FAILURE) {
81
        php_error(E_WARNING,"Wrong SaxonProcessor argument");
82 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
83 72bf04c6 Norman Walsh
    } 
84
85
86
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "bs", &license, &cwdi, &len1) == FAILURE) {
87
        php_error(E_WARNING,"Wrong SaxonProcessor arguments");
88 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
89 72bf04c6 Norman Walsh
    }
90
 
91
92
    zval *object = getThis();
93
    SaxonProcessor * saxonProc;
94
    saxonProcessor_object * obj = (saxonProcessor_object *)zend_object_store_get_object(object TSRMLS_CC);
95
    saxonProc =  obj->saxonProcessor;
96 ead48a5d O'Neil Delpratt
    if(saxonProc == nullptr) {
97 72bf04c6 Norman Walsh
98
        saxonProc = new SaxonProcessor(license); //TODO: add license flag to PHP function argument
99
100
        obj->saxonProcessor = saxonProc;
101
    }
102
103 ead48a5d O'Neil Delpratt
    if(cwdi==nullptr) {
104 72bf04c6 Norman Walsh
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
105
            TCHAR s[256];
106
107
            // --
108
            DWORD a = GetCurrentDirectory(256, s);
109
            const size_t newsize = wcslen(s)*2;
110
            char* cwd = new char[newsize];
111
            wcstombs_s(0, cwd, newsize, s, _TRUNCATE);
112
            // -- code above returns the apache installtion directory as the CWD
113
114
            char* cwd2;
115
116
            //php_error(E_WARNING,cwd2);
117
118
            saxonProc->setcwd(cwd2);
119
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
120
#else
121
122
            char cwd[256];
123
124
            VCWD_GETCWD(cwd, sizeof(cwd));
125 ead48a5d O'Neil Delpratt
            if(cwd == nullptr) {
126
             //php_error(E_WARNING,"cwd is nullptr");
127 72bf04c6 Norman Walsh
           }else {
128
             //php_error(E_WARNING,cwd);
129
130
            saxonProc->setcwd(cwd);
131
          }
132
#endif
133
134
    } else {
135
        saxonProc->setcwd(cwdi);
136
    }
137
138
}
139
140
PHP_METHOD(SaxonProcessor, __destruct)
141
{
142
    
143
    saxonProcessor_object *obj = (saxonProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
144
145
    SaxonProcessor * saxonProc= obj->saxonProcessor;
146
147
    delete saxonProc;
148
}
149
150
PHP_METHOD(SaxonProcessor, setResourcesDirectory)
151
{
152
    SaxonProcessor *saxonProcessor;
153
    char * dirStr;
154
    int len;
155
    
156
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dirStr, &len) == FAILURE) {
157 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
158 72bf04c6 Norman Walsh
    }
159
    
160
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
161
    saxonProcessor = obj->saxonProcessor;
162 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
163 72bf04c6 Norman Walsh
       
164 ead48a5d O'Neil Delpratt
        if(dirStr != nullptr) {
165 72bf04c6 Norman Walsh
            saxonProcessor->setResourcesDirectory(dirStr);
166
        }
167
    }
168
}
169
170
PHP_METHOD(SaxonProcessor, setcwd)
171
{
172
    SaxonProcessor *saxonProcessor;
173
    char * cwdStr;
174
    int len;
175
    
176
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cwdStr, &len) == FAILURE) {
177 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
178 72bf04c6 Norman Walsh
    }
179
    
180
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
181
    saxonProcessor = obj->saxonProcessor;
182 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
183 72bf04c6 Norman Walsh
        
184 ead48a5d O'Neil Delpratt
        if(cwdStr != nullptr) {
185 72bf04c6 Norman Walsh
            saxonProcessor->setcwd(cwdStr);
186
        }
187
    }
188
}
189
190
191
PHP_METHOD(SaxonProcessor, parseXmlFromString)
192
{
193
    SaxonProcessor * saxonProcessor;
194
    char * source;
195
    int len1;
196
197
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &len1) == FAILURE) {
198 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
199 72bf04c6 Norman Walsh
    }
200
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
201 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
202 72bf04c6 Norman Walsh
    saxonProcessor = obj->saxonProcessor;
203 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
204 72bf04c6 Norman Walsh
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
205 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
206 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
207 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
208 72bf04c6 Norman Walsh
            } else {
209
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
210 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
211 72bf04c6 Norman Walsh
                vobj->xdmNode = node;
212
            }
213
        } else {
214
            if(obj->saxonProcessor->exceptionOccurred()){
215
                //TODO throw exception
216
            }
217
        }
218
    } else {
219 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
220 72bf04c6 Norman Walsh
    }
221
}
222
223
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
224
{
225
    SaxonProcessor * saxonProcessor;
226
    char * source;
227
    int len1;
228
229
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &len1) == FAILURE) {
230 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
231 72bf04c6 Norman Walsh
    }
232
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
233 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
234 72bf04c6 Norman Walsh
    saxonProcessor = obj->saxonProcessor;
235 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
236 72bf04c6 Norman Walsh
        XdmValue* node = (XdmValue*)saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
237 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
238 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
239 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
240 72bf04c6 Norman Walsh
            } else {
241
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
242 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
243 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
244
            }
245
        } else {
246
           // obj->xsltProcessor->checkException();//TODO
247
        }
248
    } else {
249 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
250 72bf04c6 Norman Walsh
    }
251
}
252
253
254
PHP_METHOD(SaxonProcessor, createAtomicValue)
255
{
256 ead48a5d O'Neil Delpratt
    XdmAtomicValue * xdmValue = nullptr;
257 72bf04c6 Norman Walsh
    SaxonProcessor * proc;
258
    char * source;
259
    int len1;
260
    zval *zvalue;
261
    bool bVal;
262
    char * sVal;
263
    int len;
264
    long iVal;
265
    double dVal;
266
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&zvalue) == FAILURE) {
267 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
268 72bf04c6 Norman Walsh
    }
269
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
270 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
271 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
272 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
273
    if (proc != nullptr) {
274 72bf04c6 Norman Walsh
        switch (Z_TYPE_P(zvalue)) {
275
            case IS_BOOL:
276
                bVal = Z_BVAL_P(zvalue);
277
                xdmValue = proc->makeBooleanValue((bool)bVal);
278
            break;
279
            case IS_LONG:
280
                iVal = Z_LVAL_P(zvalue);
281
                 xdmValue = proc->makeIntegerValue((int)iVal);
282
            break;
283
            case IS_STRING:
284
                sVal = Z_STRVAL_P(zvalue);
285
                len = Z_STRLEN_P(zvalue);
286
                xdmValue = proc->makeStringValue((const char*)sVal);
287
            break;
288 ead48a5d O'Neil Delpratt
            case IS_nullptr:
289 72bf04c6 Norman Walsh
                xdmValue = new XdmAtomicValue();
290
            break;
291
            case IS_DOUBLE:
292
                dVal = (double)Z_DVAL_P(zvalue);
293
                xdmValue = proc->makeDoubleValue((double)iVal);
294
                break;
295
            case IS_ARRAY:
296
                // TODO: Should not be expected. Do this some other way
297
                //break;
298
            case IS_OBJECT:
299
                // TODO: implement this
300
                //break;
301
            default:
302 ead48a5d O'Neil Delpratt
                obj = nullptr;
303 72bf04c6 Norman Walsh
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC); 
304 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
305 72bf04c6 Norman Walsh
        }
306 ead48a5d O'Neil Delpratt
        if(xdmValue == nullptr) {
307
            RETURN_nullptr();
308 72bf04c6 Norman Walsh
        }
309
        if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
310 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
311 72bf04c6 Norman Walsh
        } else {
312
            struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
313 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
314 72bf04c6 Norman Walsh
            vobj->xdmAtomicValue = xdmValue;
315
        }
316
    } else {
317
       
318 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
319 72bf04c6 Norman Walsh
    }
320
}
321
322
323
PHP_METHOD(SaxonProcessor, newXPathProcessor)
324
{
325
   
326
    if (ZEND_NUM_ARGS()>0) {
327
        WRONG_PARAM_COUNT;
328
    }
329
    SaxonProcessor * proc;
330 ead48a5d O'Neil Delpratt
    XPathProcessor * xpathProcessor = nullptr;
331
    if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
332 72bf04c6 Norman Walsh
      
333
    }
334
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
335
336 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
337 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
338 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
339
    if (proc != nullptr) {
340 72bf04c6 Norman Walsh
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
341 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
342 72bf04c6 Norman Walsh
        } else {
343
           struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
344 ead48a5d O'Neil Delpratt
            assert (vobji != nullptr);
345 72bf04c6 Norman Walsh
            xpathProcessor = proc->newXPathProcessor();
346
            vobji->xpathProcessor = xpathProcessor;
347
        }
348
    } else {
349
       
350 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
351 72bf04c6 Norman Walsh
    }
352
}
353
354
PHP_METHOD(SaxonProcessor, newXsltProcessor)
355
{
356
    //php_error(E_WARNING,"new xsltProc 1");
357
    if (ZEND_NUM_ARGS()>0) {
358
        WRONG_PARAM_COUNT;
359
    }
360
    SaxonProcessor * proc;
361 ead48a5d O'Neil Delpratt
    XsltProcessor * xsltProcessor = nullptr;
362
if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
363 72bf04c6 Norman Walsh
   
364
}
365
366
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
367 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
368 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
369 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
370
    if (proc != nullptr) {
371 72bf04c6 Norman Walsh
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
372 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
373 72bf04c6 Norman Walsh
        } else {
374
           struct xsltProcessor_object* vobj = (struct xsltProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
375
        
376 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
377 72bf04c6 Norman Walsh
            xsltProcessor = proc->newXsltProcessor();
378
            vobj->xsltProcessor = xsltProcessor;
379
    }
380
    } else {
381
       
382 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
383 72bf04c6 Norman Walsh
    }
384
}
385
386
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
387
{
388
   
389
    if (ZEND_NUM_ARGS()>0) {
390
        WRONG_PARAM_COUNT;
391
    }
392
    SaxonProcessor * proc;
393 ead48a5d O'Neil Delpratt
    XQueryProcessor * xqueryProcessor = nullptr;
394
   if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
395 72bf04c6 Norman Walsh
   
396
   }
397
   
398
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
399 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
400 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
401 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
402
    if (proc != nullptr) {
403 72bf04c6 Norman Walsh
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
404 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
405 72bf04c6 Norman Walsh
        } else {
406
           struct xqueryProcessor_object* vobj = (struct xqueryProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
407
408 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
409 72bf04c6 Norman Walsh
            xqueryProcessor = proc->newXQueryProcessor();
410
            vobj->xqueryProcessor = xqueryProcessor;
411
     }
412
    } else {
413
       
414 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
415 72bf04c6 Norman Walsh
    }
416
}
417
418
PHP_METHOD(SaxonProcessor, newSchemaValidator)
419
{
420
   
421
    if (ZEND_NUM_ARGS()>0) {
422
        WRONG_PARAM_COUNT;
423
    }
424
    SaxonProcessor * proc;
425 ead48a5d O'Neil Delpratt
    SchemaValidator * schemaValidator = nullptr;
426 72bf04c6 Norman Walsh
   
427
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
428 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
429 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
430 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
431
    if (proc != nullptr) {
432 72bf04c6 Norman Walsh
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
433 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
434 72bf04c6 Norman Walsh
        } else {
435
           struct schemaValidator_object* vobj = (struct schemaValidator_object *)zend_object_store_get_object(return_value TSRMLS_CC);
436 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
437 72bf04c6 Norman Walsh
            schemaValidator = proc->newSchemaValidator();
438 ead48a5d O'Neil Delpratt
            if(schemaValidator == nullptr){
439
                RETURN_nullptr();
440 72bf04c6 Norman Walsh
            }
441
            vobj->schemaValidator = schemaValidator;
442
        }
443
    } else {
444
       
445 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
446 72bf04c6 Norman Walsh
    }
447
}
448
449
450
PHP_METHOD(SaxonProcessor, version)
451
{
452
    SaxonProcessor *saxonProcessor;
453
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
454
    if (ZEND_NUM_ARGS()>0) {
455
        WRONG_PARAM_COUNT;
456
    }
457
    saxonProcessor = obj->saxonProcessor;
458 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
459 72bf04c6 Norman Walsh
        char *str = estrdup(saxonProcessor->version());
460
        RETURN_STRING(str, 0);
461
    }
462 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
463 72bf04c6 Norman Walsh
}
464
465
466
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
467
{
468
    SaxonProcessor *saxonProcessor;
469
    char * name;
470
    int len1;
471
    char * value;
472
    int len2;
473
    if (ZEND_NUM_ARGS()!= 2) {
474
        WRONG_PARAM_COUNT;
475
    }
476
477
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
478 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
479 72bf04c6 Norman Walsh
    }
480
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
481
482
    saxonProcessor = obj->saxonProcessor;
483 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr && name != nullptr && value != nullptr) {
484 72bf04c6 Norman Walsh
        saxonProcessor->setConfigurationProperty(name, value);
485
    }
486
    
487
}
488
489
PHP_METHOD(SaxonProcessor, registerPHPFunction)
490
{
491
    SaxonProcessor *saxonProcessor;
492
    char * libName;
493
    int len1;
494
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
495
    if (ZEND_NUM_ARGS()!= 1) {
496
        WRONG_PARAM_COUNT;
497
    }
498
499
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &libName, &len1) == FAILURE) {
500 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
501 72bf04c6 Norman Walsh
    }
502
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
503
504
    saxonProcessor = obj->saxonProcessor;
505 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr && libName != nullptr) {
506 72bf04c6 Norman Walsh
        saxonProcessor->setConfigurationProperty("extc", libName);
507
    }
508
saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PhpFunction",
509
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
510
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
511
}
512
513
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
514
515
void XsltProcessor_free_storage(void *object TSRMLS_DC)
516
{
517
518
    xsltProcessor_object *obj = (xsltProcessor_object *)object;
519
520
    zend_hash_destroy(obj->std.properties);
521
    FREE_HASHTABLE(obj->std.properties);
522
    efree(obj);
523
524
}
525
526
zend_object_value xsltProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
527
{
528
    zval *tmp;
529
    zend_object_value retval;
530
531
    xsltProcessor_object *obj = (xsltProcessor_object *)emalloc(sizeof(xsltProcessor_object));
532
    memset(obj, 0, sizeof(xsltProcessor_object));
533
    obj->std.ce = type;
534
535
    ALLOC_HASHTABLE(obj->std.properties);
536 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
537 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
538 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, XsltProcessor_free_storage, nullptr TSRMLS_CC);
539 72bf04c6 Norman Walsh
    retval.handlers = &xsltProcessor_object_handlers;
540
541
    return retval;
542
}
543
544
545
546
PHP_METHOD(XsltProcessor, __destruct)
547
{
548
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
549
550
551
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
552
553
    delete xsltProcessor;
554
    
555
}
556
557
PHP_METHOD(XsltProcessor, transformFileToFile)
558
{
559
    XsltProcessor *xsltProcessor;
560
    char * outfileName;
561
    char * infilename;
562
    char * styleFileName;
563
    int len1, len2, len3;
564
565
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
566 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
567 72bf04c6 Norman Walsh
    }
568
569
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
570
    xsltProcessor = obj->xsltProcessor;
571
 
572 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
573 72bf04c6 Norman Walsh
574
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
575
        if(xsltProcessor->exceptionOccurred()) {
576
               // TODO: throw exception
577
        }
578
    }
579
}
580
581
PHP_METHOD(XsltProcessor, transformFileToValue)
582
{
583
    XsltProcessor *xsltProcessor;
584
    char * infilename;
585
    char * styleFileName;
586
    int len1, len2;
587
588
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
589 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
590 72bf04c6 Norman Walsh
    }
591
592
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
593
    xsltProcessor = obj->xsltProcessor;
594
    
595 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
596 72bf04c6 Norman Walsh
597
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
598 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
599 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
600 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
601 72bf04c6 Norman Walsh
            } else {
602
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
603 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
604 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
605
            }
606
        } else {
607
            if(obj->xsltProcessor->exceptionOccurred()){
608
                  //TODO
609
            }
610
        }
611
    }else {
612 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
613 72bf04c6 Norman Walsh
    }
614
}
615
616
617
PHP_METHOD(XsltProcessor, transformFileToString)
618
{
619
    XsltProcessor *xsltProcessor;
620
    char * infilename;
621
    char * styleFileName;
622
    int len1, len2;
623
624
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
625 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
626 72bf04c6 Norman Walsh
    }
627
628
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
629
    xsltProcessor = obj->xsltProcessor;
630
631 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
632 72bf04c6 Norman Walsh
633
        const char * result = xsltProcessor->transformFileToString(infilename, styleFileName);
634 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
635 72bf04c6 Norman Walsh
            char *str = estrdup(result);
636
            RETURN_STRING(str, 0);
637
        } else if(xsltProcessor->exceptionOccurred()){
638
            //TODO: xsltProcessor->checkException();
639
            const char * errStr = xsltProcessor->getErrorMessage(0);
640 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
641 72bf04c6 Norman Walsh
                const char * errorCode = xsltProcessor->getErrorCode(0);
642 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
643 72bf04c6 Norman Walsh
                    // TODO: throw exception
644
                }
645
            }
646
        }
647
    }
648
}
649
650
/*enum saxonTypeEnum
651
{
652
        enumNode,
653
        enumString,
654
        enumInteger,
655
        enumDouble,
656
        enumFloat,
657
        enumBool,
658
        enumArrXdmValue
659
};*/
660
661
jobject JNICALL phpNativeCall
662
  (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
663
        JNIEnv *senv = SaxonProcessor::sxn_environ->env;
664
665 ead48a5d O'Neil Delpratt
        const char *nativeString = senv->GetStringUTFChars(funcName, nullptr);
666 72bf04c6 Norman Walsh
667 ead48a5d O'Neil Delpratt
        if(nativeString == nullptr) {
668
                return nullptr;
669 72bf04c6 Norman Walsh
        }
670
671
        zval *function_name;
672
        zval *retval;
673
        
674
        int argLength = 0;
675 ead48a5d O'Neil Delpratt
        zvalArr * php_argv= nullptr;
676
        if(arguments != nullptr) {
677 72bf04c6 Norman Walsh
                argLength = (int)senv->GetArrayLength(arguments);
678
                php_argv = new zvalArr[argLength];
679
        }
680
        zval **params[argLength];
681
        if(argLength>0) {
682
                (*params) = (zval**)malloc(sizeof(zval*) * argLength);
683
        } else {
684 ead48a5d O'Neil Delpratt
                (*params) = nullptr;
685 72bf04c6 Norman Walsh
        }
686
        std::map<std::string, saxonTypeEnum> typeMap;
687
        typeMap["node"] = enumNode;
688
        typeMap["string"] = enumString;
689
        typeMap["integer"] = enumInteger;
690
        typeMap["double"] = enumDouble;
691
        typeMap["float"] = enumFloat;
692
        typeMap["boolean"] = enumBool;
693
        typeMap["[xdmvalue"] = enumArrXdmValue;
694
        sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
695
        SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
696
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
697
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
698
        
699
        for(int i=0; i<argLength;i++){
700
701
                jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
702
                jobject argObj = senv->GetObjectArrayElement(arguments, i);
703
704 ead48a5d O'Neil Delpratt
                const char * str = senv->GetStringUTFChars(argType,nullptr);
705
                const char *stri = nullptr;
706 72bf04c6 Norman Walsh
                double dnumber = 0;
707
                long lnumber = 0;
708
                bool bvalue = false;
709
                float fnumber = 0;
710
                
711
712
         
713
                struct xdmNode_object* vobj;
714 ead48a5d O'Neil Delpratt
                XdmNode * node = nullptr;
715 72bf04c6 Norman Walsh
                std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
716
                if (it != typeMap.end()){
717
                        switch (it->second)
718
                        {
719
                                case enumNode:
720
                                        if(!nprocessor->proc){
721
                                                nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
722
                                        }
723
                                        node = new XdmNode(argObj);
724
                                        node->setProcessor(nprocessor);
725
726
                                        MAKE_STD_ZVAL(php_argv[i]._val);
727
                                        object_init_ex(php_argv[i]._val, xdmNode_ce);
728
                                           vobj = (struct xdmNode_object *)zend_object_store_get_object(php_argv[i]._val TSRMLS_CC);
729 ead48a5d O'Neil Delpratt
                                        assert (vobj != nullptr);
730 72bf04c6 Norman Walsh
                                        vobj->xdmNode = node;
731
                                        break;
732
                                case enumString:
733 ead48a5d O'Neil Delpratt
                                        stri = senv->GetStringUTFChars((jstring)argObj, nullptr);
734 72bf04c6 Norman Walsh
                                        MAKE_STD_ZVAL(php_argv[i]._val);
735
                                        ZVAL_STRING(php_argv[i]._val, stri, 1);
736
                                        break;
737
                                case enumInteger:
738
                                        sresult->xdmvalue = argObj; 
739
                                        lnumber = getLongValue(*SaxonProcessor::sxn_environ, *sresult, 0);
740
741
                                        MAKE_STD_ZVAL(php_argv[i]._val);
742
                                        ZVAL_LONG(php_argv[i]._val, lnumber);                                        
743
                                        break;
744
                                case enumDouble:
745
                                        sresult->xdmvalue = argObj; 
746
                                        dnumber = getDoubleValue(*SaxonProcessor::sxn_environ, *sresult, 0);
747
                                        MAKE_STD_ZVAL(php_argv[i]._val);
748
                                        ZVAL_DOUBLE(php_argv[i]._val, dnumber);
749
                                        break;
750
                                case enumFloat:
751
                                        sresult->xdmvalue = argObj; 
752
                                        fnumber = getFloatValue(*SaxonProcessor::sxn_environ, *sresult, 0);
753
                                        MAKE_STD_ZVAL(php_argv[i]._val);
754
                                        ZVAL_DOUBLE(php_argv[i]._val, fnumber);                                        
755
                                        break;
756
                                case enumBool:
757
                                        sresult->xdmvalue = argObj; 
758
                                        bvalue = getBooleanValue(*SaxonProcessor::sxn_environ, *sresult);
759
                                        MAKE_STD_ZVAL(php_argv[i]._val);
760
                                        ZVAL_BOOL(php_argv[i]._val, bvalue);                                                
761
                                        break;
762
                                case enumArrXdmValue:
763
                                        //TODO - not currently supported
764
                                        argLength--;
765
                                        break;
766
                        }
767
                        senv->ReleaseStringUTFChars(argType, str);
768
                } 
769
770
        //TODO should free sresult but it causes memory corruption        
771
                
772
// array of zvals to execute
773
    
774
775
 
776
            // convert all the values
777
            for(int i = 0; i < argLength; i++) { params[i] = &php_argv[i]._val; }
778
779
        }
780
        //note: no implicit type conversion.
781
782 ead48a5d O'Neil Delpratt
        zval *argvv = nullptr;//xparams;
783 72bf04c6 Norman Walsh
        MAKE_STD_ZVAL(function_name);
784
        ZVAL_STRING(function_name, nativeString, 1);
785 ead48a5d O'Neil Delpratt
        if(call_user_function_ex(CG(function_table), nullptr, function_name, &retval, argLength, params, 0, nullptr TSRMLS_CC) != SUCCESS)
786 72bf04c6 Norman Walsh
        {
787
            zend_error(E_ERROR, "Function call failed");
788
        }
789
790
791
792
        if(Z_TYPE(*retval) ==0){
793 ead48a5d O'Neil Delpratt
                zend_error(E_ERROR, "Function returned nullptr");
794 72bf04c6 Norman Walsh
        }
795
796 ead48a5d O'Neil Delpratt
        char * sVal = nullptr;
797 72bf04c6 Norman Walsh
        int len = 0;
798 ead48a5d O'Neil Delpratt
        jobject obj = nullptr;
799 72bf04c6 Norman Walsh
        std::cerr<<" Return type="<<Z_TYPE_P(retval)<<std::endl;
800
//TODO handle XdmValue wrapped object
801 ead48a5d O'Neil Delpratt
const char * objName = nullptr;
802
xdmNode_object* ooth = nullptr;
803 72bf04c6 Norman Walsh
        switch (Z_TYPE_P(retval)) {
804
            case IS_BOOL:
805
                obj= booleanValue(*SaxonProcessor::sxn_environ, Z_BVAL_P(retval));
806
                break;
807
            
808
            case IS_LONG:
809
                obj= longValue(*SaxonProcessor::sxn_environ, Z_LVAL_P(retval));
810
                break;
811
            case IS_STRING:
812
                sVal = Z_STRVAL_P(retval);
813
                len = Z_STRLEN_P(retval);
814
                obj = getJavaStringValue(*SaxonProcessor::sxn_environ,estrndup(sVal, len)); 
815
                break;
816
            break;
817 ead48a5d O'Neil Delpratt
            case IS_nullptr:
818 72bf04c6 Norman Walsh
                
819
                    break;
820
            case IS_DOUBLE:
821
                obj = doubleValue(*SaxonProcessor::sxn_environ, (double)Z_DVAL_P(retval));                
822
                 break;
823
            
824
            case IS_ARRAY:
825
            //break;
826
            case IS_OBJECT:
827
                    objName =Z_OBJCE_P(retval)->name;
828
      
829
830
                      if(strcmp(objName, "Saxon\\XdmNode")==0) {
831
                        ooth = (xdmNode_object*)zend_object_store_get_object(retval TSRMLS_CC);
832 ead48a5d O'Neil Delpratt
                        if(ooth != nullptr) {
833
                                    obj = ooth->xdmNode->getUnderlyingValue(nullptr);
834 72bf04c6 Norman Walsh
                    
835
                        }
836
                      }
837
                break;
838
            default:
839 ead48a5d O'Neil Delpratt
                obj = nullptr;
840 72bf04c6 Norman Walsh
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
841
        }
842
843
        //zend_printf("We have %i as type<br>", retval->type);
844
        //*return_value = *retval;
845
        //zval_copy_ctor(return_value);
846
        //zval_ptr_dtor(&retval);
847
        /*int cstrlen = Z_STRLEN_P(retval);
848
        char * str = estrndup(Z_STRVAL_P(retval), cstrlen);
849
        
850
        jstring jstrBuf = SaxonProcessor::sxn_environ->env->NewStringUTF(str);*/
851
        zval_ptr_dtor(&retval);
852
        return obj;
853
}
854
855
856
857
PHP_METHOD(XsltProcessor, transformToString)
858
{
859
    XsltProcessor *xsltProcessor;
860
 
861
    if (ZEND_NUM_ARGS()>0) {
862
        WRONG_PARAM_COUNT;
863
    }
864
////
865
/*zval *function_name;
866
zval *retval;
867

868
char * str = "userFunction";
869

870

871
MAKE_STD_ZVAL(function_name);
872
ZVAL_STRING(function_name, str, 1);
873 ead48a5d O'Neil Delpratt
if(call_user_function_ex(CG(function_table), nullptr, function_name, &retval, 0, nullptr, 0, nullptr TSRMLS_CC) != SUCCESS)
874 72bf04c6 Norman Walsh
{
875
    zend_error(E_ERROR, "Function call failed");
876
}
877

878
if(Z_TYPE(*retval) ==0){
879 ead48a5d O'Neil Delpratt
zend_error(E_ERROR, "DATAYYY is nullptr");
880 72bf04c6 Norman Walsh
}else {
881
str = Z_STRVAL_P(retval);
882
zend_printf("DATAYYY= %i <br>", str);
883
} 
884

885
zend_printf("We have %i as type<br>", retval->type);
886
*return_value = *retval;
887
zval_copy_ctor(return_value);
888
zval_ptr_dtor(&retval);*/
889
890
891
////
892
893
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
894
    xsltProcessor = obj->xsltProcessor;
895
896 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
897 72bf04c6 Norman Walsh
898
        const char * result = xsltProcessor->transformToString();
899 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
900 72bf04c6 Norman Walsh
            char *str = estrdup(result);
901
            RETURN_STRING(str, 0);
902
        } else if(xsltProcessor->exceptionOccurred()){
903
            xsltProcessor->checkException();
904
            const char * errStr = xsltProcessor->getErrorMessage(0);
905 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
906 72bf04c6 Norman Walsh
                const char * errorCode = xsltProcessor->getErrorCode(0);
907 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
908 72bf04c6 Norman Walsh
                    // TODO: throw exception
909
                }
910
            }
911
        }
912
    }
913 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
914 72bf04c6 Norman Walsh
}
915
916
PHP_METHOD(XsltProcessor, transformToValue)
917
{
918
    XsltProcessor *xsltProcessor;
919
920
    if (ZEND_NUM_ARGS()>0) {
921
        WRONG_PARAM_COUNT;
922
    }
923
924
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
925
    xsltProcessor = obj->xsltProcessor;
926
927 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
928 72bf04c6 Norman Walsh
929
        XdmValue * node = xsltProcessor->transformToValue();
930 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
931 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
932 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
933 72bf04c6 Norman Walsh
            } else {
934
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
935 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
936 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
937
            }
938
        } else if(xsltProcessor->exceptionOccurred()){
939
            xsltProcessor->checkException();
940
        }
941
    } else {
942 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
943 72bf04c6 Norman Walsh
    }
944
}
945
946
PHP_METHOD(XsltProcessor, transformToFile)
947
{
948
    XsltProcessor *xsltProcessor;
949
 
950
    if (ZEND_NUM_ARGS()>0) {
951
        WRONG_PARAM_COUNT;
952
    }
953
954
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
955
    xsltProcessor = obj->xsltProcessor;
956
957 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
958 72bf04c6 Norman Walsh
959
        xsltProcessor->transformToFile();
960
        if(xsltProcessor->exceptionOccurred()) {
961
           //TODO
962
            const char * exStr = xsltProcessor->checkException();
963
        }
964
    } else {
965 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
966 72bf04c6 Norman Walsh
    }
967
}
968
969
PHP_METHOD(XsltProcessor, compileFromFile)
970
{
971
    XsltProcessor *xsltProcessor;
972
    char * name;
973
    int len1;
974
975
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
976 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
977 72bf04c6 Norman Walsh
    }
978
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
979
    xsltProcessor = obj->xsltProcessor;
980 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
981 72bf04c6 Norman Walsh
        xsltProcessor->compileFromFile(name);
982
    }
983
}
984
985
PHP_METHOD(XsltProcessor, compileFromString)
986
{
987
    XsltProcessor *xsltProcessor;
988
    char * stylesheetStr;
989
    int len1, myint;
990
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &stylesheetStr, &len1) == FAILURE) {
991 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
992 72bf04c6 Norman Walsh
    }
993
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
994
    xsltProcessor = obj->xsltProcessor;
995 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
996 72bf04c6 Norman Walsh
        xsltProcessor->compileFromString(stylesheetStr);
997
    }
998
}
999
1000
PHP_METHOD(XsltProcessor, compileFromValue)
1001
{
1002
    XsltProcessor *xsltProcessor;
1003
   zval* oth;
1004
1005
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &oth, xdmValue_ce) == FAILURE) {
1006 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1007 72bf04c6 Norman Walsh
    }
1008
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1009
    xsltProcessor = obj->xsltProcessor;
1010 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1011 72bf04c6 Norman Walsh
         xdmValue_object* ooth = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
1012 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1013 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1014 ead48a5d O'Neil Delpratt
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
1015 72bf04c6 Norman Walsh
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1016
            }
1017
        }
1018
    }
1019
}
1020
1021
1022
1023
1024
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1025
{
1026
    XsltProcessor *xsltProcessor;
1027 ead48a5d O'Neil Delpratt
    zval* oth = nullptr;
1028 72bf04c6 Norman Walsh
1029
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
1030 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1031 72bf04c6 Norman Walsh
    }
1032
1033
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1034
    xsltProcessor = obj->xsltProcessor;
1035 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1036 72bf04c6 Norman Walsh
1037
    if(!oth) {
1038
        php_error(E_WARNING, "Error setting source value");
1039
        return;
1040
    } else {
1041
1042
      const char * objName =Z_OBJCE_P(oth)->name;
1043
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1044
1045
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1046
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1047 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1048 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
1049 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1050 72bf04c6 Norman Walsh
                XdmItem  *valueX = (XdmItem*)value;
1051
                xsltProcessor->setSourceFromXdmValue(valueX);
1052
1053
            }
1054
        }
1055
      } else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1056
        xdmValue_object* ooth = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
1057 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1058 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1059 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1060 72bf04c6 Norman Walsh
                xsltProcessor->setSourceFromXdmValue((XdmItem*)value);
1061
            }
1062
        }
1063
      }  
1064
1065
        
1066
    }
1067
  }
1068
}
1069
1070
PHP_METHOD(XsltProcessor, setOutputFile)
1071
{
1072
    XsltProcessor *xsltProcessor;
1073
    char * outputFilename;
1074
    int len1;
1075
1076
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &outputFilename, &len1, xdmValue_ce) == FAILURE) {
1077 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1078 72bf04c6 Norman Walsh
    }
1079
1080
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1081
    xsltProcessor = obj->xsltProcessor;
1082 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr && outputFilename != nullptr) {
1083 72bf04c6 Norman Walsh
        
1084
         xsltProcessor->setOutputFile(outputFilename);
1085
            
1086
        
1087
    }
1088
}
1089
1090
PHP_METHOD(XsltProcessor, setSourceFromFile)
1091
{
1092
    XsltProcessor *xsltProcessor;
1093
    char * inFilename;
1094
    int len1;
1095
1096
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &inFilename, &len1, xdmValue_ce) == FAILURE) {
1097 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1098 72bf04c6 Norman Walsh
    }
1099
1100
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1101
    xsltProcessor = obj->xsltProcessor;
1102 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr && inFilename != nullptr) {
1103 72bf04c6 Norman Walsh
        
1104
         xsltProcessor->setSourceFromFile(inFilename);
1105
            
1106
        
1107
    }
1108
}
1109
1110
1111
PHP_METHOD(XsltProcessor, setProperty)
1112
{
1113
    XsltProcessor *xsltProcessor;
1114
    char * name;
1115
    char * value;
1116
    int len1, len2, myint;
1117
1118
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1119 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1120 72bf04c6 Norman Walsh
    }
1121
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1122
    xsltProcessor = obj->xsltProcessor;
1123 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1124 72bf04c6 Norman Walsh
        xsltProcessor->setProperty(name, value);
1125
    }
1126
}
1127
1128
PHP_METHOD(XsltProcessor, setParameter)
1129
{
1130
1131
   XsltProcessor *xsltProcessor;
1132
   char * name;
1133
   zval* oth;
1134
   int len1, len2, myint;        
1135
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1136 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1137 72bf04c6 Norman Walsh
    }
1138
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1139
    xsltProcessor = obj->xsltProcessor;
1140 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1141 72bf04c6 Norman Walsh
1142
1143
      const char * objName =Z_OBJCE_P(oth)->name;
1144
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1145
1146
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1147
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1148 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1149 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
1150 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1151 72bf04c6 Norman Walsh
                xsltProcessor->setParameter(name, (XdmValue *)value);
1152
1153
            }
1154
        }
1155
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1156
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1157 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1158 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1159 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1160 72bf04c6 Norman Walsh
                
1161
                xsltProcessor->setParameter(name, value);
1162
            }
1163
        }
1164
1165
1166
1167
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1168
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1169 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1170 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1171 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1172 72bf04c6 Norman Walsh
                
1173
                xsltProcessor->setParameter(name, (XdmValue *)value);
1174
            }
1175
        }
1176
1177
1178
1179
      }
1180
1181
    }
1182
}
1183
1184
PHP_METHOD(XsltProcessor, clearParameters)
1185
{
1186
    XsltProcessor *xsltProcessor;
1187
    if (ZEND_NUM_ARGS()>0) {
1188
        WRONG_PARAM_COUNT;
1189
    }
1190
1191
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1192
    xsltProcessor = obj->xsltProcessor;
1193 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1194 72bf04c6 Norman Walsh
        xsltProcessor->clearParameters(true);
1195
    }
1196
}
1197
1198
PHP_METHOD(XsltProcessor, clearProperties)
1199
{
1200
    XsltProcessor *xsltProcessor;
1201
    if (ZEND_NUM_ARGS()>0) {
1202
        WRONG_PARAM_COUNT;
1203
    }
1204
1205
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1206
    xsltProcessor = obj->xsltProcessor;
1207 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1208 72bf04c6 Norman Walsh
        xsltProcessor->clearProperties();
1209
    }
1210
}
1211
1212
PHP_METHOD(XsltProcessor, exceptionOccurred)
1213
{
1214
    XsltProcessor *xsltProcessor;
1215
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1216
    if (ZEND_NUM_ARGS()>0) {
1217
        WRONG_PARAM_COUNT;
1218
    }
1219
1220
    xsltProcessor = obj->xsltProcessor;
1221 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1222 72bf04c6 Norman Walsh
        bool result = xsltProcessor->exceptionOccurred();
1223
        RETURN_BOOL(result);
1224
    }
1225
    RETURN_BOOL(false);
1226
}
1227
1228
PHP_METHOD(XsltProcessor, getExceptionCount)
1229
{
1230
    XsltProcessor *xsltProcessor;
1231
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1232
    if (ZEND_NUM_ARGS()>0) {
1233
        WRONG_PARAM_COUNT;
1234
    }
1235
1236
    xsltProcessor = obj->xsltProcessor;
1237 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1238 72bf04c6 Norman Walsh
        int count = xsltProcessor->exceptionCount();
1239
        RETURN_LONG(count);
1240
    }
1241
    RETURN_LONG(0);
1242
}
1243
1244
PHP_METHOD(XsltProcessor, getErrorCode)
1245
{
1246
    XsltProcessor *xsltProcessor;
1247
    long index;
1248
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1249 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1250 72bf04c6 Norman Walsh
    }
1251
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1252
    xsltProcessor = obj->xsltProcessor;
1253 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1254 72bf04c6 Norman Walsh
        const char * errCode = xsltProcessor->getErrorCode((int)index);
1255 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
1256 72bf04c6 Norman Walsh
            char *str = estrdup(errCode);
1257
            RETURN_STRING(str, 0);
1258
        }
1259
    }
1260 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
1261 72bf04c6 Norman Walsh
}
1262
1263
PHP_METHOD(XsltProcessor, getErrorMessage)
1264
{
1265
    XsltProcessor *xsltProcessor;
1266
    long index;
1267
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1268 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1269 72bf04c6 Norman Walsh
    }
1270
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1271
    xsltProcessor = obj->xsltProcessor;
1272 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1273 72bf04c6 Norman Walsh
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1274 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
1275 72bf04c6 Norman Walsh
            char *str = estrdup(errStr);
1276
            RETURN_STRING(str, 0);
1277
        }
1278
    }
1279 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
1280 72bf04c6 Norman Walsh
}
1281
PHP_METHOD(XsltProcessor, exceptionClear)
1282
{
1283
    XsltProcessor *xsltProcessor;
1284
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1285
    xsltProcessor = obj->xsltProcessor;
1286 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1287 72bf04c6 Norman Walsh
        xsltProcessor->exceptionClear();
1288
    }
1289
}
1290
1291
1292
1293
1294
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
1295
1296
void xqueryProcessor_free_storage(void *object TSRMLS_DC)
1297
{
1298
    xqueryProcessor_object *obj = (xqueryProcessor_object *)object;
1299
    //obj->xqueryProcessor->clearParameters(true);
1300
    //obj->xqueryProcessor->clearProperties();
1301
    zend_hash_destroy(obj->std.properties);
1302
    FREE_HASHTABLE(obj->std.properties);
1303
    efree(obj);
1304
}
1305
1306
zend_object_value xqueryProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
1307
{
1308
    zval *tmp;
1309
    zend_object_value retval;
1310
    xqueryProcessor_object *obj = (xqueryProcessor_object *)emalloc(sizeof(xqueryProcessor_object));
1311
    memset(obj, 0, sizeof(xqueryProcessor_object));
1312
    obj->std.ce = type;
1313
1314
    ALLOC_HASHTABLE(obj->std.properties);
1315 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
1316 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
1317 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, xqueryProcessor_free_storage, nullptr TSRMLS_CC);
1318 72bf04c6 Norman Walsh
    retval.handlers = &xqueryProcessor_object_handlers;
1319
1320
    return retval;
1321
}
1322
1323
PHP_METHOD(XQueryProcessor, __destruct)
1324
{
1325
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1326
1327
1328
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
1329
1330
    delete xqueryProcessor;
1331
    
1332
}
1333
1334
1335
PHP_METHOD(XQueryProcessor, runQueryToValue)
1336
{
1337
    XQueryProcessor *xqueryProcessor;
1338
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1339
1340
    if (ZEND_NUM_ARGS()>0) {
1341
        WRONG_PARAM_COUNT;
1342
    }
1343
1344
    xqueryProcessor = obj->xqueryProcessor;
1345
1346 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1347 72bf04c6 Norman Walsh
        XdmValue * node = xqueryProcessor->runQueryToValue();
1348 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
1349 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1350 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
1351 72bf04c6 Norman Walsh
                return;
1352
            } else {
1353
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
1354 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1355 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
1356
                return;
1357
            }
1358
        }
1359
        xqueryProcessor->checkException();//TODO
1360
    } else {
1361 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1362 72bf04c6 Norman Walsh
    }
1363
}
1364
1365
PHP_METHOD(XQueryProcessor, runQueryToString)
1366
{
1367
    XQueryProcessor *xqueryProcessor;
1368
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1369
1370
    if (ZEND_NUM_ARGS()>0) {
1371
        WRONG_PARAM_COUNT;
1372
    }
1373
1374
    xqueryProcessor = obj->xqueryProcessor;
1375
1376 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1377 72bf04c6 Norman Walsh
        const char * result = xqueryProcessor->runQueryToString();
1378 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1379 72bf04c6 Norman Walsh
            char *str = estrdup(result);
1380
            RETURN_STRING(str, 0);
1381
            return;
1382
        } else {
1383
          xqueryProcessor->checkException(); //TODO
1384
        }
1385
    }
1386 ead48a5d O'Neil Delpratt
   RETURN_nullptr();
1387 72bf04c6 Norman Walsh
}
1388
1389
PHP_METHOD(XQueryProcessor, runQueryToFile)
1390
{
1391
1392
     char * ofilename;
1393
     int len1 =0;
1394
    if (ZEND_NUM_ARGS()!= 1) {
1395
        WRONG_PARAM_COUNT;
1396
    }
1397
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ofilename, &len1) == FAILURE) {
1398 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1399 72bf04c6 Norman Walsh
    }
1400
    XQueryProcessor *xqueryProcessor;
1401
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1402
1403
1404
1405
    xqueryProcessor = obj->xqueryProcessor;
1406
1407 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1408
        if(ofilename != nullptr) {
1409 72bf04c6 Norman Walsh
                xqueryProcessor->setOutputFile(ofilename);        
1410
        }
1411
        xqueryProcessor->runQueryToFile(); 
1412
    }
1413
1414
}
1415
1416
PHP_METHOD(XQueryProcessor, setQueryContent)
1417
{
1418
    char * queryStr;
1419
    int len1;
1420
1421
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &queryStr, &len1) == FAILURE) {
1422 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1423 72bf04c6 Norman Walsh
    }
1424
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC); 
1425 ead48a5d O'Neil Delpratt
    if(queryStr != nullptr) {
1426 72bf04c6 Norman Walsh
      obj->xqueryProcessor->setProperty("qs", queryStr);
1427
   }
1428
}
1429
1430
PHP_METHOD(XQueryProcessor, setQueryFile)
1431
{
1432
   char * fileName;
1433
   int len1;
1434
    XQueryProcessor *xqueryProcessor;
1435
1436
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fileName, &len1) == FAILURE) {
1437 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1438 72bf04c6 Norman Walsh
    }
1439 ead48a5d O'Neil Delpratt
    if(fileName != nullptr) {
1440 72bf04c6 Norman Walsh
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1441
            xqueryProcessor = obj->xqueryProcessor;
1442
            xqueryProcessor->setQueryFile(fileName);
1443
    }
1444
            
1445
}
1446
1447
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
1448
{
1449
   char * base;
1450
   int len1;
1451
    XQueryProcessor *xqueryProcessor;
1452
1453
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &base, &len1) == FAILURE) {
1454 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1455 72bf04c6 Norman Walsh
    }
1456 ead48a5d O'Neil Delpratt
    if(base != nullptr) {
1457 72bf04c6 Norman Walsh
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1458
            xqueryProcessor = obj->xqueryProcessor;
1459
            xqueryProcessor->setQueryBaseURI(base);
1460
    }
1461
            
1462
}
1463
1464
PHP_METHOD(XQueryProcessor, declareNamespace)
1465
{
1466
   char * prefix;
1467
   char * ns;
1468
   int len1, len2;
1469
    XQueryProcessor *xqueryProcessor;
1470
1471
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
1472 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1473 72bf04c6 Norman Walsh
    }
1474 ead48a5d O'Neil Delpratt
    if(prefix != nullptr && ns != nullptr) {
1475 72bf04c6 Norman Walsh
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1476
            xqueryProcessor = obj->xqueryProcessor;
1477
            xqueryProcessor->declareNamespace(prefix, ns);
1478
    }
1479
            
1480
}
1481
1482
1483
1484
PHP_METHOD(XQueryProcessor, setContextItem)
1485
{
1486
   char * context;
1487
   int len1;
1488
   zval* oth;
1489
    XQueryProcessor *xqueryProcessor;
1490
1491
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
1492 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1493 72bf04c6 Norman Walsh
    }
1494 ead48a5d O'Neil Delpratt
    if(oth != nullptr) {
1495 72bf04c6 Norman Walsh
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1496
            xqueryProcessor = obj->xqueryProcessor;
1497
    const char * objName =Z_OBJCE_P(oth)->name;
1498
      //std::cerr<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1499
1500
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1501
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1502 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1503 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
1504 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1505 72bf04c6 Norman Walsh
                xqueryProcessor->setContextItem((XdmItem *)value);
1506
                return;
1507
            }
1508
        }
1509
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
1510
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
1511 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1512 72bf04c6 Norman Walsh
            XdmItem * value = ooth->xdmItem;
1513 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1514 72bf04c6 Norman Walsh
                xqueryProcessor->setContextItem(value);
1515
                return;
1516
            }
1517
         }
1518
        
1519
1520
1521
1522
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1523
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1524 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1525 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1526 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1527 72bf04c6 Norman Walsh
                
1528
                xqueryProcessor->setContextItem((XdmItem *)value);
1529
                return;
1530
            }
1531
        }
1532
1533
1534
1535
      } 
1536
1537
1538
1539
1540
        /*xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
1541 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1542 72bf04c6 Norman Walsh
            XdmItem * value = ooth->xdmItem;
1543 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1544 72bf04c6 Norman Walsh
                    xqueryProcessor->setContextItem(value);
1545
            }
1546
        }*/
1547
    }
1548
        //throw exception
1549
        php_error(E_WARNING,"contextItem not set");
1550
        
1551
            
1552
}
1553
1554
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
1555
{
1556
   char * cfilename;
1557
   int len1;
1558
    XQueryProcessor *xqueryProcessor;
1559
1560
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cfilename, &len1) == FAILURE) {
1561 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1562 72bf04c6 Norman Walsh
    }
1563 ead48a5d O'Neil Delpratt
    if(cfilename != nullptr) {
1564 72bf04c6 Norman Walsh
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1565
            xqueryProcessor = obj->xqueryProcessor;
1566
            xqueryProcessor->setContextItemFromFile(cfilename);
1567
    }
1568
            
1569
}
1570
1571
1572
PHP_METHOD(XQueryProcessor, setProperty)
1573
{
1574
    XQueryProcessor *xqueryProcessor;
1575
    char * name;
1576
    char * value;
1577
    int len1, len2, myint;
1578
1579
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1580 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1581 72bf04c6 Norman Walsh
    }
1582
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1583
    xqueryProcessor = obj->xqueryProcessor;
1584 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1585 72bf04c6 Norman Walsh
        xqueryProcessor->setProperty(name, value);
1586
    }
1587
}
1588
1589
PHP_METHOD(XQueryProcessor, setParameter)
1590
{
1591
1592
   XQueryProcessor *xqueryProcessor;
1593
   char * name;
1594
   zval* oth;
1595
   int len1, len2, myint;        
1596
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1597 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1598 72bf04c6 Norman Walsh
    }
1599
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1600
    xqueryProcessor = obj->xqueryProcessor;
1601 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1602 72bf04c6 Norman Walsh
             const char * objName =Z_OBJCE_P(oth)->name;
1603
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1604
1605
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1606
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1607 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1608 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
1609 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1610 72bf04c6 Norman Walsh
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1611
1612
            }
1613
        }
1614
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1615
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1616 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1617 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1618 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1619 72bf04c6 Norman Walsh
                
1620
                xqueryProcessor->setParameter(name, value);
1621
            }
1622
        }
1623
1624
1625
1626
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1627
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1628 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1629 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1630 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1631 72bf04c6 Norman Walsh
                
1632
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1633
            } 
1634
        }
1635
1636
1637
1638
      }
1639
1640
    }
1641
}
1642
1643
1644
1645
1646
PHP_METHOD(XQueryProcessor, clearParameters)
1647
{
1648
    XQueryProcessor *xqueryProcessor;
1649
    if (ZEND_NUM_ARGS()>0) {
1650
        WRONG_PARAM_COUNT;
1651
    }
1652
1653
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1654
    xqueryProcessor = obj->xqueryProcessor;
1655 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1656 72bf04c6 Norman Walsh
        xqueryProcessor->clearParameters(true);
1657
    }
1658
}
1659
1660
PHP_METHOD(XQueryProcessor, clearProperties)
1661
{
1662
    XQueryProcessor *xqueryProcessor;
1663
1664
    if (ZEND_NUM_ARGS()>0) {
1665
        WRONG_PARAM_COUNT;
1666
    }
1667
1668
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1669
    xqueryProcessor = obj->xqueryProcessor;
1670 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1671 72bf04c6 Norman Walsh
        xqueryProcessor->clearProperties();
1672
    }
1673
}
1674
1675
PHP_METHOD(XQueryProcessor, exceptionOccurred)
1676
{
1677
    XQueryProcessor *xqueryProcessor;
1678
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1679
    if (ZEND_NUM_ARGS()>0) {
1680
        WRONG_PARAM_COUNT;
1681
    }
1682
1683
    xqueryProcessor = obj->xqueryProcessor;
1684 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1685 72bf04c6 Norman Walsh
        bool result = xqueryProcessor->exceptionOccurred();
1686
        RETURN_BOOL(result);
1687
    }
1688
    RETURN_BOOL(false);
1689
}
1690
1691
PHP_METHOD(XQueryProcessor, getExceptionCount)
1692
{
1693
    XQueryProcessor *xqueryProcessor;
1694
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1695
    if (ZEND_NUM_ARGS()>0) {
1696
        WRONG_PARAM_COUNT;
1697
    }
1698
1699
    xqueryProcessor = obj->xqueryProcessor;
1700 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1701 72bf04c6 Norman Walsh
        int count = xqueryProcessor->exceptionCount();
1702
        RETURN_LONG(count);
1703
    }
1704
    RETURN_LONG(0);
1705
}
1706
1707
PHP_METHOD(XQueryProcessor, getErrorCode)
1708
{
1709
    XQueryProcessor *xqueryProcessor;
1710
    long index;
1711
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1712 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1713 72bf04c6 Norman Walsh
    }
1714
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1715
    xqueryProcessor = obj->xqueryProcessor;
1716 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1717 72bf04c6 Norman Walsh
        const char * errCode = xqueryProcessor->getErrorCode((int)index);
1718 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
1719 72bf04c6 Norman Walsh
            char *str = estrdup(errCode);
1720
            RETURN_STRING(str, 0);
1721
        }
1722
    }
1723 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
1724 72bf04c6 Norman Walsh
}
1725
1726
PHP_METHOD(XQueryProcessor, getErrorMessage)
1727
{
1728
    XQueryProcessor *xqueryProcessor;
1729
    long index;
1730
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1731 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1732 72bf04c6 Norman Walsh
    }
1733
    xqueryProcessor_object *obj = (xqueryProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1734
    xqueryProcessor = obj->xqueryProcessor;
1735 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1736 72bf04c6 Norman Walsh
        const char * errStr = xqueryProcessor->getErrorMessage((int)index);
1737 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
1738 72bf04c6 Norman Walsh
            char *str = estrdup(errStr);
1739
            RETURN_STRING(str, 0);
1740
        }
1741
    }
1742 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
1743 72bf04c6 Norman Walsh
}
1744
PHP_METHOD(XQueryProcessor, exceptionClear)
1745
{
1746
    XQueryProcessor *xqueryProcessor;
1747
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1748
    xqueryProcessor = obj->xqueryProcessor;
1749 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1750 72bf04c6 Norman Walsh
        xqueryProcessor->exceptionClear();
1751
    }
1752
}
1753
1754
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
1755
1756
void xpathProcessor_free_storage(void *object TSRMLS_DC)
1757
{
1758
    xpathProcessor_object *obj = (xpathProcessor_object *)object;
1759
1760
    zend_hash_destroy(obj->std.properties);
1761
    FREE_HASHTABLE(obj->std.properties);
1762
    efree(obj);
1763
}
1764
1765
PHP_METHOD(XPathProcessor, __destruct)
1766
{
1767
   xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1768
   XPathProcessor * xpathProc= obj->xpathProcessor;
1769
1770
1771
    delete xpathProc;
1772
    
1773
}
1774
1775
zend_object_value xpathProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
1776
{
1777
    zval *tmp;
1778
    zend_object_value retval;
1779
    xpathProcessor_object *obj = (xpathProcessor_object *)emalloc(sizeof(xpathProcessor_object));
1780
    memset(obj, 0, sizeof(xpathProcessor_object));
1781
    obj->std.ce = type;
1782
1783
    ALLOC_HASHTABLE(obj->std.properties);
1784 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
1785 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
1786
1787 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, xpathProcessor_free_storage, nullptr TSRMLS_CC);
1788 72bf04c6 Norman Walsh
    retval.handlers = &xpathProcessor_object_handlers;
1789
1790
    return retval;
1791
}
1792
1793
1794
1795
PHP_METHOD(XPathProcessor, setProperty)
1796
{
1797
    XPathProcessor *xpathProcessor;
1798
    char * name;
1799
    char * value;
1800
    int len1, len2;
1801
1802
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1803 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1804 72bf04c6 Norman Walsh
    }
1805
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1806
    xpathProcessor = obj->xpathProcessor;
1807 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
1808 72bf04c6 Norman Walsh
        xpathProcessor->setProperty(name, value);
1809
    }
1810
}
1811
1812
PHP_METHOD(XPathProcessor, setParameter)
1813
{
1814
1815
   XPathProcessor *xpathProcessor;
1816
   char * name;
1817
   zval* oth;
1818
   int len1, len2;        
1819
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1820 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1821 72bf04c6 Norman Walsh
    }
1822
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1823
    xpathProcessor = obj->xpathProcessor;
1824 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
1825 72bf04c6 Norman Walsh
            const char * objName =Z_OBJCE_P(oth)->name;
1826
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1827
1828
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1829
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1830 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1831 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
1832 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1833 72bf04c6 Norman Walsh
                xpathProcessor->setParameter(name, (XdmValue *)value);
1834
1835
            }
1836
        }
1837
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1838
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1839 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1840 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1841 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1842 72bf04c6 Norman Walsh
                
1843
                xpathProcessor->setParameter(name, value);
1844
            }
1845
        }
1846
1847
1848
1849
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1850
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1851 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1852 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1853 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1854 72bf04c6 Norman Walsh
                
1855
                xpathProcessor->setParameter(name, (XdmValue *)value);
1856
            }
1857
        }
1858
1859
1860
1861
      }
1862
1863
    }
1864
}
1865
1866
PHP_METHOD(XPathProcessor, declareNamespace)
1867
{
1868
   char * prefix;
1869
   char * ns;
1870
   int len1, len2;
1871
   XPathProcessor *xpathProcessor;
1872
1873
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
1874 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1875 72bf04c6 Norman Walsh
    }
1876 ead48a5d O'Neil Delpratt
    if(prefix != nullptr && ns != nullptr) {
1877 72bf04c6 Norman Walsh
            xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1878
            xpathProcessor = obj->xpathProcessor;
1879
            xpathProcessor->declareNamespace(prefix, ns);
1880
    }
1881
            
1882
}
1883
1884
1885
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
1886
1887
    XPathProcessor *xpathProcessor;
1888
    bool allow = false;
1889
    size_t len1;
1890
1891
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &allow) == FAILURE) {
1892 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1893 72bf04c6 Norman Walsh
    }
1894
1895
     xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1896
     xpathProcessor = obj->xpathProcessor;
1897 ead48a5d O'Neil Delpratt
     if (xpathProcessor != nullptr ) {
1898 72bf04c6 Norman Walsh
            xpathProcessor->setBackwardsCompatible(allow);
1899
         }
1900
}
1901
1902
PHP_METHOD(XPathProcessor, setCaching){
1903
    XPathProcessor *xpathProcessor;
1904
    bool isCaching = false;
1905
    size_t len1;
1906
1907
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &isCaching) == FAILURE) {
1908 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1909 72bf04c6 Norman Walsh
    }
1910
1911
     xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1912
     xpathProcessor = obj->xpathProcessor;
1913 ead48a5d O'Neil Delpratt
     if (xpathProcessor != nullptr) {
1914 72bf04c6 Norman Walsh
            xpathProcessor->setCaching(isCaching);
1915
         }
1916
}
1917
1918
PHP_METHOD(XPathProcessor, importSchemaNamespace){
1919
      char * name;
1920
      int len1;
1921
      XPathProcessor *xpathProcessor;
1922
1923
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
1924 ead48a5d O'Neil Delpratt
           RETURN_nullptr();
1925 72bf04c6 Norman Walsh
       }
1926
       xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1927
       xpathProcessor = obj->xpathProcessor;
1928 ead48a5d O'Neil Delpratt
       if (xpathProcessor != nullptr && name != nullptr) {
1929 72bf04c6 Norman Walsh
            xpathProcessor->importSchemaNamespace(name);
1930
       }
1931
1932
}
1933
1934
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
1935
{
1936
1937
   XPathProcessor *xpathProcessor;
1938
   char * xpathStr;
1939
   zval* oth;
1940
   int len1, myint;        
1941
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
1942 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1943 72bf04c6 Norman Walsh
    }
1944
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1945
    xpathProcessor = obj->xpathProcessor;
1946 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
1947 72bf04c6 Norman Walsh
        
1948
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
1949
                RETURN_BOOL(result);
1950
    }
1951
}
1952
1953
PHP_METHOD(XPathProcessor, evaluate)
1954
{
1955
1956
   XPathProcessor *xpathProcessor;
1957
   char * xpathStr;
1958
   zval* oth;
1959
   int len1, myint;        
1960
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
1961 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1962 72bf04c6 Norman Walsh
    }
1963
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1964
    xpathProcessor = obj->xpathProcessor;
1965 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
1966 72bf04c6 Norman Walsh
        
1967
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
1968 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
1969 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1970 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
1971 72bf04c6 Norman Walsh
                return;
1972
            } else {
1973
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
1974 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1975 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
1976
                return;
1977
            }
1978
        }
1979
        xpathProcessor->checkException();//TODO
1980
    } 
1981 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
1982 72bf04c6 Norman Walsh
    
1983
}
1984
1985
PHP_METHOD(XPathProcessor, evaluateSingle)
1986
{
1987
1988
   XPathProcessor *xpathProcessor;
1989
   char * xpathStr;
1990
   zval* oth;
1991
   int len1, myint;        
1992
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
1993 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1994 72bf04c6 Norman Walsh
    }
1995
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1996
    xpathProcessor = obj->xpathProcessor;
1997
1998 ead48a5d O'Neil Delpratt
    if(xpathStr == nullptr) {
1999
        RETURN_nullptr();
2000 72bf04c6 Norman Walsh
        return;
2001
        }
2002
2003
2004 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2005 72bf04c6 Norman Walsh
        
2006
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
2007 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2008 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2009 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2010 72bf04c6 Norman Walsh
                return;
2011
            } else {
2012
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2013 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2014 72bf04c6 Norman Walsh
                vobj->xdmItem = node;
2015
                return;
2016
            }
2017
        } 
2018
        xpathProcessor->checkException();//TODO
2019
    } 
2020 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2021 72bf04c6 Norman Walsh
}
2022
2023
PHP_METHOD(XPathProcessor, setContextItem)
2024
{
2025
2026
   XPathProcessor *xpathProcessor;
2027
2028
   zval* oth;
2029
        //TODO this should be relaxed to accept item/atomic/node as well as Value
2030
2031
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2032 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2033 72bf04c6 Norman Walsh
    }
2034
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2035
    xpathProcessor = obj->xpathProcessor;
2036 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2037 72bf04c6 Norman Walsh
        if(!oth) {
2038
                php_error(E_WARNING, "Error setting source value");
2039
                return;
2040
         } 
2041
        const char * objName =Z_OBJCE_P(oth)->name;
2042
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
2043
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
2044
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2045 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2046 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2047 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2048 72bf04c6 Norman Walsh
                xpathProcessor->setContextItem((XdmItem *)value);
2049
                value->incrementRefCount();
2050
2051
            }
2052
        }
2053
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2054
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2055 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2056 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2057 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2058 72bf04c6 Norman Walsh
                
2059
                xpathProcessor->setContextItem((XdmItem *)value);
2060
                value->incrementRefCount();
2061
            }
2062
        }
2063
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
2064
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
2065 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2066 72bf04c6 Norman Walsh
            XdmItem * value = ooth->xdmItem;
2067 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2068 72bf04c6 Norman Walsh
                
2069
                xpathProcessor->setContextItem(value);
2070
                value->incrementRefCount();
2071
            }
2072
        }
2073
2074
      }
2075
    }
2076
}
2077
2078
PHP_METHOD(XPathProcessor, setBaseURI)
2079
{
2080
2081
   XPathProcessor *xpathProcessor;
2082
2083
   char * uriStr;
2084
   int len1;
2085
        
2086
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &uriStr, &len1, xdmValue_ce) == FAILURE) {
2087 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2088 72bf04c6 Norman Walsh
    }
2089
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2090
    xpathProcessor = obj->xpathProcessor;
2091 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2092 72bf04c6 Norman Walsh
        
2093 ead48a5d O'Neil Delpratt
        if(uriStr != nullptr) {
2094 72bf04c6 Norman Walsh
           
2095
                xpathProcessor->setBaseURI(uriStr);
2096
            
2097
        }
2098
    }
2099
}
2100
2101
PHP_METHOD(XPathProcessor, setContextFile)
2102
{
2103
2104
   XPathProcessor *xpathProcessor;
2105
2106
   char * name;
2107
   int len1;
2108
        
2109
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1, xdmValue_ce) == FAILURE) {
2110 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2111 72bf04c6 Norman Walsh
    }
2112
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2113
    xpathProcessor = obj->xpathProcessor;
2114 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2115 72bf04c6 Norman Walsh
        
2116 ead48a5d O'Neil Delpratt
        if(name != nullptr) {
2117 72bf04c6 Norman Walsh
           
2118
                xpathProcessor->setContextFile(name);
2119
            
2120
        }
2121
    }
2122
}
2123
2124
PHP_METHOD(XPathProcessor, clearParameters)
2125
{
2126
    XPathProcessor *xpathProcessor;
2127
    if (ZEND_NUM_ARGS()>0) {
2128
        WRONG_PARAM_COUNT;
2129
    }
2130
2131
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2132
    xpathProcessor = obj->xpathProcessor;
2133 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2134 72bf04c6 Norman Walsh
        xpathProcessor->clearParameters(true);
2135
    }
2136
}
2137
2138
PHP_METHOD(XPathProcessor, clearProperties)
2139
{
2140
     XPathProcessor *xpathProcessor;
2141
    if (ZEND_NUM_ARGS()>0) {
2142
        WRONG_PARAM_COUNT;
2143
    }
2144
2145
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2146
    xpathProcessor = obj->xpathProcessor;
2147 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2148 72bf04c6 Norman Walsh
        xpathProcessor->clearProperties();
2149
    }
2150
}
2151
2152
2153
PHP_METHOD(XPathProcessor, exceptionOccurred)
2154
{
2155
   XPathProcessor *xpathProcessor;
2156
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2157
    if (ZEND_NUM_ARGS()>0) {
2158
        WRONG_PARAM_COUNT;
2159
    }
2160
2161
    xpathProcessor = obj->xpathProcessor;
2162 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2163 72bf04c6 Norman Walsh
        bool result = xpathProcessor->exceptionOccurred();
2164
        RETURN_BOOL(result);
2165
    }
2166
    RETURN_BOOL(false);
2167
}
2168
2169
PHP_METHOD(XPathProcessor, getExceptionCount)
2170
{
2171
    XPathProcessor *xpathProcessor;
2172
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2173
    if (ZEND_NUM_ARGS()>0) {
2174
        WRONG_PARAM_COUNT;
2175
    }
2176
2177
    xpathProcessor = obj->xpathProcessor;
2178 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2179 72bf04c6 Norman Walsh
        int count = xpathProcessor->exceptionCount();
2180
        RETURN_LONG(count);
2181
    }
2182
    RETURN_LONG(0);
2183
}
2184
2185
PHP_METHOD(XPathProcessor, getErrorCode)
2186
{
2187
    XPathProcessor *xpathProcessor;
2188
    long index;
2189
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2190 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2191 72bf04c6 Norman Walsh
    }
2192
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2193
    xpathProcessor = obj->xpathProcessor;
2194 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2195 72bf04c6 Norman Walsh
        const char * errCode = xpathProcessor->getErrorCode((int)index);
2196 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
2197 72bf04c6 Norman Walsh
            char *str = estrdup(errCode);
2198
            RETURN_STRING(str, 0);
2199
        }
2200
    }
2201 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2202 72bf04c6 Norman Walsh
}
2203
2204
PHP_METHOD(XPathProcessor, getErrorMessage)
2205
{
2206
    XPathProcessor *xpathProcessor;
2207
    long index;
2208
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2209 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2210 72bf04c6 Norman Walsh
    }
2211
    xpathProcessor_object *obj = (xpathProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2212
    xpathProcessor = obj->xpathProcessor;
2213 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2214 72bf04c6 Norman Walsh
        const char * errStr = xpathProcessor->getErrorMessage((int)index);
2215 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
2216 72bf04c6 Norman Walsh
            char *str = estrdup(errStr);
2217
            RETURN_STRING(str, 0);
2218
        }
2219
    }
2220 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2221 72bf04c6 Norman Walsh
}
2222
PHP_METHOD(XPathProcessor, exceptionClear)
2223
{
2224
    XPathProcessor *xpathProcessor;
2225
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2226
    xpathProcessor = obj->xpathProcessor;
2227 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2228 72bf04c6 Norman Walsh
        xpathProcessor->exceptionClear();
2229
    }
2230
}
2231
2232
/*     ============== PHP Interface of   SchemaValidator =============== */
2233
2234
void schemaValidator_free_storage(void *object TSRMLS_DC)
2235
{
2236
    schemaValidator_object *obj = (schemaValidator_object *)object;
2237
2238
    zend_hash_destroy(obj->std.properties);
2239
    FREE_HASHTABLE(obj->std.properties);
2240
    efree(obj);
2241
}
2242
2243
zend_object_value schemaValidator_create_handler(zend_class_entry *type TSRMLS_DC)
2244
{
2245
    zval *tmp;
2246
    zend_object_value retval;
2247
    schemaValidator_object *obj = (schemaValidator_object *)emalloc(sizeof(schemaValidator_object));
2248
    memset(obj, 0, sizeof(schemaValidator_object));
2249
    obj->std.ce = type;
2250
2251
    ALLOC_HASHTABLE(obj->std.properties);
2252 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
2253 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
2254
2255 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, schemaValidator_free_storage, nullptr TSRMLS_CC);
2256 72bf04c6 Norman Walsh
    retval.handlers = &schemaValidator_object_handlers;
2257
2258
    return retval;
2259
}
2260
2261
2262
2263
PHP_METHOD(SchemaValidator, __destruct)
2264
{
2265
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2266
2267
2268
    SchemaValidator * schemaValidator= obj->schemaValidator;
2269
2270
    delete schemaValidator;
2271
    
2272
}
2273
2274
2275
2276
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
2277
{
2278
    SchemaValidator *schemaValidator;
2279
    char * name;
2280
    int len1;
2281
2282
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2283 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2284 72bf04c6 Norman Walsh
    }
2285
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2286
    schemaValidator = obj->schemaValidator;
2287 ead48a5d O'Neil Delpratt
    if (name != nullptr && schemaValidator != nullptr) {
2288 72bf04c6 Norman Walsh
        schemaValidator->registerSchemaFromFile(name);
2289
    }
2290
}
2291
2292
PHP_METHOD(SchemaValidator, registerSchemaFromString)
2293
{
2294
    char * schemaStr;
2295
    int len1;
2296
    SchemaValidator *schemaValidator;
2297
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &schemaStr, &len1) == FAILURE) {
2298 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2299 72bf04c6 Norman Walsh
    }
2300
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2301
    schemaValidator = obj->schemaValidator;
2302 ead48a5d O'Neil Delpratt
    if (schemaStr!= nullptr && schemaValidator != nullptr) {
2303 72bf04c6 Norman Walsh
        schemaValidator->registerSchemaFromString(schemaStr);
2304
    }
2305
}
2306
2307
PHP_METHOD(SchemaValidator, validate)
2308
{
2309 ead48a5d O'Neil Delpratt
    char * name = nullptr;
2310 72bf04c6 Norman Walsh
    int len1;
2311
    SchemaValidator *schemaValidator;
2312
    if (ZEND_NUM_ARGS()>1) {
2313
        WRONG_PARAM_COUNT;
2314
    }
2315
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2316 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2317 72bf04c6 Norman Walsh
    }
2318
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2319
    schemaValidator = obj->schemaValidator;
2320 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2321 72bf04c6 Norman Walsh
        schemaValidator->validate(name);
2322
    }
2323
}
2324
2325
PHP_METHOD(SchemaValidator, validateToNode)
2326
{
2327 ead48a5d O'Neil Delpratt
    char * name = nullptr;
2328 72bf04c6 Norman Walsh
    int len1;
2329
    SchemaValidator *schemaValidator;
2330
    if (ZEND_NUM_ARGS()>1) {
2331
        WRONG_PARAM_COUNT;
2332
    }
2333
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2334 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2335 72bf04c6 Norman Walsh
    }
2336
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2337
    schemaValidator = obj->schemaValidator;
2338 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2339 72bf04c6 Norman Walsh
        XdmNode * node = schemaValidator->validateToNode(name);
2340 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2341 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2342 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2343 72bf04c6 Norman Walsh
                return;
2344
            } else {
2345
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2346 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2347 72bf04c6 Norman Walsh
                vobj->xdmNode = node;
2348
                return;
2349
            }
2350
        } 
2351
            schemaValidator->checkException();//TODO
2352
    } 
2353 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2354 72bf04c6 Norman Walsh
}
2355
2356
2357
PHP_METHOD(SchemaValidator, getValidationReport)
2358
{
2359
2360
    SchemaValidator *schemaValidator;
2361
    if (ZEND_NUM_ARGS()>0) {
2362
        WRONG_PARAM_COUNT;
2363
    }
2364
2365
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2366
    schemaValidator = obj->schemaValidator;
2367 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2368 72bf04c6 Norman Walsh
        XdmNode * node = schemaValidator->getValidationReport();
2369 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2370 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2371 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2372 72bf04c6 Norman Walsh
                return;
2373
            } else {
2374
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2375 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2376 72bf04c6 Norman Walsh
                vobj->xdmNode = node;
2377
                return;
2378
            }
2379
        } 
2380
            schemaValidator->checkException();//TODO
2381
    } 
2382 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2383 72bf04c6 Norman Walsh
}
2384
2385
2386
PHP_METHOD(SchemaValidator, setSourceNode)
2387
{
2388
    SchemaValidator *schemaValidator;
2389
2390
    zval* oth;
2391
   
2392
2393
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2394 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2395 72bf04c6 Norman Walsh
    }
2396
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2397
    schemaValidator = obj->schemaValidator;
2398 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2399 72bf04c6 Norman Walsh
        const char * objName =Z_OBJCE_P(oth)->name;
2400
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2401
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2402 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2403 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2404 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2405 72bf04c6 Norman Walsh
                schemaValidator->setSourceNode(value);
2406
2407
            }
2408
        }
2409
      
2410
        
2411
      }
2412
    }
2413
}
2414
2415
PHP_METHOD(SchemaValidator, setOutputFile)
2416
{
2417
    SchemaValidator *schemaValidator;
2418
    char * name;
2419
    int len1;
2420
2421
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2422 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2423 72bf04c6 Norman Walsh
    }
2424
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2425
    schemaValidator = obj->schemaValidator;
2426 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2427 72bf04c6 Norman Walsh
        schemaValidator->setOutputFile(name);
2428
    }
2429
}
2430
2431
2432
PHP_METHOD(SchemaValidator, setProperty)
2433
{
2434
    SchemaValidator *schemaValidator;
2435
    char * name;
2436
    char * value;
2437
    int len1, len2, myint;
2438
2439
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
2440 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2441 72bf04c6 Norman Walsh
    }
2442
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2443
    schemaValidator = obj->schemaValidator;
2444 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2445 72bf04c6 Norman Walsh
        schemaValidator->setProperty(name, value);
2446
    }
2447
}
2448
2449
PHP_METHOD(SchemaValidator, setParameter)
2450
{
2451
2452
   SchemaValidator *schemaValidator;
2453
   char * name;
2454
   zval* oth;
2455
   int len1, len2, myint;        
2456
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
2457 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2458 72bf04c6 Norman Walsh
    }
2459
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2460
    schemaValidator = obj->schemaValidator;
2461 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2462 72bf04c6 Norman Walsh
      const char * objName =Z_OBJCE_P(oth)->name;
2463
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2464
2465
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2466
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2467 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2468 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2469 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2470 72bf04c6 Norman Walsh
                schemaValidator->setParameter(name, (XdmValue *)value);
2471
2472
            }
2473
        }
2474
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2475
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2476 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2477 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
2478 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2479 72bf04c6 Norman Walsh
                
2480
                schemaValidator->setParameter(name, value);
2481
            }
2482
        }
2483
2484
2485
2486
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2487
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2488 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2489 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2490 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2491 72bf04c6 Norman Walsh
                
2492
                schemaValidator->setParameter(name, (XdmValue *)value);
2493
            }
2494
        }
2495
2496
2497
2498
      }
2499
2500
    }
2501
}
2502
2503
PHP_METHOD(SchemaValidator, clearProperties)
2504
{
2505
    SchemaValidator *schemaValidator;
2506
    if (ZEND_NUM_ARGS()>0) {
2507
        WRONG_PARAM_COUNT;
2508
    }
2509
2510
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2511
    schemaValidator = obj->schemaValidator;
2512 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2513 72bf04c6 Norman Walsh
        schemaValidator->clearProperties();
2514
        schemaValidator->exceptionClear();
2515
    }
2516
}
2517
2518
PHP_METHOD(SchemaValidator, clearParameters)
2519
{
2520
2521
   SchemaValidator *schemaValidator;
2522
    if (ZEND_NUM_ARGS()>0) {
2523
        WRONG_PARAM_COUNT;
2524
    }
2525
2526
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2527
    schemaValidator = obj->schemaValidator;
2528 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2529 72bf04c6 Norman Walsh
       
2530
                schemaValidator->clearParameters(true);
2531
                schemaValidator->exceptionClear();
2532
        }
2533
    }
2534
2535
PHP_METHOD(SchemaValidator, exceptionOccurred)
2536
{
2537
    SchemaValidator *schemaValidator;
2538
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2539
    if (ZEND_NUM_ARGS()>0) {
2540
        WRONG_PARAM_COUNT;
2541
    }
2542
2543
    schemaValidator = obj->schemaValidator;
2544 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2545 72bf04c6 Norman Walsh
        bool result = schemaValidator->exceptionOccurred();
2546
        RETURN_BOOL(result);
2547
    }
2548
    RETURN_BOOL(false);
2549
}
2550
2551
PHP_METHOD(SchemaValidator, getExceptionCount)
2552
{
2553
    SchemaValidator *schemaValidator;
2554
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2555
    if (ZEND_NUM_ARGS()>0) {
2556
        WRONG_PARAM_COUNT;
2557
    }
2558
2559
    schemaValidator = obj->schemaValidator;
2560 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2561 72bf04c6 Norman Walsh
        int count = schemaValidator->exceptionCount();
2562
        RETURN_LONG(count);
2563
    }
2564
    RETURN_LONG(0);
2565
}
2566
2567
PHP_METHOD(SchemaValidator, getErrorCode)
2568
{
2569
    SchemaValidator *schemaValidator;
2570
    long index;
2571
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2572 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2573 72bf04c6 Norman Walsh
    }
2574
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2575
    schemaValidator = obj->schemaValidator;
2576 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2577 72bf04c6 Norman Walsh
        const char * errCode = schemaValidator->getErrorCode((int)index);
2578 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
2579 72bf04c6 Norman Walsh
            char *str = estrdup(errCode);
2580
            RETURN_STRING(str, 0);
2581
        }
2582
    }
2583 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2584 72bf04c6 Norman Walsh
}
2585
2586
PHP_METHOD(SchemaValidator, getErrorMessage)
2587
{
2588
    SchemaValidator *schemaValidator;
2589
    long index;
2590
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2591 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2592 72bf04c6 Norman Walsh
    }
2593
    schemaValidator_object *obj = (schemaValidator_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2594
    schemaValidator = obj->schemaValidator;
2595 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2596 72bf04c6 Norman Walsh
        const char * errStr = schemaValidator->getErrorMessage((int)index);
2597 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
2598 72bf04c6 Norman Walsh
            char *str = estrdup(errStr);
2599
            RETURN_STRING(str, 0);
2600
        }
2601
    }
2602 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2603 72bf04c6 Norman Walsh
}
2604
PHP_METHOD(SchemaValidator, exceptionClear)
2605
{
2606
    SchemaValidator * schemaValidator;
2607
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2608
    schemaValidator = obj->schemaValidator;
2609 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2610 72bf04c6 Norman Walsh
        schemaValidator->exceptionClear();
2611
    }
2612
}
2613
2614
/*     ============== PHP Interface of   XdmValue =============== */
2615
void xdmValue_free_storage(void *object TSRMLS_DC)
2616
{
2617
    xdmValue_object *obj = (xdmValue_object *)object;
2618 ead48a5d O'Neil Delpratt
    //obj->xdmValue->releaseXdmValue(nullptr);
2619 72bf04c6 Norman Walsh
    zend_hash_destroy(obj->std.properties);
2620
    FREE_HASHTABLE(obj->std.properties);
2621
    efree(obj);
2622
}
2623
2624
zend_object_value xdmValue_create_handler(zend_class_entry *type TSRMLS_DC)
2625
{
2626
    zval *tmp;
2627
    zend_object_value retval;
2628
    xdmValue_object *obj = (xdmValue_object *)emalloc(sizeof(xdmValue_object));
2629
    memset(obj, 0, sizeof(xdmValue_object));
2630
    obj->std.ce = type;
2631
2632
    ALLOC_HASHTABLE(obj->std.properties);
2633 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
2634 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
2635
2636 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, xdmValue_free_storage, nullptr TSRMLS_CC);
2637 72bf04c6 Norman Walsh
    retval.handlers = &xdmValue_object_handlers;
2638
2639
    return retval;
2640
}
2641
2642
PHP_METHOD(XdmValue, __construct)
2643
{
2644 ead48a5d O'Neil Delpratt
    XdmValue *xdmValue = nullptr;
2645 72bf04c6 Norman Walsh
    bool bVal;
2646
    char * sVal;
2647
    int len;
2648
    long iVal;
2649
    double dVal;
2650
    zval *zvalue;
2651
2652 ead48a5d O'Neil Delpratt
    SaxonProcessor *proc= nullptr;
2653 72bf04c6 Norman Walsh
    xdmValue_object *obj = (xdmValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2654
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&zvalue) == SUCCESS) {
2655
        switch (Z_TYPE_P(zvalue)) {
2656
            case IS_BOOL:
2657
                bVal = Z_BVAL_P(zvalue);
2658
                xdmValue = new XdmValue(bVal);
2659
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2660
                obj->xdmValue = xdmValue;
2661
            break;
2662
            case IS_LONG:
2663
                iVal = Z_LVAL_P(zvalue);
2664
                xdmValue = new XdmValue((int)iVal);
2665
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2666
                obj->xdmValue = xdmValue;
2667
            break;
2668
            case IS_STRING:
2669
                sVal = Z_STRVAL_P(zvalue);
2670
                len = Z_STRLEN_P(zvalue);
2671
                xdmValue = new XdmValue("string", sVal);
2672
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2673
                obj->xdmValue = xdmValue;
2674
            break;
2675 ead48a5d O'Neil Delpratt
            case IS_nullptr:
2676 72bf04c6 Norman Walsh
                xdmValue = new XdmValue();
2677
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2678
                obj->xdmValue = xdmValue;
2679
            break;
2680
            case IS_DOUBLE:
2681
                // TODO: implement this
2682
                //index = (long)Z_DVAL_P(zvalue);
2683
            //break;
2684
            case IS_ARRAY:
2685
            //break;
2686
            case IS_OBJECT:
2687
            //break;
2688
            default:
2689 ead48a5d O'Neil Delpratt
                obj = nullptr;
2690 72bf04c6 Norman Walsh
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
2691
        }
2692
    }*/
2693
}
2694
2695
PHP_METHOD(XdmValue, __destruct)
2696
{
2697
    xdmValue_object *obj = (xdmValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2698
    XdmValue * xdmValue= obj->xdmValue;
2699
    xdmValue->decrementRefCount();
2700
    if(xdmValue->getRefCount()< 1){
2701
            delete xdmValue;
2702
    } 
2703
    
2704
    
2705
}
2706
2707
PHP_METHOD(XdmValue,  getHead){
2708
    XdmValue *xdmValue;
2709
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2710
    xdmValue = obj->xdmValue;
2711 ead48a5d O'Neil Delpratt
    if (xdmValue != nullptr) {
2712 72bf04c6 Norman Walsh
        XdmItem * item = xdmValue->getHead();
2713 ead48a5d O'Neil Delpratt
        if(item != nullptr) {
2714 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2715 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2716 72bf04c6 Norman Walsh
                return;
2717
            } else {
2718
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2719 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2720 72bf04c6 Norman Walsh
                vobj->xdmItem = item;
2721
                return;
2722
            }
2723
        }
2724
        
2725
    } else {
2726 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2727 72bf04c6 Norman Walsh
    }
2728
}
2729
2730
2731
PHP_METHOD(XdmValue,  itemAt){
2732
    XdmValue *xdmValue;
2733
2734
    long index;
2735
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2736 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2737 72bf04c6 Norman Walsh
    }
2738
2739
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2740
    xdmValue = obj->xdmValue;
2741 ead48a5d O'Neil Delpratt
    if (xdmValue != nullptr) {
2742 72bf04c6 Norman Walsh
        XdmItem * item = xdmValue->itemAt((int)index);
2743 ead48a5d O'Neil Delpratt
        if(item != nullptr) {
2744 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2745 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2746 72bf04c6 Norman Walsh
                return;
2747
            } else {
2748
                item->incrementRefCount();
2749
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2750 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2751 72bf04c6 Norman Walsh
                vobj->xdmItem = item;
2752
                return;
2753
            }
2754
        }
2755
        
2756
    } else {
2757 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2758 72bf04c6 Norman Walsh
    }
2759
}
2760
2761
2762
PHP_METHOD(XdmValue,  size){
2763
    XdmValue *xdmValue;
2764
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2765
    xdmValue = obj->xdmValue;
2766
    int sizei = 0;
2767 ead48a5d O'Neil Delpratt
    if (xdmValue != nullptr) {
2768 72bf04c6 Norman Walsh
        sizei = xdmValue->size();
2769
    }
2770
     RETURN_LONG(sizei);
2771
}
2772
2773
2774
PHP_METHOD(XdmValue, addXdmItem){
2775
    XdmValue *xdmValue;
2776
    zval* oth;
2777
           
2778
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2779 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2780 72bf04c6 Norman Walsh
    }
2781
2782
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2783
    xdmValue = obj->xdmValue;
2784 ead48a5d O'Neil Delpratt
    if (xdmValue != nullptr) {
2785 72bf04c6 Norman Walsh
     const char * objName =Z_OBJCE_P(oth)->name;
2786
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2787
2788
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2789
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2790 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2791 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2792 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2793 72bf04c6 Norman Walsh
                xdmValue->addXdmItem((XdmItem *)value);
2794
                return;
2795
            }
2796
        }
2797
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
2798
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
2799 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2800 72bf04c6 Norman Walsh
            XdmItem * value = ooth->xdmItem;
2801 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2802 72bf04c6 Norman Walsh
                xdmValue->addXdmItem(value);
2803
                return;
2804
            }
2805
        }
2806
2807
2808
2809
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2810
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2811 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2812 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2813 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2814 72bf04c6 Norman Walsh
                xdmValue->addXdmItem((XdmItem *)value);
2815
                return;
2816
            }
2817
        }
2818
2819
      } else {
2820
                //TODO exception
2821
        }
2822
    }
2823
}
2824
2825
2826
2827
/*     ============== PHP Interface of   XdmItem =============== */
2828
2829
void xdmItem_free_storage(void *object TSRMLS_DC)
2830
{
2831
    xdmItem_object *obj = (xdmItem_object *)object;
2832 ead48a5d O'Neil Delpratt
    //obj->xdmItem->releaseXdmValue(nullptr);
2833 72bf04c6 Norman Walsh
    zend_hash_destroy(obj->std.properties);
2834
    FREE_HASHTABLE(obj->std.properties);
2835
    efree(obj);
2836
}
2837
2838
zend_object_value xdmItem_create_handler(zend_class_entry *type TSRMLS_DC)
2839
{
2840
    zval *tmp;
2841
    zend_object_value retval;
2842
    xdmItem_object *obj = (xdmItem_object *)emalloc(sizeof(xdmItem_object));
2843
    memset(obj, 0, sizeof(xdmItem_object));
2844
    obj->std.ce = type;
2845
2846
    ALLOC_HASHTABLE(obj->std.properties);
2847 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
2848 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
2849
2850 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, xdmItem_free_storage, nullptr TSRMLS_CC);
2851 72bf04c6 Norman Walsh
    retval.handlers = &xdmItem_object_handlers;
2852
2853
    return retval;
2854
}
2855
2856
PHP_METHOD(XdmItem, __construct)
2857
{
2858 ead48a5d O'Neil Delpratt
    XdmItem *xdmItem = nullptr;
2859 72bf04c6 Norman Walsh
    bool bVal;
2860
    char * sVal;
2861
    int len;
2862
    long iVal;
2863
    double dVal;
2864
    zval *zvalue;
2865
2866 ead48a5d O'Neil Delpratt
    SaxonProcessor *proc= nullptr;
2867 72bf04c6 Norman Walsh
    xdmItem_object *obj = (xdmItem_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2868
2869
}
2870
2871
PHP_METHOD(XdmItem, __destruct)
2872
{
2873
    xdmItem_object *obj = (xdmItem_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2874
2875
    XdmItem * xdmItem= obj->xdmItem;
2876
    xdmItem->decrementRefCount();
2877
    if(xdmItem->getRefCount()< 1){
2878
            delete xdmItem;
2879
    }
2880
    
2881
}
2882
2883
PHP_METHOD(XdmItem, getStringValue)
2884
{
2885
    XdmItem *xdmItem;
2886
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2887
    xdmItem = obj->xdmItem;
2888
2889
    SaxonProcessor * saxonProc;
2890
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2891
    saxonProc =  obj2->saxonProcessor;
2892
2893 ead48a5d O'Neil Delpratt
    if (xdmItem != nullptr) {
2894 72bf04c6 Norman Walsh
        const char * valueStr = saxonProc->getStringValue(xdmItem);
2895 ead48a5d O'Neil Delpratt
        if(valueStr != nullptr) {
2896 72bf04c6 Norman Walsh
            char *str = estrdup(valueStr);
2897
            RETURN_STRING(str, 0);
2898
        }
2899
    }
2900 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2901 72bf04c6 Norman Walsh
}
2902
2903
PHP_METHOD(XdmItem, isAtomic)
2904
{
2905
    XdmItem *xdmItem;
2906
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2907
    xdmItem = obj->xdmItem;
2908
2909 ead48a5d O'Neil Delpratt
    if (xdmItem != nullptr) {
2910 72bf04c6 Norman Walsh
        bool isAtomic = xdmItem->isAtomic();
2911
        RETURN_BOOL(isAtomic);
2912
    }
2913
    RETURN_BOOL(false);
2914
}
2915
2916
PHP_METHOD(XdmItem, isNode)
2917
{
2918
    XdmItem *xdmItem;
2919
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2920
    xdmItem = obj->xdmItem;
2921
2922 ead48a5d O'Neil Delpratt
    if (xdmItem != nullptr && xdmItem->getType() == XDM_NODE) {
2923 72bf04c6 Norman Walsh
        RETURN_TRUE;
2924
    }
2925
    RETURN_FALSE;
2926
}
2927
2928
PHP_METHOD(XdmItem, getAtomicValue)
2929
{
2930
    XdmItem *xdmItem;
2931
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2932
    xdmItem = obj->xdmItem;
2933
2934 ead48a5d O'Neil Delpratt
    if (xdmItem != nullptr) {
2935 72bf04c6 Norman Walsh
          if(!xdmItem->isAtomic()) {
2936 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2937 72bf04c6 Norman Walsh
                return;
2938
          }
2939
          if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
2940 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2941 72bf04c6 Norman Walsh
                return;
2942
            } else {
2943
                xdmItem->incrementRefCount();
2944
                struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2945 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2946 72bf04c6 Norman Walsh
                vobj->xdmAtomicValue = (XdmAtomicValue *)xdmItem;
2947
                return;
2948
            }
2949
    }
2950 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2951 72bf04c6 Norman Walsh
}
2952
2953
PHP_METHOD(XdmItem, getNodeValue)
2954
{
2955
    XdmItem *xdmItem;
2956
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2957
    xdmItem = obj->xdmItem;
2958
2959 ead48a5d O'Neil Delpratt
    if (xdmItem != nullptr) {
2960 72bf04c6 Norman Walsh
          if(xdmItem->isAtomic()) {
2961 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2962 72bf04c6 Norman Walsh
                return;
2963
          }
2964
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2965 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2966 72bf04c6 Norman Walsh
                return;
2967
            } else {
2968
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2969 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2970 72bf04c6 Norman Walsh
                vobj->xdmNode = (XdmNode *)xdmItem;
2971
                vobj->xdmNode->incrementRefCount();
2972
2973
                return;
2974
            }
2975
    }
2976 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2977 72bf04c6 Norman Walsh
}
2978
2979
2980
2981
/*     ============== PHP Interface of   XdmNode =============== */
2982
2983
void xdmNode_free_storage(void *object TSRMLS_DC)
2984
{
2985
    xdmNode_object *obj = (xdmNode_object *)object;
2986 ead48a5d O'Neil Delpratt
    //obj->xdmItem->releaseXdmValue(nullptr);
2987 72bf04c6 Norman Walsh
    zend_hash_destroy(obj->std.properties);
2988
    FREE_HASHTABLE(obj->std.properties);
2989
    efree(obj);
2990
}
2991
2992
zend_object_value xdmNode_create_handler(zend_class_entry *type TSRMLS_DC)
2993
{
2994
    zval *tmp;
2995
    zend_object_value retval;
2996
    xdmNode_object *obj = (xdmNode_object *)emalloc(sizeof(xdmNode_object));
2997
    memset(obj, 0, sizeof(xdmNode_object));
2998
   // type->name ="XdmNode";
2999
         
3000
    obj->std.ce = type;        
3001
3002
    ALLOC_HASHTABLE(obj->std.properties);
3003 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
3004 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
3005
3006 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, xdmNode_free_storage, nullptr TSRMLS_CC);
3007 72bf04c6 Norman Walsh
    retval.handlers = &xdmNode_object_handlers;
3008
3009
    return retval;
3010
}
3011
3012
PHP_METHOD(XdmNode, __construct)
3013
{