Project

Profile

Help

How to connect?
Download (132 KB) Statistics
| Branch: | Revision:

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

1
#ifdef HAVE_CONFIG_H
2
    #include "config.h"
3
#endif
4

    
5
#include "php_saxon.h"
6

    
7
#ifdef COMPILE_DL_SAXON
8
    extern "C" {
9
        ZEND_GET_MODULE(saxon)
10
    }
11
#endif
12

    
13
JNINativeMethod phpMethods[] =
14
{
15
    {
16
         "_phpCall",
17
         "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;",
18
         (void *)&phpNativeCall
19
    }
20
};
21

    
22
zend_object_handlers saxonProcessor_object_handlers;
23
zend_object_handlers xsltProcessor_object_handlers;
24
zend_object_handlers xqueryProcessor_object_handlers;
25
zend_object_handlers xpathProcessor_object_handlers;
26
zend_object_handlers schemaValidator_object_handlers;
27
zend_object_handlers xdmValue_object_handlers;
28
zend_object_handlers xdmItem_object_handlers;
29
zend_object_handlers xdmNode_object_handlers;
30
zend_object_handlers xdmAtomicValue_object_handlers;
31

    
32
zend_class_entry *saxonProcessor_ce;
33
zend_class_entry *xsltProcessor_ce;
34
zend_class_entry *xqueryProcessor_ce;
35
zend_class_entry *xpathProcessor_ce;
36
zend_class_entry *schemaValidator_ce;
37
zend_class_entry *xdmValue_ce;
38
zend_class_entry *xdmItem_ce;
39
zend_class_entry *xdmNode_ce;
40
zend_class_entry *xdmAtomicValue_ce;
41

    
42

    
43
#include "php7_Xslt30Processor.cpp"
44
#include "php7_XsltExecutable.cpp"
45

    
46
void SaxonProcessor_free_storage(zend_object *object)
47
{
48

    
49
//std::cerr<<"_free_Storage called php-saxonProc"<<std::endl;
50
         
51
    saxonProcessor_object *obj;
52
        
53
        obj =  (saxonProcessor_object *)((char *)object - XtOffsetOf(saxonProcessor_object, std));
54

    
55
 SaxonProcessor * saxonProc= obj->saxonProcessor;
56
    if(saxonProc != nullptr) {
57
        //SaxonProcessor::release();    
58
        delete saxonProc;
59
    }
60
 zend_object_std_dtor(object);
61

    
62
    efree(obj);
63
}
64

    
65
void SaxonProcessor_destroy_storage(zend_object *pobj)
66
{
67

    
68
        //php_error(E_WARNING,"_destroy_Storage called php-saxonProc");
69
          //  saxonProcessor_object *obj;
70
        //zend_object* pobj = Z_OBJ_P(getThis()); 
71
 /*  saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
72

73
    SaxonProcessor * saxonProc= obj->saxonProcessor;
74
    if(saxonProc != nullptr) {
75
        SaxonProcessor::release();    
76
        delete saxonProc;
77
    }*/
78
        
79
    zend_objects_destroy_object(pobj);
80

    
81
    
82
}
83

    
84
zend_object *saxonProcessor_create_handler(zend_class_entry *type)
85
{
86
    zval *tmp;
87
    zend_object retval;
88
    saxonProcessor_object *obj = (saxonProcessor_object *)ecalloc(1, sizeof(saxonProcessor_object) + zend_object_properties_size(type));
89
 
90

    
91
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
92
    object_properties_init(&obj->std, type);
93

    
94
    obj->std.handlers = &saxonProcessor_object_handlers;
95

    
96
    return &obj->std;
97
}
98

    
99
PHP_METHOD(SaxonProcessor, __construct)
100
{
101
    if (ZEND_NUM_ARGS()>2) {
102
        WRONG_PARAM_COUNT;
103
    }
104

    
105
    char * cwdi = nullptr;
106
   bool license = false;
107
    size_t len1;
108
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS(), "b", &license) == FAILURE) {
109
        RETURN_NULL();
110
    } 
111

    
112

    
113
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS(), "bs", &license, &cwdi, &len1) == FAILURE) {
114
        RETURN_NULL();
115
    }
116

    
117

    
118
    zval *object = getThis();
119
    SaxonProcessor * saxonProc = nullptr;
120
    zend_object * zobj = Z_OBJ_P(object);
121

    
122
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)zobj - XtOffsetOf(saxonProcessor_object, std));
123

    
124
        saxonProc = new SaxonProcessor(license); //TODO: add license flag to PHP function argument
125
                
126
    
127
        obj->saxonProcessor = saxonProc;
128
//std::cerr<<"SaxonProcessorConstructor cp1"<<std::endl;
129
    if(cwdi==nullptr) {
130
//std::cerr<<"SaxonProcessorConstructor cp1-1"<<std::endl;
131
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
132
            TCHAR s[256];
133

    
134
            // --
135
            DWORD a = GetCurrentDirectory(256, s);
136
            const size_t newsize = wcslen(s)*2;
137
            char* cwd = new char[newsize];
138
            wcstombs_s(0, cwd, newsize, s, _TRUNCATE);
139
            // -- code above returns the apache installation directory as the CWD
140

    
141
            char* cwd2;
142

    
143
            //php_error(E_WARNING,cwd2);
144

    
145
            saxonProc->setcwd(cwd);
146
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
147
#else
148
            char cwd[256];
149

    
150
            VCWD_GETCWD(cwd, sizeof(cwd));
151
            if(cwd == nullptr) {
152
             //php_error(E_WARNING,"cwd is nullptrXXXXXXXXXXXXXXXXXXXXXXX");
153
           }else {
154
           //  php_error(E_WARNING,cwd);
155
 
156
            saxonProc->setcwd(cwd);
157

    
158
          }
159
#endif
160

    
161
    } else {
162
        saxonProc->setcwd(cwdi);
163
    }
164

    
165
}
166

    
167
PHP_METHOD(SaxonProcessor, __destruct)
168
{
169
    //php_error(E_WARNING,"__destruct called php-saxonProc");
170
    //std::cerr<<"__destruct call saxonProc"<<std::endl;
171
        zend_object* pobj = Z_OBJ_P(getThis()); 
172
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
173

    
174
    SaxonProcessor * saxonProc= obj->saxonProcessor;
175
    if(saxonProc != nullptr) {
176
        //SaxonProcessor::release();    
177
        //delete saxonProc;
178
    }
179
}
180

    
181

    
182
PHP_METHOD(SaxonProcessor, release)
183
{
184
//php_error(E_WARNING,"__destruct called php-saxonProc");
185
  //  std::cerr<<"__destruct call saxonProc"<<std::endl;
186
        zend_object* pobj = Z_OBJ_P(getThis()); 
187
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
188

    
189
    SaxonProcessor * saxonProc= obj->saxonProcessor;
190
    if(saxonProc != nullptr) {
191
        SaxonProcessor::release();    
192
    }
193
}
194

    
195

    
196
PHP_METHOD(SaxonProcessor, isSchemaAware)
197
{
198
    SaxonProcessor *saxonProcessor;
199
    
200
    if (ZEND_NUM_ARGS()>0) {
201
        WRONG_PARAM_COUNT;
202
    }
203
    zend_object* pobj = Z_OBJ_P(getThis()); 
204
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
205
    saxonProcessor = obj->saxonProcessor;
206
    if (saxonProcessor != nullptr) {
207
       
208
         if(saxonProcessor->isSchemaAwareProcessor()){
209

    
210
                RETURN_TRUE;
211
         }
212
    }
213
    RETURN_FALSE;
214
}
215

    
216
PHP_METHOD(SaxonProcessor, setCatalog)
217
{
218
    SaxonProcessor *saxonProcessor;
219
    char * catalogFile;
220
    size_t len;
221
    bool trace = false;
222
    
223
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sb", &catalogFile, &len, &trace) == FAILURE) {
224
        RETURN_NULL();
225
    }
226
    
227
    zend_object* pobj = Z_OBJ_P(getThis()); 
228
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
229
    saxonProcessor = obj->saxonProcessor;
230
    if (saxonProcessor != nullptr) {
231
       
232
        if(catalogFile != nullptr) {
233
            saxonProcessor->setCatalog(catalogFile, trace);
234
        }
235
    }
236
}
237

    
238

    
239

    
240
PHP_METHOD(SaxonProcessor, setcwd)
241
{
242
    SaxonProcessor *saxonProcessor;
243
    char * cwdStr;
244
    size_t len;
245
    
246
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &cwdStr, &len) == FAILURE) {
247
        RETURN_NULL();
248
    }
249
    
250
    zend_object* pobj = Z_OBJ_P(getThis()); 
251
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
252
    saxonProcessor = obj->saxonProcessor;
253
    if (saxonProcessor != nullptr) {
254
        
255
        if(cwdStr != nullptr) {
256
            saxonProcessor->setcwd(cwdStr);
257
        }
258
    }
259
}
260

    
261

    
262
PHP_METHOD(SaxonProcessor, parseXmlFromString)
263
{
264
    SaxonProcessor * saxonProcessor;
265
    char * source;
266
    size_t len1;
267

    
268
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
269
        RETURN_NULL();
270
    }
271
    zend_object* pobj = Z_OBJ_P(getThis()); 
272
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
273
    assert (obj != nullptr);
274
    saxonProcessor = obj->saxonProcessor;
275
    if (saxonProcessor != nullptr) {
276
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
277
        if(node != nullptr) {
278
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
279
                RETURN_NULL();
280
            } else {
281
                zend_object* vobj = Z_OBJ_P(return_value);
282
                 xdmNode_object * xdmNObj = (xdmNode_object *)((char *)vobj - XtOffsetOf(xdmNode_object, std));
283
                assert (xdmNObj != nullptr);
284
                xdmNObj->xdmNode = node;
285
            }
286
        } else {
287
            if(obj->saxonProcessor->exceptionOccurred()){
288
                //TODO throw exception
289
            }
290
        }
291
    } else {
292
        RETURN_NULL();
293
    }
294
}
295

    
296
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
297
{
298
    SaxonProcessor * saxonProcessor;
299
    char * source;
300
    size_t len1;
301

    
302
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
303
        RETURN_NULL();
304
    }
305
    zend_object* pobj = Z_OBJ_P(getThis()); 
306
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
307
    assert (obj != nullptr);
308
    saxonProcessor = obj->saxonProcessor;
309
    if (saxonProcessor != nullptr) {
310
        XdmNode* node = saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
311
        if(node != nullptr) {
312
      
313
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
314
                RETURN_NULL();
315
            } else {
316
          
317
            zend_object* vvobj = Z_OBJ_P(return_value);
318
            xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
319
                
320
                assert (vobj != nullptr);
321
                vobj->xdmNode = node;
322
            }
323
        } else {
324
           // obj->xsltProcessor->checkException();//TODO
325
        }
326
    } else {
327
  //  std::cerr<<"parseXmlFromFile cp2"<<std::endl;
328
        RETURN_NULL();
329
    }
330
   // std::cerr<<"parseXmlFromFile cp3"<<std::endl;
331
}
332

    
333

    
334
PHP_METHOD(SaxonProcessor, createAtomicValue)
335
{
336
    XdmAtomicValue * xdmValue = nullptr;
337
    SaxonProcessor * proc;
338
    char * source;
339
    int len1;
340
    zval *zvalue;
341
    bool bVal;
342
    char * sVal;
343
    int len;
344
    long iVal;
345
    double dVal;
346
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == FAILURE) {
347
        RETURN_NULL();
348
    }
349
    zend_object* pobj = Z_OBJ_P(getThis()); 
350
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
351
    assert (obj != nullptr);
352
    proc = obj->saxonProcessor;
353
    assert (proc != nullptr);
354
    if (proc != nullptr) {
355
        switch (Z_TYPE_P(zvalue)) {
356
            case IS_FALSE:
357
            xdmValue = proc->makeBooleanValue(false);
358
            case IS_TRUE:
359
                xdmValue = proc->makeBooleanValue(true);
360
            break;
361
            case IS_LONG:
362
                iVal = Z_LVAL_P(zvalue);
363
                 xdmValue = proc->makeIntegerValue((int)iVal);
364
            break;
365
            case IS_STRING:
366
                sVal = Z_STRVAL_P(zvalue);
367
                len = Z_STRLEN_P(zvalue);
368
                
369
                xdmValue = proc->makeStringValue((const char*)sVal);
370
                //efree(sVal);
371
            break;
372
            case IS_NULL:
373
                xdmValue = new XdmAtomicValue();
374
            break;
375
            case IS_DOUBLE:
376
                dVal = (double)Z_DVAL_P(zvalue);
377
                xdmValue = proc->makeDoubleValue((double)iVal);
378
                break;
379
            case IS_ARRAY:
380
                // TODO: Should not be expected. Do this some other way
381
                //break;
382
            case IS_OBJECT:
383
                // TODO: implement this
384
                //break;
385
            default:
386
                obj = nullptr;
387
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC); 
388
                RETURN_NULL();
389
        }
390
//std::cerr<<"createAtomicValue cp0"<<std::endl;
391
        if(xdmValue == nullptr) {
392
            RETURN_NULL();
393
        }
394
        if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
395
            RETURN_NULL();
396
        } else {
397
            //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value);
398
             zend_object* vvobj = Z_OBJ_P(return_value);
399
           xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
400
            assert (vobj != nullptr);
401
            vobj->xdmAtomicValue = xdmValue;
402
        }
403
    } else {
404
       
405
        RETURN_NULL();
406
    }
407
}
408

    
409

    
410
PHP_METHOD(SaxonProcessor, newXPathProcessor)
411
{
412
   
413
    if (ZEND_NUM_ARGS()>0) {
414
        WRONG_PARAM_COUNT;
415
    }
416
    SaxonProcessor * proc;
417
    XPathProcessor * xpathProcessor = nullptr;
418

    
419
    zend_object* pobj = Z_OBJ_P(getThis()); 
420
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
421

    
422
    assert (obj != nullptr);
423
    proc = obj->saxonProcessor;
424
    assert (proc != nullptr);
425
    if (proc != nullptr) {
426
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
427
            RETURN_NULL();
428
        } else {
429
          // struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)Z_OBJ_P(return_value TSRMLS_CC);
430
           zend_object* vvobj = Z_OBJ_P(return_value);
431
           xpathProcessor_object * vobj = (xpathProcessor_object *)((char *)vvobj - XtOffsetOf(xpathProcessor_object, std));
432
            assert (vobj != nullptr);
433
            xpathProcessor = proc->newXPathProcessor();
434
            vobj->xpathProcessor = xpathProcessor;
435
        }
436
    } else {
437
       
438
        RETURN_NULL();
439
    }
440
}
441

    
442
PHP_METHOD(SaxonProcessor, newXsltProcessor)
443
{
444
//std::cerr<<"SaxonProcessor newXsltproc point 1"<<std::endl;
445
    //php_error(E_WARNING,"new xsltProc 1");
446
    if (ZEND_NUM_ARGS()>0) {
447
        WRONG_PARAM_COUNT;
448
    }
449
    SaxonProcessor * proc;
450
    XsltProcessor * xsltProcessor = nullptr;
451

    
452
      zend_object* pobj = Z_OBJ_P(getThis()); 
453
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
454

    
455
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
456
    assert (obj != nullptr);
457
    proc = obj->saxonProcessor;
458

    
459
    assert (proc != nullptr);
460
    if (proc != nullptr) {
461
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
462
            RETURN_NULL();
463
        } else {
464
        xsltProcessor = proc->newXsltProcessor();
465
           zend_object* vobj = Z_OBJ_P(return_value);
466
           xsltProcessor_object * xproc_object = (xsltProcessor_object *)((char *)vobj - XtOffsetOf(xsltProcessor_object, std));
467
            assert (vobj != nullptr);
468
            
469
            xproc_object->xsltProcessor = xsltProcessor;
470

    
471
    }
472
    } else {
473
       
474
        RETURN_NULL();
475
    }
476
}
477

    
478

    
479
PHP_METHOD(SaxonProcessor, newXslt30Processor)
480
{
481
//std::cerr<<"SaxonProcessor newXslt30proc point 1"<<std::endl;
482
   // php_error(E_WARNING,"new xslt30Proc 1");
483
    if (ZEND_NUM_ARGS()>0) {
484
        WRONG_PARAM_COUNT;
485
    }
486
    SaxonProcessor * proc;
487
    Xslt30Processor * xslt30Processor = nullptr;
488

    
489
      zend_object* pobj = Z_OBJ_P(getThis());
490
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
491

    
492
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
493
    assert (obj != nullptr);
494
    proc = obj->saxonProcessor;
495

    
496
    assert (proc != nullptr);
497
    if (proc != nullptr) {
498
    if (object_init_ex(return_value, xslt30Processor_ce) != SUCCESS) {
499
            RETURN_NULL();
500
        } else {
501
        xslt30Processor = proc->newXslt30Processor();        
502
           zend_object* vobj = Z_OBJ_P(return_value);
503
           xslt30Processor_object * xproc_object = (xslt30Processor_object *)((char *)vobj - XtOffsetOf(xslt30Processor_object, std));
504
            assert (vobj != nullptr);
505

    
506
            xproc_object->xslt30Processor = xslt30Processor;
507

    
508
    }
509
    } else {
510

    
511
        RETURN_NULL();
512
    }
513
}
514

    
515
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
516
{
517
   
518
    if (ZEND_NUM_ARGS()>0) {
519
        WRONG_PARAM_COUNT;
520
    }
521
    SaxonProcessor * proc;
522
    XQueryProcessor * xqueryProcessor = nullptr;
523
     zend_object* pobj = Z_OBJ_P(getThis()); 
524
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
525
    assert (obj != nullptr);
526
    proc = obj->saxonProcessor;
527
    assert (proc != nullptr);
528
    if (proc != nullptr) {
529
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
530
            RETURN_NULL();
531
        } else {
532
          xqueryProcessor = proc->newXQueryProcessor();
533
          zend_object* vvobj = Z_OBJ_P(return_value);
534
           xqueryProcessor_object * vobj = (xqueryProcessor_object *)((char *)vvobj - XtOffsetOf(xqueryProcessor_object, std));
535
            assert (vvobj != nullptr);
536
            
537
            vobj->xqueryProcessor = xqueryProcessor;
538
     }
539
    } else {
540
       
541
        RETURN_NULL();
542
    }
543
}
544

    
545
PHP_METHOD(SaxonProcessor, newSchemaValidator)
546
{
547
   
548
    if (ZEND_NUM_ARGS()>0) {
549
        WRONG_PARAM_COUNT;
550
    }
551
    SaxonProcessor * proc;
552
    SchemaValidator * schemaValidator = nullptr;
553
   
554
    zend_object* pobj = Z_OBJ_P(getThis()); 
555
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
556
    assert (obj != nullptr);
557
    proc = obj->saxonProcessor;
558
    assert (proc != nullptr);
559
    if (proc != nullptr) {
560
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
561
            RETURN_NULL();
562
        } else {
563
           //struct schemaValidator_object* vobj = (struct schemaValidator_object *)Z_OBJ_P(return_value TSRMLS_CC);
564
           zend_object* vvobj = Z_OBJ_P(return_value);
565
           schemaValidator_object * vobj = (schemaValidator_object *)((char *)vvobj - XtOffsetOf(schemaValidator_object, std));
566
            assert (vobj != nullptr);
567
            schemaValidator = proc->newSchemaValidator();
568
            if(schemaValidator == nullptr){
569
                RETURN_NULL();
570
            }
571
            vobj->schemaValidator = schemaValidator;
572
        }
573
    } else {
574
       
575
        RETURN_NULL();
576
    }
577
}
578

    
579

    
580
PHP_METHOD(SaxonProcessor, version)
581
{
582
    SaxonProcessor *saxonProcessor;
583

    
584
   
585
    if (ZEND_NUM_ARGS()>0) {
586
        WRONG_PARAM_COUNT;
587
    }
588
    zend_object* pobj = Z_OBJ_P(getThis()); 
589
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
590
    saxonProcessor = obj->saxonProcessor;
591
    if (saxonProcessor != nullptr) {
592
        const char * verStr = saxonProcessor->version();
593
        //char *str = estrdup(saxonProcessor->version());
594
        _RETURN_STRING(verStr);
595
//efree(verStr);
596
    }
597
    RETURN_NULL();
598
}
599

    
600

    
601

    
602
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
603
{
604
    SaxonProcessor *saxonProcessor;
605
    char * name;
606
    char * value;
607
    size_t len1, len2;
608
    if (ZEND_NUM_ARGS()!= 2) {
609
        WRONG_PARAM_COUNT;
610
    }
611

    
612
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
613
        RETURN_NULL();
614
    }
615
    zend_object* pobj = Z_OBJ_P(getThis()); 
616
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
617

    
618
    saxonProcessor = obj->saxonProcessor;
619
    if (saxonProcessor != nullptr && name != nullptr && value != nullptr) {
620
        saxonProcessor->setConfigurationProperty(name, value);
621
    }
622
    
623
}
624

    
625

    
626
PHP_METHOD(SaxonProcessor, clearConfigurationProperty)
627
{
628
    SaxonProcessor *saxonProcessor;
629

    
630
    if (ZEND_NUM_ARGS()!= 0) {
631
        WRONG_PARAM_COUNT;
632
    }
633

    
634
    zend_object* pobj = Z_OBJ_P(getThis());
635
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
636

    
637
    saxonProcessor = obj->saxonProcessor;
638
    if (saxonProcessor != nullptr) {
639
        saxonProcessor->clearConfigurationProperty();
640
    }
641

    
642
}
643

    
644
PHP_METHOD(SaxonProcessor, registerPHPFunctions)
645
{
646
    SaxonProcessor *saxonProcessor;
647
    char * libName;
648
    size_t len1;
649
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
650
    if (ZEND_NUM_ARGS()!= 1) {
651
        WRONG_PARAM_COUNT;
652
    }
653

    
654
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &libName, &len1) == FAILURE) {
655
        RETURN_NULL();
656
    }
657
//std::cerr<<"checkpoint in registerPHPFunction cp2"<<std::endl;
658
    zend_object* pobj = Z_OBJ_P(getThis()); 
659
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
660

    
661
    saxonProcessor = obj->saxonProcessor;
662
    if (saxonProcessor != nullptr && libName != nullptr) {
663
        saxonProcessor->setConfigurationProperty("extc", libName);
664
    }
665
saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PHPFunction",
666
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
667
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
668
}
669

    
670
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
671

    
672
void XsltProcessor_free_storage(zend_object *object)
673
{
674

    
675
    zend_object_std_dtor(object);
676
}
677

    
678
void XsltProcessor_destroy_storage(zend_object *object)
679
{
680
    xsltProcessor_object *obj;
681

    
682
    zend_objects_destroy_object(object);
683
}
684

    
685
zend_object * xsltProcessor_create_handler(zend_class_entry *type)
686
{
687
   
688

    
689
    xsltProcessor_object *obj = (xsltProcessor_object *)ecalloc(1, sizeof(xsltProcessor_object)+ zend_object_properties_size(type));
690
   
691
    
692
   zend_object_std_init(&obj->std,type);
693
    object_properties_init(&obj->std, type);
694
    
695
    obj->std.handlers = &xsltProcessor_object_handlers;
696

    
697
    return &obj->std;
698
}
699

    
700

    
701

    
702
PHP_METHOD(XsltProcessor, __destruct)
703
{
704

    
705
    zend_object* pobj = Z_OBJ_P(getThis()); 
706
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
707

    
708

    
709
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
710
    if(xsltProcessor != nullptr){
711
            delete xsltProcessor;
712
     }
713
 
714
    
715
}
716

    
717
PHP_METHOD(XsltProcessor, transformFileToFile)
718
{
719
    XsltProcessor *xsltProcessor;
720
    char * outfileName;
721
    char * infilename;
722
    char * styleFileName;
723
    size_t len1, len2, len3;
724

    
725
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
726
        RETURN_NULL();
727
    }
728

    
729
    zend_object* pobj = Z_OBJ_P(getThis()); 
730
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
731
    xsltProcessor = obj->xsltProcessor;
732
 
733
    if (xsltProcessor != nullptr) {
734

    
735
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
736
        if(xsltProcessor->exceptionOccurred()) {
737
               // TODO: throw exception
738
        }
739
    }
740
}
741

    
742
PHP_METHOD(XsltProcessor, transformFileToValue)
743
{
744
    XsltProcessor *xsltProcessor;
745
    char * infilename;
746
    char * styleFileName;
747
   size_t len1, len2;
748

    
749
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
750
        RETURN_NULL();
751
    }
752

    
753
    zend_object* pobj = Z_OBJ_P(getThis()); 
754
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
755
    xsltProcessor = obj->xsltProcessor;
756
    
757
    if (xsltProcessor != nullptr) {
758

    
759
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
760
        if(node != nullptr) {
761
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
762
                RETURN_NULL();
763
            } else {
764
                zend_object *ooth =  Z_OBJ_P(return_value);
765
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
766
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
767
                assert (vobj != nullptr);
768
                vobj->xdmValue = node;
769
            }
770
        } else {
771
            if(obj->xsltProcessor->exceptionOccurred()){
772
                  //TODO
773
            }
774
        }
775
    }else {
776
        RETURN_NULL();
777
    }
778
}
779

    
780

    
781
PHP_METHOD(XsltProcessor, transformFileToString)
782
{
783
    XsltProcessor *xsltProcessor;
784
    char * infilename;
785
    char * styleFileName;
786
    size_t len1, len2;
787

    
788
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
789
        RETURN_NULL();
790
    }
791

    
792
    zend_object* pobj = Z_OBJ_P(getThis()); 
793
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
794
    xsltProcessor = obj->xsltProcessor;
795

    
796
    if (xsltProcessor != nullptr) {
797

    
798
        const char * result = xsltProcessor->transformFileToString(infilename, styleFileName);
799
        if(result != nullptr) {
800
            //char *str = estrdup(result);
801
            _RETURN_STRING(result);
802
        } else if(xsltProcessor->exceptionOccurred()){
803
            //TODO: xsltProcessor->checkException();
804
            const char * errStr = xsltProcessor->getErrorMessage();
805
            if(errStr != nullptr) {
806
                const char * errorCode = xsltProcessor->getErrorCode();
807
                if(errorCode!=nullptr) {
808
                    // TODO: throw exception
809
                }
810
            }
811
        }
812
    }
813
}
814

    
815
/*enum saxonTypeEnum
816
{
817
        enumNode,
818
        enumString,
819
        enumInteger,
820
        enumDouble,
821
        enumFloat,
822
        enumBool,
823
        enumArrXdmValue
824
};*/
825

    
826

    
827
jobject JNICALL phpNativeCall
828
        (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
829
    JNIEnv *senv = SaxonProcessor::sxn_environ->env;
830
    char *nativeString = (char *)senv->GetStringUTFChars(funcName, NULL);
831
    //std::string nativeString2 = std::string(nativeString);
832
    if(nativeString == NULL) {
833
        return NULL;
834
    }
835
    int nativeStrLen = strlen(nativeString);
836
    //std::cerr<<"phpNative called. nativeString="<<nativeString<<", length="<<nativeStrLen<<std::endl;
837
    zval function_name;
838
    zval retval;
839

    
840
    int argLength = 0;
841
    zval  *  params;
842
    if(arguments != NULL) {
843
        argLength = (int)senv->GetArrayLength(arguments);
844
        //(*params) = (zval**)malloc(sizeof(zval*) * argLength);
845
        params =  new zval[argLength];
846
    } else {
847
        params = NULL;
848
    }
849
    std::map<std::string, saxonTypeEnum> typeMap;
850
    typeMap["node"] = enumNode;
851
    typeMap["string"] = enumString;
852
    typeMap["integer"] = enumInteger;
853
    typeMap["double"] = enumDouble;
854
    typeMap["float"] = enumFloat;
855
    typeMap["boolean"] = enumBool;
856
    typeMap["[xdmvalue"] = enumArrXdmValue;
857
    sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
858

    
859
    SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
860
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
861
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
862

    
863
    for(int i=0; i<argLength;i++){
864
        jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
865
        jobject argObj = senv->GetObjectArrayElement(arguments, i);
866

    
867
        const char * str = senv->GetStringUTFChars(argType,NULL);
868
        const char *stri = NULL;
869
        double dnumber = 0;
870
        long lnumber = 0;
871
        bool bvalue = false;
872
        float fnumber = 0;
873

    
874

    
875

    
876
        struct xdmNode_object* vobj;
877
        zend_object* zend_vobj;
878
        XdmNode * node = NULL;
879
        std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
880
        if (it != typeMap.end()){
881
            switch (it->second)
882
            {
883
                case enumNode:
884
                    std::cerr<<"enumNode path - cp0 - phpNtiveCall"<<std::endl;
885
                    if(!nprocessor->proc){
886
                        nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
887
                    }
888
                    if (object_init_ex(&params[i], xdmNode_ce) != SUCCESS) {
889
                        //error
890

    
891
                        //php_error(E_WARNING,"error phpNative xdmNode creation failed");
892
                        break;
893
                    }
894
                    node = new XdmNode(argObj);
895
                    node->setProcessor(nprocessor);
896

    
897
                    //MAKE_STD_ZVAL(php_argv[i]._val);
898
                    zend_vobj = Z_OBJ_P(&params[i]);
899
                    vobj = (xdmNode_object *)((char *)zend_vobj - XtOffsetOf(xdmNode_object, std));
900
                    assert (vobj != NULL);
901

    
902
                    vobj->xdmNode = node;
903
                    break;
904
                case enumString:
905
                    //sresult->xdmvalue = argObj;
906
                    stri = stringValue(SaxonProcessor::sxn_environ, argObj);
907
                    //stri = getStringValue(SaxonProcessor::sxn_environ, *sresult);
908
                    //stri = senv->GetStringUTFChars((jstring)argObj, 0);
909
                    //ZVAL_STRING(php_argv[i]._val);
910
                    ZVAL_STRING(&params[i], stri);
911
                    break;
912
                case enumInteger:
913
                    sresult->xdmvalue = argObj;
914
                    lnumber = getLongValue(SaxonProcessor::sxn_environ, *sresult, 0);
915

    
916
                    //MAKE_STD_ZVAL(php_argv[i]._val);
917
                    ZVAL_LONG(&params[i], lnumber);
918
                    break;
919
                case enumDouble:
920
                    sresult->xdmvalue = argObj;
921
                    dnumber = getDoubleValue(SaxonProcessor::sxn_environ, *sresult, 0);                                        //MAKE_STD_ZVAL(php_argv[i]._val);
922
                    ZVAL_DOUBLE(&params[i], dnumber);
923
                    break;
924
                case enumFloat:
925
                    sresult->xdmvalue = argObj;
926
                    fnumber = getFloatValue(SaxonProcessor::sxn_environ, *sresult, 0);
927
                    //MAKE_STD_ZVAL(php_argv[i]._val);
928
                    ZVAL_DOUBLE(&params[i], fnumber);
929
                    break;
930
                case enumBool:
931
                    sresult->xdmvalue = argObj;
932
                    bvalue = getBooleanValue(SaxonProcessor::sxn_environ, *sresult);
933
                    //MAKE_STD_ZVAL(php_argv[i]._val);
934
                    ZVAL_BOOL(&params[i], bvalue);
935
                    break;
936
                case enumArrXdmValue:
937
                    //TODO - not currently supported
938
                    argLength--;
939
                    break;
940
            }
941
            senv->ReleaseStringUTFChars(argType, str);
942
        }
943

    
944
    }
945

    
946

    
947
    free(sresult);
948

    
949

    
950
    zval *argvv = NULL;
951
    zval* callOnObj = NULL;
952
    //MAKE_STD_ZVAL(function_name);
953
    //nativeString[nativeStrLen] = '\0';
954

    
955
    ZVAL_STRING(&function_name, nativeString);
956
    if(call_user_function_ex(CG(function_table), (zval*)callOnObj, &function_name, &retval, argLength, params, 0, NULL) != SUCCESS)
957
    {
958
        zend_error(E_ERROR, "Function call failed");
959
    }
960

    
961
    if(Z_TYPE(retval) ==0){
962
        zend_error(E_ERROR, "Function returned null");
963
    }
964

    
965
    char * sVal = NULL;
966
    int len = 0;
967
    jobject obj = NULL;
968
//TODO handle XdmValue wrapped object
969
    const char * objName = NULL;
970
    xdmNode_object* ooth = NULL;
971
    zend_object* zend_vobj2;
972
    bool bVal;
973
    switch (Z_TYPE_P(&retval)) {
974
        case IS_FALSE:
975
                obj= booleanValue(SaxonProcessor::sxn_environ, false);
976
                break;
977
        case IS_TRUE:
978
            obj= booleanValue(SaxonProcessor::sxn_environ, true);
979
            break;
980

    
981
        case IS_LONG:
982
            obj= longValue(SaxonProcessor::sxn_environ, Z_LVAL_P(&retval));
983
            break;
984
        case IS_STRING:
985
            sVal = Z_STRVAL_P(&retval);
986
            len = Z_STRLEN_P(&retval);
987
            obj = getJavaStringValue(SaxonProcessor::sxn_environ,estrndup(sVal, len));
988
            break;
989
            break;
990
        case IS_NULL:
991

    
992
            break;
993
        case IS_DOUBLE:
994
            obj = doubleValue(SaxonProcessor::sxn_environ, (double)Z_DVAL_P(&retval));
995
            break;
996

    
997
        case IS_ARRAY:
998
            //break;
999
        case IS_OBJECT:
1000

    
1001
            objName =ZSTR_VAL(Z_OBJCE_P(&retval)->name);
1002

    
1003

    
1004
            if(strcmp(objName, "Saxon\\XdmNode")==0) {
1005

    
1006
                zend_vobj2 =  Z_OBJ_P(&retval);
1007
                ooth = (xdmNode_object *)((char *)zend_vobj2 - XtOffsetOf(xdmNode_object, std));
1008

    
1009
                if(ooth != NULL) {
1010
                    obj = ooth->xdmNode->getUnderlyingValue();
1011
                }
1012
            }
1013
            break;
1014
        default:
1015
            obj = NULL;
1016
            zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
1017
    }
1018

    
1019
    delete nprocessor;
1020
    zval_ptr_dtor(&retval);
1021
    return obj;
1022
}
1023

    
1024

    
1025

    
1026
PHP_METHOD(XsltProcessor, transformToString)
1027
{
1028
    XsltProcessor *xsltProcessor;
1029
 
1030
    if (ZEND_NUM_ARGS()>0) {
1031
        WRONG_PARAM_COUNT;
1032
    }
1033

    
1034

    
1035
    zend_object* pobj = Z_OBJ_P(getThis()); 
1036
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1037
    xsltProcessor = obj->xsltProcessor;
1038
    if (xsltProcessor != nullptr) {
1039

    
1040
        const char * result = xsltProcessor->transformToString();
1041
        if(result != nullptr) {
1042
            _RETURN_STRING(result);
1043
        } else if(xsltProcessor->exceptionOccurred()){
1044
            xsltProcessor->checkException();
1045
            const char * errStr = xsltProcessor->getErrorMessage();
1046
            if(errStr != nullptr) {
1047
                const char * errorCode = xsltProcessor->getErrorCode();
1048
                if(errorCode!=nullptr) {
1049
                    // TODO: throw exception
1050
                }
1051
            }
1052
        }
1053
    }
1054
    RETURN_NULL();
1055
}
1056

    
1057
PHP_METHOD(XsltProcessor, transformToValue)
1058
{
1059
    XsltProcessor *xsltProcessor;
1060

    
1061
    if (ZEND_NUM_ARGS()>0) {
1062
        WRONG_PARAM_COUNT;
1063
    }
1064

    
1065
    zend_object* pobj = Z_OBJ_P(getThis()); 
1066
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1067
    xsltProcessor = obj->xsltProcessor;
1068

    
1069
    if (xsltProcessor != nullptr) {
1070

    
1071
        XdmValue * node = xsltProcessor->transformToValue();
1072
        if(node != nullptr) {
1073
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1074
                RETURN_NULL();
1075
            } else {
1076
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value);
1077
                zend_object *vvobj =  Z_OBJ_P(return_value);
1078
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1079
                assert (vobj != nullptr);
1080
                vobj->xdmValue = node;
1081
            }
1082
        } else if(xsltProcessor->exceptionOccurred()){
1083
            xsltProcessor->checkException();
1084
            RETURN_NULL();
1085
        }
1086
    } else {
1087
        RETURN_NULL();
1088
    }
1089
}
1090

    
1091
PHP_METHOD(XsltProcessor, transformToFile)
1092
{
1093
    XsltProcessor *xsltProcessor;
1094
 
1095
    if (ZEND_NUM_ARGS()>0) {
1096
        WRONG_PARAM_COUNT;
1097
    }
1098

    
1099
    zend_object* pobj = Z_OBJ_P(getThis()); 
1100
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1101
    xsltProcessor = obj->xsltProcessor;
1102

    
1103
    if (xsltProcessor != nullptr) {
1104

    
1105
        xsltProcessor->transformToFile();
1106
        if(xsltProcessor->exceptionOccurred()) {
1107
           //TODO
1108
            const char * exStr = xsltProcessor->checkException();
1109
        }
1110
    } else {
1111
        RETURN_NULL();
1112
    }
1113
}
1114

    
1115
PHP_METHOD(XsltProcessor, compileFromFile)
1116
{
1117
    XsltProcessor *xsltProcessor;
1118
    char * name;
1119
    size_t len1;
1120
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
1121
        RETURN_NULL();
1122
    }
1123
    zend_object* pobj = Z_OBJ_P(getThis()); 
1124
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1125
    xsltProcessor = obj->xsltProcessor;
1126
    if (xsltProcessor != nullptr) {
1127
        xsltProcessor->compileFromFile(name);
1128
    }
1129
}
1130

    
1131
PHP_METHOD(XsltProcessor, compileFromString)
1132
{
1133
    XsltProcessor *xsltProcessor;
1134
    char * stylesheetStr;
1135
    size_t len1, myint;
1136
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
1137
        RETURN_NULL();
1138
    }
1139
    zend_object* pobj = Z_OBJ_P(getThis()); 
1140
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1141
    xsltProcessor = obj->xsltProcessor;
1142
    if (xsltProcessor != nullptr) {
1143
        xsltProcessor->compileFromString(stylesheetStr);
1144
    }
1145
}
1146

    
1147
PHP_METHOD(XsltProcessor, compileFromStringAndSave)
1148
{
1149
    XsltProcessor *xsltProcessor;
1150
    char * stylesheetStr;
1151
    char * filename;
1152
    size_t len1, len2, myint;
1153
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetStr, &filename, &len1, &len2) == FAILURE) {
1154
        RETURN_NULL();
1155
    }
1156
    zend_object* pobj = Z_OBJ_P(getThis()); 
1157
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1158
    xsltProcessor = obj->xsltProcessor;
1159
    if (xsltProcessor != nullptr) {
1160
        xsltProcessor->compileFromStringAndSave(stylesheetStr, filename);
1161
    }
1162
}
1163

    
1164
PHP_METHOD(XsltProcessor, compileFromFileAndSave)
1165
{
1166
    XsltProcessor *xsltProcessor;
1167
    char * stylesheetFilename;
1168
    char * filename;
1169
    size_t len1, len2, myint;
1170
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, &filename, &len1, &len2) == FAILURE) {
1171
        RETURN_NULL();
1172
    }
1173
    zend_object* pobj = Z_OBJ_P(getThis()); 
1174
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1175
    xsltProcessor = obj->xsltProcessor;
1176
    if (xsltProcessor != nullptr) {
1177
        xsltProcessor->compileFromStringAndSave(stylesheetFilename, filename);
1178
    }
1179
}
1180

    
1181

    
1182

    
1183
PHP_METHOD(XsltProcessor, compileFromValue)
1184
{
1185
    XsltProcessor *xsltProcessor;
1186
   zval* oth;
1187

    
1188
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
1189
        RETURN_NULL();
1190
    }
1191
    zend_object* pobj = Z_OBJ_P(getThis()); 
1192
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1193
    xsltProcessor = obj->xsltProcessor;
1194
    if (xsltProcessor != nullptr) {
1195
        zend_object* vvobj = Z_OBJ_P(oth);
1196
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1197
        if(ooth != nullptr) {
1198
            XdmValue * value = ooth->xdmValue;
1199
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
1200
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1201
            }
1202
        }
1203
    }
1204
}
1205

    
1206

    
1207

    
1208

    
1209
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1210
{
1211
    XsltProcessor *xsltProcessor;
1212
    zval* oth = nullptr;
1213

    
1214
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1215
        RETURN_NULL();
1216
    }
1217

    
1218
    zend_object* pobj = Z_OBJ_P(getThis()); 
1219
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1220
    xsltProcessor = obj->xsltProcessor;
1221
    if (xsltProcessor != nullptr) {
1222

    
1223
    if(!oth) {
1224
        php_error(E_WARNING, "Error setting source value");
1225
        return;
1226
    } else {
1227
        if(Z_TYPE_P(oth) ==IS_NULL){
1228
                php_error(E_WARNING, "Error setting source value");
1229
                return;
1230
        }
1231
        
1232
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1233
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1234

    
1235
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1236
        zend_object * nobj = Z_OBJ_P(oth);
1237

    
1238
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1239
        if(ooth != nullptr) {
1240
            XdmNode * value = ooth->xdmNode;
1241
            if(value != nullptr) {
1242
                
1243
                xsltProcessor->setSourceFromXdmNode(value);
1244

    
1245
            }
1246
        }
1247
      } /*else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1248
        zend_object* vvobj = Z_OBJ_P(oth);
1249
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1250
        if(ooth != nullptr) {
1251
            XdmValue * value = ooth->xdmValue;
1252
            if(value != nullptr && value) {
1253
                xsltProcessor->setSourceFromXdmNode((XdmNode*)value);
1254
            }
1255
        }
1256
      }  */
1257

    
1258
        
1259
    }
1260
  }
1261
}
1262

    
1263

    
1264
PHP_METHOD(XsltProcessor, setJustInTimeCompilation)
1265
{
1266
    XsltProcessor *xsltProcessor;
1267
    bool jit = false;
1268
    size_t len1;
1269

    
1270
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
1271
        RETURN_NULL();
1272
    }
1273

    
1274
    zend_object* pobj = Z_OBJ_P(getThis());
1275
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1276
    xsltProcessor = obj->xsltProcessor;
1277
    if (xsltProcessor != nullptr) {
1278
         xsltProcessor->setJustInTimeCompilation(jit);
1279
    }
1280
}
1281

    
1282
PHP_METHOD(XsltProcessor, setOutputFile)
1283
{
1284
    XsltProcessor *xsltProcessor;
1285
    char * outputFilename;
1286
    size_t len1;
1287

    
1288
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
1289
        RETURN_NULL();
1290
    }
1291

    
1292
    zend_object* pobj = Z_OBJ_P(getThis()); 
1293
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1294
    xsltProcessor = obj->xsltProcessor;
1295
    if (xsltProcessor != nullptr && outputFilename != nullptr) {
1296
        
1297
         xsltProcessor->setOutputFile(outputFilename);
1298
            
1299
        
1300
    }
1301
}
1302

    
1303

    
1304
PHP_METHOD(XsltProcessor, setBaseOutputURI)
1305
{
1306
    XsltProcessor *xsltProcessor;
1307
    char * baseOutputURI = nullptr;
1308
    size_t len1;
1309

    
1310
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &len1) == FAILURE) {
1311
        RETURN_NULL();
1312
    }
1313

    
1314
    zend_object* pobj = Z_OBJ_P(getThis());
1315
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1316
    xsltProcessor = obj->xsltProcessor;
1317
    if (xsltProcessor != nullptr && baseOutputURI != nullptr) {
1318

    
1319
         xsltProcessor->setBaseOutputURI(baseOutputURI);
1320

    
1321

    
1322
    }
1323
}
1324

    
1325

    
1326
int size_t2int(size_t val) {
1327
    return (val <= INT_MAX) ? (int)((ssize_t)val) : -1;
1328
}
1329

    
1330
PHP_METHOD(XsltProcessor, setSourceFromFile)
1331
{
1332
    XsltProcessor *xsltProcessor;
1333
    char * inFilename;
1334
    size_t len1;
1335
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
1336
        RETURN_NULL();
1337
    }
1338

    
1339
    zend_object* pobj = Z_OBJ_P(getThis()); 
1340
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1341
    xsltProcessor = obj->xsltProcessor;
1342
    if (xsltProcessor != nullptr && inFilename != nullptr) {
1343
         xsltProcessor->setSourceFromFile(inFilename);
1344
            
1345
        
1346
    }
1347
}
1348

    
1349

    
1350
PHP_METHOD(XsltProcessor, setProperty)
1351
{
1352
    XsltProcessor *xsltProcessor;
1353
    char * name;
1354
    char * value;
1355
    size_t len1, len2, myint;
1356

    
1357
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
1358
        RETURN_NULL();
1359
    }
1360
    zend_object* pobj = Z_OBJ_P(getThis()); 
1361
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1362
    xsltProcessor = obj->xsltProcessor;
1363
    if (xsltProcessor != nullptr) {
1364
        xsltProcessor->setProperty(name, value);
1365
    }
1366
}
1367

    
1368
PHP_METHOD(XsltProcessor, setParameter)
1369
{
1370

    
1371
   XsltProcessor *xsltProcessor;
1372
   char * name;
1373
   zval* oth;
1374
   size_t len1, len2, myint;        
1375
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1376
        RETURN_NULL();
1377
    }
1378
    zend_object* pobj = Z_OBJ_P(getThis()); 
1379
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1380
    xsltProcessor = obj->xsltProcessor;
1381
    if (xsltProcessor != nullptr) {
1382
        if(Z_TYPE_P(oth) ==IS_NULL){
1383
                php_error(E_WARNING, "Error setting source value - value is nullptr");
1384
                return;
1385
        }
1386

    
1387
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1388
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1389

    
1390
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1391
        zend_object* ooth = Z_OBJ_P(oth);
1392
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1393
        if(nobj != nullptr) {
1394
            XdmNode * value = nobj->xdmNode;
1395
            if(value != nullptr) {
1396
                xsltProcessor->setParameter(name, (XdmValue *)value);
1397

    
1398
            }
1399
        }
1400
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1401
        zend_object* ooth = Z_OBJ_P(oth);
1402
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1403
        if(vobj != nullptr) {
1404
            XdmValue * value = vobj->xdmValue;
1405
            if(value != nullptr) {
1406
                
1407
                xsltProcessor->setParameter(name, value);
1408
            }
1409
        }
1410

    
1411

    
1412

    
1413
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1414
        zend_object* ooth = Z_OBJ_P(oth);
1415
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1416
        if(aobj != nullptr) {
1417
            XdmAtomicValue * value = aobj->xdmAtomicValue;
1418
            if(value != nullptr) {
1419
                xsltProcessor->setParameter(name, (XdmValue *)value);
1420
            }
1421
        }
1422

    
1423

    
1424

    
1425
      }
1426

    
1427
    }
1428
}
1429

    
1430
PHP_METHOD(XsltProcessor, clearParameters)
1431
{
1432
    XsltProcessor *xsltProcessor;
1433
    if (ZEND_NUM_ARGS()>0) {
1434
        WRONG_PARAM_COUNT;
1435
    }
1436

    
1437
    zend_object* pobj = Z_OBJ_P(getThis()); 
1438
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1439
    xsltProcessor = obj->xsltProcessor;
1440
    if (xsltProcessor != nullptr) {
1441
        xsltProcessor->clearParameters(true);
1442
    }
1443
}
1444

    
1445
PHP_METHOD(XsltProcessor, clearProperties)
1446
{
1447
    XsltProcessor *xsltProcessor;
1448
    if (ZEND_NUM_ARGS()>0) {
1449
        WRONG_PARAM_COUNT;
1450
    }
1451

    
1452
    zend_object* pobj = Z_OBJ_P(getThis()); 
1453
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1454
    xsltProcessor = obj->xsltProcessor;
1455
    if (xsltProcessor != nullptr) {
1456
        xsltProcessor->clearProperties();
1457
    }
1458
}
1459

    
1460

    
1461

    
1462
PHP_METHOD(XsltProcessor, setupXslMessage)
1463
{
1464
    XsltProcessor *xsltProcessor;
1465
    bool show = false;
1466
    char * filename = nullptr;
1467
    size_t len1;
1468
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename,  &len1) == FAILURE) {
1469
        RETURN_NULL();
1470
    }
1471

    
1472
    zend_object* pobj = Z_OBJ_P(getThis());
1473
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1474
    xsltProcessor = obj->xsltProcessor;
1475

    
1476
    if (xsltProcessor != nullptr) {
1477

    
1478
            xsltProcessor->setupXslMessage(show, filename);
1479
        }
1480

    
1481
}
1482

    
1483

    
1484

    
1485
PHP_METHOD(XsltProcessor, exceptionOccurred)
1486
{
1487
    XsltProcessor *xsltProcessor;
1488
    zend_object* pobj = Z_OBJ_P(getThis()); 
1489
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1490
    if (ZEND_NUM_ARGS()>0) {
1491
        WRONG_PARAM_COUNT;
1492
    }
1493

    
1494
    xsltProcessor = obj->xsltProcessor;
1495
    if (xsltProcessor != nullptr) {
1496
        bool result = xsltProcessor->exceptionOccurred();
1497
        RETURN_BOOL(result);
1498
    }
1499
    RETURN_BOOL(false);
1500
}
1501

    
1502

    
1503

    
1504
PHP_METHOD(XsltProcessor, getErrorCode)
1505
{
1506
    XsltProcessor *xsltProcessor;
1507
    if (ZEND_NUM_ARGS()>0) {
1508
        WRONG_PARAM_COUNT;
1509
    }
1510
    zend_object* pobj = Z_OBJ_P(getThis()); 
1511
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1512
    xsltProcessor = obj->xsltProcessor;
1513
    if (xsltProcessor != nullptr) {
1514
        const char * errCode = xsltProcessor->getErrorCode();
1515
        if(errCode != nullptr) {
1516
            //char *str = estrdup(errCode);
1517
            _RETURN_STRING(errCode);
1518
        }
1519
    }
1520
    RETURN_NULL();
1521
}
1522

    
1523
PHP_METHOD(XsltProcessor, getErrorMessage)
1524
{
1525
    XsltProcessor *xsltProcessor;
1526
    long index;
1527
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1528
        RETURN_NULL();
1529
    }
1530
    zend_object* pobj = Z_OBJ_P(getThis()); 
1531
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1532
    xsltProcessor = obj->xsltProcessor;
1533
    if (xsltProcessor != nullptr) {
1534
        const char * errStr = xsltProcessor->getErrorMessage();
1535
        if(errStr != nullptr) {
1536
            //char *str = estrdup(errStr);
1537
            _RETURN_STRING(errStr);
1538
        }
1539
    }
1540
    RETURN_NULL();
1541
}
1542
PHP_METHOD(XsltProcessor, exceptionClear)
1543
{
1544
    XsltProcessor *xsltProcessor;
1545
    zend_object* pobj = Z_OBJ_P(getThis()); 
1546
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1547
    xsltProcessor = obj->xsltProcessor;
1548
    if (xsltProcessor != nullptr) {
1549
        xsltProcessor->exceptionClear();
1550
    }
1551
}
1552

    
1553

    
1554

    
1555
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
1556

    
1557
void xqueryProcessor_free_storage(zend_object *object)
1558
{
1559
    zend_object_std_dtor(object);
1560
}
1561

    
1562
void xqueryProcessor_destroy_storage(zend_object *object)
1563
{
1564
    zend_objects_destroy_object(object);
1565
}
1566

    
1567
zend_object *xqueryProcessor_create_handler(zend_class_entry *type)
1568
{
1569

    
1570
    xqueryProcessor_object *obj = (xqueryProcessor_object *)ecalloc(1, sizeof(xqueryProcessor_object)+ zend_object_properties_size(type));
1571
    zend_object_std_init(&obj->std, type); 
1572
    object_properties_init(&obj->std, type);
1573
    obj->std.handlers = &xqueryProcessor_object_handlers;
1574

    
1575
    return &obj->std;
1576
}
1577

    
1578
PHP_METHOD(XQueryProcessor, __destruct)
1579
{
1580
    zend_object* pobj = Z_OBJ_P(getThis());
1581
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1582
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
1583
    if(xqueryProcessor != nullptr){
1584
            delete xqueryProcessor;
1585
    }
1586
}
1587

    
1588

    
1589
PHP_METHOD(XQueryProcessor, runQueryToValue)
1590
{
1591
    XQueryProcessor *xqueryProcessor;
1592
    zend_object* pobj = Z_OBJ_P(getThis()); 
1593
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1594

    
1595
    if (ZEND_NUM_ARGS()>0) {
1596
        WRONG_PARAM_COUNT;
1597
    }
1598

    
1599
    xqueryProcessor = obj->xqueryProcessor;
1600

    
1601
    if (xqueryProcessor != nullptr) {
1602
        XdmValue * node = xqueryProcessor->runQueryToValue();
1603
        if(node != nullptr) {
1604
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1605
                RETURN_NULL();
1606
                return;
1607
            } else {
1608
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
1609
                zend_object *vvobj =  Z_OBJ_P(return_value);
1610
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1611
                assert (vobj != nullptr);
1612
                vobj->xdmValue = node;
1613
                return;
1614
            }
1615
        }
1616
        xqueryProcessor->checkException();//TODO
1617
    } else {
1618
        RETURN_NULL();
1619
    }
1620
}
1621

    
1622
PHP_METHOD(XQueryProcessor, runQueryToString)
1623
{
1624
    XQueryProcessor *xqueryProcessor;
1625
   
1626

    
1627
    if (ZEND_NUM_ARGS()>0) {
1628
        WRONG_PARAM_COUNT;
1629
    }
1630
    zend_object* pobj = Z_OBJ_P(getThis()); 
1631
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1632
    xqueryProcessor = obj->xqueryProcessor;
1633

    
1634
    if (xqueryProcessor != nullptr) {
1635
        const char * result = xqueryProcessor->runQueryToString();
1636
        if(result != nullptr) {
1637
            //char *str = estrdup(result);
1638
            _RETURN_STRING(result);
1639
            return;
1640
        } else {
1641
          xqueryProcessor->checkException(); //TODO
1642
        }
1643
    }
1644
   RETURN_NULL();
1645
}
1646

    
1647
PHP_METHOD(XQueryProcessor, runQueryToFile)
1648
{
1649

    
1650
     char * ofilename;
1651
    size_t len1 =0;
1652
    if (ZEND_NUM_ARGS()!= 1) {
1653
        WRONG_PARAM_COUNT;
1654
    }
1655
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &ofilename, &len1) == FAILURE) {
1656
        RETURN_NULL();
1657
    }
1658
    XQueryProcessor *xqueryProcessor;
1659
    zend_object* pobj = Z_OBJ_P(getThis()); 
1660
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1661

    
1662

    
1663

    
1664
    xqueryProcessor = obj->xqueryProcessor;
1665

    
1666
    if (xqueryProcessor != nullptr) {
1667
        if(ofilename != nullptr) {
1668
                xqueryProcessor->setOutputFile(ofilename);        
1669
        }
1670
        xqueryProcessor->runQueryToFile(); 
1671
    }
1672

    
1673
}
1674

    
1675
PHP_METHOD(XQueryProcessor, setQueryContent)
1676
{
1677
    char * queryStr;
1678
    size_t len1;
1679

    
1680
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &queryStr, &len1) == FAILURE) {
1681
        RETURN_NULL();
1682
    }
1683
    zend_object* pobj = Z_OBJ_P(getThis()); 
1684
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std)); 
1685
    if(queryStr != nullptr) {
1686
      obj->xqueryProcessor->setProperty("qs", queryStr);
1687
   }
1688
}
1689

    
1690
PHP_METHOD(XQueryProcessor, setQueryFile)
1691
{
1692
   char * fileName;
1693
   size_t len1;
1694
    XQueryProcessor *xqueryProcessor;
1695

    
1696
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fileName, &len1) == FAILURE) {
1697
        RETURN_NULL();
1698
    }
1699
    if(fileName != nullptr) {
1700
            zend_object* pobj = Z_OBJ_P(getThis()); 
1701
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1702
            xqueryProcessor = obj->xqueryProcessor;
1703
            xqueryProcessor->setQueryFile(fileName);
1704
    }
1705
            
1706
}
1707

    
1708
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
1709
{
1710
   char * base;
1711
   size_t len1;
1712
    XQueryProcessor *xqueryProcessor;
1713

    
1714
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &base, &len1) == FAILURE) {
1715
        RETURN_NULL();
1716
    }
1717
    if(base != nullptr) {
1718
            zend_object* pobj = Z_OBJ_P(getThis()); 
1719
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1720
            xqueryProcessor = obj->xqueryProcessor;
1721
            xqueryProcessor->setQueryBaseURI(base);
1722
    }
1723
            
1724
}
1725

    
1726
PHP_METHOD(XQueryProcessor, declareNamespace)
1727
{
1728
   char * prefix;
1729
   char * ns;
1730
   size_t len1, len2;
1731
    XQueryProcessor *xqueryProcessor;
1732

    
1733
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
1734
        RETURN_NULL();
1735
    }
1736
    if(prefix != nullptr && ns != nullptr) {
1737
            zend_object* pobj = Z_OBJ_P(getThis()); 
1738
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1739
            xqueryProcessor = obj->xqueryProcessor;
1740
            xqueryProcessor->declareNamespace(prefix, ns);
1741
    }
1742
            
1743
}
1744

    
1745

    
1746

    
1747
PHP_METHOD(XQueryProcessor, setContextItem)
1748
{
1749
   char * context;
1750
   int len1;
1751
   zval* oth;
1752
    XQueryProcessor *xqueryProcessor;
1753

    
1754
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &oth) == FAILURE) {
1755
        RETURN_NULL();
1756
    }
1757
    if(oth != nullptr) {
1758
            zend_object* pobj = Z_OBJ_P(getThis()); 
1759
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1760
            xqueryProcessor = obj->xqueryProcessor;
1761
    const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name); 
1762
        
1763
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1764
        zend_object *vvobj =  Z_OBJ_P(oth);
1765
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
1766
        //xdmNode_object* ooth = (xdmNode_object*)Z_OBJ_P(oth TSRMLS_CC);
1767
        if(ooth != nullptr) {
1768
            XdmNode * value = ooth->xdmNode;
1769
            if(value != nullptr) {
1770
                xqueryProcessor->setContextItem((XdmItem *)value);
1771
               
1772
                return;
1773
            }
1774
        }
1775
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
1776
        zend_object *vvobj =  Z_OBJ_P(oth);
1777
        xdmItem_object* ooth  = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
1778
        if(ooth != nullptr) {
1779
            XdmItem * value = ooth->xdmItem;
1780
            if(value != nullptr) {
1781
                xqueryProcessor->setContextItem(value);
1782
               
1783
                return;
1784
            }
1785
         }
1786
        
1787

    
1788

    
1789

    
1790
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1791
        zend_object *vvobj =  Z_OBJ_P(oth);
1792
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
1793
        if(ooth != nullptr) {
1794
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1795
            if(value != nullptr) {
1796
                
1797
                xqueryProcessor->setContextItem((XdmItem *)value);
1798
      
1799
                return;
1800
            }
1801
        }
1802

    
1803

    
1804

    
1805
      } 
1806

    
1807

    
1808
    }
1809
        //throw exception
1810
        
1811
            
1812
}
1813

    
1814
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
1815
{
1816
   char * cfilename;
1817
   size_t len1;
1818
    XQueryProcessor *xqueryProcessor;
1819

    
1820
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &cfilename, &len1) == FAILURE) {
1821
        RETURN_NULL();
1822
    }
1823
    if(cfilename != nullptr) {
1824
             zend_object* pobj = Z_OBJ_P(getThis()); 
1825
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1826
            xqueryProcessor = obj->xqueryProcessor;
1827
            xqueryProcessor->setContextItemFromFile(cfilename);
1828
    }
1829
            
1830
}
1831

    
1832

    
1833
PHP_METHOD(XQueryProcessor, setProperty)
1834
{
1835
    XQueryProcessor *xqueryProcessor;
1836
    char * name;
1837
    char * value;
1838
    size_t len1, len2, myint;
1839

    
1840
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
1841
        RETURN_NULL();
1842
    }
1843
    zend_object* pobj = Z_OBJ_P(getThis()); 
1844
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1845
    xqueryProcessor = obj->xqueryProcessor;
1846
    if (xqueryProcessor != nullptr) {
1847
        xqueryProcessor->setProperty(name, value);
1848
    }
1849
}
1850

    
1851
PHP_METHOD(XQueryProcessor, setParameter)
1852
{
1853

    
1854
   XQueryProcessor *xqueryProcessor;
1855
   char * name;
1856
   zval* oth;
1857
   size_t len1, len2, myint;        
1858
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1859
        RETURN_NULL();
1860
    }
1861
    zend_object* pobj = Z_OBJ_P(getThis()); 
1862
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1863
    xqueryProcessor = obj->xqueryProcessor;
1864
    if (xqueryProcessor != nullptr) {
1865
        if(Z_TYPE_P(oth) ==IS_NULL){
1866
                php_error(E_WARNING, "Error setting source value - value is nullptr");
1867
                return;
1868
        }
1869
             const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1870
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1871
//Z_ADDREF_P(oth);
1872
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1873
        zend_object *vvobj =  Z_OBJ_P(oth);
1874
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
1875
        if(ooth != nullptr) {
1876
            XdmNode * value = ooth->xdmNode;
1877
            if(value != nullptr) {
1878
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1879

    
1880
            }
1881
        }
1882
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1883
        zend_object *vvobj =  Z_OBJ_P(oth);
1884
        xdmValue_object* ooth  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1885
        if(ooth != nullptr) {
1886
            XdmValue * value = ooth->xdmValue;
1887
            if(value != nullptr) {
1888
                
1889
                xqueryProcessor->setParameter(name, value);
1890
            }
1891
        }
1892

    
1893

    
1894

    
1895
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1896
        zend_object *vvobj =  Z_OBJ_P(oth);
1897
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
1898
        if(ooth != nullptr) {
1899
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1900
            if(value != nullptr) {
1901
                
1902
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1903
            } 
1904
        }
1905

    
1906

    
1907

    
1908
      }
1909

    
1910
    }
1911
}
1912

    
1913

    
1914

    
1915

    
1916
PHP_METHOD(XQueryProcessor, clearParameters)
1917
{
1918
    XQueryProcessor *xqueryProcessor;
1919
    if (ZEND_NUM_ARGS()>0) {
1920
        WRONG_PARAM_COUNT;
1921
    }
1922

    
1923
    zend_object* pobj = Z_OBJ_P(getThis()); 
1924
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1925
    xqueryProcessor = obj->xqueryProcessor;
1926
    if (xqueryProcessor != nullptr) {
1927
        xqueryProcessor->clearParameters(true);
1928
    }
1929
}
1930

    
1931
PHP_METHOD(XQueryProcessor, clearProperties)
1932
{
1933
    XQueryProcessor *xqueryProcessor;
1934

    
1935
    if (ZEND_NUM_ARGS()>0) {
1936
        WRONG_PARAM_COUNT;
1937
    }
1938

    
1939
    zend_object* pobj = Z_OBJ_P(getThis()); 
1940
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1941
    xqueryProcessor = obj->xqueryProcessor;
1942
    if (xqueryProcessor != nullptr) {
1943
        xqueryProcessor->clearProperties();
1944
    }
1945
}
1946

    
1947
PHP_METHOD(XQueryProcessor, exceptionOccurred)
1948
{
1949
    XQueryProcessor *xqueryProcessor;
1950
    zend_object* pobj = Z_OBJ_P(getThis()); 
1951
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1952
    if (ZEND_NUM_ARGS()>0) {
1953
        WRONG_PARAM_COUNT;
1954
    }
1955

    
1956
    xqueryProcessor = obj->xqueryProcessor;
1957
    if (xqueryProcessor != nullptr) {
1958
        bool result = xqueryProcessor->exceptionOccurred();
1959
        RETURN_BOOL(result);
1960
    }
1961
    RETURN_BOOL(false);
1962
}
1963

    
1964

    
1965
PHP_METHOD(XQueryProcessor, getErrorCode)
1966
{
1967
    XQueryProcessor *xqueryProcessor;
1968
    if (ZEND_NUM_ARGS()>0) {
1969
        WRONG_PARAM_COUNT;
1970
    }
1971
    zend_object* pobj = Z_OBJ_P(getThis()); 
1972
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1973
    xqueryProcessor = obj->xqueryProcessor;
1974
    if (xqueryProcessor != nullptr) {
1975
        const char * errCode = xqueryProcessor->getErrorCode();
1976
        if(errCode != nullptr) {
1977
            //char *str = estrdup(errCode);
1978
            _RETURN_STRING(errCode);
1979
        }
1980
    }
1981
    RETURN_NULL();
1982
}
1983

    
1984
PHP_METHOD(XQueryProcessor, getErrorMessage)
1985
{
1986
    XQueryProcessor *xqueryProcessor;
1987
    long index;
1988
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1989
        RETURN_NULL();
1990
    }
1991
    zend_object* pobj = Z_OBJ_P(getThis()); 
1992
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1993
    xqueryProcessor = obj->xqueryProcessor;
1994
    if (xqueryProcessor != nullptr) {
1995
        const char * errStr = xqueryProcessor->getErrorMessage();
1996
        if(errStr != nullptr) {
1997
            //char *str = estrdup(errStr);
1998
            _RETURN_STRING(errStr);
1999
        }
2000
    }
2001
    RETURN_NULL();
2002
}
2003
PHP_METHOD(XQueryProcessor, exceptionClear)
2004
{
2005
    XQueryProcessor *xqueryProcessor;
2006
    zend_object* pobj = Z_OBJ_P(getThis()); 
2007
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
2008
    xqueryProcessor = obj->xqueryProcessor;
2009
    if (xqueryProcessor != nullptr) {
2010
        xqueryProcessor->exceptionClear();
2011
    }
2012
}
2013

    
2014
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
2015

    
2016
void xpathProcessor_free_storage(zend_object *object)
2017
{
2018
    zend_object_std_dtor(object);
2019
}
2020

    
2021
void xpathProcessor_destroy_storage(zend_object *object)
2022
{
2023
    zend_objects_destroy_object(object);
2024
}
2025

    
2026
PHP_METHOD(XPathProcessor, __destruct)
2027
{
2028

    
2029
   zend_object* pobj = Z_OBJ_P(getThis()); 
2030
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2031

    
2032

    
2033
   XPathProcessor * xpathProc= obj->xpathProcessor;
2034
    if(xpathProc != nullptr){
2035
            delete xpathProc;
2036
     }
2037

    
2038
   
2039
    
2040
}
2041

    
2042
zend_object *xpathProcessor_create_handler(zend_class_entry *type)
2043
{
2044
    xpathProcessor_object *obj = (xpathProcessor_object *)ecalloc(1, sizeof(xpathProcessor_object)+ zend_object_properties_size(type));
2045
    
2046
    zend_object_std_init(&obj->std, type); 
2047
    
2048
    object_properties_init(&obj->std, type);
2049
    
2050
    obj->std.handlers = &xpathProcessor_object_handlers;
2051

    
2052
    return &obj->std;
2053
}
2054

    
2055

    
2056

    
2057
PHP_METHOD(XPathProcessor, setProperty)
2058
{
2059
    XPathProcessor *xpathProcessor;
2060
    char * name;
2061
    char * value;
2062
    size_t len1, len2;
2063

    
2064
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
2065
        RETURN_NULL();
2066
    }
2067
    zend_object* pobj = Z_OBJ_P(getThis()); 
2068
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2069
    xpathProcessor = obj->xpathProcessor;
2070
    if (xpathProcessor != nullptr) {
2071
        xpathProcessor->setProperty(name, value);
2072
    }
2073
}
2074

    
2075
PHP_METHOD(XPathProcessor, setParameter)
2076
{
2077

    
2078
   XPathProcessor *xpathProcessor;
2079
   char * name;
2080
   zval* oth;
2081
   size_t len1, len2;        
2082
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name, &len2, &oth) == FAILURE) {
2083
        RETURN_NULL();
2084
    }
2085
    zend_object* pobj = Z_OBJ_P(getThis()); 
2086
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2087
    xpathProcessor = obj->xpathProcessor;
2088
    if (xpathProcessor != nullptr) {
2089
            const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2090
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2091

    
2092
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2093
        
2094
        zend_object* vvobj = Z_OBJ_P(oth);
2095
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2096
        if(ooth != nullptr) {
2097
            XdmNode * value = ooth->xdmNode;
2098
            if(value != nullptr) {
2099
                xpathProcessor->setParameter(name, (XdmValue *)value);
2100

    
2101
            }
2102
        }
2103
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2104
        
2105
        zend_object* vvobj = Z_OBJ_P(oth);
2106
        xdmValue_object * ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2107
        if(ooth != nullptr) {
2108
            XdmValue * value = ooth->xdmValue;
2109
            if(value != nullptr) {
2110
                
2111
                xpathProcessor->setParameter(name, value);
2112
            }
2113
        }
2114

    
2115

    
2116

    
2117
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2118
        
2119
        zend_object* vvobj = Z_OBJ_P(oth);
2120
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2121
        if(ooth != nullptr) {
2122
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2123
            if(value != nullptr) {
2124
                
2125
                xpathProcessor->setParameter(name, (XdmValue *)value);
2126
            }
2127
        }
2128

    
2129

    
2130

    
2131
      }
2132

    
2133
    }
2134
}
2135

    
2136
PHP_METHOD(XPathProcessor, declareNamespace)
2137
{
2138
   char * prefix;
2139
   char * ns;
2140
   int len1, len2;
2141
   XPathProcessor *xpathProcessor;
2142

    
2143
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
2144
        RETURN_NULL();
2145
    }
2146
    if(prefix != nullptr && ns != nullptr) {
2147
            zend_object* pobj = Z_OBJ_P(getThis()); 
2148
        xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2149
            xpathProcessor = obj->xpathProcessor;
2150
            xpathProcessor->declareNamespace(prefix, ns);
2151
    }
2152
            
2153
}
2154

    
2155

    
2156

    
2157
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
2158

    
2159
    XPathProcessor *xpathProcessor;
2160
    bool allow = false;
2161
    size_t len1;
2162

    
2163
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &allow) == FAILURE) {
2164
        RETURN_NULL();
2165
    }
2166

    
2167
    zend_object* pobj = Z_OBJ_P(getThis());
2168
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2169
    xpathProcessor = obj->xpathProcessor;
2170
    if (xpathProcessor != nullptr) {
2171
            xpathProcessor->setBackwardsCompatible(allow);
2172
         }
2173
}
2174

    
2175
PHP_METHOD(XPathProcessor, setCaching){
2176
    XPathProcessor *xpathProcessor;
2177
    bool isCaching = false;
2178
    size_t len1;
2179

    
2180
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &isCaching) == FAILURE) {
2181
        RETURN_NULL();
2182
    }
2183

    
2184
    zend_object* pobj = Z_OBJ_P(getThis());
2185
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2186
    xpathProcessor = obj->xpathProcessor;
2187
    if (xpathProcessor != nullptr) {
2188
            xpathProcessor->setCaching(isCaching);
2189
         }
2190
}
2191

    
2192
PHP_METHOD(XPathProcessor, importSchemaNamespace){
2193
      char * name;
2194
      int len1;
2195
      XPathProcessor *xpathProcessor;
2196

    
2197
       if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2198
           RETURN_NULL();
2199
       }
2200
       if(name != nullptr) {
2201
               zend_object* pobj = Z_OBJ_P(getThis());
2202
           xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2203
               xpathProcessor = obj->xpathProcessor;
2204
               xpathProcessor->importSchemaNamespace(name);
2205
       }
2206
}
2207

    
2208
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
2209
{
2210

    
2211
   XPathProcessor *xpathProcessor;
2212
   char * xpathStr;
2213
   zval* oth;
2214
   size_t len1, myint;        
2215
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &xpathStr, &len1) == FAILURE) {
2216
        RETURN_NULL();
2217
    }
2218
    zend_object* pobj = Z_OBJ_P(getThis()); 
2219
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2220
    xpathProcessor = obj->xpathProcessor;
2221
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
2222
        
2223
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
2224
                RETURN_BOOL(result);
2225
    }
2226
}
2227

    
2228
PHP_METHOD(XPathProcessor, evaluate)
2229
{
2230

    
2231
   XPathProcessor *xpathProcessor;
2232
   char * xpathStr;
2233
   zval* oth;
2234
   size_t len1, myint;        
2235
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
2236
        RETURN_NULL();
2237
    }
2238
    zend_object* pobj = Z_OBJ_P(getThis()); 
2239
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2240
    xpathProcessor = obj->xpathProcessor;
2241
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
2242
        
2243
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
2244
        if(node != nullptr) {
2245
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2246
                RETURN_NULL();
2247
                return;
2248
            } else {
2249
                zend_object* vvobj = Z_OBJ_P(return_value);
2250
                        
2251
                if(node->getType() == XDM_NODE) {
2252
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2253
                                assert (vobj != nullptr);
2254
                                  vobj->xdmNode = (XdmNode *)node;
2255
                        return;
2256

    
2257
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
2258
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2259
                assert (vobj != nullptr);
2260
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
2261
                return;
2262

    
2263
                } else {
2264
                  xdmValue_object * vobj = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2265
                  assert (vobj != nullptr);
2266
                  vobj->xdmValue = node;
2267
                  return;
2268
                }
2269
            }
2270
        }
2271
       // xpathProcessor->checkException();//TODO
2272
    } 
2273
    RETURN_NULL();
2274
    
2275
}
2276

    
2277
PHP_METHOD(XPathProcessor, evaluateSingle)
2278
{
2279

    
2280
   XPathProcessor *xpathProcessor;
2281
   char * xpathStr;
2282
   zval* oth;
2283
   size_t len1, myint;        
2284
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
2285
        RETURN_NULL();
2286
    }
2287
    zend_object* pobj = Z_OBJ_P(getThis()); 
2288
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2289
    xpathProcessor = obj->xpathProcessor;
2290

    
2291
    if(xpathStr == nullptr) {
2292
        RETURN_NULL();
2293
        return;
2294
        }
2295

    
2296

    
2297
    if (xpathProcessor != nullptr) {
2298
        
2299
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
2300
        if(node != nullptr) {
2301
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2302
                RETURN_NULL();
2303
                return;
2304
            } else {
2305
                //struct xdmItem_object* vobj = (struct xdmItem_object *)Z_OBJ_P(return_value TSRMLS_CC);
2306
                zend_object* vvobj = Z_OBJ_P(return_value);
2307
                if(node->getType() == XDM_NODE) {
2308
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2309
                        assert (vobj != nullptr);
2310
                        vobj->xdmNode = (XdmNode *)node;
2311
                        return;
2312

    
2313
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
2314

    
2315
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2316
                assert (vobj != nullptr);
2317
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
2318
                return;
2319

    
2320
                } else {
2321
                        xdmItem_object * vobj = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
2322
                        assert (vobj != nullptr);
2323
                        vobj->xdmItem = node;
2324
                        return;
2325
                }
2326
            }
2327
        } 
2328
       // xpathProcessor->checkException();//TODO
2329
    } 
2330
    RETURN_NULL();
2331
}
2332

    
2333
PHP_METHOD(XPathProcessor, setContextItem)
2334
{
2335

    
2336
   XPathProcessor *xpathProcessor;
2337

    
2338
   zval* oth;
2339
        //TODO this should be relaxed to accept item/atomic/node as well as Value
2340

    
2341
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2342
        RETURN_NULL();
2343
    }
2344
    zend_object* pobj = Z_OBJ_P(getThis()); 
2345
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2346
    xpathProcessor = obj->xpathProcessor;
2347
    if (xpathProcessor != nullptr) {
2348
        if(!oth) {
2349
                php_error(E_WARNING, "Error setting source value");
2350
                return;
2351
         } 
2352
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2353
        
2354
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
2355
        zend_object* vvobj = Z_OBJ_P(oth);
2356
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2357
        if(ooth != nullptr) {
2358
            XdmNode * value = ooth->xdmNode;
2359
            if(value != nullptr) {
2360
                xpathProcessor->setContextItem((XdmItem *)value);
2361
                value->incrementRefCount();
2362

    
2363
            }
2364
        }
2365
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2366
        zend_object* vvobj = Z_OBJ_P(oth);
2367
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2368
        if(ooth != nullptr) {
2369
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2370
            if(value != nullptr) {
2371
                
2372
                xpathProcessor->setContextItem((XdmItem *)value);
2373
                value->incrementRefCount();
2374
            }
2375
        }
2376
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
2377
        zend_object* vvobj = Z_OBJ_P(oth);
2378
        xdmItem_object * ooth = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
2379
        if(ooth != nullptr) {
2380
            XdmItem * value = ooth->xdmItem;
2381
            if(value != nullptr) {
2382
                
2383
                xpathProcessor->setContextItem(value);
2384
                value->incrementRefCount();
2385
            }
2386
        }
2387

    
2388
      }
2389
    }
2390
}
2391

    
2392
PHP_METHOD(XPathProcessor, setBaseURI)
2393
{
2394

    
2395
   XPathProcessor *xpathProcessor;
2396

    
2397
   char * uriStr;
2398
   size_t len1;
2399
        
2400
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &uriStr, &len1) == FAILURE) {
2401
        RETURN_NULL();
2402
    }
2403
    zend_object* pobj = Z_OBJ_P(getThis()); 
2404
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2405
    xpathProcessor = obj->xpathProcessor;
2406
    if (xpathProcessor != nullptr) {
2407
        
2408
        if(uriStr != nullptr) {
2409
           
2410
                xpathProcessor->setBaseURI(uriStr);
2411
            
2412
        }
2413
    }
2414
}
2415

    
2416
PHP_METHOD(XPathProcessor, setContextFile)
2417
{
2418

    
2419
   XPathProcessor *xpathProcessor;
2420

    
2421
   char * name;
2422
   size_t len1;
2423
        
2424
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2425
        RETURN_NULL();
2426
    }
2427
    zend_object* pobj = Z_OBJ_P(getThis()); 
2428
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2429
    xpathProcessor = obj->xpathProcessor;
2430
    if (xpathProcessor != nullptr) {
2431
        
2432
        if(name != nullptr) {
2433
           
2434
                xpathProcessor->setContextFile(name);
2435
            
2436
        }
2437
    }
2438
}
2439

    
2440
PHP_METHOD(XPathProcessor, clearParameters)
2441
{
2442
    XPathProcessor *xpathProcessor;
2443
    if (ZEND_NUM_ARGS()>0) {
2444
        WRONG_PARAM_COUNT;
2445
    }
2446

    
2447
    zend_object* pobj = Z_OBJ_P(getThis()); 
2448
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2449
    xpathProcessor = obj->xpathProcessor;
2450
    if (xpathProcessor != nullptr) {
2451
        xpathProcessor->clearParameters(true);
2452
    }
2453
}
2454

    
2455
PHP_METHOD(XPathProcessor, clearProperties)
2456
{
2457
     XPathProcessor *xpathProcessor;
2458
    if (ZEND_NUM_ARGS()>0) {
2459
        WRONG_PARAM_COUNT;
2460
    }
2461

    
2462
    zend_object* pobj = Z_OBJ_P(getThis()); 
2463
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2464
    xpathProcessor = obj->xpathProcessor;
2465
    if (xpathProcessor != nullptr) {
2466
        xpathProcessor->clearProperties();
2467
    }
2468
}
2469

    
2470

    
2471
PHP_METHOD(XPathProcessor, exceptionOccurred)
2472
{
2473
   XPathProcessor *xpathProcessor;
2474
    zend_object* pobj = Z_OBJ_P(getThis()); 
2475
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2476
    if (ZEND_NUM_ARGS()>0) {
2477
        WRONG_PARAM_COUNT;
2478
    }
2479

    
2480
    xpathProcessor = obj->xpathProcessor;
2481
    if (xpathProcessor != nullptr) {
2482
        bool result = xpathProcessor->exceptionOccurred();
2483
        RETURN_BOOL(result);
2484
    }
2485
    RETURN_BOOL(false);
2486
}
2487

    
2488

    
2489
PHP_METHOD(XPathProcessor, getErrorCode)
2490
{
2491
    XPathProcessor *xpathProcessor;
2492
    long index;
2493
    if (ZEND_NUM_ARGS()>0) {
2494
        WRONG_PARAM_COUNT;
2495
    }
2496
    zend_object* pobj = Z_OBJ_P(getThis()); 
2497
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2498
    xpathProcessor = obj->xpathProcessor;
2499
    if (xpathProcessor != nullptr) {
2500
        const char * errCode = xpathProcessor->getErrorCode();
2501
        if(errCode != nullptr) {
2502
           // char *str = estrdup(errCode);
2503
            _RETURN_STRING(errCode);
2504
        }
2505
    }
2506
    RETURN_NULL();
2507
}
2508

    
2509
PHP_METHOD(XPathProcessor, getErrorMessage)
2510
{
2511
    XPathProcessor *xpathProcessor;
2512
    long index;
2513
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
2514
        RETURN_NULL();
2515
    }
2516
    zend_object* pobj = Z_OBJ_P(getThis()); 
2517
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2518
    xpathProcessor = obj->xpathProcessor;
2519
    if (xpathProcessor != nullptr) {
2520
        const char * errStr = xpathProcessor->getErrorMessage();
2521
        if(errStr != nullptr) {
2522
            //char *str = estrdup(errStr);
2523
            _RETURN_STRING(errStr);
2524
        }
2525
    }
2526
    RETURN_NULL();
2527
}
2528
PHP_METHOD(XPathProcessor, exceptionClear)
2529
{
2530
    XPathProcessor *xpathProcessor;
2531
    zend_object* pobj = Z_OBJ_P(getThis()); 
2532
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2533
    xpathProcessor = obj->xpathProcessor;
2534
    if (xpathProcessor != nullptr) {
2535
        xpathProcessor->exceptionClear();
2536
    }
2537
}
2538

    
2539
/*     ============== PHP Interface of   SchemaValidator =============== */
2540

    
2541
void schemaValidator_free_storage(zend_object *object)
2542
{
2543
    zend_object_std_dtor(object);
2544
}
2545

    
2546
void schemaValidator_destroy_storage(zend_object *object)
2547
{
2548
    zend_objects_destroy_object(object);
2549
}
2550

    
2551
zend_object *schemaValidator_create_handler(zend_class_entry *type)
2552
{
2553
    zval *tmp;
2554
    zend_object retval;
2555
    schemaValidator_object *obj = (schemaValidator_object *)ecalloc(1, sizeof(schemaValidator_object)+ zend_object_properties_size(type));
2556

    
2557
    zend_object_std_init(&obj->std, type);    
2558
    object_properties_init(&obj->std, type);
2559

    
2560
    obj->std.handlers = &schemaValidator_object_handlers;
2561

    
2562
    return &obj->std;
2563
}
2564

    
2565

    
2566

    
2567
PHP_METHOD(SchemaValidator, __destruct)
2568
{
2569
    zend_object* pobj = Z_OBJ_P(getThis()); 
2570
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2571

    
2572

    
2573
    SchemaValidator * schemaValidator= obj->schemaValidator;
2574
    if(schemaValidator != nullptr) {
2575
            delete schemaValidator;
2576
    }
2577
    
2578
}
2579

    
2580

    
2581

    
2582
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
2583
{
2584
    SchemaValidator *schemaValidator;
2585
    char * name;
2586
    size_t len1;
2587

    
2588
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2589
        RETURN_NULL();
2590
    }
2591
    zend_object* pobj = Z_OBJ_P(getThis()); 
2592
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2593
    schemaValidator = obj->schemaValidator;
2594
    if (name != nullptr && schemaValidator != nullptr) {
2595
        schemaValidator->registerSchemaFromFile(name);
2596
    }
2597
}
2598

    
2599
PHP_METHOD(SchemaValidator, registerSchemaFromString)
2600
{
2601
    char * schemaStr;
2602
    size_t len1;
2603
    SchemaValidator *schemaValidator;
2604
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &schemaStr, &len1) == FAILURE) {
2605
        RETURN_NULL();
2606
    }
2607
    zend_object* pobj = Z_OBJ_P(getThis()); 
2608
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2609
    schemaValidator = obj->schemaValidator;
2610
    if (schemaStr!= nullptr && schemaValidator != nullptr) {
2611
        schemaValidator->registerSchemaFromString(schemaStr);
2612
    }
2613
}
2614

    
2615
PHP_METHOD(SchemaValidator, validate)
2616
{
2617
    char * name = nullptr;
2618
    size_t len1;
2619
    SchemaValidator *schemaValidator;
2620
    if (ZEND_NUM_ARGS()>1) {
2621
        WRONG_PARAM_COUNT;
2622
    }
2623
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2624
        RETURN_NULL();
2625
    }
2626
    zend_object* pobj = Z_OBJ_P(getThis()); 
2627
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2628
    schemaValidator = obj->schemaValidator;
2629
    if (schemaValidator != nullptr) {
2630
        schemaValidator->validate(name);
2631
    }
2632
}
2633

    
2634
PHP_METHOD(SchemaValidator, validateToNode)
2635
{
2636
    char * name = nullptr;
2637
   size_t len1;
2638
    SchemaValidator *schemaValidator;
2639
    if (ZEND_NUM_ARGS()>1) {
2640
        WRONG_PARAM_COUNT;
2641
    }
2642
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2643
        RETURN_NULL();
2644
    }
2645
    zend_object* pobj = Z_OBJ_P(getThis()); 
2646
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2647
    schemaValidator = obj->schemaValidator;
2648
    if (schemaValidator != nullptr) {
2649
        XdmNode * node = schemaValidator->validateToNode(name);
2650
        if(node != nullptr) {
2651
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2652
                RETURN_NULL();
2653
                return;
2654
            } else {
2655
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
2656
                zend_object* vvobj = Z_OBJ_P(return_value);
2657
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2658
                assert (vobj != nullptr);
2659
                vobj->xdmNode = node;
2660
                return;
2661
            }
2662
        } 
2663
            schemaValidator->checkException();//TODO
2664
    } 
2665
    RETURN_NULL();
2666
}
2667

    
2668

    
2669
PHP_METHOD(SchemaValidator, getValidationReport)
2670
{
2671

    
2672
    SchemaValidator *schemaValidator;
2673
    if (ZEND_NUM_ARGS()>0) {
2674
        WRONG_PARAM_COUNT;
2675
    }
2676

    
2677
    zend_object* pobj = Z_OBJ_P(getThis()); 
2678
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2679
    schemaValidator = obj->schemaValidator;
2680
    if (schemaValidator != nullptr) {
2681
        XdmNode * node = schemaValidator->getValidationReport();
2682
        if(node != nullptr) {
2683
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2684
                RETURN_NULL();
2685
                return;
2686
            } else {
2687
                zend_object* vvobj = Z_OBJ_P(return_value);
2688
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2689
                assert (vobj != nullptr);
2690
                vobj->xdmNode = node;
2691
                return;
2692
            }
2693
        } 
2694
            schemaValidator->checkException();//TODO
2695
    } 
2696
    RETURN_NULL();
2697
}
2698

    
2699

    
2700
PHP_METHOD(SchemaValidator, setSourceNode)
2701
{
2702
    SchemaValidator *schemaValidator;
2703

    
2704
    zval* oth;
2705
   
2706

    
2707
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2708
        RETURN_NULL();
2709
    }
2710
    zend_object* pobj = Z_OBJ_P(getThis()); 
2711
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2712
    schemaValidator = obj->schemaValidator;
2713
    if (schemaValidator != nullptr) {
2714
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2715
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2716
        zend_object * nobj = Z_OBJ_P(oth);
2717
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
2718
        if(ooth != nullptr) {
2719
            XdmNode * value = ooth->xdmNode;
2720
            if(value != nullptr) {
2721
                schemaValidator->setSourceNode(value);
2722

    
2723
            }
2724
        }
2725
      
2726
        
2727
      }
2728
    }
2729
}
2730

    
2731
PHP_METHOD(SchemaValidator, setOutputFile)
2732
{
2733
    SchemaValidator *schemaValidator;
2734
    char * name;
2735
    int len1;
2736

    
2737
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2738
        RETURN_NULL();
2739
    }
2740
    zend_object* pobj = Z_OBJ_P(getThis()); 
2741
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2742
    schemaValidator = obj->schemaValidator;
2743
    if (schemaValidator != nullptr) {
2744
        schemaValidator->setOutputFile(name);
2745
    }
2746
}
2747

    
2748

    
2749
PHP_METHOD(SchemaValidator, exportSchema)
2750
{
2751
    SchemaValidator *schemaValidator;
2752
    char * name;
2753
    int len1;
2754

    
2755
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2756
        RETURN_NULL();
2757
    }
2758
    zend_object* pobj = Z_OBJ_P(getThis());
2759
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2760
    schemaValidator = obj->schemaValidator;
2761
    if (schemaValidator != nullptr) {
2762
        schemaValidator->exportSchema(name);
2763
    }
2764
}
2765

    
2766

    
2767
PHP_METHOD(SchemaValidator, setProperty)
2768
{
2769
    SchemaValidator *schemaValidator;
2770
    char * name;
2771
    char * value;
2772
    size_t len1, len2, myint;
2773

    
2774
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
2775
        RETURN_NULL();
2776
    }
2777
    zend_object* pobj = Z_OBJ_P(getThis()); 
2778
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2779
    schemaValidator = obj->schemaValidator;
2780
    if (schemaValidator != nullptr) {
2781
        schemaValidator->setProperty(name, value);
2782
    }
2783
}
2784

    
2785
PHP_METHOD(SchemaValidator, setParameter)
2786
{
2787

    
2788
   SchemaValidator *schemaValidator;
2789
   char * name;
2790
   zval* oth;
2791
   size_t len1, len2, myint;        
2792
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
2793
        RETURN_NULL();
2794
    }
2795
    zend_object* pobj = Z_OBJ_P(getThis()); 
2796
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2797
    schemaValidator = obj->schemaValidator;
2798
    if (schemaValidator != nullptr) {
2799
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2800
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2801

    
2802
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2803
        zend_object * nobj = Z_OBJ_P(oth);
2804

    
2805
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
2806
        if(ooth != nullptr) {
2807
            XdmNode * value = ooth->xdmNode;
2808
            if(value != nullptr) {
2809
                schemaValidator->setParameter(name, (XdmValue *)value);
2810

    
2811
            }
2812
        }
2813
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2814
        zend_object* vvobj = Z_OBJ_P(oth);
2815
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2816
        if(ooth != nullptr) {
2817
            XdmValue * value = ooth->xdmValue;
2818
            if(value != nullptr) {
2819
                
2820
                schemaValidator->setParameter(name, value);
2821
            }
2822
        }
2823

    
2824

    
2825

    
2826
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2827
        zend_object* vvobj = Z_OBJ_P(oth);
2828
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2829
        if(ooth != nullptr) {
2830
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2831
            if(value != nullptr) {
2832
                
2833
                schemaValidator->setParameter(name, (XdmValue *)value);
2834
            }
2835
        }
2836

    
2837

    
2838

    
2839
      }
2840

    
2841
    }
2842
}
2843

    
2844
PHP_METHOD(SchemaValidator, clearProperties)
2845
{
2846
    SchemaValidator *schemaValidator;
2847
    if (ZEND_NUM_ARGS()>0) {
2848
        WRONG_PARAM_COUNT;
2849
    }
2850

    
2851
    zend_object* pobj = Z_OBJ_P(getThis()); 
2852
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2853
    schemaValidator = obj->schemaValidator;
2854
    if (schemaValidator != nullptr) {
2855
        schemaValidator->clearProperties();
2856
        schemaValidator->exceptionClear();
2857
    }
2858
}
2859

    
2860
PHP_METHOD(SchemaValidator, clearParameters)
2861
{
2862

    
2863
   SchemaValidator *schemaValidator;
2864
    if (ZEND_NUM_ARGS()>0) {
2865
        WRONG_PARAM_COUNT;
2866
    }
2867
    zend_object* pobj = Z_OBJ_P(getThis()); 
2868
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2869
    schemaValidator = obj->schemaValidator;
2870
    if (schemaValidator != nullptr) {
2871
       
2872
                schemaValidator->clearParameters(true);
2873
                schemaValidator->exceptionClear();
2874
        }
2875
    }
2876

    
2877
PHP_METHOD(SchemaValidator, exceptionOccurred)
2878
{
2879
    SchemaValidator *schemaValidator;
2880
    if (ZEND_NUM_ARGS()>0) {
2881
        WRONG_PARAM_COUNT;
2882
    }
2883
    zend_object* pobj = Z_OBJ_P(getThis()); 
2884
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2885
    schemaValidator = obj->schemaValidator;
2886
    if (schemaValidator != nullptr) {
2887
        bool result = schemaValidator->exceptionOccurred();
2888
        RETURN_BOOL(result);
2889
    }
2890
    RETURN_BOOL(false);
2891
}
2892

    
2893

    
2894
PHP_METHOD(SchemaValidator, getErrorCode)
2895
{
2896
    SchemaValidator *schemaValidator;
2897
    long index;
2898
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
2899
        RETURN_NULL();
2900
    }
2901
    zend_object* pobj = Z_OBJ_P(getThis()); 
2902
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2903
    schemaValidator = obj->schemaValidator;
2904
    if (schemaValidator != nullptr) {
2905
        const char * errCode = schemaValidator->getErrorCode((int)index);
2906
        if(errCode != nullptr) {
2907
            //char *str = estrdup(errCode);
2908
            _RETURN_STRING(errCode);
2909
        }
2910
    }
2911
    RETURN_NULL();
2912
}
2913

    
2914
PHP_METHOD(SchemaValidator, getErrorMessage)
2915
{
2916
    SchemaValidator *schemaValidator;
2917
    long index;
2918
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
2919
        RETURN_NULL();
2920
    }
2921
    zend_object* pobj = Z_OBJ_P(getThis()); 
2922
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2923
    schemaValidator = obj->schemaValidator;
2924
    if (schemaValidator != nullptr) {
2925
        const char * errStr = schemaValidator->getErrorMessage(index);
2926
        if(errStr != nullptr) {
2927
            //char *str = estrdup(errStr);
2928
            _RETURN_STRING(errStr);
2929
        }
2930
    }
2931
    RETURN_NULL();
2932
}
2933
PHP_METHOD(SchemaValidator, exceptionClear)
2934
{
2935
    SchemaValidator * schemaValidator;
2936
    zend_object* pobj = Z_OBJ_P(getThis()); 
2937
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2938
    schemaValidator = obj->schemaValidator;
2939
    if (schemaValidator != nullptr) {
2940
        schemaValidator->exceptionClear();
2941
    }
2942
}
2943

    
2944
/*     ============== PHP Interface of   XdmValue =============== */
2945
void xdmValue_free_storage(zend_object *object)
2946
{
2947
    zend_object_std_dtor(object);
2948
}
2949

    
2950
zend_object *xdmValue_create_handler(zend_class_entry *type)
2951
{
2952
    zval *tmp;
2953
    zend_object retval;
2954
    xdmValue_object *obj = (xdmValue_object *)ecalloc(1, sizeof(xdmValue_object)+ zend_object_properties_size(type));
2955
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
2956
    object_properties_init(&obj->std, type);
2957
    
2958
    obj->std.handlers = &xdmValue_object_handlers;
2959

    
2960
    return &obj->std;
2961
}
2962

    
2963
void XdmValue_destroy_storage(zend_object *object)
2964
{
2965
    zend_objects_destroy_object(object);
2966
}
2967

    
2968
PHP_METHOD(XdmValue, __construct)
2969
{
2970
    XdmValue *xdmValue = nullptr;
2971
    bool bVal;
2972
    char * sVal;
2973
    int len;
2974
    long iVal;
2975
    double dVal;
2976
    zval *zvalue;
2977

    
2978

    
2979

    
2980
    SaxonProcessor *proc= nullptr;
2981
    //xdmValue_object *obj = (xdmValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
2982
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == SUCCESS) {
2983
        switch (Z_TYPE_P(zvalue)) {
2984
            case IS_FALSE:
2985
            case IS_TRUE:
2986
                bVal = Z_BVAL_P(zvalue);
2987
                xdmValue = new XdmValue(bVal);
2988
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2989
                obj->xdmValue = xdmValue;
2990
            break;
2991
            case IS_LONG:
2992
                iVal = Z_LVAL_P(zvalue);
2993
                xdmValue = new XdmValue((int)iVal);
2994
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2995
                obj->xdmValue = xdmValue;
2996
            break;
2997
            case IS_STRING:
2998
                sVal = Z_STRVAL_P(zvalue);
2999
                len = Z_STRLEN_P(zvalue);
3000
                xdmValue = new XdmValue("string", sVal);
3001
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
3002
                obj->xdmValue = xdmValue;
3003
            break;
3004
            case IS_NULL:
3005
                xdmValue = new XdmValue();
3006
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
3007
                obj->xdmValue = xdmValue;
3008
            break;
3009
            case IS_DOUBLE:
3010
                // TODO: implement this
3011
                //index = (long)Z_DVAL_P(zvalue);
3012
            //break;
3013
            case IS_ARRAY:
3014
            //break;
3015
            case IS_OBJECT:
3016
            //break;
3017
            default:
3018
                obj = nullptr;
3019
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
3020
        }
3021
    }*/
3022
}
3023

    
3024
PHP_METHOD(XdmValue, __destruct)
3025
{
3026

    
3027
     zend_object *oobj = Z_OBJ_P(getThis());
3028
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3029
    XdmValue * xdmValue= obj->xdmValue;
3030
   if(xdmValue != nullptr) {
3031
            xdmValue->decrementRefCount();
3032
            if(xdmValue!= nullptr && xdmValue->getRefCount()< 1){
3033
                    delete xdmValue;
3034
            } 
3035
    }
3036
}
3037

    
3038
PHP_METHOD(XdmValue, __toString)
3039
    {
3040
             XdmValue *xdmValue;
3041
         zend_object *oobj = Z_OBJ_P(getThis());
3042
         xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3043
         xdmValue = obj->xdmValue;
3044
         if (xdmValue != nullptr) {
3045
                const char * value = xdmValue->toString();
3046
                  if(value != nullptr) {
3047
                      _RETURN_STRING(value);
3048
                   } else {
3049
                   _RETURN_STRING("");
3050

    
3051
                   }
3052
                 }else {
3053
                      _RETURN_STRING("");
3054
              }
3055
    }
3056

    
3057
PHP_METHOD(XdmValue,  getHead){
3058
    XdmValue *xdmValue;
3059
     zend_object *oobj = Z_OBJ_P(getThis());
3060
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3061
    xdmValue = obj->xdmValue;
3062
    if (xdmValue != nullptr) {
3063
        XdmItem * item = xdmValue->getHead();
3064
        if(item != nullptr) {
3065
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
3066
                RETURN_NULL();
3067
              } else {
3068
                item->incrementRefCount();
3069
                zend_object * oobj = Z_OBJ_P(return_value);
3070
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
3071
                assert (vobj != nullptr);
3072
                vobj->xdmItem = item;
3073
                
3074
            }
3075
        } else {
3076
                RETURN_NULL();
3077
        }
3078
        
3079
    } else {
3080
        RETURN_NULL();
3081
    }
3082
}
3083

    
3084

    
3085
PHP_METHOD(XdmValue,  itemAt){
3086
    XdmValue *xdmValue;
3087

    
3088
    long index;
3089
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
3090
        RETURN_NULL();
3091
    }
3092

    
3093
     zend_object *oobj = Z_OBJ_P(getThis());
3094
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3095
    xdmValue = obj->xdmValue;
3096
    if (xdmValue != nullptr) {
3097
        XdmItem * item = xdmValue->itemAt((unsigned int)index);
3098
        if(item != nullptr) {
3099
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
3100
                RETURN_NULL();
3101
                return;
3102
            } else {
3103
                item->incrementRefCount();
3104
                zend_object * oobj = Z_OBJ_P(return_value);
3105
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
3106
               
3107
                assert (vobj != nullptr);
3108
                vobj->xdmItem = item;
3109
                return;
3110
            }
3111
        }
3112
        
3113
    } else {
3114
        RETURN_NULL();
3115
    }
3116
}
3117

    
3118

    
3119
PHP_METHOD(XdmValue,  size){
3120
    XdmValue *xdmValue;
3121
    zend_object *oobj = Z_OBJ_P(getThis());
3122
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3123
    xdmValue = obj->xdmValue;
3124
    int sizei = 0;
3125
    if (xdmValue != nullptr) {
3126
        sizei = xdmValue->size();
3127
    }
3128
     RETURN_LONG(sizei);
3129
}
3130

    
3131

    
3132
PHP_METHOD(XdmValue, addXdmItem){
3133
    XdmValue *xdmValue;
3134
    zval* oth;
3135
           
3136
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
3137
        RETURN_NULL();
3138
    }
3139

    
3140
    xdmValue_object *obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
3141
    xdmValue = obj->xdmValue;
3142
    if (xdmValue != nullptr) {
3143
     const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
3144
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3145

    
3146
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3147
        zend_object * nobj = Z_OBJ_P(oth);
3148
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
3149
        if(ooth != nullptr) {
3150
            XdmNode * value = ooth->xdmNode;
3151
            if(value != nullptr) {
3152
                xdmValue->addXdmItem((XdmItem *)value);
3153
                return;
3154
            }
3155
        }
3156
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
3157
        zend_object * iobj = Z_OBJ_P(oth);
3158
        xdmItem_object* ooth = (xdmItem_object *)((char *)iobj - XtOffsetOf(xdmItem_object, std));
3159
        if(ooth != nullptr) {
3160
            XdmItem * value = ooth->xdmItem;
3161
            if(value != nullptr) {
3162
                xdmValue->addXdmItem(value);
3163
                return;
3164
            }
3165
        }
3166

    
3167

    
3168

    
3169
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3170
        zend_object * aobj = Z_OBJ_P(oth);
3171
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)aobj - XtOffsetOf(xdmAtomicValue_object, std));
3172
        if(ooth != nullptr) {
3173
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3174
            if(value != nullptr) {
3175
                xdmValue->addXdmItem((XdmItem *)value);
3176
                return;
3177
            }
3178
        }
3179

    
3180
      } else {
3181
                //TODO exception
3182
        }
3183
    }
3184
}
3185

    
3186

    
3187

    
3188
/*     ============== PHP Interface of   XdmItem =============== */
3189

    
3190
void xdmItem_free_storage(zend_object *object)
3191
{
3192
    zend_object_std_dtor(object);
3193
}
3194

    
3195
zend_object *xdmItem_create_handler(zend_class_entry *type)
3196
{
3197
    zval *tmp;
3198
    zend_object retval;
3199
    xdmItem_object *obj = (xdmItem_object *)ecalloc(1, sizeof(xdmItem_object)+ zend_object_properties_size(type));
3200
    
3201
    object_properties_init(&obj->std, type);
3202
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
3203
    
3204
    obj->std.handlers = &xdmItem_object_handlers;
3205

    
3206
    return &obj->std;
3207
}
3208

    
3209
PHP_METHOD(XdmItem, __construct)
3210
{
3211
    XdmItem *xdmItem = nullptr;
3212
    bool bVal;
3213
    char * sVal;
3214
    int len;
3215
    long iVal;
3216
    double dVal;
3217
    zval *zvalue;
3218

    
3219
    SaxonProcessor *proc= nullptr;
3220
    
3221
   zval *object = getThis();
3222
   
3223
    zend_object * zobj = Z_OBJ_P(object);
3224

    
3225
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3226
    //saxonProc =  obj->saxonProcessor;
3227
 
3228
}
3229

    
3230
void XdmItem_destroy_storage(zend_object *object)
3231
{
3232
    zend_objects_destroy_object(object);
3233
    
3234
}
3235

    
3236
PHP_METHOD(XdmItem, __destruct)
3237
{
3238
     zval *object = getThis();
3239
     zend_object * zobj = Z_OBJ_P(object);
3240

    
3241
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3242

    
3243
    XdmItem * xdmItem= obj->xdmItem;
3244
    xdmItem->decrementRefCount();
3245
    if(xdmItem != nullptr && xdmItem->getRefCount()< 1){
3246
            delete xdmItem;
3247
    }
3248
    
3249
}
3250

    
3251
PHP_METHOD(XdmItem, getStringValue)
3252
{
3253
    XdmItem *xdmItem;
3254
     zval *object = getThis();
3255
    zend_object * zobj = Z_OBJ_P(object);
3256
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3257
    xdmItem = obj->xdmItem;
3258

    
3259
    if (xdmItem != nullptr) {
3260
        const char * valueStr = xdmItem->getStringValue();
3261
        if(valueStr != nullptr) {
3262
            _RETURN_STRING(valueStr);
3263
        }
3264
    }
3265
    RETURN_NULL();
3266
}
3267

    
3268
    /* {{{ __toString()
3269
       Returns the string content */
3270
PHP_METHOD(XdmItem, __toString)
3271
    {
3272
             XdmItem *xdmItem;
3273
         zend_object *oobj = Z_OBJ_P(getThis());
3274
         xdmItem_object* obj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
3275
         xdmItem = obj->xdmItem;
3276
         if (xdmItem != nullptr) {
3277
                const char * value = xdmItem->toString();
3278
                  if(value != nullptr) {
3279
                      _RETURN_STRING(value);
3280
                   } else {
3281
                   _RETURN_STRING("");
3282

    
3283
                   }
3284
                 }else {
3285
                      _RETURN_STRING("");
3286
              }
3287
    }
3288

    
3289
PHP_METHOD(XdmItem, isAtomic)
3290
{
3291
    XdmItem *xdmItem;
3292
    zend_object * zobj = Z_OBJ_P(getThis());
3293
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3294
    xdmItem = obj->xdmItem;
3295

    
3296
    if (xdmItem != nullptr) {
3297
        bool isAtomic = xdmItem->isAtomic();
3298
        RETURN_BOOL(isAtomic);
3299
    }
3300
    RETURN_BOOL(false);
3301
}
3302

    
3303
PHP_METHOD(XdmItem, isNode)
3304
{
3305
    XdmItem *xdmItem;
3306
    zend_object * zobj = Z_OBJ_P(getThis());
3307
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3308
    xdmItem = obj->xdmItem;
3309

    
3310
    if (xdmItem != nullptr && xdmItem->getType() == XDM_NODE) {
3311
        RETURN_TRUE;
3312
    }
3313
    RETURN_FALSE;
3314
}
3315

    
3316
PHP_METHOD(XdmItem, getAtomicValue)
3317
{
3318
    XdmItem *xdmItem;
3319
    zend_object * zobj = Z_OBJ_P(getThis());
3320
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3321
    xdmItem = obj->xdmItem;
3322

    
3323
    if (xdmItem != nullptr) {
3324
          if(!xdmItem->isAtomic()) {
3325
                RETURN_NULL();
3326
                return;
3327
          }
3328
          if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
3329
                RETURN_NULL();
3330
                return;
3331
            } else {
3332
                xdmItem->incrementRefCount();
3333
//Z_ADDREF_P(return_value);
3334
                   zend_object * zobj = Z_OBJ_P(return_value);
3335
                    xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3336
                //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
3337
                assert (vobj != nullptr);
3338
                vobj->xdmAtomicValue = (XdmAtomicValue *)xdmItem;
3339
                return;
3340
            }
3341
    }
3342
    RETURN_NULL();
3343
}
3344

    
3345
PHP_METHOD(XdmItem, getNodeValue)
3346
{
3347
    XdmItem *xdmItem;
3348
    zend_object * zobj = Z_OBJ_P(getThis());
3349
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3350
    xdmItem = obj->xdmItem;
3351

    
3352
    if (xdmItem != nullptr) {
3353
          if(xdmItem->isAtomic()) {
3354
                RETURN_NULL();
3355
                return;
3356
          }
3357
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3358
                RETURN_NULL();
3359
                return;
3360
            } else {
3361
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
3362
                   zend_object * zobj = Z_OBJ_P(return_value);
3363
                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3364
                assert (vobj != nullptr);
3365
                vobj->xdmNode = (XdmNode *)xdmItem;
3366
                vobj->xdmNode->incrementRefCount();
3367

    
3368
                return;
3369
            }
3370
    }
3371
    RETURN_NULL();
3372
}
3373

    
3374

    
3375

    
3376
/*     ============== PHP Interface of   XdmNode =============== */
3377

    
3378
void xdmNode_free_storage(zend_object *object)
3379
{
3380
   zend_object_std_dtor(object);
3381

    
3382
    
3383
}
3384

    
3385
zend_object *xdmNode_create_handler(zend_class_entry *type)
3386
{
3387
    zval *tmp;
3388
    zend_object retval;
3389
    xdmNode_object *obj = (xdmNode_object *)ecalloc(1, sizeof(xdmNode_object)+ zend_object_properties_size(type));
3390
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
3391
    object_properties_init(&obj->std, type);
3392
    obj->std.handlers = &xdmNode_object_handlers;
3393
        
3394
    return &obj->std;
3395
}
3396

    
3397
PHP_METHOD(XdmNode, __construct)
3398
{
3399
    //xdmNode_object *obj = (xdmNode_object *) Z_OBJ_P(getThis() TSRMLS_CC);
3400
}
3401

    
3402
void XdmNode_destroy_storage(zend_object *object)
3403
{
3404
 
3405
 zend_objects_destroy_object(object);
3406
   
3407
}
3408

    
3409
PHP_METHOD(XdmNode, __destruct)
3410
{
3411
    zval *object = getThis();
3412
     zend_object * zobj = Z_OBJ_P(object);
3413

    
3414
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3415

    
3416
    if(obj != nullptr) {
3417
    XdmNode * xdmNode= obj->xdmNode;
3418
    if(xdmNode != nullptr) {
3419
            xdmNode->decrementRefCount();
3420
            if(xdmNode->getRefCount()< 1){
3421
                    delete xdmNode;
3422
            } 
3423
    }
3424
    }
3425
}
3426

    
3427
PHP_METHOD(XdmNode, getStringValue)
3428
{
3429
    XdmNode *xdmNode;
3430
    zval *object = getThis();
3431
    zend_object * zobj = Z_OBJ_P(object);
3432

    
3433
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3434
    xdmNode = obj->xdmNode;
3435

    
3436
   
3437
    if (xdmNode != nullptr) {
3438
        const char * valueStr = xdmNode->getStringValue();
3439
        if(valueStr != nullptr) {
3440
            _RETURN_STRING(valueStr);
3441
            return;
3442
        }
3443
    } 
3444
    RETURN_NULL();
3445
    
3446
}
3447

    
3448

    
3449
    /* {{{ __toString()
3450
       Returns the string content */
3451
PHP_METHOD(XdmNode, __toString)
3452
    {
3453
             XdmNode *xdmNode;
3454
         zend_object *oobj = Z_OBJ_P(getThis());
3455
         xdmNode_object* obj = (xdmNode_object *)((char *)oobj - XtOffsetOf(xdmNode_object, std));
3456
         xdmNode = obj->xdmNode;
3457
         if (xdmNode != nullptr) {
3458
                const char * value = xdmNode->toString();
3459
                  if(value != nullptr) {
3460
                      _RETURN_STRING(value);
3461
                   } else {
3462
                   _RETURN_STRING("");
3463

    
3464
                   }
3465
                 }else {
3466
                      _RETURN_STRING("");
3467
              }
3468
    }
3469

    
3470
PHP_METHOD(XdmNode, getTypedValue)
3471
{
3472
    XdmNode *xdmNode;
3473
    zval *object = getThis();
3474
    zend_object * zobj = Z_OBJ_P(object);
3475

    
3476
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3477
    xdmNode = obj->xdmNode;
3478

    
3479

    
3480
    if (xdmNode != nullptr) {
3481
        XdmValue * typedValue = xdmNode->getTypedValue();
3482
        if(typedValue == nullptr) {
3483
                                RETURN_NULL();
3484
                                return;
3485
                }
3486
                  if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3487
                        RETURN_NULL();
3488
                        return;
3489
                    } else {
3490
                        typedValue->incrementRefCount();
3491

    
3492
                        zend_object * zobj = Z_OBJ_P(return_value);
3493
                            xdmValue_object * vobj = (xdmValue_object *)((char *)zobj - XtOffsetOf(xdmValue_object, std));
3494
                               assert (vobj != nullptr);
3495
                               vobj->xdmValue = typedValue;
3496
                               return;
3497
                    }
3498
            }
3499
            RETURN_NULL();
3500
}
3501

    
3502
PHP_METHOD(XdmNode, getNodeName)
3503
{
3504
    XdmNode *xdmNode;
3505
    zend_object * zobj = Z_OBJ_P(getThis());
3506
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3507
    xdmNode = obj->xdmNode;
3508
    xdmNode = obj->xdmNode;
3509

    
3510
    if (xdmNode != nullptr) {
3511
        const char * valueStr = xdmNode->getNodeName();
3512
        if(valueStr != nullptr) {
3513
            //char *str = estrdup(valueStr);
3514
            _RETURN_STRING(valueStr);
3515
        }
3516
    } 
3517
    RETURN_NULL();
3518
}
3519

    
3520
PHP_METHOD(XdmNode, getNodeKind)
3521
{
3522
    XdmNode *xdmNode;
3523
    zend_object * zobj = Z_OBJ_P(getThis());
3524
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3525
    xdmNode = obj->xdmNode;
3526

    
3527
    int nodeKind = 0;
3528
    if (xdmNode != nullptr) {
3529
        nodeKind = xdmNode->getNodeKind();
3530
        
3531
    }
3532
     RETURN_LONG(nodeKind);
3533
}
3534

    
3535
PHP_METHOD(XdmNode, isAtomic)
3536
{
3537

    
3538
    RETURN_FALSE;
3539
}
3540

    
3541

    
3542
PHP_METHOD(XdmNode,  getChildCount){
3543
    XdmNode *xdmNode;
3544
    zend_object * zobj = Z_OBJ_P(getThis());
3545
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3546
    xdmNode = obj->xdmNode;
3547

    
3548
    int nodeChildCount = 0;
3549
    if (xdmNode != nullptr) {
3550
        nodeChildCount = xdmNode->getChildCount();
3551
        
3552
    }
3553
     RETURN_LONG(nodeChildCount);
3554
}   
3555

    
3556
PHP_METHOD(XdmNode,  getAttributeCount){
3557
    XdmNode *xdmNode;
3558
    zend_object * zobj = Z_OBJ_P(getThis());
3559
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3560
    xdmNode = obj->xdmNode;
3561

    
3562
    int nodeAttrCount = 0;
3563
    if (xdmNode != nullptr) {
3564
        nodeAttrCount = xdmNode->getAttributeCount();
3565
        
3566
    }
3567
     RETURN_LONG(nodeAttrCount);
3568

    
3569
} 
3570

    
3571
PHP_METHOD(XdmNode,  getChildNode){
3572
    long indexi;        
3573
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l",&indexi) == FAILURE) {
3574
       RETURN_NULL();
3575
    }
3576

    
3577
    XdmNode *xdmNode;
3578
    zend_object * zobj = Z_OBJ_P(getThis());
3579
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3580
    xdmNode = obj->xdmNode;
3581

    
3582
    if (xdmNode != nullptr) {
3583
         int count = xdmNode->getChildCount();
3584
          if(count==0) {
3585
                RETURN_NULL();
3586
                return;
3587
          }        
3588
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3589
               RETURN_NULL();
3590
                return;
3591
            } else {
3592
                
3593
                if(indexi>=0 && indexi < count) {
3594
                        XdmNode ** childNodes = xdmNode->getChildren();
3595
                        if(childNodes == nullptr) {
3596
                                RETURN_NULL();
3597
                                return;
3598
                        }
3599
                        XdmNode * childNode = childNodes[indexi];
3600
                        if(childNode != nullptr) {
3601
                                childNode->incrementRefCount();
3602
                                zend_object * zobj = Z_OBJ_P(return_value);
3603
                                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3604
                                assert (vobj != nullptr);
3605
                                vobj->xdmNode = childNode;
3606
                                return;
3607
                        }
3608
                }
3609
            }
3610
    }                        
3611
    RETURN_NULL();
3612
}
3613

    
3614
PHP_METHOD(XdmNode,  getParent){
3615
    XdmNode *xdmNode;
3616
    zend_object * zobj = Z_OBJ_P(getThis());
3617
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3618
    xdmNode = obj->xdmNode;
3619

    
3620
    if (xdmNode != nullptr) {
3621
        XdmNode * parent = xdmNode->getParent();
3622
        if(parent == nullptr) {
3623
                        RETURN_NULL();
3624
                        return;
3625
        }
3626
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3627
                RETURN_NULL();
3628
                return;
3629
            } else {
3630
                parent->incrementRefCount();
3631
                       //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
3632
                zend_object * zobj = Z_OBJ_P(return_value);
3633
                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3634
                       assert (vobj != nullptr);
3635
                       vobj->xdmNode = parent;
3636
                       return;
3637
            }
3638
    }
3639
    RETURN_NULL();
3640
}
3641

    
3642
PHP_METHOD(XdmNode,  getAttributeNode){
3643
    long indexi;        
3644
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l",&indexi) == FAILURE) {
3645
        RETURN_NULL();
3646
    }
3647

    
3648
    XdmNode *xdmNode;
3649
    zend_object * zobj = Z_OBJ_P(getThis());
3650
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3651
    xdmNode = obj->xdmNode;
3652

    
3653
    if (xdmNode != nullptr) {
3654
          int count = xdmNode->getAttributeCount();
3655
          if(count > 0) {
3656
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3657
                RETURN_NULL();
3658
                return;
3659
            } else {
3660
                
3661
                if(indexi < count) {
3662
                        XdmNode * attNode = xdmNode->getAttributeNodes()[indexi];
3663
                        if(attNode != nullptr) {
3664
                                attNode->incrementRefCount();
3665
                                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
3666
                                zend_object * zobj = Z_OBJ_P(return_value);
3667
                                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3668
                                assert (vobj != nullptr);
3669
                                vobj->xdmNode = attNode;
3670

    
3671
                                return;
3672
                        }
3673
                }
3674
            }
3675
        }
3676
    }
3677
    RETURN_NULL();
3678

    
3679
}
3680

    
3681
PHP_METHOD(XdmNode,  getAttributeValue){
3682
   char * name;
3683
   long len1;        
3684
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
3685
        RETURN_NULL();
3686
    }
3687
    XdmNode *xdmNode;
3688
    zend_object * zobj = Z_OBJ_P(getThis());
3689
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3690
    xdmNode = obj->xdmNode;
3691
    if (xdmNode != nullptr && name != nullptr) {
3692
        
3693
        const char * valueStr = xdmNode->getAttributeValue(name);
3694
        if(valueStr != nullptr) {
3695
            //char *str = estrdup(valueStr);
3696
            _RETURN_STRING(valueStr);
3697
            return;
3698
        }
3699
    }
3700
    RETURN_NULL();
3701

    
3702

    
3703
}
3704

    
3705
/*     ============== PHP Interface of   XdmAtomicValue =============== */
3706

    
3707
void xdmAtomicValue_free_storage(zend_object *object)
3708
{
3709
    zend_object_std_dtor(object);
3710
}
3711

    
3712
void XdmAtomicValue_destroy_storage(zend_object *object)
3713
{
3714
    zend_objects_destroy_object(object);
3715
    
3716
}
3717

    
3718
zend_object *xdmAtomicValue_create_handler(zend_class_entry *type)
3719
{
3720

    
3721
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)ecalloc(1, sizeof(xdmAtomicValue_object)+ zend_object_properties_size(type));
3722

    
3723
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
3724
    object_properties_init(&obj->std, type);
3725

    
3726
    obj->std.handlers = &xdmAtomicValue_object_handlers;
3727

    
3728
    return &obj->std;
3729
}
3730

    
3731
PHP_METHOD(XdmAtomicValue, __construct)
3732
{
3733
   /* XdmAtomicValue *xdmValue = nullptr;
3734
    bool bVal;
3735
    char * sVal;
3736
    int len;
3737
    long iVal;
3738
    double dVal;
3739
    zval *zvalue;*/
3740

    
3741
   // xdmAtomicValue_object *obj = (xdmAtomicValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
3742

    
3743
}
3744

    
3745
PHP_METHOD(XdmAtomicValue, __destruct)
3746
{
3747
     zval *object = getThis();
3748
     zend_object * zobj = Z_OBJ_P(object);
3749

    
3750
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3751

    
3752
    XdmAtomicValue * xdmValue= obj->xdmAtomicValue;
3753
    if(xdmValue!= nullptr && xdmValue->getRefCount()< 1){
3754
        xdmValue->decrementRefCount();
3755
            delete xdmValue;
3756
    }
3757
    
3758
}
3759

    
3760
PHP_METHOD(XdmAtomicValue, getBooleanValue)
3761
{
3762
    XdmAtomicValue *xdmAtomicValue;
3763
    zval *object = getThis();
3764
     zend_object * zobj = Z_OBJ_P(object);
3765

    
3766
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3767
    xdmAtomicValue = obj->xdmAtomicValue;
3768

    
3769

    
3770
    bool resultb = false;
3771
    if (xdmAtomicValue != nullptr) {
3772
         resultb = xdmAtomicValue->getBooleanValue();
3773
        
3774
    }
3775
    RETURN_BOOL(resultb);
3776
}
3777

    
3778

    
3779
PHP_METHOD(XdmAtomicValue, getDoubleValue)
3780
{
3781
    XdmAtomicValue *xdmAtomicValue;
3782
   zval *object = getThis();
3783
     zend_object * zobj = Z_OBJ_P(object);
3784

    
3785
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3786
    xdmAtomicValue = obj->xdmAtomicValue;
3787

    
3788

    
3789
    double resultb = 0;
3790
    if (xdmAtomicValue != nullptr) {
3791
         resultb = xdmAtomicValue->getDoubleValue();
3792
        
3793
    }
3794
    RETURN_DOUBLE(resultb);
3795
}
3796

    
3797
PHP_METHOD(XdmAtomicValue, getLongValue)
3798
{
3799
    XdmAtomicValue *xdmAtomicValue;
3800
   zval *object = getThis();
3801
     zend_object * zobj = Z_OBJ_P(object);
3802

    
3803
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3804
    xdmAtomicValue = obj->xdmAtomicValue;
3805

    
3806
    long result = 0;
3807
    if (xdmAtomicValue != nullptr) {
3808
         result = xdmAtomicValue->getLongValue();
3809
        
3810
    }
3811
    RETURN_LONG(result);
3812
}
3813

    
3814
PHP_METHOD(XdmAtomicValue, getStringValue)
3815
{
3816
    XdmAtomicValue *xdmAtomicValue;
3817
    zval *object = getThis();
3818
     zend_object * zobj = Z_OBJ_P(object);
3819

    
3820
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3821
    xdmAtomicValue = obj->xdmAtomicValue;
3822

    
3823
    SaxonProcessor * saxonProc;
3824
     zend_object * zzobj = Z_OBJ_P(getThis());
3825

    
3826
    saxonProcessor_object * obj2 = (saxonProcessor_object *)((char *)zzobj - XtOffsetOf(xdmAtomicValue_object, std));
3827
    
3828
    saxonProc =  obj2->saxonProcessor;
3829

    
3830
    if (xdmAtomicValue != nullptr) {
3831
        const char * valueStr = xdmAtomicValue->getStringValue();
3832
        if(valueStr != nullptr) {
3833
            //char *str = estrdup(valueStr);
3834
            _RETURN_STRING(valueStr);
3835
        }
3836
    }
3837
    RETURN_NULL();
3838
}
3839

    
3840
PHP_METHOD(XdmAtomicValue, getPrimitiveTypeName)
3841
{
3842
    XdmAtomicValue *xdmAtomicValue;
3843
    zval *object = getThis();
3844
     zend_object * zobj = Z_OBJ_P(object);
3845

    
3846
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3847
    xdmAtomicValue = obj->xdmAtomicValue;
3848

    
3849
    if (xdmAtomicValue != nullptr) {
3850
        const char * valueStr = xdmAtomicValue->getPrimitiveTypeName();
3851
        if(valueStr != nullptr) {
3852
            //char *str = estrdup(valueStr);
3853
            _RETURN_STRING(valueStr);
3854
        }
3855
    }
3856
    RETURN_NULL();
3857
}
3858

    
3859

    
3860

    
3861

    
3862
    /* {{{ __toString()
3863
       Returns the string content */
3864
PHP_METHOD(XdmAtomicValue, __toString)
3865
    {
3866
             XdmAtomicValue *xdmAtomicValue;
3867
         zend_object *oobj = Z_OBJ_P(getThis());
3868
         xdmAtomicValue_object* obj = (xdmAtomicValue_object *)((char *)oobj - XtOffsetOf(xdmAtomicValue_object, std));
3869
         xdmAtomicValue = obj->xdmAtomicValue;
3870
         if (xdmAtomicValue != nullptr) {
3871
                const char * value = xdmAtomicValue->getStringValue();
3872
                if(value != nullptr) {
3873
                    _RETURN_STRING(value);
3874
                 } else {
3875
                 _RETURN_STRING("");
3876

    
3877
                 }
3878
               }else {
3879
                    _RETURN_STRING("");
3880
            }
3881
    }
3882

    
3883

    
3884
PHP_METHOD(XdmAtomicValue, isAtomic)
3885
{
3886

    
3887
    RETURN_TRUE;
3888
}
3889

    
3890

    
3891
/*void php_saxonc_initialize(void){
3892
   if(SaxonProcessor::jvmCreatedCPP == 0){
3893
        SaxonProcessor::jvmCreatedCPP=1;
3894
         SaxonProcessor::sxn_environ= (sxnc_environment *)malloc(sizeof(sxnc_environment));
3895

3896
    SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll ();
3897

3898
    initDefaultJavaRT (SaxonProcessor::sxn_environ); 
3899
    }
3900
} */
3901

    
3902

    
3903
// =============================================================
3904

    
3905
zend_function_entry SaxonProcessor_methods[] = {
3906
    PHP_ME(SaxonProcessor,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3907
    PHP_ME(SaxonProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3908
    PHP_ME(SaxonProcessor,  createAtomicValue,      nullptr, ZEND_ACC_PUBLIC)
3909
    PHP_ME(SaxonProcessor,  parseXmlFromString,      nullptr, ZEND_ACC_PUBLIC)
3910
    PHP_ME(SaxonProcessor,  parseXmlFromFile,      nullptr, ZEND_ACC_PUBLIC)
3911
    PHP_ME(SaxonProcessor,  setcwd,     nullptr, ZEND_ACC_PUBLIC)
3912
    PHP_ME(SaxonProcessor,  newXPathProcessor,     nullptr, ZEND_ACC_PUBLIC)
3913
    PHP_ME(SaxonProcessor,  newXsltProcessor,     nullptr, ZEND_ACC_PUBLIC)
3914
    PHP_ME(SaxonProcessor,  newXslt30Processor,     nullptr, ZEND_ACC_PUBLIC)
3915
    PHP_ME(SaxonProcessor,  newXQueryProcessor,     nullptr, ZEND_ACC_PUBLIC)
3916
    PHP_ME(SaxonProcessor,  newSchemaValidator,     nullptr, ZEND_ACC_PUBLIC)
3917
    PHP_ME(SaxonProcessor,  setCatalog,      nullptr, ZEND_ACC_PUBLIC)
3918
    PHP_ME(SaxonProcessor, setConfigurationProperty,      nullptr, ZEND_ACC_PUBLIC)
3919
    PHP_ME(SaxonProcessor,  registerPHPFunctions,      nullptr, ZEND_ACC_PUBLIC)
3920
    PHP_ME(SaxonProcessor,  version,      nullptr, ZEND_ACC_PUBLIC)
3921
    PHP_ME(SaxonProcessor,  isSchemaAware,      nullptr, ZEND_ACC_PUBLIC)
3922
    PHP_ME(SaxonProcessor,  release,      nullptr, ZEND_ACC_PUBLIC)
3923
    {nullptr, nullptr, nullptr}
3924
};
3925

    
3926
zend_function_entry XsltProcessor_methods[] = {
3927
    PHP_ME(XsltProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3928
    PHP_ME(XsltProcessor,  transformFileToFile, nullptr, ZEND_ACC_PUBLIC)
3929
    PHP_ME(XsltProcessor,  transformFileToString, nullptr, ZEND_ACC_PUBLIC)
3930
    PHP_ME(XsltProcessor,  transformFileToValue, nullptr, ZEND_ACC_PUBLIC)
3931
    PHP_ME(XsltProcessor,  transformToString, nullptr, ZEND_ACC_PUBLIC)
3932
    PHP_ME(XsltProcessor,  transformToValue, nullptr, ZEND_ACC_PUBLIC)
3933
    PHP_ME(XsltProcessor,  transformToFile, nullptr, ZEND_ACC_PUBLIC)
3934
    PHP_ME(XsltProcessor, compileFromFile, nullptr, ZEND_ACC_PUBLIC)
3935
    PHP_ME(XsltProcessor, compileFromValue, nullptr, ZEND_ACC_PUBLIC)
3936
    PHP_ME(XsltProcessor, compileFromString, nullptr, ZEND_ACC_PUBLIC)
3937
    PHP_ME(XsltProcessor, compileFromStringAndSave, nullptr, ZEND_ACC_PUBLIC)
3938
    PHP_ME(XsltProcessor, compileFromFileAndSave, nullptr, ZEND_ACC_PUBLIC)
3939
    PHP_ME(XsltProcessor,  setOutputFile, nullptr, ZEND_ACC_PUBLIC)
3940
    PHP_ME(XsltProcessor,  setSourceFromFile, nullptr, ZEND_ACC_PUBLIC)
3941
    PHP_ME(XsltProcessor,  setSourceFromXdmValue, nullptr, ZEND_ACC_PUBLIC)
3942
    PHP_ME(XsltProcessor,  setJustInTimeCompilation, nullptr, ZEND_ACC_PUBLIC)
3943
    PHP_ME(XsltProcessor,  setParameter, nullptr, ZEND_ACC_PUBLIC)
3944
    PHP_ME(XsltProcessor,  setProperty, nullptr, ZEND_ACC_PUBLIC)
3945
    PHP_ME(XsltProcessor,  clearParameters, nullptr, ZEND_ACC_PUBLIC)
3946
    PHP_ME(XsltProcessor,  clearProperties, nullptr, ZEND_ACC_PUBLIC)
3947
    PHP_ME(XsltProcessor,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
3948
    PHP_ME(XsltProcessor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
3949
    PHP_ME(XsltProcessor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
3950
    PHP_ME(XsltProcessor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
3951
    PHP_ME(XsltProcessor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
3952
{nullptr, nullptr, nullptr}
3953
};
3954

    
3955

    
3956

    
3957

    
3958
zend_function_entry XQueryProcessor_methods[] = {
3959
    PHP_ME(XQueryProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3960
   // PHP_ME(XQueryProcessor,  getErrorCode,      nullptr, ZEND_ACC_PUBLIC)
3961
    PHP_ME(XQueryProcessor,  setQueryContent,      nullptr, ZEND_ACC_PUBLIC)
3962
    PHP_ME(XQueryProcessor,  setContextItem,      nullptr, ZEND_ACC_PUBLIC)
3963
    PHP_ME(XQueryProcessor,  setContextItemFromFile,      nullptr, ZEND_ACC_PUBLIC)
3964
    PHP_ME(XQueryProcessor,  setParameter,      nullptr, ZEND_ACC_PUBLIC)
3965
    PHP_ME(XQueryProcessor,  setProperty,      nullptr, ZEND_ACC_PUBLIC)
3966
    PHP_ME(XQueryProcessor,  clearParameters,      nullptr, ZEND_ACC_PUBLIC)
3967
    PHP_ME(XQueryProcessor,  clearProperties,      nullptr, ZEND_ACC_PUBLIC)
3968
    PHP_ME(XQueryProcessor, runQueryToValue,      nullptr, ZEND_ACC_PUBLIC)
3969
    PHP_ME(XQueryProcessor, runQueryToString,      nullptr, ZEND_ACC_PUBLIC)
3970
    PHP_ME(XQueryProcessor, runQueryToFile,      nullptr, ZEND_ACC_PUBLIC)
3971
    PHP_ME(XQueryProcessor, setQueryFile,      nullptr, ZEND_ACC_PUBLIC)
3972
    PHP_ME(XQueryProcessor, setQueryBaseURI,      nullptr, ZEND_ACC_PUBLIC)
3973
    PHP_ME(XQueryProcessor, declareNamespace,      nullptr, ZEND_ACC_PUBLIC)
3974
    PHP_ME(XQueryProcessor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
3975
    PHP_ME(XQueryProcessor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
3976
    PHP_ME(XQueryProcessor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
3977
    PHP_ME(XQueryProcessor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
3978
{nullptr, nullptr, nullptr}
3979
};
3980

    
3981
zend_function_entry XPathProcessor_methods[] = {
3982
    PHP_ME(XPathProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3983
    PHP_ME(XPathProcessor,  setContextItem,      nullptr, ZEND_ACC_PUBLIC)
3984
    PHP_ME(XPathProcessor,  setContextFile,      nullptr, ZEND_ACC_PUBLIC)
3985
    PHP_ME(XPathProcessor,  effectiveBooleanValue,      nullptr, ZEND_ACC_PUBLIC)
3986
    PHP_ME(XPathProcessor,  evaluate,      nullptr, ZEND_ACC_PUBLIC)
3987
    PHP_ME(XPathProcessor,  evaluateSingle,      nullptr, ZEND_ACC_PUBLIC)
3988
    PHP_ME(XPathProcessor,  setParameter,      nullptr, ZEND_ACC_PUBLIC)
3989
    PHP_ME(XPathProcessor,  setProperty,      nullptr, ZEND_ACC_PUBLIC)
3990
    PHP_ME(XPathProcessor,  clearParameters,      nullptr, ZEND_ACC_PUBLIC)
3991
    PHP_ME(XPathProcessor,  clearProperties,      nullptr, ZEND_ACC_PUBLIC)
3992
    PHP_ME(XPathProcessor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
3993
    PHP_ME(XPathProcessor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
3994
    PHP_ME(XPathProcessor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
3995
    PHP_ME(XPathProcessor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
3996
    PHP_ME(XPathProcessor, declareNamespace,      nullptr, ZEND_ACC_PUBLIC)
3997
    PHP_ME(XPathProcessor, setBackwardsCompatible,      nullptr, ZEND_ACC_PUBLIC)
3998
    PHP_ME(XPathProcessor, setCaching,      nullptr, ZEND_ACC_PUBLIC)
3999
    PHP_ME(XPathProcessor, importSchemaNamespace,      nullptr, ZEND_ACC_PUBLIC)
4000
    PHP_ME(XPathProcessor, setBaseURI, nullptr, ZEND_ACC_PUBLIC)
4001
{nullptr, nullptr, nullptr}
4002
};
4003

    
4004
zend_function_entry SchemaValidator_methods[] = {
4005
    PHP_ME(SchemaValidator,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4006
    PHP_ME(SchemaValidator,  setSourceNode,      nullptr, ZEND_ACC_PUBLIC)
4007
    PHP_ME(SchemaValidator,  setOutputFile,      nullptr, ZEND_ACC_PUBLIC)
4008
    PHP_ME(SchemaValidator,  validate,      nullptr, ZEND_ACC_PUBLIC)
4009
    PHP_ME(SchemaValidator,  validateToNode,      nullptr, ZEND_ACC_PUBLIC)
4010
    PHP_ME(SchemaValidator,  registerSchemaFromFile,      nullptr, ZEND_ACC_PUBLIC)
4011
    PHP_ME(SchemaValidator,  registerSchemaFromString,      nullptr, ZEND_ACC_PUBLIC)
4012
    PHP_ME(SchemaValidator,  getValidationReport,      nullptr, ZEND_ACC_PUBLIC)
4013
    PHP_ME(SchemaValidator,  setParameter,      nullptr, ZEND_ACC_PUBLIC)
4014
    PHP_ME(SchemaValidator,  setProperty,      nullptr, ZEND_ACC_PUBLIC)
4015
    PHP_ME(SchemaValidator,  clearParameters,      nullptr, ZEND_ACC_PUBLIC)
4016
    PHP_ME(SchemaValidator,  clearProperties,      nullptr, ZEND_ACC_PUBLIC)
4017
    PHP_ME(SchemaValidator,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
4018
    PHP_ME(SchemaValidator,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
4019
    PHP_ME(SchemaValidator,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
4020
    PHP_ME(SchemaValidator,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
4021
    PHP_ME(SchemaValidator,  getExceptionCount, nullptr, ZEND_ACC_PUBLIC)
4022
{nullptr, nullptr, nullptr}
4023
};
4024

    
4025
zend_function_entry xdmValue_methods[] = {
4026
    PHP_ME(XdmValue,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
4027
    PHP_ME(XdmValue,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4028
    PHP_ME(XdmValue,  __toString,      nullptr, ZEND_ACC_PUBLIC)
4029
    PHP_ME(XdmValue,  getHead,      nullptr, ZEND_ACC_PUBLIC)
4030
    PHP_ME(XdmValue,  itemAt,      nullptr, ZEND_ACC_PUBLIC)
4031
    PHP_ME(XdmValue,  size,      nullptr, ZEND_ACC_PUBLIC)
4032
    PHP_ME(XdmValue, addXdmItem,      nullptr, ZEND_ACC_PUBLIC)
4033
    {nullptr, nullptr, nullptr}
4034
};
4035

    
4036
zend_function_entry xdmItem_methods[] = {
4037
    PHP_ME(XdmItem,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
4038
    PHP_ME(XdmItem,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4039
    PHP_ME(XdmItem,  __toString,      nullptr, ZEND_ACC_PUBLIC)
4040
    PHP_ME(XdmItem,  getStringValue,      nullptr, ZEND_ACC_PUBLIC)
4041
    PHP_ME(XdmItem,  isAtomic,      nullptr, ZEND_ACC_PUBLIC)
4042
    PHP_ME(XdmItem,  isNode,      nullptr, ZEND_ACC_PUBLIC)
4043
    PHP_ME(XdmItem,  getAtomicValue,      nullptr, ZEND_ACC_PUBLIC)
4044
    PHP_ME(XdmItem,  getNodeValue,      nullptr, ZEND_ACC_PUBLIC)
4045
    {nullptr, nullptr, nullptr}
4046
};
4047

    
4048
zend_function_entry xdmNode_methods[] = {
4049
    PHP_ME(XdmNode,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
4050
    PHP_ME(XdmNode,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4051
    PHP_ME(XdmNode,  __toString,      nullptr, ZEND_ACC_PUBLIC)
4052
    PHP_ME(XdmNode,  getStringValue,      nullptr, ZEND_ACC_PUBLIC)
4053
    PHP_ME(XdmNode,  getNodeKind,      nullptr, ZEND_ACC_PUBLIC)
4054
    PHP_ME(XdmNode,  getNodeName,      nullptr, ZEND_ACC_PUBLIC)
4055
    PHP_ME(XdmNode,  isAtomic,      nullptr, ZEND_ACC_PUBLIC)
4056
    PHP_ME(XdmNode,  getChildCount,      nullptr, ZEND_ACC_PUBLIC)
4057
    PHP_ME(XdmNode,  getAttributeCount,      nullptr, ZEND_ACC_PUBLIC)
4058
    PHP_ME(XdmNode,  getChildNode,      nullptr, ZEND_ACC_PUBLIC)
4059
    PHP_ME(XdmNode,  getParent,      nullptr, ZEND_ACC_PUBLIC)
4060
    PHP_ME(XdmNode,  getAttributeNode,      nullptr, ZEND_ACC_PUBLIC)
4061
    PHP_ME(XdmNode,  getAttributeValue,      nullptr, ZEND_ACC_PUBLIC)
4062
    PHP_ME(XdmNode,  getTypedValue,      nullptr, ZEND_ACC_PUBLIC)
4063
    {nullptr, nullptr, nullptr}
4064
};
4065

    
4066
zend_function_entry xdmAtomicValue_methods[] = {
4067
    PHP_ME(XdmAtomicValue,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
4068
    PHP_ME(XdmAtomicValue,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4069
    PHP_ME(XdmAtomicValue,  __toString,      nullptr, ZEND_ACC_PUBLIC)
4070
    PHP_ME(XdmAtomicValue,  getStringValue,      nullptr, ZEND_ACC_PUBLIC)
4071
    PHP_ME(XdmAtomicValue,  isAtomic,      nullptr, ZEND_ACC_PUBLIC)
4072
    PHP_ME(XdmAtomicValue,  getBooleanValue,      nullptr, ZEND_ACC_PUBLIC)
4073
    PHP_ME(XdmAtomicValue,  getDoubleValue,      nullptr, ZEND_ACC_PUBLIC)
4074
    PHP_ME(XdmAtomicValue,  getLongValue,      nullptr, ZEND_ACC_PUBLIC)
4075
        PHP_ME(XdmAtomicValue,  getPrimitiveTypeName,      nullptr, ZEND_ACC_PUBLIC)
4076
    {nullptr, nullptr, nullptr}
4077
};
4078

    
4079
PHP_MINIT_FUNCTION(saxon)
4080
{
4081

    
4082

    
4083
    //php_saxonc_initialize(); - commented out code which causes PHP to hang see bug issue #4371
4084

    
4085
    zend_class_entry ce;
4086
    INIT_CLASS_ENTRY(ce, "Saxon\\SaxonProcessor", SaxonProcessor_methods);
4087
    saxonProcessor_ce = zend_register_internal_class(&ce);
4088
    saxonProcessor_ce->create_object = saxonProcessor_create_handler;
4089
    memcpy(&saxonProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(saxonProcessor_object_handlers));//zend_object_handlers
4090
    saxonProcessor_object_handlers.offset = XtOffsetOf(saxonProcessor_object, std);
4091
    saxonProcessor_object_handlers.free_obj = SaxonProcessor_free_storage;
4092
    saxonProcessor_object_handlers.dtor_obj = SaxonProcessor_destroy_storage;
4093
   
4094
   // saxonProcessor_object_handlers.clone_obj = nullptr;
4095

    
4096
    INIT_CLASS_ENTRY(ce, "Saxon\\XSLTProcessor", XsltProcessor_methods);
4097
    xsltProcessor_ce = zend_register_internal_class(&ce);
4098
    xsltProcessor_ce->create_object = xsltProcessor_create_handler;
4099
    memcpy(&xsltProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xsltProcessor_object_handlers));
4100
    xsltProcessor_object_handlers.offset = XtOffsetOf(xsltProcessor_object, std);
4101
    xsltProcessor_object_handlers.free_obj = XsltProcessor_free_storage;
4102
    xsltProcessor_object_handlers.dtor_obj = XsltProcessor_destroy_storage;
4103
    //xsltProcessor_object_handlers.clone_obj = nullptr;
4104

    
4105
    INIT_CLASS_ENTRY(ce, "Saxon\\XSLT30Processor", Xslt30Processor_methods);
4106
    xslt30Processor_ce = zend_register_internal_class(&ce);
4107
    xslt30Processor_ce->create_object = xslt30Processor_create_handler;
4108
    memcpy(&xslt30Processor_object_handlers, zend_get_std_object_handlers(), sizeof(xslt30Processor_object_handlers));
4109
    xslt30Processor_object_handlers.offset = XtOffsetOf(xslt30Processor_object, std);
4110
    xslt30Processor_object_handlers.free_obj = Xslt30Processor_free_storage;
4111
    xslt30Processor_object_handlers.dtor_obj = Xslt30Processor_destroy_storage;
4112
    //xslt30Processor_object_handlers.clone_obj = nullptr;
4113

    
4114
    INIT_CLASS_ENTRY(ce, "Saxon\\XQueryProcessor", XQueryProcessor_methods);
4115
    xqueryProcessor_ce = zend_register_internal_class(&ce);
4116
    xqueryProcessor_ce->create_object = xqueryProcessor_create_handler;
4117
    memcpy(&xqueryProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xqueryProcessor_object_handlers));
4118
    xqueryProcessor_object_handlers.offset = XtOffsetOf(xqueryProcessor_object, std);
4119
    xqueryProcessor_object_handlers.free_obj = xqueryProcessor_free_storage;
4120
    xqueryProcessor_object_handlers.dtor_obj = xqueryProcessor_destroy_storage;    
4121

    
4122
        //xqueryProcessor_object_handlers.clone_obj = nullptr;
4123

    
4124
    INIT_CLASS_ENTRY(ce, "Saxon\\XPathProcessor", XPathProcessor_methods);
4125
    xpathProcessor_ce = zend_register_internal_class(&ce);
4126
    xpathProcessor_ce->create_object = xpathProcessor_create_handler;
4127
    memcpy(&xpathProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xpathProcessor_object_handlers));
4128
    xpathProcessor_object_handlers.offset = XtOffsetOf(xpathProcessor_object, std);
4129
    xpathProcessor_object_handlers.free_obj = xpathProcessor_free_storage;
4130
    xpathProcessor_object_handlers.dtor_obj = xpathProcessor_destroy_storage; 
4131
    //xpathProcessor_object_handlers.clone_obj = nullptr;
4132

    
4133
    INIT_CLASS_ENTRY(ce, "Saxon\\SchemaValidator", SchemaValidator_methods);
4134
    schemaValidator_ce = zend_register_internal_class(&ce);
4135
    schemaValidator_ce->create_object = schemaValidator_create_handler;
4136
    memcpy(&schemaValidator_object_handlers, zend_get_std_object_handlers(), sizeof(schemaValidator_object_handlers));
4137
    schemaValidator_object_handlers.offset = XtOffsetOf(schemaValidator_object, std);
4138
    schemaValidator_object_handlers.free_obj = schemaValidator_free_storage;
4139
    schemaValidator_object_handlers.dtor_obj = schemaValidator_destroy_storage; 
4140
    //schemaValidator_object_handlers.clone_obj = nullptr;
4141

    
4142
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmValue", xdmValue_methods);
4143
    xdmValue_ce = zend_register_internal_class(&ce);
4144
    xdmValue_ce->create_object = xdmValue_create_handler;
4145
    memcpy(&xdmValue_object_handlers, zend_get_std_object_handlers(), sizeof(xdmValue_object_handlers));
4146
    xdmValue_object_handlers.offset = XtOffsetOf(xdmValue_object, std);
4147
    xdmValue_object_handlers.free_obj = xdmValue_free_storage;
4148
    xdmValue_object_handlers.dtor_obj = XdmValue_destroy_storage;
4149
    //xdmValue_object_handlers.clone_obj = nullptr;
4150

    
4151
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmItem", xdmItem_methods);
4152
    xdmItem_ce = zend_register_internal_class(&ce);
4153
    xdmItem_ce->create_object = xdmItem_create_handler;
4154
    memcpy(&xdmItem_object_handlers, zend_get_std_object_handlers(), sizeof(xdmItem_object_handlers));
4155
    xdmItem_object_handlers.offset = XtOffsetOf(xdmItem_object, std);
4156
    xdmItem_object_handlers.free_obj = xdmItem_free_storage;
4157
    xdmItem_object_handlers.dtor_obj = XdmItem_destroy_storage;
4158
    //xdmItem_object_handlers.clone_obj = nullptr;
4159

    
4160
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmNode", xdmNode_methods);
4161
    xdmNode_ce = zend_register_internal_class(&ce);
4162
    xdmNode_ce->create_object = xdmNode_create_handler;
4163
    memcpy(&xdmNode_object_handlers, zend_get_std_object_handlers(), sizeof(xdmNode_object_handlers));
4164
    xdmNode_object_handlers.offset = XtOffsetOf(xdmNode_object, std);
4165
    xdmNode_object_handlers.free_obj = xdmNode_free_storage;
4166
    xdmNode_object_handlers.dtor_obj = XdmNode_destroy_storage;
4167
 
4168
    //xdmNode_object_handlers.clone_obj = nullptr;
4169

    
4170
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmAtomicValue", xdmAtomicValue_methods);
4171
    xdmAtomicValue_ce = zend_register_internal_class(&ce);
4172
    xdmAtomicValue_ce->create_object = xdmAtomicValue_create_handler;
4173
    memcpy(&xdmAtomicValue_object_handlers, zend_get_std_object_handlers(), sizeof(xdmAtomicValue_object_handlers));
4174
    xdmAtomicValue_object_handlers.offset = XtOffsetOf(xdmAtomicValue_object, std);
4175
    xdmAtomicValue_object_handlers.free_obj = xdmAtomicValue_free_storage;
4176
    xdmAtomicValue_object_handlers.dtor_obj = XdmAtomicValue_destroy_storage;
4177
    //REGISTER_INI_ENTRIES();
4178
    return SUCCESS;
4179
}
4180

    
4181
PHP_MINFO_FUNCTION(saxon)
4182
{
4183
    php_info_print_table_start();
4184
    php_info_print_table_header(2, "saxonc", "enabled");
4185
    php_info_print_table_row(2, "Saxon/C EXT version", "1.3");
4186
    php_info_print_table_row(2, "Saxon", "10.4");
4187
    php_info_print_table_row(2, "Excelsior JET", "15.3 MP1");
4188
    php_info_print_table_end();
4189
    DISPLAY_INI_ENTRIES();
4190
}
4191

    
4192
PHP_MSHUTDOWN_FUNCTION(saxon) {
4193
//std::cerr<<"MSHUTDOWN called -start"<<std::endl;
4194
//SaxonProcessor *  proc = new SaxonProcessor();
4195
 SaxonProcessor::release();   
4196
//delete proc;
4197
 UNREGISTER_INI_ENTRIES();
4198
   
4199
    return SUCCESS;
4200
}
4201

    
4202
PHP_RSHUTDOWN_FUNCTION(saxon) {
4203
   // std::cerr<<"RSHUTDOWN called -start"<<std::endl;
4204
//    SaxonProcessor::release();
4205
    return SUCCESS;
4206
}
4207

    
4208
PHP_RINIT_FUNCTION(saxon) {
4209
    //SaxonProcessor::release();
4210
    //std::cerr<<"RINIT called -start"<<std::endl;
4211
    return SUCCESS;
4212
}
4213

    
4214
zend_module_entry saxon_module_entry = {
4215
#if ZEND_MODULE_API_NO >= 20010901
4216
    STANDARD_MODULE_HEADER,
4217
#endif
4218
    PHP_SAXON_EXTNAME,
4219
    nullptr,        /* Functions */
4220
    PHP_MINIT(saxon),        /* MINIT */
4221
    PHP_MSHUTDOWN(saxon),        /* MSHUTDOWN */
4222
    nullptr,        /* RINIT */
4223
    nullptr,        /* RSHUTDOWN */
4224
    PHP_MINFO(saxon),        /* MINFO */
4225
#if ZEND_MODULE_API_NO >= 20010901
4226
    PHP_SAXON_EXTVER,
4227
#endif
4228
    STANDARD_MODULE_PROPERTIES
4229
};
4230

    
4231
#ifdef COMPILE_DL_SAXONC
4232
#ifdef ZTS
4233
ZEND_TSRMLS_CACHE_DEFINE()
4234
#endif
4235
ZEND_GET_MODULE(saxonc)
4236
#endif
4237

    
(5-5/8)