Project

Profile

Help

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

he / src / main / c / Saxon.C.API / php7_saxon.cpp @ 03fcd3f9

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 xslt30Processor_object_handlers;
25
zend_object_handlers xqueryProcessor_object_handlers;
26
zend_object_handlers xpathProcessor_object_handlers;
27
zend_object_handlers schemaValidator_object_handlers;
28
zend_object_handlers xdmValue_object_handlers;
29
zend_object_handlers xdmItem_object_handlers;
30
zend_object_handlers xdmNode_object_handlers;
31
zend_object_handlers xdmAtomicValue_object_handlers;
32

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

    
44
void SaxonProcessor_free_storage(zend_object *object)
45
{
46

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

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

    
60
    efree(obj);
61
}
62

    
63
void SaxonProcessor_destroy_storage(zend_object *pobj)
64
{
65

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

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

    
79
    
80
}
81

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

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

    
92
    obj->std.handlers = &saxonProcessor_object_handlers;
93

    
94
    return &obj->std;
95
}
96

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

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

    
110

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

    
115

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

    
120
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)zobj - XtOffsetOf(saxonProcessor_object, std));
121

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

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

    
139
            char* cwd2;
140

    
141
            //php_error(E_WARNING,cwd2);
142

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

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

    
156
          }
157
#endif
158

    
159
    } else {
160
        saxonProc->setcwd(cwdi);
161
    }
162

    
163
}
164

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

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

    
179

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

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

    
193
PHP_METHOD(SaxonProcessor, setResourcesDirectory)
194
{
195
    SaxonProcessor *saxonProcessor;
196
    char * dirStr;
197
    size_t len;
198
    
199
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &dirStr, &len) == FAILURE) {
200
        RETURN_NULL();
201
    }
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(dirStr != nullptr) {
209
            saxonProcessor->setResourcesDirectory(dirStr);
210
        }
211
    }
212
}
213

    
214

    
215
PHP_METHOD(SaxonProcessor, isSchemaAware)
216
{
217
    SaxonProcessor *saxonProcessor;
218
    
219
    if (ZEND_NUM_ARGS()>0) {
220
        WRONG_PARAM_COUNT;
221
    }
222
    zend_object* pobj = Z_OBJ_P(getThis()); 
223
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
224
    saxonProcessor = obj->saxonProcessor;
225
    if (saxonProcessor != nullptr) {
226
       
227
         if(saxonProcessor->isSchemaAwareProcessor()){
228

    
229
                RETURN_TRUE;
230
         }
231
    }
232
    RETURN_FALSE;
233
}
234

    
235
PHP_METHOD(SaxonProcessor, setCatalog)
236
{
237
    SaxonProcessor *saxonProcessor;
238
    char * catalogFile;
239
    size_t len;
240
    bool trace = false;
241
    
242
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sb", &catalogFile, &len, &trace) == FAILURE) {
243
        RETURN_NULL();
244
    }
245
    
246
    zend_object* pobj = Z_OBJ_P(getThis()); 
247
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
248
    saxonProcessor = obj->saxonProcessor;
249
    if (saxonProcessor != nullptr) {
250
       
251
        if(catalogFile != nullptr) {
252
            saxonProcessor->setCatalog(catalogFile, trace);
253
        }
254
    }
255
}
256

    
257

    
258

    
259
PHP_METHOD(SaxonProcessor, setcwd)
260
{
261
    SaxonProcessor *saxonProcessor;
262
    char * cwdStr;
263
    size_t len;
264
    
265
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &cwdStr, &len) == FAILURE) {
266
        RETURN_NULL();
267
    }
268
    
269
    zend_object* pobj = Z_OBJ_P(getThis()); 
270
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
271
    saxonProcessor = obj->saxonProcessor;
272
    if (saxonProcessor != nullptr) {
273
        
274
        if(cwdStr != nullptr) {
275
            saxonProcessor->setcwd(cwdStr);
276
        }
277
    }
278
}
279

    
280

    
281
PHP_METHOD(SaxonProcessor, parseXmlFromString)
282
{
283
    SaxonProcessor * saxonProcessor;
284
    char * source;
285
    size_t len1;
286

    
287
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
288
        RETURN_NULL();
289
    }
290
    zend_object* pobj = Z_OBJ_P(getThis()); 
291
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
292
    assert (obj != nullptr);
293
    saxonProcessor = obj->saxonProcessor;
294
    if (saxonProcessor != nullptr) {
295
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
296
        if(node != nullptr) {
297
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
298
                RETURN_NULL();
299
            } else {
300
                zend_object* vobj = Z_OBJ_P(return_value);
301
                 xdmNode_object * xdmNObj = (xdmNode_object *)((char *)vobj - XtOffsetOf(xdmNode_object, std));
302
                assert (xdmNObj != nullptr);
303
                xdmNObj->xdmNode = node;
304
            }
305
        } else {
306
            if(obj->saxonProcessor->exceptionOccurred()){
307
                //TODO throw exception
308
            }
309
        }
310
    } else {
311
        RETURN_NULL();
312
    }
313
}
314

    
315
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
316
{
317
    SaxonProcessor * saxonProcessor;
318
    char * source;
319
    size_t len1;
320

    
321
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
322
        RETURN_NULL();
323
    }
324
    zend_object* pobj = Z_OBJ_P(getThis()); 
325
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
326
    assert (obj != nullptr);
327
    saxonProcessor = obj->saxonProcessor;
328
    if (saxonProcessor != nullptr) {
329
        XdmNode* node = saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
330
        if(node != nullptr) {
331
      
332
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
333
                RETURN_NULL();
334
            } else {
335
          
336
            zend_object* vvobj = Z_OBJ_P(return_value);
337
            xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
338
                
339
                assert (vobj != nullptr);
340
                vobj->xdmNode = node;
341
            }
342
        } else {
343
           // obj->xsltProcessor->checkException();//TODO
344
        }
345
    } else {
346
  //  std::cerr<<"parseXmlFromFile cp2"<<std::endl;
347
        RETURN_NULL();
348
    }
349
   // std::cerr<<"parseXmlFromFile cp3"<<std::endl;
350
}
351

    
352

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

    
428

    
429
PHP_METHOD(SaxonProcessor, newXPathProcessor)
430
{
431
   
432
    if (ZEND_NUM_ARGS()>0) {
433
        WRONG_PARAM_COUNT;
434
    }
435
    SaxonProcessor * proc;
436
    XPathProcessor * xpathProcessor = nullptr;
437

    
438
    zend_object* pobj = Z_OBJ_P(getThis()); 
439
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
440

    
441
    assert (obj != nullptr);
442
    proc = obj->saxonProcessor;
443
    assert (proc != nullptr);
444
    if (proc != nullptr) {
445
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
446
            RETURN_NULL();
447
        } else {
448
          // struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)Z_OBJ_P(return_value TSRMLS_CC);
449
           zend_object* vvobj = Z_OBJ_P(return_value);
450
           xpathProcessor_object * vobj = (xpathProcessor_object *)((char *)vvobj - XtOffsetOf(xpathProcessor_object, std));
451
            assert (vobj != nullptr);
452
            xpathProcessor = proc->newXPathProcessor();
453
            vobj->xpathProcessor = xpathProcessor;
454
        }
455
    } else {
456
       
457
        RETURN_NULL();
458
    }
459
}
460

    
461
PHP_METHOD(SaxonProcessor, newXsltProcessor)
462
{
463
//std::cerr<<"SaxonProcessor newXsltproc point 1"<<std::endl;
464
    //php_error(E_WARNING,"new xsltProc 1");
465
    if (ZEND_NUM_ARGS()>0) {
466
        WRONG_PARAM_COUNT;
467
    }
468
    SaxonProcessor * proc;
469
    XsltProcessor * xsltProcessor = nullptr;
470

    
471
      zend_object* pobj = Z_OBJ_P(getThis()); 
472
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
473

    
474
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
475
    assert (obj != nullptr);
476
    proc = obj->saxonProcessor;
477

    
478
    assert (proc != nullptr);
479
    if (proc != nullptr) {
480
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
481
            RETURN_NULL();
482
        } else {
483
        xsltProcessor = proc->newXsltProcessor();
484
           zend_object* vobj = Z_OBJ_P(return_value);
485
           xsltProcessor_object * xproc_object = (xsltProcessor_object *)((char *)vobj - XtOffsetOf(xsltProcessor_object, std));
486
            assert (vobj != nullptr);
487
            
488
            xproc_object->xsltProcessor = xsltProcessor;
489

    
490
    }
491
    } else {
492
       
493
        RETURN_NULL();
494
    }
495
}
496

    
497

    
498
PHP_METHOD(SaxonProcessor, newXslt30Processor)
499
{
500
//std::cerr<<"SaxonProcessor newXslt30proc point 1"<<std::endl;
501
   // php_error(E_WARNING,"new xslt30Proc 1");
502
    if (ZEND_NUM_ARGS()>0) {
503
        WRONG_PARAM_COUNT;
504
    }
505
    SaxonProcessor * proc;
506
    Xslt30Processor * xslt30Processor = nullptr;
507

    
508
      zend_object* pobj = Z_OBJ_P(getThis());
509
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
510

    
511
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
512
    assert (obj != nullptr);
513
    proc = obj->saxonProcessor;
514

    
515
    assert (proc != nullptr);
516
    if (proc != nullptr) {
517
    if (object_init_ex(return_value, xslt30Processor_ce) != SUCCESS) {
518
            RETURN_NULL();
519
        } else {
520
        xslt30Processor = proc->newXslt30Processor();        
521
           zend_object* vobj = Z_OBJ_P(return_value);
522
           xslt30Processor_object * xproc_object = (xslt30Processor_object *)((char *)vobj - XtOffsetOf(xslt30Processor_object, std));
523
            assert (vobj != nullptr);
524

    
525
            xproc_object->xslt30Processor = xslt30Processor;
526

    
527
    }
528
    } else {
529

    
530
        RETURN_NULL();
531
    }
532
}
533

    
534
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
535
{
536
   
537
    if (ZEND_NUM_ARGS()>0) {
538
        WRONG_PARAM_COUNT;
539
    }
540
    SaxonProcessor * proc;
541
    XQueryProcessor * xqueryProcessor = nullptr;
542
     zend_object* pobj = Z_OBJ_P(getThis()); 
543
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
544
    assert (obj != nullptr);
545
    proc = obj->saxonProcessor;
546
    assert (proc != nullptr);
547
    if (proc != nullptr) {
548
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
549
            RETURN_NULL();
550
        } else {
551
          xqueryProcessor = proc->newXQueryProcessor();
552
          zend_object* vvobj = Z_OBJ_P(return_value);
553
           xqueryProcessor_object * vobj = (xqueryProcessor_object *)((char *)vvobj - XtOffsetOf(xqueryProcessor_object, std));
554
            assert (vvobj != nullptr);
555
            
556
            vobj->xqueryProcessor = xqueryProcessor;
557
     }
558
    } else {
559
       
560
        RETURN_NULL();
561
    }
562
}
563

    
564
PHP_METHOD(SaxonProcessor, newSchemaValidator)
565
{
566
   
567
    if (ZEND_NUM_ARGS()>0) {
568
        WRONG_PARAM_COUNT;
569
    }
570
    SaxonProcessor * proc;
571
    SchemaValidator * schemaValidator = nullptr;
572
   
573
    zend_object* pobj = Z_OBJ_P(getThis()); 
574
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
575
    assert (obj != nullptr);
576
    proc = obj->saxonProcessor;
577
    assert (proc != nullptr);
578
    if (proc != nullptr) {
579
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
580
            RETURN_NULL();
581
        } else {
582
           //struct schemaValidator_object* vobj = (struct schemaValidator_object *)Z_OBJ_P(return_value TSRMLS_CC);
583
           zend_object* vvobj = Z_OBJ_P(return_value);
584
           schemaValidator_object * vobj = (schemaValidator_object *)((char *)vvobj - XtOffsetOf(schemaValidator_object, std));
585
            assert (vobj != nullptr);
586
            schemaValidator = proc->newSchemaValidator();
587
            if(schemaValidator == nullptr){
588
                RETURN_NULL();
589
            }
590
            vobj->schemaValidator = schemaValidator;
591
        }
592
    } else {
593
       
594
        RETURN_NULL();
595
    }
596
}
597

    
598

    
599
PHP_METHOD(SaxonProcessor, version)
600
{
601
    SaxonProcessor *saxonProcessor;
602

    
603
   
604
    if (ZEND_NUM_ARGS()>0) {
605
        WRONG_PARAM_COUNT;
606
    }
607
    zend_object* pobj = Z_OBJ_P(getThis()); 
608
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
609
    saxonProcessor = obj->saxonProcessor;
610
    if (saxonProcessor != nullptr) {
611
        const char * verStr = saxonProcessor->version();
612
        //char *str = estrdup(saxonProcessor->version());
613
        _RETURN_STRING(verStr);
614
//efree(verStr);
615
    }
616
    RETURN_NULL();
617
}
618

    
619

    
620

    
621
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
622
{
623
    SaxonProcessor *saxonProcessor;
624
    char * name;
625
    char * value;
626
    size_t len1, len2;
627
    if (ZEND_NUM_ARGS()!= 2) {
628
        WRONG_PARAM_COUNT;
629
    }
630

    
631
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
632
        RETURN_NULL();
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 && name != nullptr && value != nullptr) {
639
        saxonProcessor->setConfigurationProperty(name, value);
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(0);
805
            if(errStr != nullptr) {
806
                const char * errorCode = xsltProcessor->getErrorCode(0);
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(0);
1046
            if(errStr != nullptr) {
1047
                const char * errorCode = xsltProcessor->getErrorCode(0);
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
PHP_METHOD(XsltProcessor, getExceptionCount)
1503
{
1504
    XsltProcessor *xsltProcessor;
1505
    zend_object* pobj = Z_OBJ_P(getThis()); 
1506
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1507
    if (ZEND_NUM_ARGS()>0) {
1508
        WRONG_PARAM_COUNT;
1509
    }
1510

    
1511
    xsltProcessor = obj->xsltProcessor;
1512
    if (xsltProcessor != nullptr) {
1513
        int count = xsltProcessor->exceptionCount();
1514
        RETURN_LONG(count);
1515
    }
1516
    RETURN_LONG(0);
1517
}
1518

    
1519
PHP_METHOD(XsltProcessor, getErrorCode)
1520
{
1521
    XsltProcessor *xsltProcessor;
1522
    long index;
1523
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1524
        RETURN_NULL();
1525
    }
1526
    zend_object* pobj = Z_OBJ_P(getThis()); 
1527
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1528
    xsltProcessor = obj->xsltProcessor;
1529
    if (xsltProcessor != nullptr) {
1530
        const char * errCode = xsltProcessor->getErrorCode((int)index);
1531
        if(errCode != nullptr) {
1532
            //char *str = estrdup(errCode);
1533
            _RETURN_STRING(errCode);
1534
        }
1535
    }
1536
    RETURN_NULL();
1537
}
1538

    
1539
PHP_METHOD(XsltProcessor, getErrorMessage)
1540
{
1541
    XsltProcessor *xsltProcessor;
1542
    long index;
1543
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1544
        RETURN_NULL();
1545
    }
1546
    zend_object* pobj = Z_OBJ_P(getThis()); 
1547
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1548
    xsltProcessor = obj->xsltProcessor;
1549
    if (xsltProcessor != nullptr) {
1550
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1551
        if(errStr != nullptr) {
1552
            //char *str = estrdup(errStr);
1553
            _RETURN_STRING(errStr);
1554
        }
1555
    }
1556
    RETURN_NULL();
1557
}
1558
PHP_METHOD(XsltProcessor, exceptionClear)
1559
{
1560
    XsltProcessor *xsltProcessor;
1561
    zend_object* pobj = Z_OBJ_P(getThis()); 
1562
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1563
    xsltProcessor = obj->xsltProcessor;
1564
    if (xsltProcessor != nullptr) {
1565
        xsltProcessor->exceptionClear();
1566
    }
1567
}
1568

    
1569

    
1570

    
1571
/*     ============== XSLT30: PHP Interface of  Xslt30Processor class =============== */
1572

    
1573
void Xslt30Processor_free_storage(zend_object *object)
1574
{
1575

    
1576
    zend_object_std_dtor(object);
1577

    
1578
}
1579

    
1580
void Xslt30Processor_destroy_storage(zend_object *object)
1581
{
1582
    xslt30Processor_object *obj;
1583

    
1584
    zend_objects_destroy_object(object);
1585
}
1586

    
1587
zend_object * xslt30Processor_create_handler(zend_class_entry *type)
1588
{
1589

    
1590

    
1591
    xslt30Processor_object *obj = (xslt30Processor_object *)ecalloc(1, sizeof(xslt30Processor_object)+ zend_object_properties_size(type));
1592

    
1593

    
1594
   zend_object_std_init(&obj->std,type);
1595
    object_properties_init(&obj->std, type);
1596

    
1597
    obj->std.handlers = &xslt30Processor_object_handlers;
1598

    
1599
    return &obj->std;
1600
}
1601

    
1602

    
1603

    
1604
PHP_METHOD(Xslt30Processor, __destruct)
1605
{
1606

    
1607
    zend_object* pobj = Z_OBJ_P(getThis());
1608
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1609

    
1610

    
1611
    Xslt30Processor * xslt30Processor= obj->xslt30Processor;
1612
    if(xslt30Processor != nullptr){
1613
            delete xslt30Processor;
1614
     }
1615

    
1616

    
1617
}
1618

    
1619

    
1620
PHP_METHOD(Xslt30Processor, setBaseOutputURI)
1621
{
1622
    Xslt30Processor *xslt30Processor;
1623
    char * baseOutputURI = nullptr;
1624
    size_t len1;
1625

    
1626
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &len1) == FAILURE) {
1627
        RETURN_NULL();
1628
    }
1629

    
1630
    zend_object* pobj = Z_OBJ_P(getThis());
1631
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1632
    xslt30Processor = obj->xslt30Processor;
1633
    if (xslt30Processor != nullptr && baseOutputURI != nullptr) {
1634

    
1635
         xslt30Processor->setBaseOutputURI(baseOutputURI);
1636

    
1637

    
1638
    }
1639
}
1640

    
1641

    
1642

    
1643
PHP_METHOD(Xslt30Processor, callFunctionReturningValue)
1644
{
1645
//arguments: const char * stylesheetFilename, const char* functionName, XdmValue * arguments, int argument_length
1646

    
1647
    Xslt30Processor *xslt30Processor;
1648
    HashTable *arr_hash;
1649
    char* functionName;
1650
    zval * arguments_zval;
1651
    zval * val;
1652
    long num_key;
1653
    XdmValue ** arguments = nullptr;
1654
    int argument_length=0;
1655
    zend_string *key;
1656

    
1657
    char * infilename;
1658
    char * styleFileName = nullptr;
1659
    size_t len1, len2;
1660

    
1661
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len2, &arguments_zval) == FAILURE) {
1662
        RETURN_NULL();
1663
    } else if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssa", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1664
        RETURN_NULL();
1665
    }
1666

    
1667
    zend_object* pobj = Z_OBJ_P(getThis());
1668
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1669
    xslt30Processor = obj->xslt30Processor;
1670
    arr_hash = Z_ARRVAL_P(arguments_zval);
1671
    argument_length = zend_hash_num_elements(arr_hash);
1672
   
1673
    arguments = new XdmValue*[argument_length];
1674
      
1675
    if (xslt30Processor != nullptr) {
1676
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1677
        if(Z_TYPE_P(val) != nullptr) {
1678
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1679
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1680
        php_printf("num_key %d =>", num_key);
1681
        php_printf("key %d =>", key);
1682
        */
1683
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1684
                zend_object* ooth = Z_OBJ_P(val);
1685
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1686
                if(nobj != nullptr) {
1687
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1688
                            arguments[num_key] = value;
1689
                }
1690
        }
1691
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1692
                zend_object* ooth = Z_OBJ_P(val);
1693
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1694
                if(nobj != nullptr) {
1695
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1696
                            arguments[num_key] = value;
1697
                }
1698
        }
1699
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1700
                zend_object* ooth = Z_OBJ_P(val);
1701
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1702
                if(nobj != nullptr) {
1703
                            XdmValue * value = nobj->xdmValue;
1704
                            arguments[num_key] = value;
1705
                }
1706
        }
1707
        else {//TODO error warning}
1708
         }}else {
1709
                //TODO error warning
1710
        }
1711
      } ZEND_HASH_FOREACH_END();
1712

    
1713

    
1714
        //php_printf(" argument_length= %d",argument_length);
1715
        XdmValue * result = xslt30Processor->callFunctionReturningValue(styleFileName, functionName, arguments, argument_length);
1716
        if(result != nullptr) {
1717
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1718
                RETURN_NULL();
1719
            } else {
1720
                zend_object *ooth =  Z_OBJ_P(return_value);
1721
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
1722
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1723
                assert (vobj != nullptr);
1724
                vobj->xdmValue = result;
1725
            }
1726
        } else {
1727
            if(obj->xslt30Processor->exceptionOccurred()){
1728
                  //TODO
1729
            }
1730
            RETURN_NULL();
1731
        }
1732
    }
1733

    
1734

    
1735
}
1736

    
1737
PHP_METHOD(Xslt30Processor, callFunctionReturningString){
1738
    Xslt30Processor *xslt30Processor;
1739
    HashTable *arr_hash;
1740
    char* functionName;
1741
    zval * arguments_zval;
1742
    zval * val;
1743
    long num_key;
1744
    XdmValue ** arguments = nullptr;
1745
    int argument_length=0;
1746
    zend_string *key;
1747

    
1748
    char * infilename;
1749
    char * styleFileName = nullptr;
1750
    size_t len1, len2;
1751

    
1752
     if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len2, &arguments_zval) == FAILURE) {
1753
        RETURN_NULL();
1754
      }else if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssa", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1755
        RETURN_NULL();
1756
    }
1757

    
1758
    zend_object* pobj = Z_OBJ_P(getThis());
1759
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1760
    xslt30Processor = obj->xslt30Processor;
1761
    arr_hash = Z_ARRVAL_P(arguments_zval);
1762
    argument_length = zend_hash_num_elements(arr_hash);
1763
   
1764
    arguments = new XdmValue*[argument_length];
1765
      
1766
    if (xslt30Processor != nullptr) {
1767
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1768
        if(Z_TYPE_P(val) != nullptr) {
1769
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1770
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1771
        php_printf("num_key %d =>", num_key);
1772
        php_printf("key %d =>", key);
1773
        */
1774
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1775
                zend_object* ooth = Z_OBJ_P(val);
1776
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1777
                if(nobj != nullptr) {
1778
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1779
                            arguments[num_key] = value;
1780
                }
1781
        }
1782
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1783
                zend_object* ooth = Z_OBJ_P(val);
1784
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1785
                if(nobj != nullptr) {
1786
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1787
                            arguments[num_key] = value;
1788
                }
1789
        }
1790
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1791
                zend_object* ooth = Z_OBJ_P(val);
1792
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1793
                if(nobj != nullptr) {
1794
                            XdmValue * value = nobj->xdmValue;
1795
                            arguments[num_key] = value;
1796
                }
1797
        }
1798
        else {//TODO error warning}
1799
         }}else {
1800
                //TODO error warning
1801
        }
1802
      } ZEND_HASH_FOREACH_END();
1803

    
1804
        const char * result = xslt30Processor->callFunctionReturningString(styleFileName, functionName, arguments, argument_length);
1805
        if(result != nullptr) {
1806
            //char *str = estrdup(result);
1807
            _RETURN_STRING(result);
1808
        } else if(xslt30Processor->exceptionOccurred()){
1809
            //TODO: xslt30Processor->checkException();
1810
            const char * errStr = xslt30Processor->getErrorMessage(0);
1811
            if(errStr != nullptr) {
1812
                const char * errorCode = xslt30Processor->getErrorCode(0);
1813
                if(errorCode!=nullptr) {
1814
                    // TODO: throw exception
1815
                }
1816
            }
1817
        }
1818
    }
1819

    
1820

    
1821

    
1822
}
1823

    
1824

    
1825
    PHP_METHOD(Xslt30Processor, callFunctionReturningFile){
1826
    HashTable *arr_hash;
1827
    Xslt30Processor *xslt30Processor;
1828
    char* functionName;
1829
    zval * arguments_zval;
1830
    zval * val;
1831
    long num_key;
1832
    XdmValue ** arguments = nullptr;
1833
    int argument_length=0;
1834
    zend_string *key;
1835

    
1836
    char * outfilename;
1837
    char * styleFileName = nullptr;
1838
    size_t len1, len2, len3;
1839

    
1840

    
1841
    if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "sas", &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
1842
        RETURN_NULL();
1843
    } else if (ZEND_NUM_ARGS()==4 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssas", &styleFileName, &len1, &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
1844
        RETURN_NULL();
1845
    }
1846

    
1847
    zend_object* pobj = Z_OBJ_P(getThis());
1848
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1849
    xslt30Processor = obj->xslt30Processor;
1850
    arr_hash = Z_ARRVAL_P(arguments_zval);
1851
    argument_length = zend_hash_num_elements(arr_hash);
1852
   
1853
    arguments = new XdmValue*[argument_length];
1854
      
1855
    if (xslt30Processor != nullptr) {
1856
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1857
        if(Z_TYPE_P(val) != nullptr) {
1858
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1859
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1860
        php_printf("num_key %d =>", num_key);
1861
        php_printf("key %d =>", key);
1862
        */
1863
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1864
                zend_object* ooth = Z_OBJ_P(val);
1865
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1866
                if(nobj != nullptr) {
1867
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1868
                            arguments[num_key] = value;
1869
                }
1870
        }
1871
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1872
                zend_object* ooth = Z_OBJ_P(val);
1873
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1874
                if(nobj != nullptr) {
1875
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1876
                            arguments[num_key] = value;
1877
                }
1878
        }
1879
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1880
                zend_object* ooth = Z_OBJ_P(val);
1881
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1882
                if(nobj != nullptr) {
1883
                            XdmValue * value = nobj->xdmValue;
1884
                            arguments[num_key] = value;
1885
                }
1886
        }
1887
        else {//TODO error warning}
1888
         }}else {
1889
                //TODO error warning
1890
        }
1891
      } ZEND_HASH_FOREACH_END();
1892

    
1893

    
1894
        xslt30Processor->callFunctionReturningFile(styleFileName, functionName, arguments, argument_length, outfilename);
1895
        if(xslt30Processor->exceptionOccurred()){
1896
            //TODO: xslt30Processor->checkException();
1897
            const char * errStr = xslt30Processor->getErrorMessage(0);
1898
            if(errStr != nullptr) {
1899
                const char * errorCode = xslt30Processor->getErrorCode(0);
1900
            }
1901
        }
1902
    }
1903

    
1904
}
1905

    
1906
    PHP_METHOD(Xslt30Processor, callTemplateReturningValue){
1907

    
1908
  Xslt30Processor *xslt30Processor;
1909
    char* templateName = nullptr;
1910
   
1911
    char * styleFileName = nullptr;
1912
    size_t len1, len2;
1913

    
1914

    
1915
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
1916
        RETURN_NULL();
1917
    } else if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1918
        RETURN_NULL();
1919
    }
1920

    
1921

    
1922
    zend_object* pobj = Z_OBJ_P(getThis());
1923
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1924
    xslt30Processor = obj->xslt30Processor;
1925
      
1926
    if (xslt30Processor != nullptr) {
1927
   
1928

    
1929
        //php_printf(" argument_length= %d",argument_length);
1930
        XdmValue * result = xslt30Processor->callTemplateReturningValue(styleFileName, templateName);
1931
        if(result != nullptr) {
1932
 
1933
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) { 
1934
               RETURN_NULL();
1935
            } else {
1936
                zend_object *ooth =  Z_OBJ_P(return_value);
1937
              
1938
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1939
                assert (vobj != nullptr);
1940
                vobj->xdmValue = result;
1941
                
1942
            }
1943
        } else {
1944
            if(obj->xslt30Processor->exceptionOccurred()){
1945
                  //TODO
1946
            }
1947
            RETURN_NULL();
1948
        }
1949
    }
1950
   }
1951

    
1952

    
1953
    PHP_METHOD(Xslt30Processor, callTemplateReturningString){
1954
    Xslt30Processor *xslt30Processor;
1955
    char* templateName = nullptr;
1956
   
1957
    char * styleFileName = nullptr;
1958
    size_t len1, len2;
1959

    
1960
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
1961
        RETURN_NULL();
1962
    }
1963

    
1964
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1965
        RETURN_NULL();
1966
    }
1967

    
1968
    zend_object* pobj = Z_OBJ_P(getThis());
1969
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1970
    xslt30Processor = obj->xslt30Processor;
1971
      
1972
    if (xslt30Processor != nullptr) {
1973
   
1974

    
1975
        //php_printf(" argument_length= %d",argument_length);
1976
        const char * result = xslt30Processor->callTemplateReturningString(styleFileName, templateName);
1977
        if(result != nullptr) {
1978
            _RETURN_STRING(result); 
1979
        } else {
1980
            if(xslt30Processor->exceptionOccurred()){
1981
            xslt30Processor->checkException();
1982
            const char * errStr = xslt30Processor->getErrorMessage(0);
1983
            if(errStr != nullptr) {
1984
                const char * errorCode = xslt30Processor->getErrorCode(0);
1985
                if(errorCode!=nullptr) {
1986
                    // TODO: throw exception
1987
                }
1988
            }
1989
           }
1990
        }
1991
    }
1992

    
1993
     RETURN_NULL();
1994
    }
1995

    
1996
    PHP_METHOD(Xslt30Processor, callTemplateReturningFile){
1997
   Xslt30Processor *xslt30Processor;
1998
    char* templateName = nullptr;
1999
    char * filename = nullptr;
2000
    char * styleFileName = nullptr;
2001
    size_t len1, len2, len3;
2002

    
2003
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
2004
        RETURN_NULL();
2005
    }
2006

    
2007
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
2008
        RETURN_NULL();
2009
    }
2010

    
2011
    zend_object* pobj = Z_OBJ_P(getThis());
2012
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2013
    xslt30Processor = obj->xslt30Processor;
2014
      
2015
    if (xslt30Processor != nullptr) {
2016
           xslt30Processor->callTemplateReturningFile(styleFileName, templateName, filename);
2017
    }
2018

    
2019
  }
2020

    
2021

    
2022
PHP_METHOD(Xslt30Processor, applyTemplatesReturningValue){
2023
   Xslt30Processor *xslt30Processor;
2024
    char * styleFileName = nullptr;
2025
    size_t len1;
2026

    
2027
    if (ZEND_NUM_ARGS()>0) {
2028

    
2029
      if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &styleFileName, &len1) == FAILURE) {
2030
          RETURN_NULL();
2031
      }
2032
    }
2033

    
2034
    zend_object* pobj = Z_OBJ_P(getThis());
2035
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2036
    xslt30Processor = obj->xslt30Processor;
2037
      
2038
    if (xslt30Processor != nullptr) {
2039
           XdmValue * result = xslt30Processor->applyTemplatesReturningValue(styleFileName);
2040
    
2041
        if(result != nullptr) {
2042
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2043
                RETURN_NULL();
2044
            } else {
2045
                zend_object *ooth =  Z_OBJ_P(return_value);
2046
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2047
                assert (vobj != nullptr);
2048
                vobj->xdmValue = result;
2049
            }
2050
        } else {
2051
            if(obj->xslt30Processor->exceptionOccurred()){
2052
                  //TODO
2053
            }
2054
            RETURN_NULL();
2055
        }
2056

    
2057

    
2058

    
2059
    } else {
2060
     RETURN_NULL();
2061
    }
2062
}
2063

    
2064

    
2065
PHP_METHOD(Xslt30Processor, applyTemplatesReturningString){
2066
 Xslt30Processor *xslt30Processor;
2067

    
2068
    char * styleFileName = nullptr;
2069
    size_t len1;
2070

    
2071

    
2072
    if (ZEND_NUM_ARGS()>0) {
2073
    
2074
            if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &styleFileName, &len1) == FAILURE) {
2075
                RETURN_NULL();
2076
            }
2077
    }
2078

    
2079
    zend_object* pobj = Z_OBJ_P(getThis());
2080
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2081
    xslt30Processor = obj->xslt30Processor;
2082
      
2083
    if (xslt30Processor != nullptr) {
2084
        const char * result = xslt30Processor->applyTemplatesReturningString(styleFileName);
2085
   
2086
        if(result != nullptr) {
2087
            _RETURN_STRING(result); 
2088
        } else {
2089
            if(xslt30Processor->exceptionOccurred()){
2090
            xslt30Processor->checkException();
2091
            const char * errStr = xslt30Processor->getErrorMessage(0);
2092
            if(errStr != nullptr) {
2093
                const char * errorCode = xslt30Processor->getErrorCode(0);
2094
                if(errorCode!=nullptr) {
2095
                    // TODO: throw exception
2096
                }
2097
            }
2098
           }
2099
        }
2100
    }
2101

    
2102
     RETURN_NULL();
2103
   
2104

    
2105

    
2106
}
2107

    
2108

    
2109

    
2110
PHP_METHOD(Xslt30Processor, applyTemplatesReturningFile){
2111
 Xslt30Processor *xslt30Processor;
2112
    char * filename = nullptr;
2113
    char * styleFileName = nullptr;
2114
    size_t len1, len2;
2115

    
2116
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &filename, &len2) == FAILURE) {
2117
          RETURN_NULL();
2118
    }
2119

    
2120
   if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &filename, &len2) == FAILURE) {
2121
          RETURN_NULL();
2122
    }
2123
    
2124

    
2125
    zend_object* pobj = Z_OBJ_P(getThis());
2126
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2127
    xslt30Processor = obj->xslt30Processor;
2128
      
2129
    if (xslt30Processor != nullptr) {
2130
           xslt30Processor->applyTemplatesReturningFile(styleFileName, filename);
2131
    }
2132

    
2133

    
2134

    
2135
}
2136

    
2137

    
2138
/*PHP_METHOD(Xslt30Processor, addPackages){
2139
    HashTable *arr_hash;
2140
    Xslt30Processor *xslt30Processor;
2141
    char* functionName = nullptr;
2142
    zval * arguments_zval;
2143
    zval * val;
2144
    long num_key;
2145
    const char ** arguments = nullptr;
2146
    int argument_length=0;
2147
    zend_string *key;
2148

2149
    char * infilename = nullptr;
2150
    char * styleFileName = nullptr;
2151
    size_t len1, len2;
2152

2153
        if (zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
2154
        RETURN_NULL();
2155
    }
2156

2157
    zend_object* pobj = Z_OBJ_P(getThis());
2158
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2159
    xslt30Processor = obj->xslt30Processor;
2160
    arr_hash = Z_ARRVAL_P(arguments_zval);
2161
    argument_length = zend_hash_num_elements(arr_hash);
2162
   
2163
    arguments = new const char*[argument_length];
2164

2165
  if (xslt30Processor != nullptr) {
2166
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
2167
        if(Z_TYPE_P(val) != nullptr && Z_TYPE_P(val)== IS_STRING) {
2168

2169
                arguments[num_key] = (const char*)Z_STRVAL_P(val);
2170
                     
2171
        } 
2172
    }  ZEND_HASH_FOREACH_END();
2173

2174
        xslt30Processor->addPackages(arguments, argument_length);
2175
        if(xslt30Processor->exceptionOccurred()){
2176
            //TODO: xslt30Processor->checkException();
2177
            const char * errStr = xslt30Processor->getErrorMessage(0);
2178
            if(errStr != nullptr) {
2179
                const char * errorCode = xslt30Processor->getErrorCode(0);
2180
            }
2181
        }
2182
    }
2183
}    */
2184

    
2185

    
2186
    PHP_METHOD(Xslt30Processor,setInitialTemplateParameters){
2187

    
2188
  Xslt30Processor *xslt30Processor;
2189
    HashTable *arr_hash;
2190
    zval * arguments_zval;
2191
    zval * val;
2192
    long num_key;
2193
    XdmValue ** arguments;
2194
    int argument_length=0;
2195
    zend_string *key;
2196

    
2197
    bool tunnel = false;
2198
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
2199
        RETURN_NULL();
2200
    }
2201

    
2202
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ab", &arguments_zval, &tunnel) == FAILURE) {
2203
        RETURN_NULL();
2204
    }
2205

    
2206

    
2207
    zend_object* pobj = Z_OBJ_P(getThis());
2208
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2209
    xslt30Processor = obj->xslt30Processor;
2210
    arr_hash = Z_ARRVAL_P(arguments_zval);
2211
    argument_length = zend_hash_num_elements(arr_hash);
2212
   
2213
    arguments = new XdmValue*[argument_length];
2214
    std::map<std::string,XdmValue*> parameters;
2215
    if (xslt30Processor != nullptr) {
2216
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
2217
        if(Z_TYPE_P(val) != nullptr) {
2218
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
2219
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
2220
        php_printf("num_key %d =>", num_key);
2221
        php_printf("key %d =>", key);
2222
        */
2223
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2224
                zend_object* ooth = Z_OBJ_P(val);
2225
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
2226
                if(nobj != nullptr) {
2227
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
2228
                            parameters[ZSTR_VAL(key)] = value;
2229
                }
2230
        }
2231
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2232
                zend_object* ooth = Z_OBJ_P(val);
2233
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
2234
                if(nobj != nullptr) {
2235
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
2236
                            parameters[ZSTR_VAL(key)] = value;
2237
                }
2238
        }
2239
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
2240
                zend_object* ooth = Z_OBJ_P(val);
2241
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2242
                if(nobj != nullptr) {
2243
                            XdmValue * value = nobj->xdmValue;
2244
                            parameters[ZSTR_VAL(key)] = value;
2245
                }
2246
        }
2247
        else {//TODO error warning}
2248
         }}else {
2249
                //TODO error warning
2250
        }
2251
      } ZEND_HASH_FOREACH_END();
2252

    
2253

    
2254
        //php_printf(" argument_length= %d",argument_length);
2255
        xslt30Processor->setInitialTemplateParameters(parameters, tunnel);
2256
        
2257
    }
2258

    
2259
    }
2260

    
2261

    
2262
PHP_METHOD(Xslt30Processor, setInitialMatchSelection){
2263
   Xslt30Processor *xslt30Processor;
2264
    zval* oth = nullptr;
2265

    
2266
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2267
        RETURN_NULL();
2268
    }
2269

    
2270
    zend_object* pobj = Z_OBJ_P(getThis());
2271
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2272
    xslt30Processor = obj->xslt30Processor;
2273
    if (xslt30Processor != nullptr) {
2274

    
2275
    if(!oth) {
2276
        php_error(E_WARNING, "Error setting source value");
2277
        return;
2278
    } else {
2279
        if(Z_TYPE_P(oth) ==IS_NULL){
2280
                php_error(E_WARNING, "Error setting source value - nullptr found");
2281
                return;
2282
        }
2283

    
2284
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2285
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2286

    
2287
      
2288
      if(strcmp(objName, "Saxon\\XdmValue")==0) {
2289
        zend_object * nobj = Z_OBJ_P(oth);
2290

    
2291
        xdmValue_object* ooth = (xdmValue_object *)((char *)nobj - XtOffsetOf(xdmValue_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2292
        if(ooth != nullptr) {
2293
            XdmValue * value = ooth->xdmValue;
2294
            if(value != nullptr) {
2295
                xslt30Processor->setInitialMatchSelection(value);
2296

    
2297
            }
2298
        }
2299
      } else if(strcmp(objName, "Saxon\\XdmNode")==0) {
2300
        zend_object * nobj = Z_OBJ_P(oth);
2301

    
2302
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2303
        if(ooth != nullptr) {
2304
            XdmNode * value = ooth->xdmNode;
2305
            if(value != nullptr) {
2306
                XdmValue  *valueX = (XdmValue*)value;
2307
                xslt30Processor->setInitialMatchSelection(valueX);
2308

    
2309
            } else {
2310

    
2311
php_error(E_WARNING, "XdmNode - seInitialMatchSelection - cp1");
2312
}
2313
        }
2314
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2315
        zend_object* vvobj = Z_OBJ_P(oth);
2316

    
2317
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2318
        if(ooth != nullptr) {
2319
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2320
            if(value != nullptr) {
2321
                xslt30Processor->setInitialMatchSelection((XdmValue*)value);
2322
            }
2323
        }
2324
      } else {
2325
        //TODO raise warning
2326
        }
2327

    
2328

    
2329
    }
2330
  }
2331

    
2332

    
2333

    
2334

    
2335
}
2336
    
2337

    
2338
PHP_METHOD(Xslt30Processor, setGlobalContextItem)
2339
{
2340
    Xslt30Processor *xslt30Processor;
2341
    zval* oth = nullptr;
2342

    
2343
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2344
        RETURN_NULL();
2345
    }
2346

    
2347
    zend_object* pobj = Z_OBJ_P(getThis());
2348
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2349
    xslt30Processor = obj->xslt30Processor;
2350
    if (xslt30Processor != nullptr) {
2351

    
2352
    if(!oth) {
2353
        php_error(E_WARNING, "Error setting source value");
2354
        return;
2355
    } else {
2356
        if(Z_TYPE_P(oth) ==IS_NULL){
2357
                php_error(E_WARNING, "Error setting source value");
2358
                return;
2359
        }
2360

    
2361
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2362
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2363

    
2364
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2365
        zend_object * nobj = Z_OBJ_P(oth);
2366

    
2367
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2368
        if(ooth != nullptr) {
2369
            XdmNode * value = ooth->xdmNode;
2370
            if(value != nullptr) {
2371
                XdmItem  *valueX = (XdmItem*)value;
2372
                xslt30Processor->setGlobalContextItem(valueX);
2373

    
2374
            }
2375
        }
2376
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2377
        zend_object* vvobj = Z_OBJ_P(oth);
2378
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2379
        if(ooth != nullptr) {
2380
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2381
            if(value != nullptr) {
2382
                xslt30Processor->setGlobalContextItem((XdmItem*)value);
2383
            }
2384
        }
2385
      } else {
2386
        //TODO raise warning
2387
        }
2388

    
2389

    
2390
    }
2391
  }
2392
}
2393

    
2394

    
2395
PHP_METHOD(Xslt30Processor, setGlobalContextFromFile)
2396
{
2397
    Xslt30Processor *xslt30Processor;
2398
    char * inFilename = nullptr;
2399
    size_t len1;
2400
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2401
        RETURN_NULL();
2402
    }
2403

    
2404
    zend_object* pobj = Z_OBJ_P(getThis());
2405
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2406
    xslt30Processor = obj->xslt30Processor;
2407
    if (xslt30Processor != nullptr && inFilename != nullptr) {
2408
         xslt30Processor->setGlobalContextFromFile(inFilename);
2409

    
2410

    
2411
    }
2412
}
2413

    
2414

    
2415
PHP_METHOD(Xslt30Processor, setInitialMatchSelectionAsFile)
2416
{
2417
    Xslt30Processor *xslt30Processor;
2418
    char * inFilename = nullptr;
2419
    size_t len1;
2420
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2421
        RETURN_NULL();
2422
    }
2423

    
2424
    zend_object* pobj = Z_OBJ_P(getThis());
2425
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2426
    xslt30Processor = obj->xslt30Processor;
2427
    if (xslt30Processor != nullptr && inFilename != nullptr) {
2428
         xslt30Processor->setInitialMatchSelectionAsFile(inFilename);
2429

    
2430

    
2431
    }
2432
}
2433

    
2434

    
2435
PHP_METHOD(Xslt30Processor, transformFileToFile)
2436
{
2437
    Xslt30Processor *xslt30Processor;
2438
    char * outfileName = nullptr;
2439
    char * infilename = nullptr;
2440
    char * styleFileName = nullptr;
2441
    size_t len1, len2, len3;
2442

    
2443
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
2444
        RETURN_NULL();
2445
    }
2446

    
2447
    zend_object* pobj = Z_OBJ_P(getThis());
2448
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2449
    xslt30Processor = obj->xslt30Processor;
2450

    
2451
    if (xslt30Processor != nullptr) {
2452

    
2453
        xslt30Processor->transformFileToFile(infilename, styleFileName, outfileName);
2454
        if(xslt30Processor->exceptionOccurred()) {
2455
               // TODO: throw exception
2456
        }
2457
    }
2458
}
2459

    
2460
PHP_METHOD(Xslt30Processor, transformFileToValue)
2461
{
2462
    Xslt30Processor *xslt30Processor;
2463
    char * infilename = nullptr;
2464
    char * styleFileName = nullptr;
2465
   size_t len1, len2;
2466

    
2467
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2468
        RETURN_NULL();
2469
    }
2470

    
2471
    zend_object* pobj = Z_OBJ_P(getThis());
2472
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2473
    xslt30Processor = obj->xslt30Processor;
2474

    
2475
    if (xslt30Processor != nullptr) {
2476

    
2477
        XdmValue * node = xslt30Processor->transformFileToValue(infilename, styleFileName);
2478
        if(node != nullptr) {
2479
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2480
                RETURN_NULL();
2481
            } else {
2482
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
2483
                zend_object *ooth =  Z_OBJ_P(return_value);
2484
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2485
                assert (vobj != nullptr);
2486
                vobj->xdmValue = node;
2487
            }
2488
        } else {
2489
            if(obj->xslt30Processor->exceptionOccurred()){
2490
                  //TODO
2491
            }
2492
        }
2493
    }else {
2494
        RETURN_NULL();
2495
    }
2496
}
2497

    
2498

    
2499
PHP_METHOD(Xslt30Processor, transformFileToString)
2500
{
2501
    Xslt30Processor *xslt30Processor;
2502
    char * infilename = nullptr;
2503
    char * styleFileName = nullptr;
2504
    size_t len1, len2;
2505

    
2506
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2507
        RETURN_NULL();
2508
    }
2509

    
2510
    zend_object* pobj = Z_OBJ_P(getThis());
2511
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2512
    xslt30Processor = obj->xslt30Processor;
2513

    
2514
    if (xslt30Processor != nullptr) {
2515

    
2516
        const char * result = xslt30Processor->transformFileToString(infilename, styleFileName);
2517
        if(result != nullptr) {
2518
            //char *str = estrdup(result);
2519
            _RETURN_STRING(result);
2520
        } else if(xslt30Processor->exceptionOccurred()){
2521
            //TODO: xslt30Processor->checkException();
2522
            const char * errStr = xslt30Processor->getErrorMessage(0);
2523
            if(errStr != nullptr) {
2524
                const char * errorCode = xslt30Processor->getErrorCode(0);
2525
                if(errorCode!=nullptr) {
2526
                    // TODO: throw exception
2527
                }
2528
            }
2529
        }
2530
    }
2531
}
2532

    
2533

    
2534

    
2535
PHP_METHOD(Xslt30Processor, transformToString)
2536
{
2537
    Xslt30Processor *xslt30Processor;
2538

    
2539
    if (ZEND_NUM_ARGS()>1) {
2540
        WRONG_PARAM_COUNT;
2541
    }
2542

    
2543

    
2544
    zval* oth;
2545
   
2546

    
2547
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2548
        RETURN_NULL();
2549
    }
2550

    
2551

    
2552
    zend_object* pobj = Z_OBJ_P(getThis());
2553
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2554
    xslt30Processor = obj->xslt30Processor;
2555
    if (xslt30Processor != nullptr) {
2556

    
2557

    
2558
     if(ZEND_NUM_ARGS() == 0) {
2559
        const char * result = xslt30Processor->transformToString();
2560
        if(result != nullptr) {
2561
            _RETURN_STRING(result);
2562
            return;
2563

    
2564
        }
2565

    
2566

    
2567
     } else {
2568
        if(!oth) {
2569
            php_error(E_WARNING, "Error setting source value");
2570
            return;
2571
        }
2572

    
2573
            if(Z_TYPE_P(oth) ==IS_NULL){
2574
                    php_error(E_WARNING, "Error setting source value");
2575
                    return;
2576
            }
2577

    
2578
        const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2579
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2580
                zend_object * nobj = Z_OBJ_P(oth);
2581

    
2582
                xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2583
            if(ooth != nullptr) {
2584
                XdmNode * value = ooth->xdmNode;
2585
                if(value != nullptr) {
2586
                        const char * result = xslt30Processor->transformToString(value);
2587
                    if(result != nullptr) {
2588
                        _RETURN_STRING(result);
2589
                    }
2590
                }
2591

    
2592
            }
2593
        }
2594
     }
2595
    }
2596

    
2597
    RETURN_NULL();
2598
}
2599

    
2600
PHP_METHOD(Xslt30Processor, transformToValue)
2601
{
2602
    Xslt30Processor *xslt30Processor;
2603

    
2604
    if (ZEND_NUM_ARGS()>1) {
2605
        WRONG_PARAM_COUNT;
2606
    }
2607

    
2608

    
2609
    zval* oth;
2610
   
2611

    
2612
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2613
        RETURN_NULL();
2614
    }
2615

    
2616
    zend_object* pobj = Z_OBJ_P(getThis());
2617
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2618
    xslt30Processor = obj->xslt30Processor;
2619

    
2620
    if (xslt30Processor != nullptr) {
2621
      if(!oth) {
2622
        php_error(E_WARNING, "Error setting source value");
2623
        return;
2624
      } else {
2625
        XdmValue * node = nullptr;
2626
        if(ZEND_NUM_ARGS() == 0) {
2627
            XdmValue * node = xslt30Processor->transformToValue();
2628

    
2629
        } else {
2630

    
2631
            if(Z_TYPE_P(oth) == IS_NULL){
2632
                php_error(E_WARNING, "Error setting source value");
2633
                return;
2634
            }
2635

    
2636
            const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2637

    
2638
            if(strcmp(objName,"Saxon\\XdmNode")==0) {
2639
                zend_object *nobj = Z_OBJ_P(oth);
2640

    
2641
                xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
2642
                                           XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2643
                if(ooth != nullptr) {
2644
                    XdmNode *value = ooth->xdmNode;
2645
                    if(value != nullptr) {
2646
                        node = xslt30Processor->transformToValue(value);
2647
                    }
2648
                }
2649
            }
2650
        }
2651
        if(node != nullptr) {
2652
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2653
                RETURN_NULL();
2654
            } else {
2655
                zend_object *vvobj =  Z_OBJ_P(return_value);
2656
                        xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2657
                        assert (vobj != nullptr);
2658
                        vobj->xdmValue = node;
2659
                        return;
2660
            }
2661
        }
2662
      }
2663

    
2664

    
2665

    
2666
    } else {
2667
        RETURN_NULL();
2668
    }
2669
}
2670

    
2671
PHP_METHOD(Xslt30Processor, transformToFile)
2672
{
2673
    Xslt30Processor *xslt30Processor;
2674

    
2675
    if (ZEND_NUM_ARGS()>1) {
2676
        WRONG_PARAM_COUNT;
2677
    }
2678

    
2679

    
2680
    zval* oth;
2681
   
2682

    
2683
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2684
        RETURN_NULL();
2685
    }
2686

    
2687
    zend_object* pobj = Z_OBJ_P(getThis());
2688
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2689
    xslt30Processor = obj->xslt30Processor;
2690

    
2691
    if (xslt30Processor != nullptr) {
2692
      if(!oth) {
2693
        php_error(E_WARNING, "Error setting source value");
2694
        return;
2695
      } else {
2696
        if(ZEND_NUM_ARGS() == 0) {
2697
            xslt30Processor->transformToFile();
2698
        } else {
2699
            if(Z_TYPE_P(oth) == mIS_NULL){
2700
                php_error(E_WARNING,"Error setting source value");
2701
                return;
2702
            }
2703

    
2704
            const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2705

    
2706
            if(strcmp(objName,"Saxon\\XdmNode")==0) {
2707
                zend_object *nobj = Z_OBJ_P(oth);
2708

    
2709
                xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
2710
                                           XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2711
                if(ooth != nullptr) {
2712
                    XdmNode *value = ooth->xdmNode;
2713
                    if(value != nullptr) {
2714
                        xslt30Processor->transformToFile(value);
2715
                    }
2716
                }
2717
            }
2718

    
2719
        }
2720
      }
2721
    }
2722
}
2723

    
2724
PHP_METHOD(Xslt30Processor, compileFromFile)
2725
{
2726
    Xslt30Processor *xslt30Processor;
2727
    char * name = nullptr;
2728
    size_t len1;
2729
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2730
        RETURN_NULL();
2731
    }
2732
    zend_object* pobj = Z_OBJ_P(getThis());
2733
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2734
    xslt30Processor = obj->xslt30Processor;
2735
    if (xslt30Processor != nullptr) {
2736
        xslt30Processor->compileFromFile(name);
2737
    }
2738
}
2739

    
2740

    
2741
PHP_METHOD(Xslt30Processor, compileFromAssociatedFile)
2742
{
2743
    Xslt30Processor *xslt30Processor;
2744
    char * name = nullptr;
2745
    size_t len1;
2746
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2747
        RETURN_NULL();
2748
    }
2749
    zend_object* pobj = Z_OBJ_P(getThis());
2750
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2751
    xslt30Processor = obj->xslt30Processor;
2752
    if (xslt30Processor != nullptr) {
2753
        xslt30Processor->compileFromAssociatedFile(name);
2754
    }
2755
}
2756

    
2757

    
2758
PHP_METHOD(Xslt30Processor, compileFromString)
2759
{
2760
    Xslt30Processor *xslt30Processor;
2761
    char * stylesheetStr;
2762
    size_t len1, myint;
2763
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
2764
        RETURN_NULL();
2765
    }
2766
    zend_object* pobj = Z_OBJ_P(getThis());
2767
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2768
    xslt30Processor = obj->xslt30Processor;
2769
    if (xslt30Processor != nullptr) {
2770
        xslt30Processor->compileFromString(stylesheetStr);
2771
    }
2772
}
2773

    
2774
PHP_METHOD(Xslt30Processor, compileFromStringAndSave)
2775
{
2776
    Xslt30Processor *xslt30Processor;
2777
    char * stylesheetStr;
2778
    char * filename = nullptr;
2779
    size_t len1, len2, myint;
2780
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetStr, filename, &len1, &len2) == FAILURE) {
2781
        RETURN_NULL();
2782
    }
2783
    zend_object* pobj = Z_OBJ_P(getThis());
2784
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2785
    xslt30Processor = obj->xslt30Processor;
2786
    if (xslt30Processor != nullptr) {
2787
        xslt30Processor->compileFromStringAndSave(stylesheetStr, filename);
2788
    }
2789
}
2790

    
2791
PHP_METHOD(Xslt30Processor, compileFromFileAndSave)
2792
{
2793
    Xslt30Processor *xslt30Processor;
2794
    char * stylesheetFilename = nullptr;
2795
    char * filename = nullptr;
2796
    size_t len1, len2, myint;
2797
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
2798
        RETURN_NULL();
2799
    }
2800
    zend_object* pobj = Z_OBJ_P(getThis());
2801
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2802
    xslt30Processor = obj->xslt30Processor;
2803
    if (xslt30Processor != nullptr) {
2804
        xslt30Processor->compileFromStringAndSave(stylesheetFilename, filename);
2805
    }
2806
}
2807

    
2808

    
2809

    
2810
PHP_METHOD(Xslt30Processor, compileFromValue)
2811
{
2812
    Xslt30Processor *xslt30Processor;
2813
   zval* oth;
2814

    
2815
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
2816
        RETURN_NULL();
2817
    }
2818
    zend_object* pobj = Z_OBJ_P(getThis());
2819
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2820
    xslt30Processor = obj->xslt30Processor;
2821
    if (xslt30Processor != nullptr) {
2822
        zend_object* vvobj = Z_OBJ_P(oth);
2823
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2824
        if(ooth != nullptr) {
2825
            XdmValue * value = ooth->xdmValue;
2826
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
2827
                xslt30Processor->compileFromXdmNode((XdmNode*)(value->getHead()));
2828
            }
2829
        }
2830
    }
2831
}
2832

    
2833

    
2834

    
2835
PHP_METHOD(Xslt30Processor, setResultAsRawValue)
2836
{
2837
    Xslt30Processor *xslt30Processor;
2838
    bool raw = false;
2839

    
2840
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &raw) == FAILURE) {
2841
        RETURN_NULL();
2842
    }
2843

    
2844
    zend_object* pobj = Z_OBJ_P(getThis());
2845
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2846
    xslt30Processor = obj->xslt30Processor;
2847
    if (xslt30Processor != nullptr) {
2848
         xslt30Processor->setResultAsRawValue(raw);
2849
    }
2850

    
2851
}
2852

    
2853

    
2854

    
2855
PHP_METHOD(Xslt30Processor, setJustInTimeCompilation)
2856
{
2857
    Xslt30Processor *xslt30Processor;
2858
    bool jit = false;
2859
    size_t len1;
2860

    
2861
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
2862
        RETURN_NULL();
2863
    }
2864

    
2865
    zend_object* pobj = Z_OBJ_P(getThis());
2866
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2867
    xslt30Processor = obj->xslt30Processor;
2868
    if (xslt30Processor != nullptr) {
2869
         xslt30Processor->setJustInTimeCompilation(jit);
2870
    }
2871
}
2872

    
2873
PHP_METHOD(Xslt30Processor, setOutputFile)
2874
{
2875
    Xslt30Processor *xslt30Processor;
2876
    char * outputFilename = nullptr;
2877
    size_t len1;
2878

    
2879
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
2880
        RETURN_NULL();
2881
    }
2882

    
2883
    zend_object* pobj = Z_OBJ_P(getThis());
2884
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2885
    xslt30Processor = obj->xslt30Processor;
2886
    if (xslt30Processor != nullptr && outputFilename != nullptr) {
2887

    
2888
         xslt30Processor->setOutputFile(outputFilename);
2889

    
2890

    
2891
    }
2892
}
2893

    
2894

    
2895

    
2896

    
2897
PHP_METHOD(Xslt30Processor, setProperty)
2898
{
2899
    Xslt30Processor *xslt30Processor;
2900
    char * name = nullptr;
2901
    char * value;
2902
    size_t len1, len2, myint;
2903

    
2904
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
2905
        RETURN_NULL();
2906
    }
2907
    zend_object* pobj = Z_OBJ_P(getThis());
2908
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2909
    xslt30Processor = obj->xslt30Processor;
2910
    if (xslt30Processor != nullptr) {
2911
        xslt30Processor->setProperty(name, value);
2912
    }
2913
}
2914

    
2915
PHP_METHOD(Xslt30Processor, setParameter)
2916
{
2917

    
2918
   Xslt30Processor *xslt30Processor;
2919
   char * name;
2920
   zval* oth;
2921
   size_t len1, len2, myint;
2922
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
2923
        RETURN_NULL();
2924
    }
2925
    zend_object* pobj = Z_OBJ_P(getThis());
2926
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2927
    xslt30Processor = obj->xslt30Processor;
2928
    if (xslt30Processor != nullptr) {
2929
        if(Z_TYPE_P(oth) ==IS_NULL){
2930
                php_error(E_WARNING, "Error setting source value - value is nullptr");
2931
                return;
2932
        }
2933

    
2934
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2935
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2936

    
2937
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2938
        zend_object* ooth = Z_OBJ_P(oth);
2939
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
2940
        if(nobj != nullptr) {
2941
            XdmNode * value = nobj->xdmNode;
2942
            if(value != nullptr) {
2943
                xslt30Processor->setParameter(name, (XdmValue *)value);
2944

    
2945
            }
2946
        }
2947
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2948
        zend_object* ooth = Z_OBJ_P(oth);
2949
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2950
        if(vobj != nullptr) {
2951
            XdmValue * value = vobj->xdmValue;
2952
            if(value != nullptr) {
2953

    
2954
                xslt30Processor->setParameter(name, value);
2955
            }
2956
        }
2957

    
2958

    
2959

    
2960
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2961
        zend_object* ooth = Z_OBJ_P(oth);
2962
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
2963
        if(aobj != nullptr) {
2964
            XdmAtomicValue * value = aobj->xdmAtomicValue;
2965
            if(value != nullptr) {
2966
                xslt30Processor->setParameter(name, (XdmValue *)value);
2967
            }
2968
        }
2969

    
2970

    
2971

    
2972
      }
2973

    
2974
    }
2975
}
2976

    
2977
PHP_METHOD(Xslt30Processor, clearParameters)
2978
{
2979
    Xslt30Processor *xslt30Processor;
2980
    if (ZEND_NUM_ARGS()>0) {
2981
        WRONG_PARAM_COUNT;
2982
    }
2983

    
2984
    zend_object* pobj = Z_OBJ_P(getThis());
2985
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2986
    xslt30Processor = obj->xslt30Processor;
2987
    if (xslt30Processor != nullptr) {
2988
        xslt30Processor->clearParameters(true);
2989
    }
2990
}
2991

    
2992
PHP_METHOD(Xslt30Processor, clearProperties)
2993
{
2994
    Xslt30Processor *xslt30Processor;
2995
    if (ZEND_NUM_ARGS()>0) {
2996
        WRONG_PARAM_COUNT;
2997
    }
2998

    
2999
    zend_object* pobj = Z_OBJ_P(getThis());
3000
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3001
    xslt30Processor = obj->xslt30Processor;
3002
    if (xslt30Processor != nullptr) {
3003
        xslt30Processor->clearProperties();
3004
    }
3005
}
3006

    
3007

    
3008
PHP_METHOD(Xslt30Processor, setupXslMessage)
3009
{
3010
    Xslt30Processor *xslt30Processor;
3011
    bool show = false;
3012
    char * filename = nullptr;
3013
    size_t len1;
3014
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename &len1) == FAILURE) {
3015
        RETURN_NULL();
3016
    }
3017

    
3018
    zend_object* pobj = Z_OBJ_P(getThis());
3019
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3020
    xslt30Processor = obj->xslt30Processor;
3021

    
3022
    if (xslt30Processor != nullptr) {
3023

    
3024
            xslt30Processor->setupXslMessage(show, filename);
3025
        }
3026

    
3027
}
3028

    
3029

    
3030

    
3031
PHP_METHOD(Xslt30Processor, exceptionOccurred)
3032
{
3033
    Xslt30Processor *xslt30Processor;
3034
    zend_object* pobj = Z_OBJ_P(getThis());
3035
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3036
    if (ZEND_NUM_ARGS()>0) {
3037
        WRONG_PARAM_COUNT;
3038
    }
3039

    
3040
    xslt30Processor = obj->xslt30Processor;
3041
    if (xslt30Processor != nullptr) {
3042
        bool result = xslt30Processor->exceptionOccurred();
3043
        RETURN_BOOL(result);
3044
    }
3045
    RETURN_BOOL(false);
3046
}
3047

    
3048
PHP_METHOD(Xslt30Processor, getExceptionCount)
3049
{
3050
    Xslt30Processor *xslt30Processor;
3051
    zend_object* pobj = Z_OBJ_P(getThis());
3052
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3053
    if (ZEND_NUM_ARGS()>0) {
3054
        WRONG_PARAM_COUNT;
3055
    }
3056

    
3057
    xslt30Processor = obj->xslt30Processor;
3058
    if (xslt30Processor != nullptr) {
3059
        int count = xslt30Processor->exceptionCount();
3060
        RETURN_LONG(count);
3061
    }
3062
    RETURN_LONG(0);
3063
}
3064

    
3065
PHP_METHOD(Xslt30Processor, getErrorCode)
3066
{
3067
    Xslt30Processor *xslt30Processor;
3068
    long index;
3069
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3070
        RETURN_NULL();
3071
    }
3072
    zend_object* pobj = Z_OBJ_P(getThis());
3073
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3074
    xslt30Processor = obj->xslt30Processor;
3075
    if (xslt30Processor != nullptr) {
3076
        const char * errCode = xslt30Processor->getErrorCode((int)index);
3077
        if(errCode != nullptr) {
3078
            //char *str = estrdup(errCode);
3079
            _RETURN_STRING(errCode);
3080
        }
3081
    }
3082
    RETURN_NULL();
3083
}
3084

    
3085
PHP_METHOD(Xslt30Processor, getErrorMessage)
3086
{
3087
    Xslt30Processor *xslt30Processor;
3088
    long index;
3089
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3090
        RETURN_NULL();
3091
    }
3092
    zend_object* pobj = Z_OBJ_P(getThis());
3093
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3094
    xslt30Processor = obj->xslt30Processor;
3095
    if (xslt30Processor != nullptr) {
3096
        const char * errStr = xslt30Processor->getErrorMessage((int)index);
3097
        if(errStr != nullptr) {
3098
            //char *str = estrdup(errStr);
3099
            _RETURN_STRING(errStr);
3100
        }
3101
    }
3102
    RETURN_NULL();
3103
}
3104
PHP_METHOD(Xslt30Processor, exceptionClear)
3105
{
3106
    Xslt30Processor *xslt30Processor;
3107
    zend_object* pobj = Z_OBJ_P(getThis());
3108
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3109
    xslt30Processor = obj->xslt30Processor;
3110
    if (xslt30Processor != nullptr) {
3111
        xslt30Processor->exceptionClear();
3112
    }
3113
}
3114

    
3115
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
3116

    
3117
void xqueryProcessor_free_storage(zend_object *object)
3118
{
3119
    zend_object_std_dtor(object);
3120
}
3121

    
3122
void xqueryProcessor_destroy_storage(zend_object *object)
3123
{
3124
    zend_objects_destroy_object(object);
3125
}
3126

    
3127
zend_object *xqueryProcessor_create_handler(zend_class_entry *type)
3128
{
3129

    
3130
    xqueryProcessor_object *obj = (xqueryProcessor_object *)ecalloc(1, sizeof(xqueryProcessor_object)+ zend_object_properties_size(type));
3131
    zend_object_std_init(&obj->std, type); 
3132
    object_properties_init(&obj->std, type);
3133
    obj->std.handlers = &xqueryProcessor_object_handlers;
3134

    
3135
    return &obj->std;
3136
}
3137

    
3138
PHP_METHOD(XQueryProcessor, __destruct)
3139
{
3140
    zend_object* pobj = Z_OBJ_P(getThis());
3141
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3142
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
3143
    if(xqueryProcessor != nullptr){
3144
            delete xqueryProcessor;
3145
    }
3146
}
3147

    
3148

    
3149
PHP_METHOD(XQueryProcessor, runQueryToValue)
3150
{
3151
    XQueryProcessor *xqueryProcessor;
3152
    zend_object* pobj = Z_OBJ_P(getThis()); 
3153
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3154

    
3155
    if (ZEND_NUM_ARGS()>0) {
3156
        WRONG_PARAM_COUNT;
3157
    }
3158

    
3159
    xqueryProcessor = obj->xqueryProcessor;
3160

    
3161
    if (xqueryProcessor != nullptr) {
3162
        XdmValue * node = xqueryProcessor->runQueryToValue();
3163
        if(node != nullptr) {
3164
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
3165
                RETURN_NULL();
3166
                return;
3167
            } else {
3168
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
3169
                zend_object *vvobj =  Z_OBJ_P(return_value);
3170
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3171
                assert (vobj != nullptr);
3172
                vobj->xdmValue = node;
3173
                return;
3174
            }
3175
        }
3176
        xqueryProcessor->checkException();//TODO
3177
    } else {
3178
        RETURN_NULL();
3179
    }
3180
}
3181

    
3182
PHP_METHOD(XQueryProcessor, runQueryToString)
3183
{
3184
    XQueryProcessor *xqueryProcessor;
3185
   
3186

    
3187
    if (ZEND_NUM_ARGS()>0) {
3188
        WRONG_PARAM_COUNT;
3189
    }
3190
    zend_object* pobj = Z_OBJ_P(getThis()); 
3191
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3192
    xqueryProcessor = obj->xqueryProcessor;
3193

    
3194
    if (xqueryProcessor != nullptr) {
3195
        const char * result = xqueryProcessor->runQueryToString();
3196
        if(result != nullptr) {
3197
            //char *str = estrdup(result);
3198
            _RETURN_STRING(result);
3199
            return;
3200
        } else {
3201
          xqueryProcessor->checkException(); //TODO
3202
        }
3203
    }
3204
   RETURN_NULL();
3205
}
3206

    
3207
PHP_METHOD(XQueryProcessor, runQueryToFile)
3208
{
3209

    
3210
     char * ofilename;
3211
    size_t len1 =0;
3212
    if (ZEND_NUM_ARGS()!= 1) {
3213
        WRONG_PARAM_COUNT;
3214
    }
3215
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &ofilename, &len1) == FAILURE) {
3216
        RETURN_NULL();
3217
    }
3218
    XQueryProcessor *xqueryProcessor;
3219
    zend_object* pobj = Z_OBJ_P(getThis()); 
3220
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3221

    
3222

    
3223

    
3224
    xqueryProcessor = obj->xqueryProcessor;
3225

    
3226
    if (xqueryProcessor != nullptr) {
3227
        if(ofilename != nullptr) {
3228
                xqueryProcessor->setOutputFile(ofilename);        
3229
        }
3230
        xqueryProcessor->runQueryToFile(); 
3231
    }
3232

    
3233
}
3234

    
3235
PHP_METHOD(XQueryProcessor, setQueryContent)
3236
{
3237
    char * queryStr;
3238
    size_t len1;
3239

    
3240
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &queryStr, &len1) == FAILURE) {
3241
        RETURN_NULL();
3242
    }
3243
    zend_object* pobj = Z_OBJ_P(getThis()); 
3244
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std)); 
3245
    if(queryStr != nullptr) {
3246
      obj->xqueryProcessor->setProperty("qs", queryStr);
3247
   }
3248
}
3249

    
3250
PHP_METHOD(XQueryProcessor, setQueryFile)
3251
{
3252
   char * fileName;
3253
   size_t len1;
3254
    XQueryProcessor *xqueryProcessor;
3255

    
3256
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fileName, &len1) == FAILURE) {
3257
        RETURN_NULL();
3258
    }
3259
    if(fileName != nullptr) {
3260
            zend_object* pobj = Z_OBJ_P(getThis()); 
3261
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3262
            xqueryProcessor = obj->xqueryProcessor;
3263
            xqueryProcessor->setQueryFile(fileName);
3264
    }
3265
            
3266
}
3267

    
3268
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
3269
{
3270
   char * base;
3271
   size_t len1;
3272
    XQueryProcessor *xqueryProcessor;
3273

    
3274
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &base, &len1) == FAILURE) {
3275
        RETURN_NULL();
3276
    }
3277
    if(base != nullptr) {
3278
            zend_object* pobj = Z_OBJ_P(getThis()); 
3279
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3280
            xqueryProcessor = obj->xqueryProcessor;
3281
            xqueryProcessor->setQueryBaseURI(base);
3282
    }
3283
            
3284
}
3285

    
3286
PHP_METHOD(XQueryProcessor, declareNamespace)
3287
{
3288
   char * prefix;
3289
   char * ns;
3290
   size_t len1, len2;
3291
    XQueryProcessor *xqueryProcessor;
3292

    
3293
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
3294
        RETURN_NULL();
3295
    }
3296
    if(prefix != nullptr && ns != nullptr) {
3297
            zend_object* pobj = Z_OBJ_P(getThis()); 
3298
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3299
            xqueryProcessor = obj->xqueryProcessor;
3300
            xqueryProcessor->declareNamespace(prefix, ns);
3301
    }
3302
            
3303
}
3304

    
3305

    
3306

    
3307
PHP_METHOD(XQueryProcessor, setContextItem)
3308
{
3309
   char * context;
3310
   int len1;
3311
   zval* oth;
3312
    XQueryProcessor *xqueryProcessor;
3313

    
3314
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &oth) == FAILURE) {
3315
        RETURN_NULL();
3316
    }
3317
    if(oth != nullptr) {
3318
            zend_object* pobj = Z_OBJ_P(getThis()); 
3319
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3320
            xqueryProcessor = obj->xqueryProcessor;
3321
    const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name); 
3322
        
3323
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3324
        zend_object *vvobj =  Z_OBJ_P(oth);
3325
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3326
        //xdmNode_object* ooth = (xdmNode_object*)Z_OBJ_P(oth TSRMLS_CC);
3327
        if(ooth != nullptr) {
3328
            XdmNode * value = ooth->xdmNode;
3329
            if(value != nullptr) {
3330
                xqueryProcessor->setContextItem((XdmItem *)value);
3331
               
3332
                return;
3333
            }
3334
        }
3335
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
3336
        zend_object *vvobj =  Z_OBJ_P(oth);
3337
        xdmItem_object* ooth  = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
3338
        if(ooth != nullptr) {
3339
            XdmItem * value = ooth->xdmItem;
3340
            if(value != nullptr) {
3341
                xqueryProcessor->setContextItem(value);
3342
               
3343
                return;
3344
            }
3345
         }
3346
        
3347

    
3348

    
3349

    
3350
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3351
        zend_object *vvobj =  Z_OBJ_P(oth);
3352
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3353
        if(ooth != nullptr) {
3354
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3355
            if(value != nullptr) {
3356
                
3357
                xqueryProcessor->setContextItem((XdmItem *)value);
3358
      
3359
                return;
3360
            }
3361
        }
3362

    
3363

    
3364

    
3365
      } 
3366

    
3367

    
3368
    }
3369
        //throw exception
3370
        
3371
            
3372
}
3373

    
3374
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
3375
{
3376
   char * cfilename;
3377
   size_t len1;
3378
    XQueryProcessor *xqueryProcessor;
3379

    
3380
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &cfilename, &len1) == FAILURE) {
3381
        RETURN_NULL();
3382
    }
3383
    if(cfilename != nullptr) {
3384
             zend_object* pobj = Z_OBJ_P(getThis()); 
3385
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3386
            xqueryProcessor = obj->xqueryProcessor;
3387
            xqueryProcessor->setContextItemFromFile(cfilename);
3388
    }
3389
            
3390
}
3391

    
3392

    
3393
PHP_METHOD(XQueryProcessor, setProperty)
3394
{
3395
    XQueryProcessor *xqueryProcessor;
3396
    char * name;
3397
    char * value;
3398
    size_t len1, len2, myint;
3399

    
3400
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
3401
        RETURN_NULL();
3402
    }
3403
    zend_object* pobj = Z_OBJ_P(getThis()); 
3404
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3405
    xqueryProcessor = obj->xqueryProcessor;
3406
    if (xqueryProcessor != nullptr) {
3407
        xqueryProcessor->setProperty(name, value);
3408
    }
3409
}
3410

    
3411
PHP_METHOD(XQueryProcessor, setParameter)
3412
{
3413

    
3414
   XQueryProcessor *xqueryProcessor;
3415
   char * name;
3416
   zval* oth;
3417
   size_t len1, len2, myint;        
3418
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
3419
        RETURN_NULL();
3420
    }
3421
    zend_object* pobj = Z_OBJ_P(getThis()); 
3422
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3423
    xqueryProcessor = obj->xqueryProcessor;
3424
    if (xqueryProcessor != nullptr) {
3425
        if(Z_TYPE_P(oth) ==IS_NULL){
3426
                php_error(E_WARNING, "Error setting source value - value is nullptr");
3427
                return;
3428
        }
3429
             const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
3430
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3431
//Z_ADDREF_P(oth);
3432
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3433
        zend_object *vvobj =  Z_OBJ_P(oth);
3434
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3435
        if(ooth != nullptr) {
3436
            XdmNode * value = ooth->xdmNode;
3437
            if(value != nullptr) {
3438
                xqueryProcessor->setParameter(name, (XdmValue *)value);
3439

    
3440
            }
3441
        }
3442
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
3443
        zend_object *vvobj =  Z_OBJ_P(oth);
3444
        xdmValue_object* ooth  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3445
        if(ooth != nullptr) {
3446
            XdmValue * value = ooth->xdmValue;
3447
            if(value != nullptr) {
3448
                
3449
                xqueryProcessor->setParameter(name, value);
3450
            }
3451
        }
3452

    
3453

    
3454

    
3455
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3456
        zend_object *vvobj =  Z_OBJ_P(oth);
3457
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3458
        if(ooth != nullptr) {
3459
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3460
            if(value != nullptr) {
3461
                
3462
                xqueryProcessor->setParameter(name, (XdmValue *)value);
3463
            } 
3464
        }
3465

    
3466

    
3467

    
3468
      }
3469

    
3470
    }
3471
}
3472

    
3473

    
3474

    
3475

    
3476
PHP_METHOD(XQueryProcessor, clearParameters)
3477
{
3478
    XQueryProcessor *xqueryProcessor;
3479
    if (ZEND_NUM_ARGS()>0) {
3480
        WRONG_PARAM_COUNT;
3481
    }
3482

    
3483
    zend_object* pobj = Z_OBJ_P(getThis()); 
3484
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3485
    xqueryProcessor = obj->xqueryProcessor;
3486
    if (xqueryProcessor != nullptr) {
3487
        xqueryProcessor->clearParameters(true);
3488
    }
3489
}
3490

    
3491
PHP_METHOD(XQueryProcessor, clearProperties)
3492
{
3493
    XQueryProcessor *xqueryProcessor;
3494

    
3495
    if (ZEND_NUM_ARGS()>0) {
3496
        WRONG_PARAM_COUNT;
3497
    }
3498

    
3499
    zend_object* pobj = Z_OBJ_P(getThis()); 
3500
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3501
    xqueryProcessor = obj->xqueryProcessor;
3502
    if (xqueryProcessor != nullptr) {
3503
        xqueryProcessor->clearProperties();
3504
    }
3505
}
3506

    
3507
PHP_METHOD(XQueryProcessor, exceptionOccurred)
3508
{
3509
    XQueryProcessor *xqueryProcessor;
3510
    zend_object* pobj = Z_OBJ_P(getThis()); 
3511
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3512
    if (ZEND_NUM_ARGS()>0) {
3513
        WRONG_PARAM_COUNT;
3514
    }
3515

    
3516
    xqueryProcessor = obj->xqueryProcessor;
3517
    if (xqueryProcessor != nullptr) {
3518
        bool result = xqueryProcessor->exceptionOccurred();
3519
        RETURN_BOOL(result);
3520
    }
3521
    RETURN_BOOL(false);
3522
}
3523

    
3524
PHP_METHOD(XQueryProcessor, getExceptionCount)
3525
{
3526
    XQueryProcessor *xqueryProcessor;
3527
     zend_object* pobj = Z_OBJ_P(getThis()); 
3528
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3529
    if (ZEND_NUM_ARGS()>0) {
3530
        WRONG_PARAM_COUNT;
3531
    }
3532

    
3533
    xqueryProcessor = obj->xqueryProcessor;
3534
    if (xqueryProcessor != nullptr) {
3535
        int count = xqueryProcessor->exceptionCount();
3536
        RETURN_LONG(count);
3537
    }
3538
    RETURN_LONG(0);
3539
}
3540

    
3541
PHP_METHOD(XQueryProcessor, getErrorCode)
3542
{
3543
    XQueryProcessor *xqueryProcessor;
3544
    long index;
3545
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3546
        RETURN_NULL();
3547
    }
3548
    zend_object* pobj = Z_OBJ_P(getThis()); 
3549
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3550
    xqueryProcessor = obj->xqueryProcessor;
3551
    if (xqueryProcessor != nullptr) {
3552
        const char * errCode = xqueryProcessor->getErrorCode((int)index);
3553
        if(errCode != nullptr) {
3554
            //char *str = estrdup(errCode);
3555
            _RETURN_STRING(errCode);
3556
        }
3557
    }
3558
    RETURN_NULL();
3559
}
3560

    
3561
PHP_METHOD(XQueryProcessor, getErrorMessage)
3562
{
3563
    XQueryProcessor *xqueryProcessor;
3564
    long index;
3565
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3566
        RETURN_NULL();
3567
    }
3568
    zend_object* pobj = Z_OBJ_P(getThis()); 
3569
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3570
    xqueryProcessor = obj->xqueryProcessor;
3571
    if (xqueryProcessor != nullptr) {
3572
        const char * errStr = xqueryProcessor->getErrorMessage((int)index);
3573
        if(errStr != nullptr) {
3574
            //char *str = estrdup(errStr);
3575
            _RETURN_STRING(errStr);
3576
        }
3577
    }
3578
    RETURN_NULL();
3579
}
3580
PHP_METHOD(XQueryProcessor, exceptionClear)
3581
{
3582
    XQueryProcessor *xqueryProcessor;
3583
    zend_object* pobj = Z_OBJ_P(getThis()); 
3584
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3585
    xqueryProcessor = obj->xqueryProcessor;
3586
    if (xqueryProcessor != nullptr) {
3587
        xqueryProcessor->exceptionClear();
3588
    }
3589
}
3590

    
3591
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
3592

    
3593
void xpathProcessor_free_storage(zend_object *object)
3594
{
3595
    zend_object_std_dtor(object);
3596
}
3597

    
3598
void xpathProcessor_destroy_storage(zend_object *object)
3599
{
3600
    zend_objects_destroy_object(object);
3601
}
3602

    
3603
PHP_METHOD(XPathProcessor, __destruct)
3604
{
3605

    
3606
   zend_object* pobj = Z_OBJ_P(getThis()); 
3607
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3608

    
3609

    
3610
   XPathProcessor * xpathProc= obj->xpathProcessor;
3611
    if(xpathProc != nullptr){
3612
            delete xpathProc;
3613
     }
3614

    
3615
   
3616
    
3617
}
3618

    
3619
zend_object *xpathProcessor_create_handler(zend_class_entry *type)
3620
{
3621
    xpathProcessor_object *obj = (xpathProcessor_object *)ecalloc(1, sizeof(xpathProcessor_object)+ zend_object_properties_size(type));
3622
    
3623
    zend_object_std_init(&obj->std, type); 
3624
    
3625
    object_properties_init(&obj->std, type);
3626
    
3627
    obj->std.handlers = &xpathProcessor_object_handlers;
3628

    
3629
    return &obj->std;
3630
}
3631

    
3632

    
3633

    
3634
PHP_METHOD(XPathProcessor, setProperty)
3635
{
3636
    XPathProcessor *xpathProcessor;
3637
    char * name;
3638
    char * value;
3639
    size_t len1, len2;
3640

    
3641
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
3642
        RETURN_NULL();
3643
    }
3644
    zend_object* pobj = Z_OBJ_P(getThis()); 
3645
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3646
    xpathProcessor = obj->xpathProcessor;
3647
    if (xpathProcessor != nullptr) {
3648
        xpathProcessor->setProperty(name, value);
3649
    }
3650
}
3651

    
3652
PHP_METHOD(XPathProcessor, setParameter)
3653
{
3654

    
3655
   XPathProcessor *xpathProcessor;
3656
   char * name;
3657
   zval* oth;
3658
   size_t len1, len2;        
3659
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name, &len2, &oth) == FAILURE) {
3660
        RETURN_NULL();
3661
    }
3662
    zend_object* pobj = Z_OBJ_P(getThis()); 
3663
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3664
    xpathProcessor = obj->xpathProcessor;
3665
    if (xpathProcessor != nullptr) {
3666
            const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
3667
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3668

    
3669
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3670
        
3671
        zend_object* vvobj = Z_OBJ_P(oth);
3672
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3673
        if(ooth != nullptr) {
3674
            XdmNode * value = ooth->xdmNode;
3675
            if(value != nullptr) {
3676
                xpathProcessor->setParameter(name, (XdmValue *)value);
3677

    
3678
            }
3679
        }
3680
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
3681
        
3682
        zend_object* vvobj = Z_OBJ_P(oth);
3683
        xdmValue_object * ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3684
        if(ooth != nullptr) {
3685
            XdmValue * value = ooth->xdmValue;
3686
            if(value != nullptr) {
3687
                
3688
                xpathProcessor->setParameter(name, value);
3689
            }
3690
        }
3691

    
3692

    
3693

    
3694
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3695
        
3696
        zend_object* vvobj = Z_OBJ_P(oth);
3697
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3698
        if(ooth != nullptr) {
3699
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3700
            if(value != nullptr) {
3701
                
3702
                xpathProcessor->setParameter(name, (XdmValue *)value);
3703
            }
3704
        }
3705

    
3706

    
3707

    
3708
      }
3709

    
3710
    }
3711
}
3712

    
3713
PHP_METHOD(XPathProcessor, declareNamespace)
3714
{
3715
   char * prefix;
3716
   char * ns;
3717
   int len1, len2;
3718
   XPathProcessor *xpathProcessor;
3719

    
3720
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
3721
        RETURN_NULL();
3722
    }
3723
    if(prefix != nullptr && ns != nullptr) {
3724
            zend_object* pobj = Z_OBJ_P(getThis()); 
3725
        xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3726
            xpathProcessor = obj->xpathProcessor;
3727
            xpathProcessor->declareNamespace(prefix, ns);
3728
    }
3729
            
3730
}
3731

    
3732

    
3733

    
3734
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
3735

    
3736
    XPathProcessor *xpathProcessor;
3737
    bool allow = false;
3738
    size_t len1;
3739

    
3740
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &allow) == FAILURE) {
3741
        RETURN_NULL();
3742
    }
3743

    
3744
    zend_object* pobj = Z_OBJ_P(getThis());
3745
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3746
    xpathProcessor = obj->xpathProcessor;
3747
    if (xpathProcessor != nullptr) {
3748
            xpathProcessor->setBackwardsCompatible(allow);
3749
         }
3750
}
3751

    
3752
PHP_METHOD(XPathProcessor, setCaching){
3753
    XPathProcessor *xpathProcessor;
3754
    bool isCaching = false;
3755
    size_t len1;
3756

    
3757
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &isCaching) == FAILURE) {
3758
        RETURN_NULL();
3759
    }
3760

    
3761
    zend_object* pobj = Z_OBJ_P(getThis());
3762
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3763
    xpathProcessor = obj->xpathProcessor;
3764
    if (xpathProcessor != nullptr) {
3765
            xpathProcessor->setCaching(isCaching);
3766
         }
3767
}
3768

    
3769
PHP_METHOD(XPathProcessor, importSchemaNamespace){
3770
      char * name;
3771
      int len1;
3772
      XPathProcessor *xpathProcessor;
3773

    
3774
       if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
3775
           RETURN_NULL();
3776
       }
3777
       if(name != nullptr) {
3778
               zend_object* pobj = Z_OBJ_P(getThis());
3779
           xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3780
               xpathProcessor = obj->xpathProcessor;
3781
               xpathProcessor->importSchemaNamespace(name);
3782
       }
3783
}
3784

    
3785
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
3786
{
3787

    
3788
   XPathProcessor *xpathProcessor;
3789
   char * xpathStr;
3790
   zval* oth;
3791
   size_t len1, myint;        
3792
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &xpathStr, &len1) == FAILURE) {
3793
        RETURN_NULL();
3794
    }
3795
    zend_object* pobj = Z_OBJ_P(getThis()); 
3796
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3797
    xpathProcessor = obj->xpathProcessor;
3798
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
3799
        
3800
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
3801
                RETURN_BOOL(result);
3802
    }
3803
}
3804

    
3805
PHP_METHOD(XPathProcessor, evaluate)
3806
{
3807

    
3808
   XPathProcessor *xpathProcessor;
3809
   char * xpathStr;
3810
   zval* oth;
3811
   size_t len1, myint;        
3812
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
3813
        RETURN_NULL();
3814
    }
3815
    zend_object* pobj = Z_OBJ_P(getThis()); 
3816
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3817
    xpathProcessor = obj->xpathProcessor;
3818
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
3819
        
3820
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
3821
        if(node != nullptr) {
3822
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
3823
                RETURN_NULL();
3824
                return;
3825
            } else {
3826
                zend_object* vvobj = Z_OBJ_P(return_value);
3827
                        
3828
                if(node->getType() == XDM_NODE) {
3829
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3830
                                assert (vobj != nullptr);
3831
                                  vobj->xdmNode = (XdmNode *)node;
3832
                        return;
3833

    
3834
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
3835
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3836
                assert (vobj != nullptr);
3837
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
3838
                return;
3839

    
3840
                } else {
3841
                  xdmValue_object * vobj = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3842
                  assert (vobj != nullptr);
3843
                  vobj->xdmValue = node;
3844
                  return;
3845
                }
3846
            }
3847
        }
3848
        xpathProcessor->checkException();//TODO
3849
    } 
3850
    RETURN_NULL();
3851
    
3852
}
3853

    
3854
PHP_METHOD(XPathProcessor, evaluateSingle)
3855
{
3856

    
3857
   XPathProcessor *xpathProcessor;
3858
   char * xpathStr;
3859
   zval* oth;
3860
   size_t len1, myint;        
3861
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
3862
        RETURN_NULL();
3863
    }
3864
    zend_object* pobj = Z_OBJ_P(getThis()); 
3865
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3866
    xpathProcessor = obj->xpathProcessor;
3867

    
3868
    if(xpathStr == nullptr) {
3869
        RETURN_NULL();
3870
        return;
3871
        }
3872

    
3873

    
3874
    if (xpathProcessor != nullptr) {
3875
        
3876
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
3877
        if(node != nullptr) {
3878
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
3879
                RETURN_NULL();
3880
                return;
3881
            } else {
3882
                //struct xdmItem_object* vobj = (struct xdmItem_object *)Z_OBJ_P(return_value TSRMLS_CC);
3883
                zend_object* vvobj = Z_OBJ_P(return_value);
3884
                if(node->getType() == XDM_NODE) {
3885
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3886
                        assert (vobj != nullptr);
3887
                        vobj->xdmNode = (XdmNode *)node;
3888
                        return;
3889

    
3890
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
3891

    
3892
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3893
                assert (vobj != nullptr);
3894
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
3895
                return;
3896

    
3897
                } else {
3898
                        xdmItem_object * vobj = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
3899
                        assert (vobj != nullptr);
3900
                        vobj->xdmItem = node;
3901
                        return;
3902
                }
3903
            }
3904
        } 
3905
        xpathProcessor->checkException();//TODO
3906
    } 
3907
    RETURN_NULL();
3908
}
3909

    
3910
PHP_METHOD(XPathProcessor, setContextItem)
3911
{
3912

    
3913
   XPathProcessor *xpathProcessor;
3914

    
3915
   zval* oth;
3916
        //TODO this should be relaxed to accept item/atomic/node as well as Value
3917

    
3918
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
3919
        RETURN_NULL();
3920
    }
3921
    zend_object* pobj = Z_OBJ_P(getThis()); 
3922
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3923
    xpathProcessor = obj->xpathProcessor;
3924
    if (xpathProcessor != nullptr) {
3925
        if(!oth) {
3926
                php_error(E_WARNING, "Error setting source value");
3927
                return;
3928
         } 
3929
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
3930
        
3931
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
3932
        zend_object* vvobj = Z_OBJ_P(oth);
3933
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3934
        if(ooth != nullptr) {
3935
            XdmNode * value = ooth->xdmNode;
3936
            if(value != nullptr) {
3937
                xpathProcessor->setContextItem((XdmItem *)value);
3938
                value->incrementRefCount();
3939

    
3940
            }
3941
        }
3942
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3943
        zend_object* vvobj = Z_OBJ_P(oth);
3944
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3945
        if(ooth != nullptr) {
3946
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3947
            if(value != nullptr) {
3948
                
3949
                xpathProcessor->setContextItem((XdmItem *)value);
3950
                value->incrementRefCount();
3951
            }
3952
        }
3953
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
3954
        zend_object* vvobj = Z_OBJ_P(oth);
3955
        xdmItem_object * ooth = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
3956
        if(ooth != nullptr) {
3957
            XdmItem * value = ooth->xdmItem;
3958
            if(value != nullptr) {
3959
                
3960
                xpathProcessor->setContextItem(value);
3961
                value->incrementRefCount();
3962
            }
3963
        }
3964

    
3965
      }
3966
    }
3967
}
3968

    
3969
PHP_METHOD(XPathProcessor, setBaseURI)
3970
{
3971

    
3972
   XPathProcessor *xpathProcessor;
3973

    
3974
   char * uriStr;
3975
   size_t len1;
3976
        
3977
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &uriStr, &len1) == FAILURE) {
3978
        RETURN_NULL();
3979
    }
3980
    zend_object* pobj = Z_OBJ_P(getThis()); 
3981
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3982
    xpathProcessor = obj->xpathProcessor;
3983
    if (xpathProcessor != nullptr) {
3984
        
3985
        if(uriStr != nullptr) {
3986
           
3987
                xpathProcessor->setBaseURI(uriStr);
3988
            
3989
        }
3990
    }
3991
}
3992

    
3993
PHP_METHOD(XPathProcessor, setContextFile)
3994
{
3995

    
3996
   XPathProcessor *xpathProcessor;
3997

    
3998
   char * name;
3999
   size_t len1;
4000
        
4001
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4002
        RETURN_NULL();
4003
    }
4004
    zend_object* pobj = Z_OBJ_P(getThis()); 
4005
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4006
    xpathProcessor = obj->xpathProcessor;
4007
    if (xpathProcessor != nullptr) {
4008
        
4009
        if(name != nullptr) {
4010
           
4011
                xpathProcessor->setContextFile(name);
4012
            
4013
        }
4014
    }
4015
}
4016

    
4017
PHP_METHOD(XPathProcessor, clearParameters)
4018
{
4019
    XPathProcessor *xpathProcessor;
4020
    if (ZEND_NUM_ARGS()>0) {
4021
        WRONG_PARAM_COUNT;
4022
    }
4023

    
4024
    zend_object* pobj = Z_OBJ_P(getThis()); 
4025
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4026
    xpathProcessor = obj->xpathProcessor;
4027
    if (xpathProcessor != nullptr) {
4028
        xpathProcessor->clearParameters(true);
4029
    }
4030
}
4031

    
4032
PHP_METHOD(XPathProcessor, clearProperties)
4033
{
4034
     XPathProcessor *xpathProcessor;
4035
    if (ZEND_NUM_ARGS()>0) {
4036
        WRONG_PARAM_COUNT;
4037
    }
4038

    
4039
    zend_object* pobj = Z_OBJ_P(getThis()); 
4040
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4041
    xpathProcessor = obj->xpathProcessor;
4042
    if (xpathProcessor != nullptr) {
4043
        xpathProcessor->clearProperties();
4044
    }
4045
}
4046

    
4047

    
4048
PHP_METHOD(XPathProcessor, exceptionOccurred)
4049
{
4050
   XPathProcessor *xpathProcessor;
4051
    zend_object* pobj = Z_OBJ_P(getThis()); 
4052
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4053
    if (ZEND_NUM_ARGS()>0) {
4054
        WRONG_PARAM_COUNT;
4055
    }
4056

    
4057
    xpathProcessor = obj->xpathProcessor;
4058
    if (xpathProcessor != nullptr) {
4059
        bool result = xpathProcessor->exceptionOccurred();
4060
        RETURN_BOOL(result);
4061
    }
4062
    RETURN_BOOL(false);
4063
}
4064

    
4065
PHP_METHOD(XPathProcessor, getExceptionCount)
4066
{
4067
    XPathProcessor *xpathProcessor;
4068
   zend_object* pobj = Z_OBJ_P(getThis()); 
4069
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4070
    if (ZEND_NUM_ARGS()>0) {
4071
        WRONG_PARAM_COUNT;
4072
    }
4073

    
4074
    xpathProcessor = obj->xpathProcessor;
4075
    if (xpathProcessor != nullptr) {
4076
        int count = xpathProcessor->exceptionCount();
4077
        RETURN_LONG(count);
4078
    }
4079
    RETURN_LONG(0);
4080
}
4081

    
4082
PHP_METHOD(XPathProcessor, getErrorCode)
4083
{
4084
    XPathProcessor *xpathProcessor;
4085
    long index;
4086
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
4087
        RETURN_NULL();
4088
    }
4089
    zend_object* pobj = Z_OBJ_P(getThis()); 
4090
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4091
    xpathProcessor = obj->xpathProcessor;
4092
    if (xpathProcessor != nullptr) {
4093
        const char * errCode = xpathProcessor->getErrorCode((int)index);
4094
        if(errCode != nullptr) {
4095
           // char *str = estrdup(errCode);
4096
            _RETURN_STRING(errCode);
4097
        }
4098
    }
4099
    RETURN_NULL();
4100
}
4101

    
4102
PHP_METHOD(XPathProcessor, getErrorMessage)
4103
{
4104
    XPathProcessor *xpathProcessor;
4105
    long index;
4106
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
4107
        RETURN_NULL();
4108
    }
4109
    zend_object* pobj = Z_OBJ_P(getThis()); 
4110
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4111
    xpathProcessor = obj->xpathProcessor;
4112
    if (xpathProcessor != nullptr) {
4113
        const char * errStr = xpathProcessor->getErrorMessage((int)index);
4114
        if(errStr != nullptr) {
4115
            //char *str = estrdup(errStr);
4116
            _RETURN_STRING(errStr);
4117
        }
4118
    }
4119
    RETURN_NULL();
4120
}
4121
PHP_METHOD(XPathProcessor, exceptionClear)
4122
{
4123
    XPathProcessor *xpathProcessor;
4124
    zend_object* pobj = Z_OBJ_P(getThis()); 
4125
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4126
    xpathProcessor = obj->xpathProcessor;
4127
    if (xpathProcessor != nullptr) {
4128
        xpathProcessor->exceptionClear();
4129
    }
4130
}
4131

    
4132
/*     ============== PHP Interface of   SchemaValidator =============== */
4133

    
4134
void schemaValidator_free_storage(zend_object *object)
4135
{
4136
    zend_object_std_dtor(object);
4137
}
4138

    
4139
void schemaValidator_destroy_storage(zend_object *object)
4140
{
4141
    zend_objects_destroy_object(object);
4142
}
4143

    
4144
zend_object *schemaValidator_create_handler(zend_class_entry *type)
4145
{
4146
    zval *tmp;
4147
    zend_object retval;
4148
    schemaValidator_object *obj = (schemaValidator_object *)ecalloc(1, sizeof(schemaValidator_object)+ zend_object_properties_size(type));
4149

    
4150
    zend_object_std_init(&obj->std, type);    
4151
    object_properties_init(&obj->std, type);
4152

    
4153
    obj->std.handlers = &schemaValidator_object_handlers;
4154

    
4155
    return &obj->std;
4156
}
4157

    
4158

    
4159

    
4160
PHP_METHOD(SchemaValidator, __destruct)
4161
{
4162
    zend_object* pobj = Z_OBJ_P(getThis()); 
4163
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4164

    
4165

    
4166
    SchemaValidator * schemaValidator= obj->schemaValidator;
4167
    if(schemaValidator != nullptr) {
4168
            delete schemaValidator;
4169
    }
4170
    
4171
}
4172

    
4173

    
4174

    
4175
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
4176
{
4177
    SchemaValidator *schemaValidator;
4178
    char * name;
4179
    size_t len1;
4180

    
4181
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
4182
        RETURN_NULL();
4183
    }
4184
    zend_object* pobj = Z_OBJ_P(getThis()); 
4185
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4186
    schemaValidator = obj->schemaValidator;
4187
    if (name != nullptr && schemaValidator != nullptr) {
4188
        schemaValidator->registerSchemaFromFile(name);
4189
    }
4190
}
4191

    
4192
PHP_METHOD(SchemaValidator, registerSchemaFromString)
4193
{
4194
    char * schemaStr;
4195
    size_t len1;
4196
    SchemaValidator *schemaValidator;
4197
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &schemaStr, &len1) == FAILURE) {
4198
        RETURN_NULL();
4199
    }
4200
    zend_object* pobj = Z_OBJ_P(getThis()); 
4201
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4202
    schemaValidator = obj->schemaValidator;
4203
    if (schemaStr!= nullptr && schemaValidator != nullptr) {
4204
        schemaValidator->registerSchemaFromString(schemaStr);
4205
    }
4206
}
4207

    
4208
PHP_METHOD(SchemaValidator, validate)
4209
{
4210
    char * name = nullptr;
4211
    size_t len1;
4212
    SchemaValidator *schemaValidator;
4213
    if (ZEND_NUM_ARGS()>1) {
4214
        WRONG_PARAM_COUNT;
4215
    }
4216
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4217
        RETURN_NULL();
4218
    }
4219
    zend_object* pobj = Z_OBJ_P(getThis()); 
4220
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4221
    schemaValidator = obj->schemaValidator;
4222
    if (schemaValidator != nullptr) {
4223
        schemaValidator->validate(name);
4224
    }
4225
}
4226

    
4227
PHP_METHOD(SchemaValidator, validateToNode)
4228
{
4229
    char * name = nullptr;
4230
   size_t len1;
4231
    SchemaValidator *schemaValidator;
4232
    if (ZEND_NUM_ARGS()>1) {
4233
        WRONG_PARAM_COUNT;
4234
    }
4235
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4236
        RETURN_NULL();
4237
    }
4238
    zend_object* pobj = Z_OBJ_P(getThis()); 
4239
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4240
    schemaValidator = obj->schemaValidator;
4241
    if (schemaValidator != nullptr) {
4242
        XdmNode * node = schemaValidator->validateToNode(name);
4243
        if(node != nullptr) {
4244
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4245
                RETURN_NULL();
4246
                return;
4247
            } else {
4248
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
4249
                zend_object* vvobj = Z_OBJ_P(return_value);
4250
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
4251
                assert (vobj != nullptr);
4252
                vobj->xdmNode = node;
4253
                return;
4254
            }
4255
        } 
4256
            schemaValidator->checkException();//TODO
4257
    } 
4258
    RETURN_NULL();
4259
}
4260

    
4261

    
4262
PHP_METHOD(SchemaValidator, getValidationReport)
4263
{
4264

    
4265
    SchemaValidator *schemaValidator;
4266
    if (ZEND_NUM_ARGS()>0) {
4267
        WRONG_PARAM_COUNT;
4268
    }
4269

    
4270
    zend_object* pobj = Z_OBJ_P(getThis()); 
4271
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4272
    schemaValidator = obj->schemaValidator;
4273
    if (schemaValidator != nullptr) {
4274
        XdmNode * node = schemaValidator->getValidationReport();
4275
        if(node != nullptr) {
4276
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4277
                RETURN_NULL();
4278
                return;
4279
            } else {
4280
                zend_object* vvobj = Z_OBJ_P(return_value);
4281
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
4282
                assert (vobj != nullptr);
4283
                vobj->xdmNode = node;
4284
                return;
4285
            }
4286
        } 
4287
            schemaValidator->checkException();//TODO
4288
    } 
4289
    RETURN_NULL();
4290
}
4291

    
4292

    
4293
PHP_METHOD(SchemaValidator, setSourceNode)
4294
{
4295
    SchemaValidator *schemaValidator;
4296

    
4297
    zval* oth;
4298
   
4299

    
4300
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
4301
        RETURN_NULL();
4302
    }
4303
    zend_object* pobj = Z_OBJ_P(getThis()); 
4304
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4305
    schemaValidator = obj->schemaValidator;
4306
    if (schemaValidator != nullptr) {
4307
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
4308
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
4309
        zend_object * nobj = Z_OBJ_P(oth);
4310
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
4311
        if(ooth != nullptr) {
4312
            XdmNode * value = ooth->xdmNode;
4313
            if(value != nullptr) {
4314
                schemaValidator->setSourceNode(value);
4315

    
4316
            }
4317
        }
4318
      
4319
        
4320
      }
4321
    }
4322
}
4323

    
4324
PHP_METHOD(SchemaValidator, setOutputFile)
4325
{
4326
    SchemaValidator *schemaValidator;
4327
    char * name;
4328
    int len1;
4329

    
4330
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4331
        RETURN_NULL();
4332
    }
4333
    zend_object* pobj = Z_OBJ_P(getThis()); 
4334
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4335
    schemaValidator = obj->schemaValidator;
4336
    if (schemaValidator != nullptr) {
4337
        schemaValidator->setOutputFile(name);
4338
    }
4339
}
4340

    
4341

    
4342
PHP_METHOD(SchemaValidator, exportSchema)
4343
{
4344
    SchemaValidator *schemaValidator;
4345
    char * name;
4346
    int len1;
4347

    
4348
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4349
        RETURN_NULL();
4350
    }
4351
    zend_object* pobj = Z_OBJ_P(getThis());
4352
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4353
    schemaValidator = obj->schemaValidator;
4354
    if (schemaValidator != nullptr) {
4355
        schemaValidator->exportSchema(name);
4356
    }
4357
}
4358

    
4359

    
4360
PHP_METHOD(SchemaValidator, setProperty)
4361
{
4362
    SchemaValidator *schemaValidator;
4363
    char * name;
4364
    char * value;
4365
    size_t len1, len2, myint;
4366

    
4367
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
4368
        RETURN_NULL();
4369
    }
4370
    zend_object* pobj = Z_OBJ_P(getThis()); 
4371
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4372
    schemaValidator = obj->schemaValidator;
4373
    if (schemaValidator != nullptr) {
4374
        schemaValidator->setProperty(name, value);
4375
    }
4376
}
4377

    
4378
PHP_METHOD(SchemaValidator, setParameter)
4379
{
4380

    
4381
   SchemaValidator *schemaValidator;
4382
   char * name;
4383
   zval* oth;
4384
   size_t len1, len2, myint;        
4385
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
4386
        RETURN_NULL();
4387
    }
4388
    zend_object* pobj = Z_OBJ_P(getThis()); 
4389
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4390
    schemaValidator = obj->schemaValidator;
4391
    if (schemaValidator != nullptr) {
4392
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
4393
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
4394

    
4395
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
4396
        zend_object * nobj = Z_OBJ_P(oth);
4397

    
4398
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
4399
        if(ooth != nullptr) {
4400
            XdmNode * value = ooth->xdmNode;
4401
            if(value != nullptr) {
4402
                schemaValidator->setParameter(name, (XdmValue *)value);
4403

    
4404
            }
4405
        }
4406
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
4407
        zend_object* vvobj = Z_OBJ_P(oth);
4408
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
4409
        if(ooth != nullptr) {
4410
            XdmValue * value = ooth->xdmValue;
4411
            if(value != nullptr) {
4412
                
4413
                schemaValidator->setParameter(name, value);
4414
            }
4415
        }
4416

    
4417

    
4418

    
4419
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
4420
        zend_object* vvobj = Z_OBJ_P(oth);
4421
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
4422
        if(ooth != nullptr) {
4423
            XdmAtomicValue * value = ooth->xdmAtomicValue;
4424
            if(value != nullptr) {
4425
                
4426
                schemaValidator->setParameter(name, (XdmValue *)value);
4427
            }
4428
        }
4429

    
4430

    
4431

    
4432
      }
4433

    
4434
    }
4435
}
4436

    
4437
PHP_METHOD(SchemaValidator, clearProperties)
4438
{
4439
    SchemaValidator *schemaValidator;
4440
    if (ZEND_NUM_ARGS()>0) {
4441
        WRONG_PARAM_COUNT;
4442
    }
4443

    
4444
    zend_object* pobj = Z_OBJ_P(getThis()); 
4445
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4446
    schemaValidator = obj->schemaValidator;
4447
    if (schemaValidator != nullptr) {
4448
        schemaValidator->clearProperties();
4449
        schemaValidator->exceptionClear();
4450
    }
4451
}
4452

    
4453
PHP_METHOD(SchemaValidator, clearParameters)
4454
{
4455

    
4456
   SchemaValidator *schemaValidator;
4457
    if (ZEND_NUM_ARGS()>0) {
4458
        WRONG_PARAM_COUNT;
4459
    }
4460
    zend_object* pobj = Z_OBJ_P(getThis()); 
4461
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4462
    schemaValidator = obj->schemaValidator;
4463
    if (schemaValidator != nullptr) {
4464
       
4465
                schemaValidator->clearParameters(true);
4466
                schemaValidator->exceptionClear();
4467
        }
4468
    }
4469

    
4470
PHP_METHOD(SchemaValidator, exceptionOccurred)
4471
{
4472
    SchemaValidator *schemaValidator;
4473
    if (ZEND_NUM_ARGS()>0) {
4474
        WRONG_PARAM_COUNT;
4475
    }
4476
    zend_object* pobj = Z_OBJ_P(getThis()); 
4477
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4478
    schemaValidator = obj->schemaValidator;
4479
    if (schemaValidator != nullptr) {
4480
        bool result = schemaValidator->exceptionOccurred();
4481
        RETURN_BOOL(result);
4482
    }
4483
    RETURN_BOOL(false);
4484
}
4485

    
4486
PHP_METHOD(SchemaValidator, getExceptionCount)
4487
{
4488
    SchemaValidator *schemaValidator;
4489

    
4490
    if (ZEND_NUM_ARGS()>0) {
4491
        WRONG_PARAM_COUNT;
4492
    }
4493
    zend_object* pobj = Z_OBJ_P(getThis()); 
4494
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4495
    schemaValidator = obj->schemaValidator;
4496
    if (schemaValidator != nullptr) {
4497
        int count = schemaValidator->exceptionCount();
4498
        RETURN_LONG(count);
4499
    }
4500
    RETURN_LONG(0);
4501
}
4502

    
4503
PHP_METHOD(SchemaValidator, getErrorCode)
4504
{
4505
    SchemaValidator *schemaValidator;
4506
    long index;
4507
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
4508
        RETURN_NULL();
4509
    }
4510
    zend_object* pobj = Z_OBJ_P(getThis()); 
4511
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4512
    schemaValidator = obj->schemaValidator;
4513
    if (schemaValidator != nullptr) {
4514
        const char * errCode = schemaValidator->getErrorCode((int)index);
4515
        if(errCode != nullptr) {
4516
            //char *str = estrdup(errCode);
4517
            _RETURN_STRING(errCode);
4518
        }
4519
    }
4520
    RETURN_NULL();
4521
}
4522

    
4523
PHP_METHOD(SchemaValidator, getErrorMessage)
4524
{
4525
    SchemaValidator *schemaValidator;
4526
    long index;
4527
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
4528
        RETURN_NULL();
4529
    }
4530
    zend_object* pobj = Z_OBJ_P(getThis()); 
4531
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4532
    schemaValidator = obj->schemaValidator;
4533
    if (schemaValidator != nullptr) {
4534
        const char * errStr = schemaValidator->getErrorMessage((int)index);
4535
        if(errStr != nullptr) {
4536
            //char *str = estrdup(errStr);
4537
            _RETURN_STRING(errStr);
4538
        }
4539
    }
4540
    RETURN_NULL();
4541
}
4542
PHP_METHOD(SchemaValidator, exceptionClear)
4543
{
4544
    SchemaValidator * schemaValidator;
4545
    zend_object* pobj = Z_OBJ_P(getThis()); 
4546
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4547
    schemaValidator = obj->schemaValidator;
4548
    if (schemaValidator != nullptr) {
4549
        schemaValidator->exceptionClear();
4550
    }
4551
}
4552

    
4553
/*     ============== PHP Interface of   XdmValue =============== */
4554
void xdmValue_free_storage(zend_object *object)
4555
{
4556
    zend_object_std_dtor(object);
4557
}
4558

    
4559
zend_object *xdmValue_create_handler(zend_class_entry *type)
4560
{
4561
    zval *tmp;
4562
    zend_object retval;
4563
    xdmValue_object *obj = (xdmValue_object *)ecalloc(1, sizeof(xdmValue_object)+ zend_object_properties_size(type));
4564
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
4565
    object_properties_init(&obj->std, type);
4566
    
4567
    obj->std.handlers = &xdmValue_object_handlers;
4568

    
4569
    return &obj->std;
4570
}
4571

    
4572
void XdmValue_destroy_storage(zend_object *object)
4573
{
4574
    zend_objects_destroy_object(object);
4575
}
4576

    
4577
PHP_METHOD(XdmValue, __construct)
4578
{
4579
    XdmValue *xdmValue = nullptr;
4580
    bool bVal;
4581
    char * sVal;
4582
    int len;
4583
    long iVal;
4584
    double dVal;
4585
    zval *zvalue;
4586

    
4587

    
4588

    
4589
    SaxonProcessor *proc= nullptr;
4590
    //xdmValue_object *obj = (xdmValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
4591
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == SUCCESS) {
4592
        switch (Z_TYPE_P(zvalue)) {
4593
            case IS_FALSE:
4594
            case IS_TRUE:
4595
                bVal = Z_BVAL_P(zvalue);
4596
                xdmValue = new XdmValue(bVal);
4597
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4598
                obj->xdmValue = xdmValue;
4599
            break;
4600
            case IS_LONG:
4601
                iVal = Z_LVAL_P(zvalue);
4602
                xdmValue = new XdmValue((int)iVal);
4603
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4604
                obj->xdmValue = xdmValue;
4605
            break;
4606
            case IS_STRING:
4607
                sVal = Z_STRVAL_P(zvalue);
4608
                len = Z_STRLEN_P(zvalue);
4609
                xdmValue = new XdmValue("string", sVal);
4610
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4611
                obj->xdmValue = xdmValue;
4612
            break;
4613
            case IS_NULL:
4614
                xdmValue = new XdmValue();
4615
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4616
                obj->xdmValue = xdmValue;
4617
            break;
4618
            case IS_DOUBLE:
4619
                // TODO: implement this
4620
                //index = (long)Z_DVAL_P(zvalue);
4621
            //break;
4622
            case IS_ARRAY:
4623
            //break;
4624
            case IS_OBJECT:
4625
            //break;
4626
            default:
4627
                obj = nullptr;
4628
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
4629
        }
4630
    }*/
4631
}
4632

    
4633
PHP_METHOD(XdmValue, __destruct)
4634
{
4635

    
4636
     zend_object *oobj = Z_OBJ_P(getThis());
4637
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4638
    XdmValue * xdmValue= obj->xdmValue;
4639
   if(xdmValue != nullptr) {
4640
            xdmValue->decrementRefCount();
4641
            if(xdmValue!= nullptr && xdmValue->getRefCount()< 1){
4642
                    delete xdmValue;
4643
            } 
4644
    }
4645
}
4646

    
4647
PHP_METHOD(XdmValue, __toString)
4648
    {
4649
             XdmValue *xdmValue;
4650
         zend_object *oobj = Z_OBJ_P(getThis());
4651
         xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4652
         xdmValue = obj->xdmValue;
4653
         if (xdmValue != nullptr) {
4654
                const char * value = xdmValue->toString();
4655
                  if(value != nullptr) {
4656
                      _RETURN_STRING(value);
4657
                   } else {
4658
                   _RETURN_STRING("");
4659

    
4660
                   }
4661
                 }else {
4662
                      _RETURN_STRING("");
4663
              }
4664
    }
4665

    
4666
PHP_METHOD(XdmValue,  getHead){
4667
    XdmValue *xdmValue;
4668
     zend_object *oobj = Z_OBJ_P(getThis());
4669
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4670
    xdmValue = obj->xdmValue;
4671
    if (xdmValue != nullptr) {
4672
        XdmItem * item = xdmValue->getHead();
4673
        if(item != nullptr) {
4674
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
4675
                RETURN_NULL();
4676
              } else {
4677
                item->incrementRefCount();
4678
                zend_object * oobj = Z_OBJ_P(return_value);
4679
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
4680
                assert (vobj != nullptr);
4681
                vobj->xdmItem = item;
4682
                
4683
            }
4684
        } else {
4685
                RETURN_NULL();
4686
        }
4687
        
4688
    } else {
4689
        RETURN_NULL();
4690
    }
4691
}
4692

    
4693

    
4694
PHP_METHOD(XdmValue,  itemAt){
4695
    XdmValue *xdmValue;
4696

    
4697
    long index;
4698
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
4699
        RETURN_NULL();
4700
    }
4701

    
4702
     zend_object *oobj = Z_OBJ_P(getThis());
4703
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4704
    xdmValue = obj->xdmValue;
4705
    if (xdmValue != nullptr) {
4706
        XdmItem * item = xdmValue->itemAt((unsigned int)index);
4707
        if(item != nullptr) {
4708
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
4709
                RETURN_NULL();
4710
                return;
4711
            } else {
4712
                item->incrementRefCount();
4713
                zend_object * oobj = Z_OBJ_P(return_value);
4714
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
4715
               
4716
                assert (vobj != nullptr);
4717
                vobj->xdmItem = item;
4718
                return;
4719
            }
4720
        }
4721
        
4722
    } else {
4723
        RETURN_NULL();
4724
    }
4725
}
4726

    
4727

    
4728
PHP_METHOD(XdmValue,  size){
4729
    XdmValue *xdmValue;
4730
    zend_object *oobj = Z_OBJ_P(getThis());
4731
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4732
    xdmValue = obj->xdmValue;
4733
    int sizei = 0;
4734
    if (xdmValue != nullptr) {
4735
        sizei = xdmValue->size();
4736
    }
4737
     RETURN_LONG(sizei);
4738
}
4739

    
4740

    
4741
PHP_METHOD(XdmValue, addXdmItem){
4742
    XdmValue *xdmValue;
4743
    zval* oth;
4744
           
4745
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
4746
        RETURN_NULL();
4747
    }
4748

    
4749
    xdmValue_object *obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4750
    xdmValue = obj->xdmValue;
4751
    if (xdmValue != nullptr) {
4752
     const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
4753
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
4754

    
4755
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
4756
        zend_object * nobj = Z_OBJ_P(oth);
4757
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
4758
        if(ooth != nullptr) {
4759
            XdmNode * value = ooth->xdmNode;
4760
            if(value != nullptr) {
4761
                xdmValue->addXdmItem((XdmItem *)value);
4762
                return;
4763
            }
4764
        }
4765
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
4766
        zend_object * iobj = Z_OBJ_P(oth);
4767
        xdmItem_object* ooth = (xdmItem_object *)((char *)iobj - XtOffsetOf(xdmItem_object, std));
4768
        if(ooth != nullptr) {
4769
            XdmItem * value = ooth->xdmItem;
4770
            if(value != nullptr) {
4771
                xdmValue->addXdmItem(value);
4772
                return;
4773
            }
4774
        }
4775

    
4776

    
4777

    
4778
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
4779
        zend_object * aobj = Z_OBJ_P(oth);
4780
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)aobj - XtOffsetOf(xdmAtomicValue_object, std));
4781
        if(ooth != nullptr) {
4782
            XdmAtomicValue * value = ooth->xdmAtomicValue;
4783
            if(value != nullptr) {
4784
                xdmValue->addXdmItem((XdmItem *)value);
4785
                return;
4786
            }
4787
        }
4788

    
4789
      } else {
4790
                //TODO exception
4791
        }
4792
    }
4793
}
4794

    
4795

    
4796

    
4797
/*     ============== PHP Interface of   XdmItem =============== */
4798

    
4799
void xdmItem_free_storage(zend_object *object)
4800
{
4801
    zend_object_std_dtor(object);
4802
}
4803

    
4804
zend_object *xdmItem_create_handler(zend_class_entry *type)
4805
{
4806
    zval *tmp;
4807
    zend_object retval;
4808
    xdmItem_object *obj = (xdmItem_object *)ecalloc(1, sizeof(xdmItem_object)+ zend_object_properties_size(type));
4809
    
4810
    object_properties_init(&obj->std, type);
4811
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
4812
    
4813
    obj->std.handlers = &xdmItem_object_handlers;
4814

    
4815
    return &obj->std;
4816
}
4817

    
4818
PHP_METHOD(XdmItem, __construct)
4819
{
4820
    XdmItem *xdmItem = nullptr;
4821
    bool bVal;
4822
    char * sVal;
4823
    int len;
4824
    long iVal;
4825
    double dVal;
4826
    zval *zvalue;
4827

    
4828
    SaxonProcessor *proc= nullptr;
4829
    
4830
   zval *object = getThis();
4831
   
4832
    zend_object * zobj = Z_OBJ_P(object);
4833

    
4834
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4835
    //saxonProc =  obj->saxonProcessor;
4836
 
4837
}
4838

    
4839
void XdmItem_destroy_storage(zend_object *object)
4840
{
4841
    zend_objects_destroy_object(object);
4842
    
4843
}
4844

    
4845
PHP_METHOD(XdmItem, __destruct)
4846
{
4847
     zval *object = getThis();
4848
     zend_object * zobj = Z_OBJ_P(object);
4849

    
4850
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4851

    
4852
    XdmItem * xdmItem= obj->xdmItem;
4853
    xdmItem->decrementRefCount();
4854
    if(xdmItem != nullptr && xdmItem->getRefCount()< 1){
4855
            delete xdmItem;
4856
    }
4857
    
4858
}
4859

    
4860
PHP_METHOD(XdmItem, getStringValue)
4861
{
4862
    XdmItem *xdmItem;
4863
     zval *object = getThis();
4864
    zend_object * zobj = Z_OBJ_P(object);
4865
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4866
    xdmItem = obj->xdmItem;
4867

    
4868
    if (xdmItem != nullptr) {
4869
        const char * valueStr = xdmItem->getStringValue();
4870
        if(valueStr != nullptr) {
4871
            _RETURN_STRING(valueStr);
4872
        }
4873
    }
4874
    RETURN_NULL();
4875
}
4876

    
4877
    /* {{{ __toString()
4878
       Returns the string content */
4879
PHP_METHOD(XdmItem, __toString)
4880
    {
4881
             XdmItem *xdmItem;
4882
         zend_object *oobj = Z_OBJ_P(getThis());
4883
         xdmItem_object* obj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
4884
         xdmItem = obj->xdmItem;
4885
         if (xdmItem != nullptr) {
4886
                const char * value = xdmItem->toString();
4887
                  if(value != nullptr) {
4888
                      _RETURN_STRING(value);
4889
                   } else {
4890
                   _RETURN_STRING("");
4891

    
4892
                   }
4893
                 }else {
4894
                      _RETURN_STRING("");
4895
              }
4896
    }
4897

    
4898
PHP_METHOD(XdmItem, isAtomic)
4899
{
4900
    XdmItem *xdmItem;
4901
    zend_object * zobj = Z_OBJ_P(getThis());
4902
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4903
    xdmItem = obj->xdmItem;
4904

    
4905
    if (xdmItem != nullptr) {
4906
        bool isAtomic = xdmItem->isAtomic();
4907
        RETURN_BOOL(isAtomic);
4908
    }
4909
    RETURN_BOOL(false);
4910
}
4911

    
4912
PHP_METHOD(XdmItem, isNode)
4913
{
4914
    XdmItem *xdmItem;
4915
    zend_object * zobj = Z_OBJ_P(getThis());
4916
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4917
    xdmItem = obj->xdmItem;
4918

    
4919
    if (xdmItem != nullptr && xdmItem->getType() == XDM_NODE) {
4920
        RETURN_TRUE;
4921
    }
4922
    RETURN_FALSE;
4923
}
4924

    
4925
PHP_METHOD(XdmItem, getAtomicValue)
4926
{
4927
    XdmItem *xdmItem;
4928
    zend_object * zobj = Z_OBJ_P(getThis());
4929
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4930
    xdmItem = obj->xdmItem;
4931

    
4932
    if (xdmItem != nullptr) {
4933
          if(!xdmItem->isAtomic()) {
4934
                RETURN_NULL();
4935
                return;
4936
          }
4937
          if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
4938
                RETURN_NULL();
4939
                return;
4940
            } else {
4941
                xdmItem->incrementRefCount();
4942
//Z_ADDREF_P(return_value);
4943
                   zend_object * zobj = Z_OBJ_P(return_value);
4944
                    xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
4945
                //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
4946
                assert (vobj != nullptr);
4947
                vobj->xdmAtomicValue = (XdmAtomicValue *)xdmItem;
4948
                return;
4949
            }
4950
    }
4951
    RETURN_NULL();
4952
}
4953

    
4954
PHP_METHOD(XdmItem, getNodeValue)
4955
{
4956
    XdmItem *xdmItem;
4957
    zend_object * zobj = Z_OBJ_P(getThis());
4958
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4959
    xdmItem = obj->xdmItem;
4960

    
4961
    if (xdmItem != nullptr) {
4962
          if(xdmItem->isAtomic()) {
4963
                RETURN_NULL();
4964
                return;
4965
          }
4966
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4967
                RETURN_NULL();
4968
                return;
4969
            } else {
4970
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
4971
                   zend_object * zobj = Z_OBJ_P(return_value);
4972
                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
4973
                assert (vobj != nullptr);
4974
                vobj->xdmNode = (XdmNode *)xdmItem;
4975
                vobj->xdmNode->incrementRefCount();
4976

    
4977
                return;
4978
            }
4979
    }
4980
    RETURN_NULL();
4981
}
4982

    
4983

    
4984

    
4985
/*     ============== PHP Interface of   XdmNode =============== */
4986

    
4987
void xdmNode_free_storage(zend_object *object)
4988
{
4989
   zend_object_std_dtor(object);
4990

    
4991
    
4992
}
4993

    
4994
zend_object *xdmNode_create_handler(zend_class_entry *type)
4995
{
4996
    zval *tmp;
4997
    zend_object retval;
4998
    xdmNode_object *obj = (xdmNode_object *)ecalloc(1, sizeof(xdmNode_object)+ zend_object_properties_size(type));
4999
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
5000
    object_properties_init(&obj->std, type);
5001
    obj->std.handlers = &xdmNode_object_handlers;
5002
        
5003
    return &obj->std;
5004
}
5005

    
5006
PHP_METHOD(XdmNode, __construct)
5007
{
5008
    //xdmNode_object *obj = (xdmNode_object *) Z_OBJ_P(getThis() TSRMLS_CC);
5009
}
5010

    
5011
void XdmNode_destroy_storage(zend_object *object)
5012
{
5013
 
5014
 zend_objects_destroy_object(object);
5015
   
5016
}
5017

    
5018
PHP_METHOD(XdmNode, __destruct)
5019
{
5020
    zval *object = getThis();
5021
     zend_object * zobj = Z_OBJ_P(object);
5022

    
5023
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
5024

    
5025
    if(obj != nullptr) {
5026
    XdmNode * xdmNode= obj->xdmNode;
5027
    if(xdmNode != nullptr) {
5028
            xdmNode->decrementRefCount();
5029
            if(xdmNode->getRefCount()< 1){
5030
                    delete xdmNode;
5031
            } 
5032
    }
5033
    }
5034
}
5035

    
5036
PHP_METHOD(XdmNode, getStringValue)
5037
{