Project

Profile

Help

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

he / src / main / c / Saxon.C.API / PHP7-Build / php7_saxon.cpp @ 6af44631

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 xslt30Processor_object_handlers;
25
zend_object_handlers xqueryProcessor_object_handlers;
26
zend_object_handlers xpathProcessor_object_handlers;
27
zend_object_handlers schemaValidator_object_handlers;
28
zend_object_handlers xdmValue_object_handlers;
29
zend_object_handlers xdmItem_object_handlers;
30
zend_object_handlers xdmNode_object_handlers;
31
zend_object_handlers xdmAtomicValue_object_handlers;
32
33
zend_class_entry *saxonProcessor_ce;
34
zend_class_entry *xsltProcessor_ce;
35
zend_class_entry *xslt30Processor_ce;
36
zend_class_entry *xqueryProcessor_ce;
37
zend_class_entry *xpathProcessor_ce;
38
zend_class_entry *schemaValidator_ce;
39
zend_class_entry *xdmValue_ce;
40
zend_class_entry *xdmItem_ce;
41
zend_class_entry *xdmNode_ce;
42
zend_class_entry *xdmAtomicValue_ce;
43
44 6af44631 Dave Delpratt
45
#include "php7_Xslt30Processor.cpp"
46
#include "php7_XsltExecutable.cpp"
47
48 72bf04c6 Norman Walsh
void SaxonProcessor_free_storage(zend_object *object)
49
{
50
51
//std::cerr<<"_free_Storage called php-saxonProc"<<std::endl;
52
         
53
    saxonProcessor_object *obj;
54
        
55
        obj =  (saxonProcessor_object *)((char *)object - XtOffsetOf(saxonProcessor_object, std));
56
57
 SaxonProcessor * saxonProc= obj->saxonProcessor;
58 ead48a5d O'Neil Delpratt
    if(saxonProc != nullptr) {
59 72bf04c6 Norman Walsh
        //SaxonProcessor::release();    
60
        delete saxonProc;
61
    }
62
 zend_object_std_dtor(object);
63
64
    efree(obj);
65
}
66
67
void SaxonProcessor_destroy_storage(zend_object *pobj)
68
{
69
70
        //php_error(E_WARNING,"_destroy_Storage called php-saxonProc");
71
          //  saxonProcessor_object *obj;
72
        //zend_object* pobj = Z_OBJ_P(getThis()); 
73
 /*  saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
74

75
    SaxonProcessor * saxonProc= obj->saxonProcessor;
76 ead48a5d O'Neil Delpratt
    if(saxonProc != nullptr) {
77 72bf04c6 Norman Walsh
        SaxonProcessor::release();    
78
        delete saxonProc;
79
    }*/
80
        
81
    zend_objects_destroy_object(pobj);
82
83
    
84
}
85
86
zend_object *saxonProcessor_create_handler(zend_class_entry *type)
87
{
88
    zval *tmp;
89
    zend_object retval;
90
    saxonProcessor_object *obj = (saxonProcessor_object *)ecalloc(1, sizeof(saxonProcessor_object) + zend_object_properties_size(type));
91
 
92
93
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
94
    object_properties_init(&obj->std, type);
95
96
    obj->std.handlers = &saxonProcessor_object_handlers;
97
98
    return &obj->std;
99
}
100
101
PHP_METHOD(SaxonProcessor, __construct)
102
{
103
    if (ZEND_NUM_ARGS()>2) {
104
        WRONG_PARAM_COUNT;
105
    }
106
107 ead48a5d O'Neil Delpratt
    char * cwdi = nullptr;
108 72bf04c6 Norman Walsh
   bool license = false;
109
    size_t len1;
110
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS(), "b", &license) == FAILURE) {
111
        RETURN_NULL();
112
    } 
113
114
115
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS(), "bs", &license, &cwdi, &len1) == FAILURE) {
116
        RETURN_NULL();
117
    }
118
119
120
    zval *object = getThis();
121 ead48a5d O'Neil Delpratt
    SaxonProcessor * saxonProc = nullptr;
122 72bf04c6 Norman Walsh
    zend_object * zobj = Z_OBJ_P(object);
123
124
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)zobj - XtOffsetOf(saxonProcessor_object, std));
125
126
        saxonProc = new SaxonProcessor(license); //TODO: add license flag to PHP function argument
127
                
128
    
129
        obj->saxonProcessor = saxonProc;
130
//std::cerr<<"SaxonProcessorConstructor cp1"<<std::endl;
131 ead48a5d O'Neil Delpratt
    if(cwdi==nullptr) {
132 72bf04c6 Norman Walsh
//std::cerr<<"SaxonProcessorConstructor cp1-1"<<std::endl;
133
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
134
            TCHAR s[256];
135
136
            // --
137
            DWORD a = GetCurrentDirectory(256, s);
138
            const size_t newsize = wcslen(s)*2;
139
            char* cwd = new char[newsize];
140
            wcstombs_s(0, cwd, newsize, s, _TRUNCATE);
141
            // -- code above returns the apache installation directory as the CWD
142
143
            char* cwd2;
144
145
            //php_error(E_WARNING,cwd2);
146
147
            saxonProc->setcwd(cwd);
148
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
149
#else
150
            char cwd[256];
151
152
            VCWD_GETCWD(cwd, sizeof(cwd));
153 ead48a5d O'Neil Delpratt
            if(cwd == nullptr) {
154
             //php_error(E_WARNING,"cwd is nullptrXXXXXXXXXXXXXXXXXXXXXXX");
155 72bf04c6 Norman Walsh
           }else {
156
           //  php_error(E_WARNING,cwd);
157
 
158
            saxonProc->setcwd(cwd);
159
160
          }
161
#endif
162
163
    } else {
164
        saxonProc->setcwd(cwdi);
165
    }
166
167
}
168
169
PHP_METHOD(SaxonProcessor, __destruct)
170
{
171
    //php_error(E_WARNING,"__destruct called php-saxonProc");
172
    //std::cerr<<"__destruct call saxonProc"<<std::endl;
173
        zend_object* pobj = Z_OBJ_P(getThis()); 
174
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
175
176
    SaxonProcessor * saxonProc= obj->saxonProcessor;
177 ead48a5d O'Neil Delpratt
    if(saxonProc != nullptr) {
178 72bf04c6 Norman Walsh
        //SaxonProcessor::release();    
179
        //delete saxonProc;
180
    }
181
}
182
183
184
PHP_METHOD(SaxonProcessor, release)
185
{
186
//php_error(E_WARNING,"__destruct called php-saxonProc");
187
  //  std::cerr<<"__destruct call saxonProc"<<std::endl;
188
        zend_object* pobj = Z_OBJ_P(getThis()); 
189
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
190
191
    SaxonProcessor * saxonProc= obj->saxonProcessor;
192 ead48a5d O'Neil Delpratt
    if(saxonProc != nullptr) {
193 72bf04c6 Norman Walsh
        SaxonProcessor::release();    
194
    }
195
}
196
197
198
PHP_METHOD(SaxonProcessor, isSchemaAware)
199
{
200
    SaxonProcessor *saxonProcessor;
201
    
202
    if (ZEND_NUM_ARGS()>0) {
203
        WRONG_PARAM_COUNT;
204
    }
205
    zend_object* pobj = Z_OBJ_P(getThis()); 
206
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
207
    saxonProcessor = obj->saxonProcessor;
208 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
209 72bf04c6 Norman Walsh
       
210
         if(saxonProcessor->isSchemaAwareProcessor()){
211
212
                RETURN_TRUE;
213
         }
214
    }
215
    RETURN_FALSE;
216
}
217
218
PHP_METHOD(SaxonProcessor, setCatalog)
219
{
220
    SaxonProcessor *saxonProcessor;
221
    char * catalogFile;
222
    size_t len;
223
    bool trace = false;
224
    
225
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sb", &catalogFile, &len, &trace) == FAILURE) {
226
        RETURN_NULL();
227
    }
228
    
229
    zend_object* pobj = Z_OBJ_P(getThis()); 
230
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
231
    saxonProcessor = obj->saxonProcessor;
232 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
233 72bf04c6 Norman Walsh
       
234 ead48a5d O'Neil Delpratt
        if(catalogFile != nullptr) {
235 72bf04c6 Norman Walsh
            saxonProcessor->setCatalog(catalogFile, trace);
236
        }
237
    }
238
}
239
240
241
242
PHP_METHOD(SaxonProcessor, setcwd)
243
{
244
    SaxonProcessor *saxonProcessor;
245
    char * cwdStr;
246
    size_t len;
247
    
248
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &cwdStr, &len) == FAILURE) {
249
        RETURN_NULL();
250
    }
251
    
252
    zend_object* pobj = Z_OBJ_P(getThis()); 
253
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
254
    saxonProcessor = obj->saxonProcessor;
255 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
256 72bf04c6 Norman Walsh
        
257 ead48a5d O'Neil Delpratt
        if(cwdStr != nullptr) {
258 72bf04c6 Norman Walsh
            saxonProcessor->setcwd(cwdStr);
259
        }
260
    }
261
}
262
263
264
PHP_METHOD(SaxonProcessor, parseXmlFromString)
265
{
266
    SaxonProcessor * saxonProcessor;
267
    char * source;
268
    size_t len1;
269
270
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
271
        RETURN_NULL();
272
    }
273
    zend_object* pobj = Z_OBJ_P(getThis()); 
274
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
275 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
276 72bf04c6 Norman Walsh
    saxonProcessor = obj->saxonProcessor;
277 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
278 72bf04c6 Norman Walsh
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
279 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
280 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
281
                RETURN_NULL();
282
            } else {
283
                zend_object* vobj = Z_OBJ_P(return_value);
284
                 xdmNode_object * xdmNObj = (xdmNode_object *)((char *)vobj - XtOffsetOf(xdmNode_object, std));
285 ead48a5d O'Neil Delpratt
                assert (xdmNObj != nullptr);
286 72bf04c6 Norman Walsh
                xdmNObj->xdmNode = node;
287
            }
288
        } else {
289
            if(obj->saxonProcessor->exceptionOccurred()){
290
                //TODO throw exception
291
            }
292
        }
293
    } else {
294
        RETURN_NULL();
295
    }
296
}
297
298
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
299
{
300
    SaxonProcessor * saxonProcessor;
301
    char * source;
302
    size_t len1;
303
304
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
305
        RETURN_NULL();
306
    }
307
    zend_object* pobj = Z_OBJ_P(getThis()); 
308
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
309 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
310 72bf04c6 Norman Walsh
    saxonProcessor = obj->saxonProcessor;
311 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
312 72bf04c6 Norman Walsh
        XdmNode* node = saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
313 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
314 72bf04c6 Norman Walsh
      
315
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
316
                RETURN_NULL();
317
            } else {
318
          
319
            zend_object* vvobj = Z_OBJ_P(return_value);
320
            xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
321
                
322 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
323 72bf04c6 Norman Walsh
                vobj->xdmNode = node;
324
            }
325
        } else {
326
           // obj->xsltProcessor->checkException();//TODO
327
        }
328
    } else {
329
  //  std::cerr<<"parseXmlFromFile cp2"<<std::endl;
330
        RETURN_NULL();
331
    }
332
   // std::cerr<<"parseXmlFromFile cp3"<<std::endl;
333
}
334
335
336
PHP_METHOD(SaxonProcessor, createAtomicValue)
337
{
338 ead48a5d O'Neil Delpratt
    XdmAtomicValue * xdmValue = nullptr;
339 72bf04c6 Norman Walsh
    SaxonProcessor * proc;
340
    char * source;
341
    int len1;
342
    zval *zvalue;
343
    bool bVal;
344
    char * sVal;
345
    int len;
346
    long iVal;
347
    double dVal;
348
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == FAILURE) {
349
        RETURN_NULL();
350
    }
351
    zend_object* pobj = Z_OBJ_P(getThis()); 
352
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
353 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
354 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
355 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
356
    if (proc != nullptr) {
357 72bf04c6 Norman Walsh
        switch (Z_TYPE_P(zvalue)) {
358
            case IS_FALSE:
359
            xdmValue = proc->makeBooleanValue(false);
360
            case IS_TRUE:
361
                xdmValue = proc->makeBooleanValue(true);
362
            break;
363
            case IS_LONG:
364
                iVal = Z_LVAL_P(zvalue);
365
                 xdmValue = proc->makeIntegerValue((int)iVal);
366
            break;
367
            case IS_STRING:
368
                sVal = Z_STRVAL_P(zvalue);
369
                len = Z_STRLEN_P(zvalue);
370
                
371
                xdmValue = proc->makeStringValue((const char*)sVal);
372
                //efree(sVal);
373
            break;
374
            case IS_NULL:
375
                xdmValue = new XdmAtomicValue();
376
            break;
377
            case IS_DOUBLE:
378
                dVal = (double)Z_DVAL_P(zvalue);
379
                xdmValue = proc->makeDoubleValue((double)iVal);
380
                break;
381
            case IS_ARRAY:
382
                // TODO: Should not be expected. Do this some other way
383
                //break;
384
            case IS_OBJECT:
385
                // TODO: implement this
386
                //break;
387
            default:
388 ead48a5d O'Neil Delpratt
                obj = nullptr;
389 72bf04c6 Norman Walsh
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC); 
390
                RETURN_NULL();
391
        }
392
//std::cerr<<"createAtomicValue cp0"<<std::endl;
393 ead48a5d O'Neil Delpratt
        if(xdmValue == nullptr) {
394 72bf04c6 Norman Walsh
            RETURN_NULL();
395
        }
396
        if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
397
            RETURN_NULL();
398
        } else {
399
            //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value);
400
             zend_object* vvobj = Z_OBJ_P(return_value);
401
           xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
402 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
403 72bf04c6 Norman Walsh
            vobj->xdmAtomicValue = xdmValue;
404
        }
405
    } else {
406
       
407
        RETURN_NULL();
408
    }
409
}
410
411
412
PHP_METHOD(SaxonProcessor, newXPathProcessor)
413
{
414
   
415
    if (ZEND_NUM_ARGS()>0) {
416
        WRONG_PARAM_COUNT;
417
    }
418
    SaxonProcessor * proc;
419 ead48a5d O'Neil Delpratt
    XPathProcessor * xpathProcessor = nullptr;
420 72bf04c6 Norman Walsh
421
    zend_object* pobj = Z_OBJ_P(getThis()); 
422
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
423
424 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
425 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
426 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
427
    if (proc != nullptr) {
428 72bf04c6 Norman Walsh
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
429
            RETURN_NULL();
430
        } else {
431
          // struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)Z_OBJ_P(return_value TSRMLS_CC);
432
           zend_object* vvobj = Z_OBJ_P(return_value);
433
           xpathProcessor_object * vobj = (xpathProcessor_object *)((char *)vvobj - XtOffsetOf(xpathProcessor_object, std));
434 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
435 72bf04c6 Norman Walsh
            xpathProcessor = proc->newXPathProcessor();
436
            vobj->xpathProcessor = xpathProcessor;
437
        }
438
    } else {
439
       
440
        RETURN_NULL();
441
    }
442
}
443
444
PHP_METHOD(SaxonProcessor, newXsltProcessor)
445
{
446
//std::cerr<<"SaxonProcessor newXsltproc point 1"<<std::endl;
447
    //php_error(E_WARNING,"new xsltProc 1");
448
    if (ZEND_NUM_ARGS()>0) {
449
        WRONG_PARAM_COUNT;
450
    }
451
    SaxonProcessor * proc;
452 ead48a5d O'Neil Delpratt
    XsltProcessor * xsltProcessor = nullptr;
453 72bf04c6 Norman Walsh
454
      zend_object* pobj = Z_OBJ_P(getThis()); 
455
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
456
457
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
458 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
459 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
460
461 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
462
    if (proc != nullptr) {
463 72bf04c6 Norman Walsh
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
464
            RETURN_NULL();
465
        } else {
466
        xsltProcessor = proc->newXsltProcessor();
467
           zend_object* vobj = Z_OBJ_P(return_value);
468
           xsltProcessor_object * xproc_object = (xsltProcessor_object *)((char *)vobj - XtOffsetOf(xsltProcessor_object, std));
469 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
470 72bf04c6 Norman Walsh
            
471
            xproc_object->xsltProcessor = xsltProcessor;
472
473
    }
474
    } else {
475
       
476
        RETURN_NULL();
477
    }
478
}
479
480
481
PHP_METHOD(SaxonProcessor, newXslt30Processor)
482
{
483
//std::cerr<<"SaxonProcessor newXslt30proc point 1"<<std::endl;
484
   // php_error(E_WARNING,"new xslt30Proc 1");
485
    if (ZEND_NUM_ARGS()>0) {
486
        WRONG_PARAM_COUNT;
487
    }
488
    SaxonProcessor * proc;
489 ead48a5d O'Neil Delpratt
    Xslt30Processor * xslt30Processor = nullptr;
490 72bf04c6 Norman Walsh
491
      zend_object* pobj = Z_OBJ_P(getThis());
492
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
493
494
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
495 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
496 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
497
498 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
499
    if (proc != nullptr) {
500 72bf04c6 Norman Walsh
    if (object_init_ex(return_value, xslt30Processor_ce) != SUCCESS) {
501
            RETURN_NULL();
502
        } else {
503
        xslt30Processor = proc->newXslt30Processor();        
504
           zend_object* vobj = Z_OBJ_P(return_value);
505
           xslt30Processor_object * xproc_object = (xslt30Processor_object *)((char *)vobj - XtOffsetOf(xslt30Processor_object, std));
506 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
507 72bf04c6 Norman Walsh
508
            xproc_object->xslt30Processor = xslt30Processor;
509
510
    }
511
    } else {
512
513
        RETURN_NULL();
514
    }
515
}
516
517
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
518
{
519
   
520
    if (ZEND_NUM_ARGS()>0) {
521
        WRONG_PARAM_COUNT;
522
    }
523
    SaxonProcessor * proc;
524 ead48a5d O'Neil Delpratt
    XQueryProcessor * xqueryProcessor = nullptr;
525 72bf04c6 Norman Walsh
     zend_object* pobj = Z_OBJ_P(getThis()); 
526
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
527 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
528 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
529 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
530
    if (proc != nullptr) {
531 72bf04c6 Norman Walsh
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
532
            RETURN_NULL();
533
        } else {
534
          xqueryProcessor = proc->newXQueryProcessor();
535
          zend_object* vvobj = Z_OBJ_P(return_value);
536
           xqueryProcessor_object * vobj = (xqueryProcessor_object *)((char *)vvobj - XtOffsetOf(xqueryProcessor_object, std));
537 ead48a5d O'Neil Delpratt
            assert (vvobj != nullptr);
538 72bf04c6 Norman Walsh
            
539
            vobj->xqueryProcessor = xqueryProcessor;
540
     }
541
    } else {
542
       
543
        RETURN_NULL();
544
    }
545
}
546
547
PHP_METHOD(SaxonProcessor, newSchemaValidator)
548
{
549
   
550
    if (ZEND_NUM_ARGS()>0) {
551
        WRONG_PARAM_COUNT;
552
    }
553
    SaxonProcessor * proc;
554 ead48a5d O'Neil Delpratt
    SchemaValidator * schemaValidator = nullptr;
555 72bf04c6 Norman Walsh
   
556
    zend_object* pobj = Z_OBJ_P(getThis()); 
557
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
558 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
559 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
560 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
561
    if (proc != nullptr) {
562 72bf04c6 Norman Walsh
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
563
            RETURN_NULL();
564
        } else {
565
           //struct schemaValidator_object* vobj = (struct schemaValidator_object *)Z_OBJ_P(return_value TSRMLS_CC);
566
           zend_object* vvobj = Z_OBJ_P(return_value);
567
           schemaValidator_object * vobj = (schemaValidator_object *)((char *)vvobj - XtOffsetOf(schemaValidator_object, std));
568 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
569 72bf04c6 Norman Walsh
            schemaValidator = proc->newSchemaValidator();
570 ead48a5d O'Neil Delpratt
            if(schemaValidator == nullptr){
571 72bf04c6 Norman Walsh
                RETURN_NULL();
572
            }
573
            vobj->schemaValidator = schemaValidator;
574
        }
575
    } else {
576
       
577
        RETURN_NULL();
578
    }
579
}
580
581
582
PHP_METHOD(SaxonProcessor, version)
583
{
584
    SaxonProcessor *saxonProcessor;
585
586
   
587
    if (ZEND_NUM_ARGS()>0) {
588
        WRONG_PARAM_COUNT;
589
    }
590
    zend_object* pobj = Z_OBJ_P(getThis()); 
591
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
592
    saxonProcessor = obj->saxonProcessor;
593 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
594 72bf04c6 Norman Walsh
        const char * verStr = saxonProcessor->version();
595
        //char *str = estrdup(saxonProcessor->version());
596
        _RETURN_STRING(verStr);
597
//efree(verStr);
598
    }
599
    RETURN_NULL();
600
}
601
602
603
604
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
605
{
606
    SaxonProcessor *saxonProcessor;
607
    char * name;
608
    char * value;
609
    size_t len1, len2;
610
    if (ZEND_NUM_ARGS()!= 2) {
611
        WRONG_PARAM_COUNT;
612
    }
613
614
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
615
        RETURN_NULL();
616
    }
617
    zend_object* pobj = Z_OBJ_P(getThis()); 
618
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
619
620
    saxonProcessor = obj->saxonProcessor;
621 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr && name != nullptr && value != nullptr) {
622 72bf04c6 Norman Walsh
        saxonProcessor->setConfigurationProperty(name, value);
623
    }
624
    
625
}
626
627 02e2c377 O'Neil Delpratt
628
PHP_METHOD(SaxonProcessor, clearConfigurationProperty)
629
{
630
    SaxonProcessor *saxonProcessor;
631
632
    if (ZEND_NUM_ARGS()!= 0) {
633
        WRONG_PARAM_COUNT;
634
    }
635
636
    zend_object* pobj = Z_OBJ_P(getThis());
637
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
638
639
    saxonProcessor = obj->saxonProcessor;
640
    if (saxonProcessor != nullptr) {
641
        saxonProcessor->clearConfigurationProperty();
642
    }
643
644
}
645
646 72bf04c6 Norman Walsh
PHP_METHOD(SaxonProcessor, registerPHPFunctions)
647
{
648
    SaxonProcessor *saxonProcessor;
649
    char * libName;
650
    size_t len1;
651
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
652
    if (ZEND_NUM_ARGS()!= 1) {
653
        WRONG_PARAM_COUNT;
654
    }
655
656
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &libName, &len1) == FAILURE) {
657
        RETURN_NULL();
658
    }
659
//std::cerr<<"checkpoint in registerPHPFunction cp2"<<std::endl;
660
    zend_object* pobj = Z_OBJ_P(getThis()); 
661
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
662
663
    saxonProcessor = obj->saxonProcessor;
664 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr && libName != nullptr) {
665 72bf04c6 Norman Walsh
        saxonProcessor->setConfigurationProperty("extc", libName);
666
    }
667
saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PHPFunction",
668
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
669
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
670
}
671
672
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
673
674
void XsltProcessor_free_storage(zend_object *object)
675
{
676
677
    zend_object_std_dtor(object);
678
}
679
680
void XsltProcessor_destroy_storage(zend_object *object)
681
{
682
    xsltProcessor_object *obj;
683
684
    zend_objects_destroy_object(object);
685
}
686
687
zend_object * xsltProcessor_create_handler(zend_class_entry *type)
688
{
689
   
690
691
    xsltProcessor_object *obj = (xsltProcessor_object *)ecalloc(1, sizeof(xsltProcessor_object)+ zend_object_properties_size(type));
692
   
693
    
694
   zend_object_std_init(&obj->std,type);
695
    object_properties_init(&obj->std, type);
696
    
697
    obj->std.handlers = &xsltProcessor_object_handlers;
698
699
    return &obj->std;
700
}
701
702
703
704
PHP_METHOD(XsltProcessor, __destruct)
705
{
706
707
    zend_object* pobj = Z_OBJ_P(getThis()); 
708
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
709
710
711
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
712 ead48a5d O'Neil Delpratt
    if(xsltProcessor != nullptr){
713 72bf04c6 Norman Walsh
            delete xsltProcessor;
714
     }
715
 
716
    
717
}
718
719
PHP_METHOD(XsltProcessor, transformFileToFile)
720
{
721
    XsltProcessor *xsltProcessor;
722
    char * outfileName;
723
    char * infilename;
724
    char * styleFileName;
725
    size_t len1, len2, len3;
726
727
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
728
        RETURN_NULL();
729
    }
730
731
    zend_object* pobj = Z_OBJ_P(getThis()); 
732
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
733
    xsltProcessor = obj->xsltProcessor;
734
 
735 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
736 72bf04c6 Norman Walsh
737
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
738
        if(xsltProcessor->exceptionOccurred()) {
739
               // TODO: throw exception
740
        }
741
    }
742
}
743
744
PHP_METHOD(XsltProcessor, transformFileToValue)
745
{
746
    XsltProcessor *xsltProcessor;
747
    char * infilename;
748
    char * styleFileName;
749
   size_t len1, len2;
750
751
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
752
        RETURN_NULL();
753
    }
754
755
    zend_object* pobj = Z_OBJ_P(getThis()); 
756
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
757
    xsltProcessor = obj->xsltProcessor;
758
    
759 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
760 72bf04c6 Norman Walsh
761
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
762 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
763 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
764
                RETURN_NULL();
765
            } else {
766
                zend_object *ooth =  Z_OBJ_P(return_value);
767
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
768
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
769 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
770 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
771
            }
772
        } else {
773
            if(obj->xsltProcessor->exceptionOccurred()){
774
                  //TODO
775
            }
776
        }
777
    }else {
778
        RETURN_NULL();
779
    }
780
}
781
782
783
PHP_METHOD(XsltProcessor, transformFileToString)
784
{
785
    XsltProcessor *xsltProcessor;
786
    char * infilename;
787
    char * styleFileName;
788
    size_t len1, len2;
789
790
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
791
        RETURN_NULL();
792
    }
793
794
    zend_object* pobj = Z_OBJ_P(getThis()); 
795
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
796
    xsltProcessor = obj->xsltProcessor;
797
798 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
799 72bf04c6 Norman Walsh
800
        const char * result = xsltProcessor->transformFileToString(infilename, styleFileName);
801 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
802 72bf04c6 Norman Walsh
            //char *str = estrdup(result);
803
            _RETURN_STRING(result);
804
        } else if(xsltProcessor->exceptionOccurred()){
805
            //TODO: xsltProcessor->checkException();
806 02e2c377 O'Neil Delpratt
            const char * errStr = xsltProcessor->getErrorMessage();
807 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
808 02e2c377 O'Neil Delpratt
                const char * errorCode = xsltProcessor->getErrorCode();
809 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
810 72bf04c6 Norman Walsh
                    // TODO: throw exception
811
                }
812
            }
813
        }
814
    }
815
}
816
817
/*enum saxonTypeEnum
818
{
819
        enumNode,
820
        enumString,
821
        enumInteger,
822
        enumDouble,
823
        enumFloat,
824
        enumBool,
825
        enumArrXdmValue
826
};*/
827
828 e05bbe34 O'Neil Delpratt
829 72bf04c6 Norman Walsh
jobject JNICALL phpNativeCall
830 e05bbe34 O'Neil Delpratt
        (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
831
    JNIEnv *senv = SaxonProcessor::sxn_environ->env;
832
    char *nativeString = (char *)senv->GetStringUTFChars(funcName, NULL);
833
    //std::string nativeString2 = std::string(nativeString);
834
    if(nativeString == NULL) {
835
        return NULL;
836
    }
837
    int nativeStrLen = strlen(nativeString);
838
    //std::cerr<<"phpNative called. nativeString="<<nativeString<<", length="<<nativeStrLen<<std::endl;
839
    zval function_name;
840
    zval retval;
841
842
    int argLength = 0;
843
    zval  *  params;
844
    if(arguments != NULL) {
845
        argLength = (int)senv->GetArrayLength(arguments);
846
        //(*params) = (zval**)malloc(sizeof(zval*) * argLength);
847
        params =  new zval[argLength];
848
    } else {
849
        params = NULL;
850
    }
851
    std::map<std::string, saxonTypeEnum> typeMap;
852
    typeMap["node"] = enumNode;
853
    typeMap["string"] = enumString;
854
    typeMap["integer"] = enumInteger;
855
    typeMap["double"] = enumDouble;
856
    typeMap["float"] = enumFloat;
857
    typeMap["boolean"] = enumBool;
858
    typeMap["[xdmvalue"] = enumArrXdmValue;
859
    sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
860
861
    SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
862 72bf04c6 Norman Walsh
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
863
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
864
865 e05bbe34 O'Neil Delpratt
    for(int i=0; i<argLength;i++){
866
        jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
867
        jobject argObj = senv->GetObjectArrayElement(arguments, i);
868
869
        const char * str = senv->GetStringUTFChars(argType,NULL);
870
        const char *stri = NULL;
871
        double dnumber = 0;
872
        long lnumber = 0;
873
        bool bvalue = false;
874
        float fnumber = 0;
875
876
877
878
        struct xdmNode_object* vobj;
879
        zend_object* zend_vobj;
880
        XdmNode * node = NULL;
881
        std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
882
        if (it != typeMap.end()){
883
            switch (it->second)
884
            {
885
                case enumNode:
886
                    std::cerr<<"enumNode path - cp0 - phpNtiveCall"<<std::endl;
887
                    if(!nprocessor->proc){
888
                        nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
889
                    }
890
                    if (object_init_ex(&params[i], xdmNode_ce) != SUCCESS) {
891
                        //error
892
893
                        //php_error(E_WARNING,"error phpNative xdmNode creation failed");
894
                        break;
895
                    }
896
                    node = new XdmNode(argObj);
897
                    node->setProcessor(nprocessor);
898
899
                    //MAKE_STD_ZVAL(php_argv[i]._val);
900
                    zend_vobj = Z_OBJ_P(&params[i]);
901
                    vobj = (xdmNode_object *)((char *)zend_vobj - XtOffsetOf(xdmNode_object, std));
902
                    assert (vobj != NULL);
903
904
                    vobj->xdmNode = node;
905
                    break;
906
                case enumString:
907
                    //sresult->xdmvalue = argObj;
908
                    stri = stringValue(SaxonProcessor::sxn_environ, argObj);
909
                    //stri = getStringValue(SaxonProcessor::sxn_environ, *sresult);
910
                    //stri = senv->GetStringUTFChars((jstring)argObj, 0);
911
                    //ZVAL_STRING(php_argv[i]._val);
912
                    ZVAL_STRING(&params[i], stri);
913
                    break;
914
                case enumInteger:
915
                    sresult->xdmvalue = argObj;
916
                    lnumber = getLongValue(SaxonProcessor::sxn_environ, *sresult, 0);
917
918
                    //MAKE_STD_ZVAL(php_argv[i]._val);
919
                    ZVAL_LONG(&params[i], lnumber);
920
                    break;
921
                case enumDouble:
922
                    sresult->xdmvalue = argObj;
923
                    dnumber = getDoubleValue(SaxonProcessor::sxn_environ, *sresult, 0);                                        //MAKE_STD_ZVAL(php_argv[i]._val);
924
                    ZVAL_DOUBLE(&params[i], dnumber);
925
                    break;
926
                case enumFloat:
927
                    sresult->xdmvalue = argObj;
928
                    fnumber = getFloatValue(SaxonProcessor::sxn_environ, *sresult, 0);
929
                    //MAKE_STD_ZVAL(php_argv[i]._val);
930
                    ZVAL_DOUBLE(&params[i], fnumber);
931
                    break;
932
                case enumBool:
933
                    sresult->xdmvalue = argObj;
934
                    bvalue = getBooleanValue(SaxonProcessor::sxn_environ, *sresult);
935
                    //MAKE_STD_ZVAL(php_argv[i]._val);
936
                    ZVAL_BOOL(&params[i], bvalue);
937
                    break;
938
                case enumArrXdmValue:
939
                    //TODO - not currently supported
940
                    argLength--;
941
                    break;
942
            }
943
            senv->ReleaseStringUTFChars(argType, str);
944
        }
945 72bf04c6 Norman Walsh
946 e05bbe34 O'Neil Delpratt
    }
947 72bf04c6 Norman Walsh
948
949 e05bbe34 O'Neil Delpratt
    free(sresult);
950 72bf04c6 Norman Walsh
951
952 e05bbe34 O'Neil Delpratt
    zval *argvv = NULL;
953
    zval* callOnObj = NULL;
954
    //MAKE_STD_ZVAL(function_name);
955
    //nativeString[nativeStrLen] = '\0';
956 72bf04c6 Norman Walsh
957 e05bbe34 O'Neil Delpratt
    ZVAL_STRING(&function_name, nativeString);
958
    if(call_user_function_ex(CG(function_table), (zval*)callOnObj, &function_name, &retval, argLength, params, 0, NULL) != SUCCESS)
959
    {
960
        zend_error(E_ERROR, "Function call failed");
961
    }
962 72bf04c6 Norman Walsh
963 e05bbe34 O'Neil Delpratt
    if(Z_TYPE(retval) ==0){
964
        zend_error(E_ERROR, "Function returned null");
965
    }
966 72bf04c6 Norman Walsh
967 e05bbe34 O'Neil Delpratt
    char * sVal = NULL;
968
    int len = 0;
969
    jobject obj = NULL;
970 72bf04c6 Norman Walsh
//TODO handle XdmValue wrapped object
971 e05bbe34 O'Neil Delpratt
    const char * objName = NULL;
972
    xdmNode_object* ooth = NULL;
973
    zend_object* zend_vobj2;
974
    bool bVal;
975
    switch (Z_TYPE_P(&retval)) {
976
        case IS_FALSE:
977 72bf04c6 Norman Walsh
                obj= booleanValue(SaxonProcessor::sxn_environ, false);
978
                break;
979 e05bbe34 O'Neil Delpratt
        case IS_TRUE:
980
            obj= booleanValue(SaxonProcessor::sxn_environ, true);
981 72bf04c6 Norman Walsh
            break;
982 e05bbe34 O'Neil Delpratt
983
        case IS_LONG:
984
            obj= longValue(SaxonProcessor::sxn_environ, Z_LVAL_P(&retval));
985
            break;
986
        case IS_STRING:
987
            sVal = Z_STRVAL_P(&retval);
988
            len = Z_STRLEN_P(&retval);
989
            obj = getJavaStringValue(SaxonProcessor::sxn_environ,estrndup(sVal, len));
990
            break;
991
            break;
992
        case IS_NULL:
993
994
            break;
995
        case IS_DOUBLE:
996
            obj = doubleValue(SaxonProcessor::sxn_environ, (double)Z_DVAL_P(&retval));
997
            break;
998
999
        case IS_ARRAY:
1000 72bf04c6 Norman Walsh
            //break;
1001 e05bbe34 O'Neil Delpratt
        case IS_OBJECT:
1002 72bf04c6 Norman Walsh
1003 e05bbe34 O'Neil Delpratt
            objName =ZSTR_VAL(Z_OBJCE_P(&retval)->name);
1004 72bf04c6 Norman Walsh
1005 e05bbe34 O'Neil Delpratt
1006
            if(strcmp(objName, "Saxon\\XdmNode")==0) {
1007
1008
                zend_vobj2 =  Z_OBJ_P(&retval);
1009
                ooth = (xdmNode_object *)((char *)zend_vobj2 - XtOffsetOf(xdmNode_object, std));
1010
1011
                if(ooth != NULL) {
1012
                    obj = ooth->xdmNode->getUnderlyingValue();
1013
                }
1014
            }
1015
            break;
1016
        default:
1017
            obj = NULL;
1018
            zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
1019
    }
1020
1021
    delete nprocessor;
1022
    zval_ptr_dtor(&retval);
1023
    return obj;
1024 72bf04c6 Norman Walsh
}
1025
1026
1027
1028
PHP_METHOD(XsltProcessor, transformToString)
1029
{
1030
    XsltProcessor *xsltProcessor;
1031
 
1032
    if (ZEND_NUM_ARGS()>0) {
1033
        WRONG_PARAM_COUNT;
1034
    }
1035
1036
1037
    zend_object* pobj = Z_OBJ_P(getThis()); 
1038
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1039
    xsltProcessor = obj->xsltProcessor;
1040 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1041 72bf04c6 Norman Walsh
1042
        const char * result = xsltProcessor->transformToString();
1043 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1044 72bf04c6 Norman Walsh
            _RETURN_STRING(result);
1045
        } else if(xsltProcessor->exceptionOccurred()){
1046
            xsltProcessor->checkException();
1047 02e2c377 O'Neil Delpratt
            const char * errStr = xsltProcessor->getErrorMessage();
1048 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
1049 02e2c377 O'Neil Delpratt
                const char * errorCode = xsltProcessor->getErrorCode();
1050 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
1051 72bf04c6 Norman Walsh
                    // TODO: throw exception
1052
                }
1053
            }
1054
        }
1055
    }
1056
    RETURN_NULL();
1057
}
1058
1059
PHP_METHOD(XsltProcessor, transformToValue)
1060
{
1061
    XsltProcessor *xsltProcessor;
1062
1063
    if (ZEND_NUM_ARGS()>0) {
1064
        WRONG_PARAM_COUNT;
1065
    }
1066
1067
    zend_object* pobj = Z_OBJ_P(getThis()); 
1068
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1069
    xsltProcessor = obj->xsltProcessor;
1070
1071 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1072 72bf04c6 Norman Walsh
1073
        XdmValue * node = xsltProcessor->transformToValue();
1074 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
1075 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1076
                RETURN_NULL();
1077
            } else {
1078
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value);
1079
                zend_object *vvobj =  Z_OBJ_P(return_value);
1080
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1081 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1082 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
1083
            }
1084
        } else if(xsltProcessor->exceptionOccurred()){
1085
            xsltProcessor->checkException();
1086
            RETURN_NULL();
1087
        }
1088
    } else {
1089
        RETURN_NULL();
1090
    }
1091
}
1092
1093
PHP_METHOD(XsltProcessor, transformToFile)
1094
{
1095
    XsltProcessor *xsltProcessor;
1096
 
1097
    if (ZEND_NUM_ARGS()>0) {
1098
        WRONG_PARAM_COUNT;
1099
    }
1100
1101
    zend_object* pobj = Z_OBJ_P(getThis()); 
1102
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1103
    xsltProcessor = obj->xsltProcessor;
1104
1105 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1106 72bf04c6 Norman Walsh
1107
        xsltProcessor->transformToFile();
1108
        if(xsltProcessor->exceptionOccurred()) {
1109
           //TODO
1110
            const char * exStr = xsltProcessor->checkException();
1111
        }
1112
    } else {
1113
        RETURN_NULL();
1114
    }
1115
}
1116
1117
PHP_METHOD(XsltProcessor, compileFromFile)
1118
{
1119
    XsltProcessor *xsltProcessor;
1120
    char * name;
1121
    size_t len1;
1122
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
1123
        RETURN_NULL();
1124
    }
1125
    zend_object* pobj = Z_OBJ_P(getThis()); 
1126
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1127
    xsltProcessor = obj->xsltProcessor;
1128 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1129 72bf04c6 Norman Walsh
        xsltProcessor->compileFromFile(name);
1130
    }
1131
}
1132
1133
PHP_METHOD(XsltProcessor, compileFromString)
1134
{
1135
    XsltProcessor *xsltProcessor;
1136
    char * stylesheetStr;
1137
    size_t len1, myint;
1138
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
1139
        RETURN_NULL();
1140
    }
1141
    zend_object* pobj = Z_OBJ_P(getThis()); 
1142
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1143
    xsltProcessor = obj->xsltProcessor;
1144 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1145 72bf04c6 Norman Walsh
        xsltProcessor->compileFromString(stylesheetStr);
1146
    }
1147
}
1148
1149
PHP_METHOD(XsltProcessor, compileFromStringAndSave)
1150
{
1151
    XsltProcessor *xsltProcessor;
1152
    char * stylesheetStr;
1153
    char * filename;
1154
    size_t len1, len2, myint;
1155
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetStr, &filename, &len1, &len2) == FAILURE) {
1156
        RETURN_NULL();
1157
    }
1158
    zend_object* pobj = Z_OBJ_P(getThis()); 
1159
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1160
    xsltProcessor = obj->xsltProcessor;
1161 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1162 72bf04c6 Norman Walsh
        xsltProcessor->compileFromStringAndSave(stylesheetStr, filename);
1163
    }
1164
}
1165
1166
PHP_METHOD(XsltProcessor, compileFromFileAndSave)
1167
{
1168
    XsltProcessor *xsltProcessor;
1169
    char * stylesheetFilename;
1170
    char * filename;
1171
    size_t len1, len2, myint;
1172
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, &filename, &len1, &len2) == FAILURE) {
1173
        RETURN_NULL();
1174
    }
1175
    zend_object* pobj = Z_OBJ_P(getThis()); 
1176
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1177
    xsltProcessor = obj->xsltProcessor;
1178 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1179 72bf04c6 Norman Walsh
        xsltProcessor->compileFromStringAndSave(stylesheetFilename, filename);
1180
    }
1181
}
1182
1183
1184
1185 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, compileFromValue)
1186 72bf04c6 Norman Walsh
{
1187 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1188 72bf04c6 Norman Walsh
   zval* oth;
1189
1190
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
1191
        RETURN_NULL();
1192
    }
1193 02e2c377 O'Neil Delpratt
    zend_object* pobj = Z_OBJ_P(getThis()); 
1194
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1195
    xsltProcessor = obj->xsltProcessor;
1196
    if (xsltProcessor != nullptr) {
1197 72bf04c6 Norman Walsh
        zend_object* vvobj = Z_OBJ_P(oth);
1198
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1199 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1200 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1201 ead48a5d O'Neil Delpratt
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
1202 02e2c377 O'Neil Delpratt
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1203 72bf04c6 Norman Walsh
            }
1204
        }
1205
    }
1206
}
1207
1208
1209
1210 02e2c377 O'Neil Delpratt
1211
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1212 72bf04c6 Norman Walsh
{
1213 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1214
    zval* oth = nullptr;
1215 72bf04c6 Norman Walsh
1216 02e2c377 O'Neil Delpratt
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1217 72bf04c6 Norman Walsh
        RETURN_NULL();
1218
    }
1219
1220 02e2c377 O'Neil Delpratt
    zend_object* pobj = Z_OBJ_P(getThis()); 
1221
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1222
    xsltProcessor = obj->xsltProcessor;
1223
    if (xsltProcessor != nullptr) {
1224 72bf04c6 Norman Walsh
1225 02e2c377 O'Neil Delpratt
    if(!oth) {
1226
        php_error(E_WARNING, "Error setting source value");
1227
        return;
1228
    } else {
1229
        if(Z_TYPE_P(oth) ==IS_NULL){
1230
                php_error(E_WARNING, "Error setting source value");
1231
                return;
1232
        }
1233
        
1234
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1235
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1236
1237
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1238
        zend_object * nobj = Z_OBJ_P(oth);
1239
1240
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1241
        if(ooth != nullptr) {
1242
            XdmNode * value = ooth->xdmNode;
1243
            if(value != nullptr) {
1244
                
1245
                xsltProcessor->setSourceFromXdmNode(value);
1246
1247
            }
1248
        }
1249
      } /*else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1250
        zend_object* vvobj = Z_OBJ_P(oth);
1251
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1252
        if(ooth != nullptr) {
1253
            XdmValue * value = ooth->xdmValue;
1254
            if(value != nullptr && value) {
1255
                xsltProcessor->setSourceFromXdmNode((XdmNode*)value);
1256
            }
1257
        }
1258
      }  */
1259 72bf04c6 Norman Walsh
1260 02e2c377 O'Neil Delpratt
        
1261
    }
1262
  }
1263
}
1264 72bf04c6 Norman Walsh
1265
1266 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, setJustInTimeCompilation)
1267 72bf04c6 Norman Walsh
{
1268 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1269 72bf04c6 Norman Walsh
    bool jit = false;
1270
    size_t len1;
1271
1272
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
1273
        RETURN_NULL();
1274
    }
1275
1276
    zend_object* pobj = Z_OBJ_P(getThis());
1277 02e2c377 O'Neil Delpratt
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1278
    xsltProcessor = obj->xsltProcessor;
1279
    if (xsltProcessor != nullptr) {
1280
         xsltProcessor->setJustInTimeCompilation(jit);
1281 72bf04c6 Norman Walsh
    }
1282
}
1283
1284 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, setOutputFile)
1285 72bf04c6 Norman Walsh
{
1286 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1287
    char * outputFilename;
1288 72bf04c6 Norman Walsh
    size_t len1;
1289
1290
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
1291
        RETURN_NULL();
1292
    }
1293
1294 02e2c377 O'Neil Delpratt
    zend_object* pobj = Z_OBJ_P(getThis()); 
1295
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1296
    xsltProcessor = obj->xsltProcessor;
1297
    if (xsltProcessor != nullptr && outputFilename != nullptr) {
1298
        
1299
         xsltProcessor->setOutputFile(outputFilename);
1300
            
1301
        
1302
    }
1303
}
1304
1305
1306
PHP_METHOD(XsltProcessor, setBaseOutputURI)
1307
{
1308
    XsltProcessor *xsltProcessor;
1309
    char * baseOutputURI = nullptr;
1310
    size_t len1;
1311
1312
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &len1) == FAILURE) {
1313
        RETURN_NULL();
1314
    }
1315
1316 72bf04c6 Norman Walsh
    zend_object* pobj = Z_OBJ_P(getThis());
1317 02e2c377 O'Neil Delpratt
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1318
    xsltProcessor = obj->xsltProcessor;
1319
    if (xsltProcessor != nullptr && baseOutputURI != nullptr) {
1320 72bf04c6 Norman Walsh
1321 02e2c377 O'Neil Delpratt
         xsltProcessor->setBaseOutputURI(baseOutputURI);
1322 72bf04c6 Norman Walsh
1323
1324
    }
1325
}
1326
1327
1328 02e2c377 O'Neil Delpratt
int size_t2int(size_t val) {
1329
    return (val <= INT_MAX) ? (int)((ssize_t)val) : -1;
1330
}
1331
1332
PHP_METHOD(XsltProcessor, setSourceFromFile)
1333
{
1334
    XsltProcessor *xsltProcessor;
1335
    char * inFilename;
1336
    size_t len1;
1337
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
1338
        RETURN_NULL();
1339
    }
1340
1341
    zend_object* pobj = Z_OBJ_P(getThis()); 
1342
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1343
    xsltProcessor = obj->xsltProcessor;
1344
    if (xsltProcessor != nullptr && inFilename != nullptr) {
1345
         xsltProcessor->setSourceFromFile(inFilename);
1346
            
1347
        
1348
    }
1349
}
1350 72bf04c6 Norman Walsh
1351
1352 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, setProperty)
1353 72bf04c6 Norman Walsh
{
1354 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1355
    char * name;
1356 72bf04c6 Norman Walsh
    char * value;
1357
    size_t len1, len2, myint;
1358
1359
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
1360
        RETURN_NULL();
1361
    }
1362 02e2c377 O'Neil Delpratt
    zend_object* pobj = Z_OBJ_P(getThis()); 
1363
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1364
    xsltProcessor = obj->xsltProcessor;
1365
    if (xsltProcessor != nullptr) {
1366
        xsltProcessor->setProperty(name, value);
1367 72bf04c6 Norman Walsh
    }
1368
}
1369
1370 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, setParameter)
1371 72bf04c6 Norman Walsh
{
1372
1373 02e2c377 O'Neil Delpratt
   XsltProcessor *xsltProcessor;
1374 72bf04c6 Norman Walsh
   char * name;
1375
   zval* oth;
1376 02e2c377 O'Neil Delpratt
   size_t len1, len2, myint;        
1377 72bf04c6 Norman Walsh
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1378
        RETURN_NULL();
1379
    }
1380 02e2c377 O'Neil Delpratt
    zend_object* pobj = Z_OBJ_P(getThis()); 
1381
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1382
    xsltProcessor = obj->xsltProcessor;
1383
    if (xsltProcessor != nullptr) {
1384 72bf04c6 Norman Walsh
        if(Z_TYPE_P(oth) ==IS_NULL){
1385 ead48a5d O'Neil Delpratt
                php_error(E_WARNING, "Error setting source value - value is nullptr");
1386 72bf04c6 Norman Walsh
                return;
1387
        }
1388
1389
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1390
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1391
1392
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1393
        zend_object* ooth = Z_OBJ_P(oth);
1394
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1395 ead48a5d O'Neil Delpratt
        if(nobj != nullptr) {
1396 72bf04c6 Norman Walsh
            XdmNode * value = nobj->xdmNode;
1397 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1398 02e2c377 O'Neil Delpratt
                xsltProcessor->setParameter(name, (XdmValue *)value);
1399 72bf04c6 Norman Walsh
1400
            }
1401
        }
1402
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1403
        zend_object* ooth = Z_OBJ_P(oth);
1404
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1405 ead48a5d O'Neil Delpratt
        if(vobj != nullptr) {
1406 72bf04c6 Norman Walsh
            XdmValue * value = vobj->xdmValue;
1407 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1408 02e2c377 O'Neil Delpratt
                
1409
                xsltProcessor->setParameter(name, value);
1410 72bf04c6 Norman Walsh
            }
1411
        }
1412
1413
1414
1415
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1416
        zend_object* ooth = Z_OBJ_P(oth);
1417
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1418 ead48a5d O'Neil Delpratt
        if(aobj != nullptr) {
1419 72bf04c6 Norman Walsh
            XdmAtomicValue * value = aobj->xdmAtomicValue;
1420 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1421 02e2c377 O'Neil Delpratt
                xsltProcessor->setParameter(name, (XdmValue *)value);
1422 72bf04c6 Norman Walsh
            }
1423
        }
1424
1425
1426
1427
      }
1428
1429
    }
1430
}
1431
1432 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, clearParameters)
1433 72bf04c6 Norman Walsh
{
1434 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1435 72bf04c6 Norman Walsh
    if (ZEND_NUM_ARGS()>0) {
1436
        WRONG_PARAM_COUNT;
1437
    }
1438
1439 02e2c377 O'Neil Delpratt
    zend_object* pobj = Z_OBJ_P(getThis()); 
1440
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1441
    xsltProcessor = obj->xsltProcessor;
1442
    if (xsltProcessor != nullptr) {
1443
        xsltProcessor->clearParameters(true);
1444 72bf04c6 Norman Walsh
    }
1445
}
1446
1447 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, clearProperties)
1448 72bf04c6 Norman Walsh
{
1449 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1450 72bf04c6 Norman Walsh
    if (ZEND_NUM_ARGS()>0) {
1451
        WRONG_PARAM_COUNT;
1452
    }
1453
1454 02e2c377 O'Neil Delpratt
    zend_object* pobj = Z_OBJ_P(getThis()); 
1455
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1456
    xsltProcessor = obj->xsltProcessor;
1457
    if (xsltProcessor != nullptr) {
1458
        xsltProcessor->clearProperties();
1459 72bf04c6 Norman Walsh
    }
1460
}
1461
1462
1463 02e2c377 O'Neil Delpratt
1464
PHP_METHOD(XsltProcessor, setupXslMessage)
1465 72bf04c6 Norman Walsh
{
1466 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1467 72bf04c6 Norman Walsh
    bool show = false;
1468 ead48a5d O'Neil Delpratt
    char * filename = nullptr;
1469 72bf04c6 Norman Walsh
    size_t len1;
1470
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename &len1) == FAILURE) {
1471
        RETURN_NULL();
1472
    }
1473
1474
    zend_object* pobj = Z_OBJ_P(getThis());
1475 02e2c377 O'Neil Delpratt
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1476
    xsltProcessor = obj->xsltProcessor;
1477 72bf04c6 Norman Walsh
1478 02e2c377 O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1479 72bf04c6 Norman Walsh
1480 02e2c377 O'Neil Delpratt
            xsltProcessor->setupXslMessage(show, filename);
1481 72bf04c6 Norman Walsh
        }
1482
1483
}
1484
1485
1486
1487 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, exceptionOccurred)
1488 72bf04c6 Norman Walsh
{
1489 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1490
    zend_object* pobj = Z_OBJ_P(getThis()); 
1491
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1492 72bf04c6 Norman Walsh
    if (ZEND_NUM_ARGS()>0) {
1493
        WRONG_PARAM_COUNT;
1494
    }
1495
1496 02e2c377 O'Neil Delpratt
    xsltProcessor = obj->xsltProcessor;
1497
    if (xsltProcessor != nullptr) {
1498
        bool result = xsltProcessor->exceptionOccurred();
1499 72bf04c6 Norman Walsh
        RETURN_BOOL(result);
1500
    }
1501
    RETURN_BOOL(false);
1502
}
1503
1504
1505
1506 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, getErrorCode)
1507 72bf04c6 Norman Walsh
{
1508 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1509
    if (ZEND_NUM_ARGS()>0) {
1510
        WRONG_PARAM_COUNT;
1511 72bf04c6 Norman Walsh
    }
1512 02e2c377 O'Neil Delpratt
    zend_object* pobj = Z_OBJ_P(getThis()); 
1513
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1514
    xsltProcessor = obj->xsltProcessor;
1515
    if (xsltProcessor != nullptr) {
1516
        const char * errCode = xsltProcessor->getErrorCode();
1517 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
1518 72bf04c6 Norman Walsh
            //char *str = estrdup(errCode);
1519
            _RETURN_STRING(errCode);
1520
        }
1521
    }
1522
    RETURN_NULL();
1523
}
1524
1525 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, getErrorMessage)
1526 72bf04c6 Norman Walsh
{
1527 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1528 72bf04c6 Norman Walsh
    long index;
1529
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1530
        RETURN_NULL();
1531
    }
1532 02e2c377 O'Neil Delpratt
    zend_object* pobj = Z_OBJ_P(getThis()); 
1533
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1534
    xsltProcessor = obj->xsltProcessor;
1535
    if (xsltProcessor != nullptr) {
1536 6af44631 Dave Delpratt
        const char * errStr = xsltProcessor->getErrorMessage();
1537 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
1538 72bf04c6 Norman Walsh
            //char *str = estrdup(errStr);
1539
            _RETURN_STRING(errStr);
1540
        }
1541
    }
1542
    RETURN_NULL();
1543
}
1544 02e2c377 O'Neil Delpratt
PHP_METHOD(XsltProcessor, exceptionClear)
1545 72bf04c6 Norman Walsh
{
1546 02e2c377 O'Neil Delpratt
    XsltProcessor *xsltProcessor;
1547
    zend_object* pobj = Z_OBJ_P(getThis()); 
1548
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1549
    xsltProcessor = obj->xsltProcessor;
1550
    if (xsltProcessor != nullptr) {
1551
        xsltProcessor->exceptionClear();
1552 72bf04c6 Norman Walsh
    }
1553
}
1554
1555 02e2c377 O'Neil Delpratt
1556
1557 72bf04c6 Norman Walsh
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
1558
1559
void xqueryProcessor_free_storage(zend_object *object)
1560
{
1561
    zend_object_std_dtor(object);
1562
}
1563
1564
void xqueryProcessor_destroy_storage(zend_object *object)
1565
{
1566
    zend_objects_destroy_object(object);
1567
}
1568
1569
zend_object *xqueryProcessor_create_handler(zend_class_entry *type)
1570
{
1571
1572
    xqueryProcessor_object *obj = (xqueryProcessor_object *)ecalloc(1, sizeof(xqueryProcessor_object)+ zend_object_properties_size(type));
1573
    zend_object_std_init(&obj->std, type); 
1574
    object_properties_init(&obj->std, type);
1575
    obj->std.handlers = &xqueryProcessor_object_handlers;
1576
1577
    return &obj->std;
1578
}
1579
1580
PHP_METHOD(XQueryProcessor, __destruct)
1581
{
1582
    zend_object* pobj = Z_OBJ_P(getThis());
1583
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1584
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
1585 ead48a5d O'Neil Delpratt
    if(xqueryProcessor != nullptr){
1586 72bf04c6 Norman Walsh
            delete xqueryProcessor;
1587
    }
1588
}
1589
1590
1591
PHP_METHOD(XQueryProcessor, runQueryToValue)
1592
{
1593
    XQueryProcessor *xqueryProcessor;
1594
    zend_object* pobj = Z_OBJ_P(getThis()); 
1595
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1596
1597
    if (ZEND_NUM_ARGS()>0) {
1598
        WRONG_PARAM_COUNT;
1599
    }
1600
1601
    xqueryProcessor = obj->xqueryProcessor;
1602
1603 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1604 72bf04c6 Norman Walsh
        XdmValue * node = xqueryProcessor->runQueryToValue();
1605 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
1606 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1607
                RETURN_NULL();
1608
                return;
1609
            } else {
1610
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
1611
                zend_object *vvobj =  Z_OBJ_P(return_value);
1612
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1613 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1614 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
1615
                return;
1616
            }
1617
        }
1618
        xqueryProcessor->checkException();//TODO
1619
    } else {
1620
        RETURN_NULL();
1621
    }
1622
}
1623
1624
PHP_METHOD(XQueryProcessor, runQueryToString)
1625
{
1626
    XQueryProcessor *xqueryProcessor;
1627
   
1628
1629
    if (ZEND_NUM_ARGS()>0) {
1630
        WRONG_PARAM_COUNT;
1631
    }
1632
    zend_object* pobj = Z_OBJ_P(getThis()); 
1633
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1634
    xqueryProcessor = obj->xqueryProcessor;
1635
1636 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1637 72bf04c6 Norman Walsh
        const char * result = xqueryProcessor->runQueryToString();
1638 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1639 72bf04c6 Norman Walsh
            //char *str = estrdup(result);
1640
            _RETURN_STRING(result);
1641
            return;
1642
        } else {
1643
          xqueryProcessor->checkException(); //TODO
1644
        }
1645
    }
1646
   RETURN_NULL();
1647
}
1648
1649
PHP_METHOD(XQueryProcessor, runQueryToFile)
1650
{
1651
1652
     char * ofilename;
1653
    size_t len1 =0;
1654
    if (ZEND_NUM_ARGS()!= 1) {
1655
        WRONG_PARAM_COUNT;
1656
    }
1657
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &ofilename, &len1) == FAILURE) {
1658
        RETURN_NULL();
1659
    }
1660
    XQueryProcessor *xqueryProcessor;
1661
    zend_object* pobj = Z_OBJ_P(getThis()); 
1662
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1663
1664
1665
1666
    xqueryProcessor = obj->xqueryProcessor;
1667
1668 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1669
        if(ofilename != nullptr) {
1670 72bf04c6 Norman Walsh
                xqueryProcessor->setOutputFile(ofilename);        
1671
        }
1672
        xqueryProcessor->runQueryToFile(); 
1673
    }
1674
1675
}
1676
1677
PHP_METHOD(XQueryProcessor, setQueryContent)
1678
{
1679
    char * queryStr;
1680
    size_t len1;
1681
1682
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &queryStr, &len1) == FAILURE) {
1683
        RETURN_NULL();
1684
    }
1685
    zend_object* pobj = Z_OBJ_P(getThis()); 
1686
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std)); 
1687 ead48a5d O'Neil Delpratt
    if(queryStr != nullptr) {
1688 72bf04c6 Norman Walsh
      obj->xqueryProcessor->setProperty("qs", queryStr);
1689
   }
1690
}
1691
1692
PHP_METHOD(XQueryProcessor, setQueryFile)
1693
{
1694
   char * fileName;
1695
   size_t len1;
1696
    XQueryProcessor *xqueryProcessor;
1697
1698
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fileName, &len1) == FAILURE) {
1699
        RETURN_NULL();
1700
    }
1701 ead48a5d O'Neil Delpratt
    if(fileName != nullptr) {
1702 72bf04c6 Norman Walsh
            zend_object* pobj = Z_OBJ_P(getThis()); 
1703
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1704
            xqueryProcessor = obj->xqueryProcessor;
1705
            xqueryProcessor->setQueryFile(fileName);
1706
    }
1707
            
1708
}
1709
1710
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
1711
{
1712
   char * base;
1713
   size_t len1;
1714
    XQueryProcessor *xqueryProcessor;
1715
1716
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &base, &len1) == FAILURE) {
1717
        RETURN_NULL();
1718
    }
1719 ead48a5d O'Neil Delpratt
    if(base != nullptr) {
1720 72bf04c6 Norman Walsh
            zend_object* pobj = Z_OBJ_P(getThis()); 
1721
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1722
            xqueryProcessor = obj->xqueryProcessor;
1723
            xqueryProcessor->setQueryBaseURI(base);
1724
    }
1725
            
1726
}
1727
1728
PHP_METHOD(XQueryProcessor, declareNamespace)
1729
{
1730
   char * prefix;
1731
   char * ns;
1732
   size_t len1, len2;
1733
    XQueryProcessor *xqueryProcessor;
1734
1735
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
1736
        RETURN_NULL();
1737
    }
1738 ead48a5d O'Neil Delpratt
    if(prefix != nullptr && ns != nullptr) {
1739 72bf04c6 Norman Walsh
            zend_object* pobj = Z_OBJ_P(getThis()); 
1740
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1741
            xqueryProcessor = obj->xqueryProcessor;
1742
            xqueryProcessor->declareNamespace(prefix, ns);
1743
    }
1744
            
1745
}
1746
1747
1748
1749
PHP_METHOD(XQueryProcessor, setContextItem)
1750
{
1751
   char * context;
1752
   int len1;
1753
   zval* oth;
1754
    XQueryProcessor *xqueryProcessor;
1755
1756
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &oth) == FAILURE) {
1757
        RETURN_NULL();
1758
    }
1759 ead48a5d O'Neil Delpratt
    if(oth != nullptr) {
1760 72bf04c6 Norman Walsh
            zend_object* pobj = Z_OBJ_P(getThis()); 
1761
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1762
            xqueryProcessor = obj->xqueryProcessor;
1763
    const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name); 
1764
        
1765
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1766
        zend_object *vvobj =  Z_OBJ_P(oth);
1767
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
1768
        //xdmNode_object* ooth = (xdmNode_object*)Z_OBJ_P(oth TSRMLS_CC);
1769 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1770 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
1771 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1772 72bf04c6 Norman Walsh
                xqueryProcessor->setContextItem((XdmItem *)value);
1773
               
1774
                return;
1775
            }
1776
        }
1777
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
1778
        zend_object *vvobj =  Z_OBJ_P(oth);
1779
        xdmItem_object* ooth  = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
1780 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1781 72bf04c6 Norman Walsh
            XdmItem * value = ooth->xdmItem;
1782 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1783 72bf04c6 Norman Walsh
                xqueryProcessor->setContextItem(value);
1784
               
1785
                return;
1786
            }
1787
         }
1788
        
1789
1790
1791
1792
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1793
        zend_object *vvobj =  Z_OBJ_P(oth);
1794
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
1795 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1796 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1797 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1798 72bf04c6 Norman Walsh
                
1799
                xqueryProcessor->setContextItem((XdmItem *)value);
1800
      
1801
                return;
1802
            }
1803
        }
1804
1805
1806
1807
      } 
1808
1809
1810
    }
1811
        //throw exception
1812
        
1813
            
1814
}
1815
1816
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
1817
{
1818
   char * cfilename;
1819
   size_t len1;
1820
    XQueryProcessor *xqueryProcessor;
1821
1822
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &cfilename, &len1) == FAILURE) {
1823
        RETURN_NULL();
1824
    }
1825 ead48a5d O'Neil Delpratt
    if(cfilename != nullptr) {
1826 72bf04c6 Norman Walsh
             zend_object* pobj = Z_OBJ_P(getThis()); 
1827
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1828
            xqueryProcessor = obj->xqueryProcessor;
1829
            xqueryProcessor->setContextItemFromFile(cfilename);
1830
    }
1831
            
1832
}
1833
1834
1835
PHP_METHOD(XQueryProcessor, setProperty)
1836
{
1837
    XQueryProcessor *xqueryProcessor;
1838
    char * name;
1839
    char * value;
1840
    size_t len1, len2, myint;
1841
1842
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
1843
        RETURN_NULL();
1844
    }
1845
    zend_object* pobj = Z_OBJ_P(getThis()); 
1846
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1847
    xqueryProcessor = obj->xqueryProcessor;
1848 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1849 72bf04c6 Norman Walsh
        xqueryProcessor->setProperty(name, value);
1850
    }
1851
}
1852
1853
PHP_METHOD(XQueryProcessor, setParameter)
1854
{
1855
1856
   XQueryProcessor *xqueryProcessor;
1857
   char * name;
1858
   zval* oth;
1859
   size_t len1, len2, myint;        
1860
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1861
        RETURN_NULL();
1862
    }
1863
    zend_object* pobj = Z_OBJ_P(getThis()); 
1864
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1865
    xqueryProcessor = obj->xqueryProcessor;
1866 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1867 72bf04c6 Norman Walsh
        if(Z_TYPE_P(oth) ==IS_NULL){
1868 ead48a5d O'Neil Delpratt
                php_error(E_WARNING, "Error setting source value - value is nullptr");
1869 72bf04c6 Norman Walsh
                return;
1870
        }
1871
             const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1872
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1873
//Z_ADDREF_P(oth);
1874
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1875
        zend_object *vvobj =  Z_OBJ_P(oth);
1876
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
1877 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1878 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
1879 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1880 72bf04c6 Norman Walsh
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1881
1882
            }
1883
        }
1884
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1885
        zend_object *vvobj =  Z_OBJ_P(oth);
1886
        xdmValue_object* ooth  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1887 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1888 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1889 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1890 72bf04c6 Norman Walsh
                
1891
                xqueryProcessor->setParameter(name, value);
1892
            }
1893
        }
1894
1895
1896
1897
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1898
        zend_object *vvobj =  Z_OBJ_P(oth);
1899
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
1900 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1901 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1902 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1903 72bf04c6 Norman Walsh
                
1904
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1905
            } 
1906
        }
1907
1908
1909
1910
      }
1911
1912
    }
1913
}
1914
1915
1916
1917
1918
PHP_METHOD(XQueryProcessor, clearParameters)
1919
{
1920
    XQueryProcessor *xqueryProcessor;
1921
    if (ZEND_NUM_ARGS()>0) {
1922
        WRONG_PARAM_COUNT;
1923
    }
1924
1925
    zend_object* pobj = Z_OBJ_P(getThis()); 
1926
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1927
    xqueryProcessor = obj->xqueryProcessor;
1928 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1929 72bf04c6 Norman Walsh
        xqueryProcessor->clearParameters(true);
1930
    }
1931
}
1932
1933
PHP_METHOD(XQueryProcessor, clearProperties)
1934
{
1935
    XQueryProcessor *xqueryProcessor;
1936
1937
    if (ZEND_NUM_ARGS()>0) {
1938
        WRONG_PARAM_COUNT;
1939
    }
1940
1941
    zend_object* pobj = Z_OBJ_P(getThis()); 
1942
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1943
    xqueryProcessor = obj->xqueryProcessor;
1944 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1945 72bf04c6 Norman Walsh
        xqueryProcessor->clearProperties();
1946
    }
1947
}
1948
1949
PHP_METHOD(XQueryProcessor, exceptionOccurred)
1950
{
1951
    XQueryProcessor *xqueryProcessor;
1952
    zend_object* pobj = Z_OBJ_P(getThis()); 
1953
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1954
    if (ZEND_NUM_ARGS()>0) {
1955
        WRONG_PARAM_COUNT;
1956
    }
1957
1958
    xqueryProcessor = obj->xqueryProcessor;
1959 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1960 72bf04c6 Norman Walsh
        bool result = xqueryProcessor->exceptionOccurred();
1961
        RETURN_BOOL(result);
1962
    }
1963
    RETURN_BOOL(false);
1964
}
1965
1966
1967
PHP_METHOD(XQueryProcessor, getErrorCode)
1968
{
1969
    XQueryProcessor *xqueryProcessor;
1970 02e2c377 O'Neil Delpratt
    if (ZEND_NUM_ARGS()>0) {
1971
        WRONG_PARAM_COUNT;
1972 72bf04c6 Norman Walsh
    }
1973
    zend_object* pobj = Z_OBJ_P(getThis()); 
1974
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1975
    xqueryProcessor = obj->xqueryProcessor;
1976 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1977 02e2c377 O'Neil Delpratt
        const char * errCode = xqueryProcessor->getErrorCode();
1978 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
1979 72bf04c6 Norman Walsh
            //char *str = estrdup(errCode);
1980
            _RETURN_STRING(errCode);
1981
        }
1982
    }
1983
    RETURN_NULL();
1984
}
1985
1986
PHP_METHOD(XQueryProcessor, getErrorMessage)
1987
{
1988
    XQueryProcessor *xqueryProcessor;
1989
    long index;
1990
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1991
        RETURN_NULL();
1992
    }
1993
    zend_object* pobj = Z_OBJ_P(getThis()); 
1994
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1995
    xqueryProcessor = obj->xqueryProcessor;
1996 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
1997 6af44631 Dave Delpratt
        const char * errStr = xqueryProcessor->getErrorMessage();
1998 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
1999 72bf04c6 Norman Walsh
            //char *str = estrdup(errStr);
2000
            _RETURN_STRING(errStr);
2001
        }
2002
    }
2003
    RETURN_NULL();
2004
}
2005
PHP_METHOD(XQueryProcessor, exceptionClear)
2006
{
2007
    XQueryProcessor *xqueryProcessor;
2008
    zend_object* pobj = Z_OBJ_P(getThis()); 
2009
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
2010
    xqueryProcessor = obj->xqueryProcessor;
2011 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
2012 72bf04c6 Norman Walsh
        xqueryProcessor->exceptionClear();
2013
    }
2014
}
2015
2016
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
2017
2018
void xpathProcessor_free_storage(zend_object *object)
2019
{
2020
    zend_object_std_dtor(object);
2021
}
2022
2023
void xpathProcessor_destroy_storage(zend_object *object)
2024
{
2025
    zend_objects_destroy_object(object);
2026
}
2027
2028
PHP_METHOD(XPathProcessor, __destruct)
2029
{
2030
2031
   zend_object* pobj = Z_OBJ_P(getThis()); 
2032
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2033
2034
2035
   XPathProcessor * xpathProc= obj->xpathProcessor;
2036 ead48a5d O'Neil Delpratt
    if(xpathProc != nullptr){
2037 72bf04c6 Norman Walsh
            delete xpathProc;
2038
     }
2039
2040
   
2041
    
2042
}
2043
2044
zend_object *xpathProcessor_create_handler(zend_class_entry *type)
2045
{
2046
    xpathProcessor_object *obj = (xpathProcessor_object *)ecalloc(1, sizeof(xpathProcessor_object)+ zend_object_properties_size(type));
2047
    
2048
    zend_object_std_init(&obj->std, type); 
2049
    
2050
    object_properties_init(&obj->std, type);
2051
    
2052
    obj->std.handlers = &xpathProcessor_object_handlers;
2053
2054
    return &obj->std;
2055
}
2056
2057
2058
2059
PHP_METHOD(XPathProcessor, setProperty)
2060
{
2061
    XPathProcessor *xpathProcessor;
2062
    char * name;
2063
    char * value;
2064
    size_t len1, len2;
2065
2066
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
2067
        RETURN_NULL();
2068
    }
2069
    zend_object* pobj = Z_OBJ_P(getThis()); 
2070
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2071
    xpathProcessor = obj->xpathProcessor;
2072 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2073 72bf04c6 Norman Walsh
        xpathProcessor->setProperty(name, value);
2074
    }
2075
}
2076
2077
PHP_METHOD(XPathProcessor, setParameter)
2078
{
2079
2080
   XPathProcessor *xpathProcessor;
2081
   char * name;
2082
   zval* oth;
2083
   size_t len1, len2;        
2084
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name, &len2, &oth) == FAILURE) {
2085
        RETURN_NULL();
2086
    }
2087
    zend_object* pobj = Z_OBJ_P(getThis()); 
2088
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2089
    xpathProcessor = obj->xpathProcessor;
2090 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2091 72bf04c6 Norman Walsh
            const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2092
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2093
2094
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2095
        
2096
        zend_object* vvobj = Z_OBJ_P(oth);
2097
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2098 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2099 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2100 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2101 72bf04c6 Norman Walsh
                xpathProcessor->setParameter(name, (XdmValue *)value);
2102
2103
            }
2104
        }
2105
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2106
        
2107
        zend_object* vvobj = Z_OBJ_P(oth);
2108
        xdmValue_object * ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2109 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2110 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
2111 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2112 72bf04c6 Norman Walsh
                
2113
                xpathProcessor->setParameter(name, value);
2114
            }
2115
        }
2116
2117
2118
2119
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2120
        
2121
        zend_object* vvobj = Z_OBJ_P(oth);
2122
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2123 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2124 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2125 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2126 72bf04c6 Norman Walsh
                
2127
                xpathProcessor->setParameter(name, (XdmValue *)value);
2128
            }
2129
        }
2130
2131
2132
2133
      }
2134
2135
    }
2136
}
2137
2138
PHP_METHOD(XPathProcessor, declareNamespace)
2139
{
2140
   char * prefix;
2141
   char * ns;
2142
   int len1, len2;
2143
   XPathProcessor *xpathProcessor;
2144
2145
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
2146
        RETURN_NULL();
2147
    }
2148 ead48a5d O'Neil Delpratt
    if(prefix != nullptr && ns != nullptr) {
2149 72bf04c6 Norman Walsh
            zend_object* pobj = Z_OBJ_P(getThis()); 
2150
        xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2151
            xpathProcessor = obj->xpathProcessor;
2152
            xpathProcessor->declareNamespace(prefix, ns);
2153
    }
2154
            
2155
}
2156
2157
2158
2159
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
2160
2161
    XPathProcessor *xpathProcessor;
2162
    bool allow = false;
2163
    size_t len1;
2164
2165
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &allow) == FAILURE) {
2166
        RETURN_NULL();
2167
    }
2168
2169
    zend_object* pobj = Z_OBJ_P(getThis());
2170
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2171
    xpathProcessor = obj->xpathProcessor;
2172 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2173 72bf04c6 Norman Walsh
            xpathProcessor->setBackwardsCompatible(allow);
2174
         }
2175
}
2176
2177
PHP_METHOD(XPathProcessor, setCaching){
2178
    XPathProcessor *xpathProcessor;
2179
    bool isCaching = false;
2180
    size_t len1;
2181
2182
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &isCaching) == FAILURE) {
2183
        RETURN_NULL();
2184
    }
2185
2186
    zend_object* pobj = Z_OBJ_P(getThis());
2187
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2188
    xpathProcessor = obj->xpathProcessor;
2189 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2190 72bf04c6 Norman Walsh
            xpathProcessor->setCaching(isCaching);
2191
         }
2192
}
2193
2194
PHP_METHOD(XPathProcessor, importSchemaNamespace){
2195
      char * name;
2196
      int len1;
2197
      XPathProcessor *xpathProcessor;
2198
2199
       if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2200
           RETURN_NULL();
2201
       }
2202 ead48a5d O'Neil Delpratt
       if(name != nullptr) {
2203 72bf04c6 Norman Walsh
               zend_object* pobj = Z_OBJ_P(getThis());
2204
           xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2205
               xpathProcessor = obj->xpathProcessor;
2206
               xpathProcessor->importSchemaNamespace(name);
2207
       }
2208
}
2209
2210
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
2211
{
2212
2213
   XPathProcessor *xpathProcessor;
2214
   char * xpathStr;
2215
   zval* oth;
2216
   size_t len1, myint;        
2217
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &xpathStr, &len1) == FAILURE) {
2218
        RETURN_NULL();
2219
    }
2220
    zend_object* pobj = Z_OBJ_P(getThis()); 
2221
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2222
    xpathProcessor = obj->xpathProcessor;
2223 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
2224 72bf04c6 Norman Walsh
        
2225
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
2226
                RETURN_BOOL(result);
2227
    }
2228
}
2229
2230
PHP_METHOD(XPathProcessor, evaluate)
2231
{
2232
2233
   XPathProcessor *xpathProcessor;
2234
   char * xpathStr;
2235
   zval* oth;
2236
   size_t len1, myint;        
2237
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
2238
        RETURN_NULL();
2239
    }
2240
    zend_object* pobj = Z_OBJ_P(getThis()); 
2241
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2242
    xpathProcessor = obj->xpathProcessor;
2243 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
2244 72bf04c6 Norman Walsh
        
2245
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
2246 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2247 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2248
                RETURN_NULL();
2249
                return;
2250
            } else {
2251
                zend_object* vvobj = Z_OBJ_P(return_value);
2252
                        
2253
                if(node->getType() == XDM_NODE) {
2254
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2255 ead48a5d O'Neil Delpratt
                                assert (vobj != nullptr);
2256 72bf04c6 Norman Walsh
                                  vobj->xdmNode = (XdmNode *)node;
2257
                        return;
2258
2259
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
2260
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2261 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2262 72bf04c6 Norman Walsh
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
2263
                return;
2264
2265
                } else {
2266
                  xdmValue_object * vobj = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2267 ead48a5d O'Neil Delpratt
                  assert (vobj != nullptr);
2268 72bf04c6 Norman Walsh
                  vobj->xdmValue = node;
2269
                  return;
2270
                }
2271
            }
2272
        }
2273 6af44631 Dave Delpratt
       // xpathProcessor->checkException();//TODO
2274 72bf04c6 Norman Walsh
    } 
2275
    RETURN_NULL();
2276
    
2277
}
2278
2279
PHP_METHOD(XPathProcessor, evaluateSingle)
2280
{
2281
2282
   XPathProcessor *xpathProcessor;
2283
   char * xpathStr;
2284
   zval* oth;
2285
   size_t len1, myint;        
2286
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
2287
        RETURN_NULL();
2288
    }
2289
    zend_object* pobj = Z_OBJ_P(getThis()); 
2290
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2291
    xpathProcessor = obj->xpathProcessor;
2292
2293 ead48a5d O'Neil Delpratt
    if(xpathStr == nullptr) {
2294
        RETURN_NULL();
2295 72bf04c6 Norman Walsh
        return;
2296
        }
2297
2298
2299 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2300 72bf04c6 Norman Walsh
        
2301
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
2302 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2303 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2304
                RETURN_NULL();
2305
                return;
2306
            } else {
2307
                //struct xdmItem_object* vobj = (struct xdmItem_object *)Z_OBJ_P(return_value TSRMLS_CC);
2308
                zend_object* vvobj = Z_OBJ_P(return_value);
2309
                if(node->getType() == XDM_NODE) {
2310
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2311 ead48a5d O'Neil Delpratt
                        assert (vobj != nullptr);
2312 72bf04c6 Norman Walsh
                        vobj->xdmNode = (XdmNode *)node;
2313
                        return;
2314
2315
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
2316
2317
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2318 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2319 72bf04c6 Norman Walsh
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
2320
                return;
2321
2322
                } else {
2323
                        xdmItem_object * vobj = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
2324 ead48a5d O'Neil Delpratt
                        assert (vobj != nullptr);
2325 72bf04c6 Norman Walsh
                        vobj->xdmItem = node;
2326
                        return;
2327
                }
2328
            }
2329
        } 
2330 6af44631 Dave Delpratt
       // xpathProcessor->checkException();//TODO
2331 72bf04c6 Norman Walsh
    } 
2332
    RETURN_NULL();
2333
}
2334
2335
PHP_METHOD(XPathProcessor, setContextItem)
2336
{
2337
2338
   XPathProcessor *xpathProcessor;
2339
2340
   zval* oth;
2341
        //TODO this should be relaxed to accept item/atomic/node as well as Value
2342
2343
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2344
        RETURN_NULL();
2345
    }
2346
    zend_object* pobj = Z_OBJ_P(getThis()); 
2347
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2348
    xpathProcessor = obj->xpathProcessor;
2349 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2350 72bf04c6 Norman Walsh
        if(!oth) {
2351
                php_error(E_WARNING, "Error setting source value");
2352
                return;
2353
         } 
2354
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2355
        
2356
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
2357
        zend_object* vvobj = Z_OBJ_P(oth);
2358
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2359 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2360 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2361 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2362 72bf04c6 Norman Walsh
                xpathProcessor->setContextItem((XdmItem *)value);
2363
                value->incrementRefCount();
2364
2365
            }
2366
        }
2367
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2368
        zend_object* vvobj = Z_OBJ_P(oth);
2369
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2370 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2371 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2372 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2373 72bf04c6 Norman Walsh
                
2374
                xpathProcessor->setContextItem((XdmItem *)value);
2375
                value->incrementRefCount();
2376
            }
2377
        }
2378
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
2379
        zend_object* vvobj = Z_OBJ_P(oth);
2380
        xdmItem_object * ooth = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
2381 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2382 72bf04c6 Norman Walsh
            XdmItem * value = ooth->xdmItem;
2383 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2384 72bf04c6 Norman Walsh
                
2385
                xpathProcessor->setContextItem(value);
2386
                value->incrementRefCount();
2387
            }
2388
        }
2389
2390
      }
2391
    }
2392
}
2393
2394
PHP_METHOD(XPathProcessor, setBaseURI)
2395
{
2396
2397
   XPathProcessor *xpathProcessor;
2398
2399
   char * uriStr;
2400
   size_t len1;
2401
        
2402
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &uriStr, &len1) == FAILURE) {
2403
        RETURN_NULL();
2404
    }
2405
    zend_object* pobj = Z_OBJ_P(getThis()); 
2406
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2407
    xpathProcessor = obj->xpathProcessor;
2408 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2409 72bf04c6 Norman Walsh
        
2410 ead48a5d O'Neil Delpratt
        if(uriStr != nullptr) {
2411 72bf04c6 Norman Walsh
           
2412
                xpathProcessor->setBaseURI(uriStr);
2413
            
2414
        }
2415
    }
2416
}
2417
2418
PHP_METHOD(XPathProcessor, setContextFile)
2419
{
2420
2421
   XPathProcessor *xpathProcessor;
2422
2423
   char * name;
2424
   size_t len1;
2425
        
2426
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2427
        RETURN_NULL();
2428
    }
2429
    zend_object* pobj = Z_OBJ_P(getThis()); 
2430
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2431
    xpathProcessor = obj->xpathProcessor;
2432 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2433 72bf04c6 Norman Walsh
        
2434 ead48a5d O'Neil Delpratt
        if(name != nullptr) {
2435 72bf04c6 Norman Walsh
           
2436
                xpathProcessor->setContextFile(name);
2437
            
2438
        }
2439
    }
2440
}
2441
2442
PHP_METHOD(XPathProcessor, clearParameters)
2443
{
2444
    XPathProcessor *xpathProcessor;
2445
    if (ZEND_NUM_ARGS()>0) {
2446
        WRONG_PARAM_COUNT;
2447
    }
2448
2449
    zend_object* pobj = Z_OBJ_P(getThis()); 
2450
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2451
    xpathProcessor = obj->xpathProcessor;
2452 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2453 72bf04c6 Norman Walsh
        xpathProcessor->clearParameters(true);
2454
    }
2455
}
2456
2457
PHP_METHOD(XPathProcessor, clearProperties)
2458
{
2459
     XPathProcessor *xpathProcessor;
2460
    if (ZEND_NUM_ARGS()>0) {
2461
        WRONG_PARAM_COUNT;
2462
    }
2463
2464
    zend_object* pobj = Z_OBJ_P(getThis()); 
2465
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2466
    xpathProcessor = obj->xpathProcessor;
2467 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2468 72bf04c6 Norman Walsh
        xpathProcessor->clearProperties();
2469
    }
2470
}
2471
2472
2473
PHP_METHOD(XPathProcessor, exceptionOccurred)
2474
{
2475
   XPathProcessor *xpathProcessor;
2476
    zend_object* pobj = Z_OBJ_P(getThis()); 
2477
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2478
    if (ZEND_NUM_ARGS()>0) {
2479
        WRONG_PARAM_COUNT;
2480
    }
2481
2482
    xpathProcessor = obj->xpathProcessor;
2483 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2484 72bf04c6 Norman Walsh
        bool result = xpathProcessor->exceptionOccurred();
2485
        RETURN_BOOL(result);
2486
    }
2487
    RETURN_BOOL(false);
2488
}
2489
2490
2491
PHP_METHOD(XPathProcessor, getErrorCode)
2492
{
2493
    XPathProcessor *xpathProcessor;
2494
    long index;
2495 02e2c377 O'Neil Delpratt
    if (ZEND_NUM_ARGS()>0) {
2496
        WRONG_PARAM_COUNT;
2497 72bf04c6 Norman Walsh
    }
2498
    zend_object* pobj = Z_OBJ_P(getThis()); 
2499
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2500
    xpathProcessor = obj->xpathProcessor;
2501 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2502 02e2c377 O'Neil Delpratt
        const char * errCode = xpathProcessor->getErrorCode();
2503 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
2504 72bf04c6 Norman Walsh
           // char *str = estrdup(errCode);
2505
            _RETURN_STRING(errCode);
2506
        }
2507
    }
2508
    RETURN_NULL();
2509
}
2510
2511
PHP_METHOD(XPathProcessor, getErrorMessage)
2512
{
2513
    XPathProcessor *xpathProcessor;
2514
    long index;
2515
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
2516
        RETURN_NULL();
2517
    }
2518
    zend_object* pobj = Z_OBJ_P(getThis()); 
2519
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2520
    xpathProcessor = obj->xpathProcessor;
2521 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2522 6af44631 Dave Delpratt
        const char * errStr = xpathProcessor->getErrorMessage();
2523 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
2524 72bf04c6 Norman Walsh
            //char *str = estrdup(errStr);
2525
            _RETURN_STRING(errStr);
2526
        }
2527
    }
2528
    RETURN_NULL();
2529
}
2530
PHP_METHOD(XPathProcessor, exceptionClear)
2531
{
2532
    XPathProcessor *xpathProcessor;
2533
    zend_object* pobj = Z_OBJ_P(getThis()); 
2534
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2535
    xpathProcessor = obj->xpathProcessor;
2536 ead48a5d O'Neil Delpratt
    if (xpathProcessor != nullptr) {
2537 72bf04c6 Norman Walsh
        xpathProcessor->exceptionClear();
2538
    }
2539
}
2540
2541
/*     ============== PHP Interface of   SchemaValidator =============== */
2542
2543
void schemaValidator_free_storage(zend_object *object)
2544
{
2545
    zend_object_std_dtor(object);
2546
}
2547
2548
void schemaValidator_destroy_storage(zend_object *object)
2549
{
2550
    zend_objects_destroy_object(object);
2551
}
2552
2553
zend_object *schemaValidator_create_handler(zend_class_entry *type)
2554
{
2555
    zval *tmp;
2556
    zend_object retval;
2557
    schemaValidator_object *obj = (schemaValidator_object *)ecalloc(1, sizeof(schemaValidator_object)+ zend_object_properties_size(type));
2558
2559
    zend_object_std_init(&obj->std, type);    
2560
    object_properties_init(&obj->std, type);
2561
2562
    obj->std.handlers = &schemaValidator_object_handlers;
2563
2564
    return &obj->std;
2565
}
2566
2567
2568
2569
PHP_METHOD(SchemaValidator, __destruct)
2570
{
2571
    zend_object* pobj = Z_OBJ_P(getThis()); 
2572
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2573
2574
2575
    SchemaValidator * schemaValidator= obj->schemaValidator;
2576 ead48a5d O'Neil Delpratt
    if(schemaValidator != nullptr) {
2577 72bf04c6 Norman Walsh
            delete schemaValidator;
2578
    }
2579
    
2580
}
2581
2582
2583
2584
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
2585
{
2586
    SchemaValidator *schemaValidator;
2587
    char * name;
2588
    size_t len1;
2589
2590
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2591
        RETURN_NULL();
2592
    }
2593
    zend_object* pobj = Z_OBJ_P(getThis()); 
2594
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2595
    schemaValidator = obj->schemaValidator;
2596 ead48a5d O'Neil Delpratt
    if (name != nullptr && schemaValidator != nullptr) {
2597 72bf04c6 Norman Walsh
        schemaValidator->registerSchemaFromFile(name);
2598
    }
2599
}
2600
2601
PHP_METHOD(SchemaValidator, registerSchemaFromString)
2602
{
2603
    char * schemaStr;
2604
    size_t len1;
2605
    SchemaValidator *schemaValidator;
2606
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &schemaStr, &len1) == FAILURE) {
2607
        RETURN_NULL();
2608
    }
2609
    zend_object* pobj = Z_OBJ_P(getThis()); 
2610
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2611
    schemaValidator = obj->schemaValidator;
2612 ead48a5d O'Neil Delpratt
    if (schemaStr!= nullptr && schemaValidator != nullptr) {
2613 72bf04c6 Norman Walsh
        schemaValidator->registerSchemaFromString(schemaStr);
2614
    }
2615
}
2616
2617
PHP_METHOD(SchemaValidator, validate)
2618
{
2619 ead48a5d O'Neil Delpratt
    char * name = nullptr;
2620 72bf04c6 Norman Walsh
    size_t len1;
2621
    SchemaValidator *schemaValidator;
2622
    if (ZEND_NUM_ARGS()>1) {
2623
        WRONG_PARAM_COUNT;
2624
    }
2625
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2626
        RETURN_NULL();
2627
    }
2628
    zend_object* pobj = Z_OBJ_P(getThis()); 
2629
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2630
    schemaValidator = obj->schemaValidator;
2631 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2632 72bf04c6 Norman Walsh
        schemaValidator->validate(name);
2633
    }
2634
}
2635
2636
PHP_METHOD(SchemaValidator, validateToNode)
2637
{
2638 ead48a5d O'Neil Delpratt
    char * name = nullptr;
2639 72bf04c6 Norman Walsh
   size_t len1;
2640
    SchemaValidator *schemaValidator;
2641
    if (ZEND_NUM_ARGS()>1) {
2642
        WRONG_PARAM_COUNT;
2643
    }
2644
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2645
        RETURN_NULL();
2646
    }
2647
    zend_object* pobj = Z_OBJ_P(getThis()); 
2648
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2649
    schemaValidator = obj->schemaValidator;
2650 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2651 72bf04c6 Norman Walsh
        XdmNode * node = schemaValidator->validateToNode(name);
2652 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2653 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2654
                RETURN_NULL();
2655
                return;
2656
            } else {
2657
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
2658
                zend_object* vvobj = Z_OBJ_P(return_value);
2659
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2660 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2661 72bf04c6 Norman Walsh
                vobj->xdmNode = node;
2662
                return;
2663
            }
2664
        } 
2665
            schemaValidator->checkException();//TODO
2666
    } 
2667
    RETURN_NULL();
2668
}
2669
2670
2671
PHP_METHOD(SchemaValidator, getValidationReport)
2672
{
2673
2674
    SchemaValidator *schemaValidator;
2675
    if (ZEND_NUM_ARGS()>0) {
2676
        WRONG_PARAM_COUNT;
2677
    }
2678
2679
    zend_object* pobj = Z_OBJ_P(getThis()); 
2680
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2681
    schemaValidator = obj->schemaValidator;
2682 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2683 72bf04c6 Norman Walsh
        XdmNode * node = schemaValidator->getValidationReport();
2684 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2685 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2686
                RETURN_NULL();
2687
                return;
2688
            } else {
2689
                zend_object* vvobj = Z_OBJ_P(return_value);
2690
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2691 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2692 72bf04c6 Norman Walsh
                vobj->xdmNode = node;
2693
                return;
2694
            }
2695
        } 
2696
            schemaValidator->checkException();//TODO
2697
    } 
2698
    RETURN_NULL();
2699
}
2700
2701
2702
PHP_METHOD(SchemaValidator, setSourceNode)
2703
{
2704
    SchemaValidator *schemaValidator;
2705
2706
    zval* oth;
2707
   
2708
2709
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2710
        RETURN_NULL();
2711
    }
2712
    zend_object* pobj = Z_OBJ_P(getThis()); 
2713
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2714
    schemaValidator = obj->schemaValidator;
2715 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2716 72bf04c6 Norman Walsh
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2717
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2718
        zend_object * nobj = Z_OBJ_P(oth);
2719
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
2720 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2721 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2722 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2723 72bf04c6 Norman Walsh
                schemaValidator->setSourceNode(value);
2724
2725
            }
2726
        }
2727
      
2728
        
2729
      }
2730
    }
2731
}
2732
2733
PHP_METHOD(SchemaValidator, setOutputFile)
2734
{
2735
    SchemaValidator *schemaValidator;
2736
    char * name;
2737
    int len1;
2738
2739
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2740
        RETURN_NULL();
2741
    }
2742
    zend_object* pobj = Z_OBJ_P(getThis()); 
2743
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2744
    schemaValidator = obj->schemaValidator;
2745 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2746 72bf04c6 Norman Walsh
        schemaValidator->setOutputFile(name);
2747
    }
2748
}
2749
2750
2751
PHP_METHOD(SchemaValidator, exportSchema)
2752
{
2753
    SchemaValidator *schemaValidator;
2754
    char * name;
2755
    int len1;
2756
2757
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2758
        RETURN_NULL();
2759
    }
2760
    zend_object* pobj = Z_OBJ_P(getThis());
2761
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2762
    schemaValidator = obj->schemaValidator;
2763 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2764 72bf04c6 Norman Walsh
        schemaValidator->exportSchema(name);
2765
    }
2766
}
2767
2768
2769
PHP_METHOD(SchemaValidator, setProperty)
2770
{
2771
    SchemaValidator *schemaValidator;
2772
    char * name;
2773
    char * value;
2774
    size_t len1, len2, myint;
2775
2776
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
2777
        RETURN_NULL();
2778
    }
2779
    zend_object* pobj = Z_OBJ_P(getThis()); 
2780
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2781
    schemaValidator = obj->schemaValidator;
2782 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2783 72bf04c6 Norman Walsh
        schemaValidator->setProperty(name, value);
2784
    }
2785
}
2786
2787
PHP_METHOD(SchemaValidator, setParameter)
2788
{
2789
2790
   SchemaValidator *schemaValidator;
2791
   char * name;
2792
   zval* oth;
2793
   size_t len1, len2, myint;        
2794
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
2795
        RETURN_NULL();
2796
    }
2797
    zend_object* pobj = Z_OBJ_P(getThis()); 
2798
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2799
    schemaValidator = obj->schemaValidator;
2800 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2801 72bf04c6 Norman Walsh
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2802
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2803
2804
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2805
        zend_object * nobj = Z_OBJ_P(oth);
2806
2807
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
2808 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2809 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2810 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2811 72bf04c6 Norman Walsh
                schemaValidator->setParameter(name, (XdmValue *)value);
2812
2813
            }
2814
        }
2815
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2816
        zend_object* vvobj = Z_OBJ_P(oth);
2817
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2818 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2819 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
2820 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2821 72bf04c6 Norman Walsh
                
2822
                schemaValidator->setParameter(name, value);
2823
            }
2824
        }
2825
2826
2827
2828
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2829
        zend_object* vvobj = Z_OBJ_P(oth);
2830
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2831 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2832 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2833 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2834 72bf04c6 Norman Walsh
                
2835
                schemaValidator->setParameter(name, (XdmValue *)value);
2836
            }
2837
        }
2838
2839
2840
2841
      }
2842
2843
    }
2844
}
2845
2846
PHP_METHOD(SchemaValidator, clearProperties)
2847
{
2848
    SchemaValidator *schemaValidator;
2849
    if (ZEND_NUM_ARGS()>0) {
2850
        WRONG_PARAM_COUNT;
2851
    }
2852
2853
    zend_object* pobj = Z_OBJ_P(getThis()); 
2854
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2855
    schemaValidator = obj->schemaValidator;
2856 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2857 72bf04c6 Norman Walsh
        schemaValidator->clearProperties();
2858
        schemaValidator->exceptionClear();
2859
    }
2860
}
2861
2862
PHP_METHOD(SchemaValidator, clearParameters)
2863
{
2864
2865
   SchemaValidator *schemaValidator;
2866
    if (ZEND_NUM_ARGS()>0) {
2867
        WRONG_PARAM_COUNT;
2868
    }
2869
    zend_object* pobj = Z_OBJ_P(getThis()); 
2870
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2871
    schemaValidator = obj->schemaValidator;
2872 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2873 72bf04c6 Norman Walsh
       
2874
                schemaValidator->clearParameters(true);
2875
                schemaValidator->exceptionClear();
2876
        }
2877
    }
2878
2879
PHP_METHOD(SchemaValidator, exceptionOccurred)
2880
{
2881
    SchemaValidator *schemaValidator;
2882
    if (ZEND_NUM_ARGS()>0) {
2883
        WRONG_PARAM_COUNT;
2884
    }
2885
    zend_object* pobj = Z_OBJ_P(getThis()); 
2886
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2887
    schemaValidator = obj->schemaValidator;
2888 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2889 72bf04c6 Norman Walsh
        bool result = schemaValidator->exceptionOccurred();
2890
        RETURN_BOOL(result);
2891
    }
2892
    RETURN_BOOL(false);
2893
}
2894
2895
2896
PHP_METHOD(SchemaValidator, getErrorCode)
2897
{
2898
    SchemaValidator *schemaValidator;
2899
    long index;
2900
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
2901
        RETURN_NULL();
2902
    }
2903
    zend_object* pobj = Z_OBJ_P(getThis()); 
2904
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2905
    schemaValidator = obj->schemaValidator;
2906 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2907 72bf04c6 Norman Walsh
        const char * errCode = schemaValidator->getErrorCode((int)index);
2908 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
2909 72bf04c6 Norman Walsh
            //char *str = estrdup(errCode);
2910
            _RETURN_STRING(errCode);
2911
        }
2912
    }
2913
    RETURN_NULL();
2914
}
2915
2916
PHP_METHOD(SchemaValidator, getErrorMessage)
2917
{
2918
    SchemaValidator *schemaValidator;
2919
    long index;
2920
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
2921
        RETURN_NULL();
2922
    }
2923
    zend_object* pobj = Z_OBJ_P(getThis()); 
2924
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2925
    schemaValidator = obj->schemaValidator;
2926 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2927 6af44631 Dave Delpratt
        const char * errStr = schemaValidator->getErrorMessage();
2928 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
2929 72bf04c6 Norman Walsh
            //char *str = estrdup(errStr);
2930
            _RETURN_STRING(errStr);
2931
        }
2932
    }
2933
    RETURN_NULL();
2934
}
2935
PHP_METHOD(SchemaValidator, exceptionClear)
2936
{
2937
    SchemaValidator * schemaValidator;
2938
    zend_object* pobj = Z_OBJ_P(getThis()); 
2939
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2940
    schemaValidator = obj->schemaValidator;
2941 ead48a5d O'Neil Delpratt
    if (schemaValidator != nullptr) {
2942 72bf04c6 Norman Walsh
        schemaValidator->exceptionClear();
2943
    }
2944
}
2945
2946
/*     ============== PHP Interface of   XdmValue =============== */
2947
void xdmValue_free_storage(zend_object *object)
2948
{
2949
    zend_object_std_dtor(object);
2950
}
2951
2952
zend_object *xdmValue_create_handler(zend_class_entry *type)
2953
{
2954
    zval *tmp;
2955
    zend_object retval;
2956
    xdmValue_object *obj = (xdmValue_object *)ecalloc(1, sizeof(xdmValue_object)+ zend_object_properties_size(type));
2957
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
2958
    object_properties_init(&obj->std, type);
2959
    
2960
    obj->std.handlers = &xdmValue_object_handlers;
2961
2962
    return &obj->std;
2963
}
2964
2965
void XdmValue_destroy_storage(zend_object *object)
2966
{
2967
    zend_objects_destroy_object(object);
2968
}
2969
2970
PHP_METHOD(XdmValue, __construct)
2971
{
2972 ead48a5d O'Neil Delpratt
    XdmValue *xdmValue = nullptr;
2973 72bf04c6 Norman Walsh
    bool bVal;
2974
    char * sVal;
2975
    int len;
2976
    long iVal;
2977
    double dVal;
2978
    zval *zvalue;
2979
2980
2981
2982 ead48a5d O'Neil Delpratt
    SaxonProcessor *proc= nullptr;
2983 72bf04c6 Norman Walsh
    //xdmValue_object *obj = (xdmValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
2984
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == SUCCESS) {
2985
        switch (Z_TYPE_P(zvalue)) {
2986
            case IS_FALSE:
2987
            case IS_TRUE:
2988
                bVal = Z_BVAL_P(zvalue);
2989
                xdmValue = new XdmValue(bVal);
2990
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2991
                obj->xdmValue = xdmValue;
2992
            break;
2993
            case IS_LONG:
2994
                iVal = Z_LVAL_P(zvalue);
2995
                xdmValue = new XdmValue((int)iVal);
2996
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2997
                obj->xdmValue = xdmValue;
2998
            break;
2999
            case IS_STRING:
3000
                sVal = Z_STRVAL_P(zvalue);
3001
                len = Z_STRLEN_P(zvalue);
3002
                xdmValue = new XdmValue("string", sVal);
3003
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
3004
                obj->xdmValue = xdmValue;
3005
            break;
3006
            case IS_NULL:
3007
                xdmValue = new XdmValue();
3008
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
3009
                obj->xdmValue = xdmValue;
3010
            break;
3011
            case IS_DOUBLE:
3012
                // TODO: implement this
3013
                //index = (long)Z_DVAL_P(zvalue);
3014
            //break;
3015
            case IS_ARRAY:
3016
            //break;
3017
            case IS_OBJECT:
3018
            //break;
3019
            default:
3020 ead48a5d O'Neil Delpratt
                obj = nullptr;
3021 72bf04c6 Norman Walsh
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
3022
        }
3023
    }*/
3024
}
3025
3026
PHP_METHOD(XdmValue, __destruct)
3027
{
3028
3029
     zend_object *oobj = Z_OBJ_P(getThis());
3030
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3031
    XdmValue * xdmValue= obj->xdmValue;
3032 ead48a5d O'Neil Delpratt
   if(xdmValue != nullptr) {
3033 72bf04c6 Norman Walsh
            xdmValue->decrementRefCount();
3034 ead48a5d O'Neil Delpratt
            if(xdmValue!= nullptr && xdmValue->getRefCount()< 1){
3035 72bf04c6 Norman Walsh
                    delete xdmValue;
3036
            } 
3037
    }
3038
}
3039
3040
PHP_METHOD(XdmValue, __toString)
3041
    {
3042
             XdmValue *xdmValue;
3043
         zend_object *oobj = Z_OBJ_P(getThis());
3044
         xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3045
         xdmValue = obj->xdmValue;
3046 ead48a5d O'Neil Delpratt
         if (xdmValue != nullptr) {
3047 72bf04c6 Norman Walsh
                const char * value = xdmValue->toString();
3048 ead48a5d O'Neil Delpratt
                  if(value != nullptr) {
3049 72bf04c6 Norman Walsh
                      _RETURN_STRING(value);
3050
                   } else {
3051
                   _RETURN_STRING("");
3052
3053
                   }
3054
                 }else {
3055
                      _RETURN_STRING("");
3056
              }
3057
    }
3058
3059
PHP_METHOD(XdmValue,  getHead){
3060
    XdmValue *xdmValue;
3061
     zend_object *oobj = Z_OBJ_P(getThis());
3062
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3063
    xdmValue = obj->xdmValue;
3064 ead48a5d O'Neil Delpratt
    if (xdmValue != nullptr) {
3065 72bf04c6 Norman Walsh
        XdmItem * item = xdmValue->getHead();
3066 ead48a5d O'Neil Delpratt
        if(item != nullptr) {
3067 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
3068
                RETURN_NULL();
3069
              } else {
3070
                item->incrementRefCount();
3071
                zend_object * oobj = Z_OBJ_P(return_value);
3072
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
3073 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
3074 72bf04c6 Norman Walsh
                vobj->xdmItem = item;
3075
                
3076
            }
3077
        } else {
3078
                RETURN_NULL();
3079
        }
3080
        
3081
    } else {
3082
        RETURN_NULL();
3083
    }
3084
}
3085
3086
3087
PHP_METHOD(XdmValue,  itemAt){
3088
    XdmValue *xdmValue;
3089
3090
    long index;
3091
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
3092
        RETURN_NULL();
3093
    }
3094
3095
     zend_object *oobj = Z_OBJ_P(getThis());
3096
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3097
    xdmValue = obj->xdmValue;
3098 ead48a5d O'Neil Delpratt
    if (xdmValue != nullptr) {
3099 72bf04c6 Norman Walsh
        XdmItem * item = xdmValue->itemAt((unsigned int)index);
3100 ead48a5d O'Neil Delpratt
        if(item != nullptr) {
3101 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
3102
                RETURN_NULL();
3103
                return;
3104
            } else {
3105
                item->incrementRefCount();
3106
                zend_object * oobj = Z_OBJ_P(return_value);
3107
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
3108
               
3109 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
3110 72bf04c6 Norman Walsh
                vobj->xdmItem = item;
3111
                return;
3112
            }
3113
        }
3114
        
3115
    } else {
3116
        RETURN_NULL();
3117
    }
3118
}
3119
3120
3121
PHP_METHOD(XdmValue,  size){
3122
    XdmValue *xdmValue;
3123
    zend_object *oobj = Z_OBJ_P(getThis());
3124
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3125
    xdmValue = obj->xdmValue;
3126
    int sizei = 0;
3127 ead48a5d O'Neil Delpratt
    if (xdmValue != nullptr) {
3128 72bf04c6 Norman Walsh
        sizei = xdmValue->size();
3129