Project

Profile

Help

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

he / latest10 / hec / Saxon.C.API / php7_saxon.cpp @ 6304fb8b

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
jobject JNICALL phpNativeCall
827
  (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
828
        JNIEnv *senv = SaxonProcessor::sxn_environ->env;
829
//        std::cerr<<"phpNative called"<<std::endl;
830
        char *nativeString = (char *)senv->GetStringUTFChars(funcName, nullptr);
831
        std::string nativeString2 = std::string(nativeString);
832
        if(nativeString == nullptr) {
833
                return nullptr;
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
        zvalArr * php_argv= nullptr;
842
        if(arguments != nullptr) {
843
                argLength = (int)senv->GetArrayLength(arguments);
844
                php_argv = new zvalArr[argLength];
845
        }
846
        zval *params;
847
        if(argLength>0) {
848
                //(*params) = (zval**)malloc(sizeof(zval*) * argLength);
849
                params =  new zval[argLength];
850
        } else {
851
                params = nullptr;
852
        }
853
        std::map<std::string, saxonTypeEnum> typeMap;
854
        typeMap["node"] = enumNode;
855
        typeMap["string"] = enumString;
856
        typeMap["integer"] = enumInteger;
857
        typeMap["double"] = enumDouble;
858
        typeMap["float"] = enumFloat;
859
        typeMap["boolean"] = enumBool;
860
        typeMap["[xdmvalue"] = enumArrXdmValue;
861
        sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
862
        SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
863
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
864
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
865
                
866
//std::cerr<<"phpNative called cp2"<<std::endl;
867

    
868
        for(int i=0; i<argLength;i++){
869

    
870
                jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
871
                jobject argObj = senv->GetObjectArrayElement(arguments, i);
872

    
873
                const char * str = senv->GetStringUTFChars(argType,nullptr);
874
                const char *stri = nullptr;
875
                double dnumber = 0;
876
                long lnumber = 0;
877
                bool bvalue = false;
878
                float fnumber = 0;
879
                
880

    
881
         
882
                struct xdmNode_object* vobj;
883
                zend_object* zend_vobj;
884
                XdmNode * node = nullptr;
885
                std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
886
                if (it != typeMap.end()){
887
                        switch (it->second)
888
                        {
889
                                case enumNode:
890
                                        if(!nprocessor->proc){
891
                                                nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
892
                                        }
893
                                        if (object_init_ex(php_argv[i]._val, xdmNode_ce) != SUCCESS) {
894
                                                //error
895
                                                
896
                                                //php_error(E_WARNING,"error phpNative xdmNode creation failed");
897
                                                    break;
898
                                        } 
899
                                        node = new XdmNode(argObj);
900
                                        node->setProcessor(nprocessor);
901

    
902
                                        //MAKE_STD_ZVAL(php_argv[i]._val);
903
                                        zend_vobj = Z_OBJ_P(php_argv[i]._val);
904
                                           vobj = (xdmNode_object *)((char *)zend_vobj - XtOffsetOf(xdmNode_object, std));
905
                                            assert (vobj != nullptr);
906
            
907
                                        vobj->xdmNode = node;
908
                                        break;
909
                                case enumString:
910
                                        stri = senv->GetStringUTFChars((jstring)argObj, nullptr);
911
                                        //ZVAL_STRING(php_argv[i]._val);
912
                                        _ZVAL_STRING(php_argv[i]._val, stri);
913
                                        break;
914
                                case enumInteger:
915
                                        sresult->xdmvalue = argObj; 
916
                                        lnumber = getLongValue(SaxonProcessor::sxn_environ, *sresult, 0);
917

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

    
947
}
948

    
949
        //TODO should free sresult but it causes memory corruption        
950
                
951
// array of zvals to execute
952
    
953
//std::cerr<<"phpNative called cp3"<<std::endl;
954
 
955
            // convert all the values
956
            for(int i = 0; i < argLength; i++) { 
957

    
958
                params[i] = *php_argv[i]._val; }
959

    
960
        //std::cerr<<"phpNative called cp3-1"<<std::endl;
961
        //note: no implicit type conversion.
962

    
963
        zval *argvv = nullptr;//xparams;
964
        zval* callOnObj = nullptr;
965
        //MAKE_STD_ZVAL(function_name);
966
        //nativeString[nativeStrLen] = '\0';
967

    
968
        ZVAL_STRING(&function_name, nativeString);
969
//std::cerr<<"phpNative called cp3-2, argumentLen="<<argLength<<std::endl;
970
        if(call_user_function_ex(CG(function_table), (zval*)callOnObj, &function_name, &retval, argLength, params, 0, nullptr) != SUCCESS)
971
        {
972
            zend_error(E_ERROR, "Function call failed");
973
        }
974

    
975
        if(Z_TYPE(retval) ==0){
976
                zend_error(E_ERROR, "Function returned nullptr");
977
        }
978

    
979
        char * sVal = nullptr;
980
        int len = 0;
981
        jobject obj = nullptr;
982
//TODO handle XdmValue wrapped object
983
const char * objName = nullptr;
984
xdmNode_object* ooth = nullptr;
985
zend_object* zend_vobj2;
986
bool bVal;
987
        switch (Z_TYPE_P(&retval)) {
988
            case IS_FALSE:
989
                obj= booleanValue(SaxonProcessor::sxn_environ, false);
990
                break;
991
            case IS_TRUE:
992
                obj= booleanValue(SaxonProcessor::sxn_environ, true);
993
                break;
994
            
995
            case IS_LONG:
996
                obj= longValue(SaxonProcessor::sxn_environ, Z_LVAL_P(&retval));
997
                break;
998
            case IS_STRING:
999
                sVal = Z_STRVAL_P(&retval);
1000
                len = Z_STRLEN_P(&retval);
1001
                obj = getJavaStringValue(SaxonProcessor::sxn_environ,estrndup(sVal, len));
1002
                break;
1003
            break;
1004
            case IS_NULL:
1005
                
1006
                    break;
1007
            case IS_DOUBLE:
1008
                obj = doubleValue(SaxonProcessor::sxn_environ, (double)Z_DVAL_P(&retval));
1009
                 break;
1010
            
1011
            case IS_ARRAY:
1012
            //break;
1013
            case IS_OBJECT:
1014
                
1015
                    objName =ZSTR_VAL(Z_OBJCE_P(&retval)->name);
1016
      
1017

    
1018
                      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1019
                
1020
                        zend_vobj2 =  Z_OBJ_P(&retval);
1021
                        ooth = (xdmNode_object *)((char *)zend_vobj2 - XtOffsetOf(xdmNode_object, std));
1022

    
1023
                        if(ooth != nullptr) {
1024
                                    obj = ooth->xdmNode->getUnderlyingValue();
1025
                        }
1026
                      }
1027
                break;
1028
            default:
1029
                obj = nullptr;
1030
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
1031
        }
1032

    
1033
        //zend_printf("We have %i as type<br>", retval->type);
1034
        //*return_value = *retval;
1035
        //zval_copy_ctor(return_value);
1036
        //zval_ptr_dtor(&retval);
1037
        /*int cstrlen = Z_STRLEN_P(retval);
1038
        char * str = estrndup(Z_STRVAL_P(retval), cstrlen);
1039
        
1040
        jstring jstrBuf = SaxonProcessor::sxn_environ->env->NewStringUTF(str);*/
1041
        zval_ptr_dtor(&retval);
1042
        return obj;
1043
}
1044

    
1045

    
1046

    
1047
PHP_METHOD(XsltProcessor, transformToString)
1048
{
1049
    XsltProcessor *xsltProcessor;
1050
 
1051
    if (ZEND_NUM_ARGS()>0) {
1052
        WRONG_PARAM_COUNT;
1053
    }
1054

    
1055

    
1056
    zend_object* pobj = Z_OBJ_P(getThis()); 
1057
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1058
    xsltProcessor = obj->xsltProcessor;
1059
    if (xsltProcessor != nullptr) {
1060

    
1061
        const char * result = xsltProcessor->transformToString();
1062
        if(result != nullptr) {
1063
            _RETURN_STRING(result);
1064
        } else if(xsltProcessor->exceptionOccurred()){
1065
            xsltProcessor->checkException();
1066
            const char * errStr = xsltProcessor->getErrorMessage(0);
1067
            if(errStr != nullptr) {
1068
                const char * errorCode = xsltProcessor->getErrorCode(0);
1069
                if(errorCode!=nullptr) {
1070
                    // TODO: throw exception
1071
                }
1072
            }
1073
        }
1074
    }
1075
    RETURN_NULL();
1076
}
1077

    
1078
PHP_METHOD(XsltProcessor, transformToValue)
1079
{
1080
    XsltProcessor *xsltProcessor;
1081

    
1082
    if (ZEND_NUM_ARGS()>0) {
1083
        WRONG_PARAM_COUNT;
1084
    }
1085

    
1086
    zend_object* pobj = Z_OBJ_P(getThis()); 
1087
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1088
    xsltProcessor = obj->xsltProcessor;
1089

    
1090
    if (xsltProcessor != nullptr) {
1091

    
1092
        XdmValue * node = xsltProcessor->transformToValue();
1093
        if(node != nullptr) {
1094
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1095
                RETURN_NULL();
1096
            } else {
1097
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value);
1098
                zend_object *vvobj =  Z_OBJ_P(return_value);
1099
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1100
                assert (vobj != nullptr);
1101
                vobj->xdmValue = node;
1102
            }
1103
        } else if(xsltProcessor->exceptionOccurred()){
1104
            xsltProcessor->checkException();
1105
            RETURN_NULL();
1106
        }
1107
    } else {
1108
        RETURN_NULL();
1109
    }
1110
}
1111

    
1112
PHP_METHOD(XsltProcessor, transformToFile)
1113
{
1114
    XsltProcessor *xsltProcessor;
1115
 
1116
    if (ZEND_NUM_ARGS()>0) {
1117
        WRONG_PARAM_COUNT;
1118
    }
1119

    
1120
    zend_object* pobj = Z_OBJ_P(getThis()); 
1121
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1122
    xsltProcessor = obj->xsltProcessor;
1123

    
1124
    if (xsltProcessor != nullptr) {
1125

    
1126
        xsltProcessor->transformToFile();
1127
        if(xsltProcessor->exceptionOccurred()) {
1128
           //TODO
1129
            const char * exStr = xsltProcessor->checkException();
1130
        }
1131
    } else {
1132
        RETURN_NULL();
1133
    }
1134
}
1135

    
1136
PHP_METHOD(XsltProcessor, compileFromFile)
1137
{
1138
    XsltProcessor *xsltProcessor;
1139
    char * name;
1140
    size_t len1;
1141
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
1142
        RETURN_NULL();
1143
    }
1144
    zend_object* pobj = Z_OBJ_P(getThis()); 
1145
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1146
    xsltProcessor = obj->xsltProcessor;
1147
    if (xsltProcessor != nullptr) {
1148
        xsltProcessor->compileFromFile(name);
1149
    }
1150
}
1151

    
1152
PHP_METHOD(XsltProcessor, compileFromString)
1153
{
1154
    XsltProcessor *xsltProcessor;
1155
    char * stylesheetStr;
1156
    size_t len1, myint;
1157
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
1158
        RETURN_NULL();
1159
    }
1160
    zend_object* pobj = Z_OBJ_P(getThis()); 
1161
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1162
    xsltProcessor = obj->xsltProcessor;
1163
    if (xsltProcessor != nullptr) {
1164
        xsltProcessor->compileFromString(stylesheetStr);
1165
    }
1166
}
1167

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

    
1185
PHP_METHOD(XsltProcessor, compileFromFileAndSave)
1186
{
1187
    XsltProcessor *xsltProcessor;
1188
    char * stylesheetFilename;
1189
    char * filename;
1190
    size_t len1, len2, myint;
1191
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, &filename, &len1, &len2) == FAILURE) {
1192
        RETURN_NULL();
1193
    }
1194
    zend_object* pobj = Z_OBJ_P(getThis()); 
1195
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1196
    xsltProcessor = obj->xsltProcessor;
1197
    if (xsltProcessor != nullptr) {
1198
        xsltProcessor->compileFromStringAndSave(stylesheetFilename, filename);
1199
    }
1200
}
1201

    
1202

    
1203

    
1204
PHP_METHOD(XsltProcessor, compileFromValue)
1205
{
1206
    XsltProcessor *xsltProcessor;
1207
   zval* oth;
1208

    
1209
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
1210
        RETURN_NULL();
1211
    }
1212
    zend_object* pobj = Z_OBJ_P(getThis()); 
1213
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1214
    xsltProcessor = obj->xsltProcessor;
1215
    if (xsltProcessor != nullptr) {
1216
        zend_object* vvobj = Z_OBJ_P(oth);
1217
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1218
        if(ooth != nullptr) {
1219
            XdmValue * value = ooth->xdmValue;
1220
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
1221
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1222
            }
1223
        }
1224
    }
1225
}
1226

    
1227

    
1228

    
1229

    
1230
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1231
{
1232
    XsltProcessor *xsltProcessor;
1233
    zval* oth = nullptr;
1234

    
1235
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1236
        RETURN_NULL();
1237
    }
1238

    
1239
    zend_object* pobj = Z_OBJ_P(getThis()); 
1240
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1241
    xsltProcessor = obj->xsltProcessor;
1242
    if (xsltProcessor != nullptr) {
1243

    
1244
    if(!oth) {
1245
        php_error(E_WARNING, "Error setting source value");
1246
        return;
1247
    } else {
1248
        if(Z_TYPE_P(oth) ==IS_NULL){
1249
                php_error(E_WARNING, "Error setting source value");
1250
                return;
1251
        }
1252
        
1253
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1254
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1255

    
1256
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1257
        zend_object * nobj = Z_OBJ_P(oth);
1258

    
1259
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1260
        if(ooth != nullptr) {
1261
            XdmNode * value = ooth->xdmNode;
1262
            if(value != nullptr) {
1263
                
1264
                xsltProcessor->setSourceFromXdmNode(value);
1265

    
1266
            }
1267
        }
1268
      } /*else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1269
        zend_object* vvobj = Z_OBJ_P(oth);
1270
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1271
        if(ooth != nullptr) {
1272
            XdmValue * value = ooth->xdmValue;
1273
            if(value != nullptr && value) {
1274
                xsltProcessor->setSourceFromXdmNode((XdmNode*)value);
1275
            }
1276
        }
1277
      }  */
1278

    
1279
        
1280
    }
1281
  }
1282
}
1283

    
1284

    
1285
PHP_METHOD(XsltProcessor, setJustInTimeCompilation)
1286
{
1287
    XsltProcessor *xsltProcessor;
1288
    bool jit = false;
1289
    size_t len1;
1290

    
1291
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
1292
        RETURN_NULL();
1293
    }
1294

    
1295
    zend_object* pobj = Z_OBJ_P(getThis());
1296
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1297
    xsltProcessor = obj->xsltProcessor;
1298
    if (xsltProcessor != nullptr) {
1299
         xsltProcessor->setJustInTimeCompilation(jit);
1300
    }
1301
}
1302

    
1303
PHP_METHOD(XsltProcessor, setOutputFile)
1304
{
1305
    XsltProcessor *xsltProcessor;
1306
    char * outputFilename;
1307
    size_t len1;
1308

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

    
1313
    zend_object* pobj = Z_OBJ_P(getThis()); 
1314
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1315
    xsltProcessor = obj->xsltProcessor;
1316
    if (xsltProcessor != nullptr && outputFilename != nullptr) {
1317
        
1318
         xsltProcessor->setOutputFile(outputFilename);
1319
            
1320
        
1321
    }
1322
}
1323

    
1324

    
1325
PHP_METHOD(XsltProcessor, setBaseOutputURI)
1326
{
1327
    XsltProcessor *xsltProcessor;
1328
    char * baseOutputURI = nullptr;
1329
    size_t len1;
1330

    
1331
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &len1) == FAILURE) {
1332
        RETURN_NULL();
1333
    }
1334

    
1335
    zend_object* pobj = Z_OBJ_P(getThis());
1336
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1337
    xsltProcessor = obj->xsltProcessor;
1338
    if (xsltProcessor != nullptr && baseOutputURI != nullptr) {
1339

    
1340
         xsltProcessor->setBaseOutputURI(baseOutputURI);
1341

    
1342

    
1343
    }
1344
}
1345

    
1346

    
1347
int size_t2int(size_t val) {
1348
    return (val <= INT_MAX) ? (int)((ssize_t)val) : -1;
1349
}
1350

    
1351
PHP_METHOD(XsltProcessor, setSourceFromFile)
1352
{
1353
    XsltProcessor *xsltProcessor;
1354
    char * inFilename;
1355
    size_t len1;
1356
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
1357
        RETURN_NULL();
1358
    }
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 && inFilename != nullptr) {
1364
         xsltProcessor->setSourceFromFile(inFilename);
1365
            
1366
        
1367
    }
1368
}
1369

    
1370

    
1371
PHP_METHOD(XsltProcessor, setProperty)
1372
{
1373
    XsltProcessor *xsltProcessor;
1374
    char * name;
1375
    char * value;
1376
    size_t len1, len2, myint;
1377

    
1378
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
1379
        RETURN_NULL();
1380
    }
1381
    zend_object* pobj = Z_OBJ_P(getThis()); 
1382
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1383
    xsltProcessor = obj->xsltProcessor;
1384
    if (xsltProcessor != nullptr) {
1385
        xsltProcessor->setProperty(name, value);
1386
    }
1387
}
1388

    
1389
PHP_METHOD(XsltProcessor, setParameter)
1390
{
1391

    
1392
   XsltProcessor *xsltProcessor;
1393
   char * name;
1394
   zval* oth;
1395
   size_t len1, len2, myint;        
1396
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1397
        RETURN_NULL();
1398
    }
1399
    zend_object* pobj = Z_OBJ_P(getThis()); 
1400
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1401
    xsltProcessor = obj->xsltProcessor;
1402
    if (xsltProcessor != nullptr) {
1403
        if(Z_TYPE_P(oth) ==IS_NULL){
1404
                php_error(E_WARNING, "Error setting source value - value is nullptr");
1405
                return;
1406
        }
1407

    
1408
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1409
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1410

    
1411
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1412
        zend_object* ooth = Z_OBJ_P(oth);
1413
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1414
        if(nobj != nullptr) {
1415
            XdmNode * value = nobj->xdmNode;
1416
            if(value != nullptr) {
1417
                xsltProcessor->setParameter(name, (XdmValue *)value);
1418

    
1419
            }
1420
        }
1421
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1422
        zend_object* ooth = Z_OBJ_P(oth);
1423
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1424
        if(vobj != nullptr) {
1425
            XdmValue * value = vobj->xdmValue;
1426
            if(value != nullptr) {
1427
                
1428
                xsltProcessor->setParameter(name, value);
1429
            }
1430
        }
1431

    
1432

    
1433

    
1434
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1435
        zend_object* ooth = Z_OBJ_P(oth);
1436
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1437
        if(aobj != nullptr) {
1438
            XdmAtomicValue * value = aobj->xdmAtomicValue;
1439
            if(value != nullptr) {
1440
                xsltProcessor->setParameter(name, (XdmValue *)value);
1441
            }
1442
        }
1443

    
1444

    
1445

    
1446
      }
1447

    
1448
    }
1449
}
1450

    
1451
PHP_METHOD(XsltProcessor, clearParameters)
1452
{
1453
    XsltProcessor *xsltProcessor;
1454
    if (ZEND_NUM_ARGS()>0) {
1455
        WRONG_PARAM_COUNT;
1456
    }
1457

    
1458
    zend_object* pobj = Z_OBJ_P(getThis()); 
1459
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1460
    xsltProcessor = obj->xsltProcessor;
1461
    if (xsltProcessor != nullptr) {
1462
        xsltProcessor->clearParameters(true);
1463
    }
1464
}
1465

    
1466
PHP_METHOD(XsltProcessor, clearProperties)
1467
{
1468
    XsltProcessor *xsltProcessor;
1469
    if (ZEND_NUM_ARGS()>0) {
1470
        WRONG_PARAM_COUNT;
1471
    }
1472

    
1473
    zend_object* pobj = Z_OBJ_P(getThis()); 
1474
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1475
    xsltProcessor = obj->xsltProcessor;
1476
    if (xsltProcessor != nullptr) {
1477
        xsltProcessor->clearProperties();
1478
    }
1479
}
1480

    
1481

    
1482

    
1483
PHP_METHOD(XsltProcessor, setupXslMessage)
1484
{
1485
    XsltProcessor *xsltProcessor;
1486
    bool show = false;
1487
    char * filename = nullptr;
1488
    size_t len1;
1489
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename &len1) == FAILURE) {
1490
        RETURN_NULL();
1491
    }
1492

    
1493
    zend_object* pobj = Z_OBJ_P(getThis());
1494
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1495
    xsltProcessor = obj->xsltProcessor;
1496

    
1497
    if (xsltProcessor != nullptr) {
1498

    
1499
            xsltProcessor->setupXslMessage(show, filename);
1500
        }
1501

    
1502
}
1503

    
1504

    
1505

    
1506
PHP_METHOD(XsltProcessor, exceptionOccurred)
1507
{
1508
    XsltProcessor *xsltProcessor;
1509
    zend_object* pobj = Z_OBJ_P(getThis()); 
1510
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1511
    if (ZEND_NUM_ARGS()>0) {
1512
        WRONG_PARAM_COUNT;
1513
    }
1514

    
1515
    xsltProcessor = obj->xsltProcessor;
1516
    if (xsltProcessor != nullptr) {
1517
        bool result = xsltProcessor->exceptionOccurred();
1518
        RETURN_BOOL(result);
1519
    }
1520
    RETURN_BOOL(false);
1521
}
1522

    
1523
PHP_METHOD(XsltProcessor, getExceptionCount)
1524
{
1525
    XsltProcessor *xsltProcessor;
1526
    zend_object* pobj = Z_OBJ_P(getThis()); 
1527
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1528
    if (ZEND_NUM_ARGS()>0) {
1529
        WRONG_PARAM_COUNT;
1530
    }
1531

    
1532
    xsltProcessor = obj->xsltProcessor;
1533
    if (xsltProcessor != nullptr) {
1534
        int count = xsltProcessor->exceptionCount();
1535
        RETURN_LONG(count);
1536
    }
1537
    RETURN_LONG(0);
1538
}
1539

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

    
1560
PHP_METHOD(XsltProcessor, getErrorMessage)
1561
{
1562
    XsltProcessor *xsltProcessor;
1563
    long index;
1564
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1565
        RETURN_NULL();
1566
    }
1567
    zend_object* pobj = Z_OBJ_P(getThis()); 
1568
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1569
    xsltProcessor = obj->xsltProcessor;
1570
    if (xsltProcessor != nullptr) {
1571
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1572
        if(errStr != nullptr) {
1573
            //char *str = estrdup(errStr);
1574
            _RETURN_STRING(errStr);
1575
        }
1576
    }
1577
    RETURN_NULL();
1578
}
1579
PHP_METHOD(XsltProcessor, exceptionClear)
1580
{
1581
    XsltProcessor *xsltProcessor;
1582
    zend_object* pobj = Z_OBJ_P(getThis()); 
1583
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1584
    xsltProcessor = obj->xsltProcessor;
1585
    if (xsltProcessor != nullptr) {
1586
        xsltProcessor->exceptionClear();
1587
    }
1588
}
1589

    
1590

    
1591

    
1592
/*     ============== XSLT30: PHP Interface of  Xslt30Processor class =============== */
1593

    
1594
void Xslt30Processor_free_storage(zend_object *object)
1595
{
1596

    
1597
    zend_object_std_dtor(object);
1598

    
1599
}
1600

    
1601
void Xslt30Processor_destroy_storage(zend_object *object)
1602
{
1603
    xslt30Processor_object *obj;
1604

    
1605
    zend_objects_destroy_object(object);
1606
}
1607

    
1608
zend_object * xslt30Processor_create_handler(zend_class_entry *type)
1609
{
1610

    
1611

    
1612
    xslt30Processor_object *obj = (xslt30Processor_object *)ecalloc(1, sizeof(xslt30Processor_object)+ zend_object_properties_size(type));
1613

    
1614

    
1615
   zend_object_std_init(&obj->std,type);
1616
    object_properties_init(&obj->std, type);
1617

    
1618
    obj->std.handlers = &xslt30Processor_object_handlers;
1619

    
1620
    return &obj->std;
1621
}
1622

    
1623

    
1624

    
1625
PHP_METHOD(Xslt30Processor, __destruct)
1626
{
1627

    
1628
    zend_object* pobj = Z_OBJ_P(getThis());
1629
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1630

    
1631

    
1632
    Xslt30Processor * xslt30Processor= obj->xslt30Processor;
1633
    if(xslt30Processor != nullptr){
1634
            delete xslt30Processor;
1635
     }
1636

    
1637

    
1638
}
1639

    
1640

    
1641
PHP_METHOD(Xslt30Processor, setBaseOutputURI)
1642
{
1643
    Xslt30Processor *xslt30Processor;
1644
    char * baseOutputURI = nullptr;
1645
    size_t len1;
1646

    
1647
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &len1) == FAILURE) {
1648
        RETURN_NULL();
1649
    }
1650

    
1651
    zend_object* pobj = Z_OBJ_P(getThis());
1652
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1653
    xslt30Processor = obj->xslt30Processor;
1654
    if (xslt30Processor != nullptr && baseOutputURI != nullptr) {
1655

    
1656
         xslt30Processor->setBaseOutputURI(baseOutputURI);
1657

    
1658

    
1659
    }
1660
}
1661

    
1662

    
1663

    
1664
PHP_METHOD(Xslt30Processor, callFunctionReturningValue)
1665
{
1666
//arguments: const char * stylesheetFilename, const char* functionName, XdmValue * arguments, int argument_length
1667

    
1668
    Xslt30Processor *xslt30Processor;
1669
    HashTable *arr_hash;
1670
    char* functionName;
1671
    zval * arguments_zval;
1672
    zval * val;
1673
    long num_key;
1674
    XdmValue ** arguments = nullptr;
1675
    int argument_length=0;
1676
    zend_string *key;
1677

    
1678
    char * infilename;
1679
    char * styleFileName = nullptr;
1680
    size_t len1, len2;
1681

    
1682
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len2, &arguments_zval) == FAILURE) {
1683
        RETURN_NULL();
1684
    } else if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssa", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1685
        RETURN_NULL();
1686
    }
1687

    
1688
    zend_object* pobj = Z_OBJ_P(getThis());
1689
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1690
    xslt30Processor = obj->xslt30Processor;
1691
    arr_hash = Z_ARRVAL_P(arguments_zval);
1692
    argument_length = zend_hash_num_elements(arr_hash);
1693
   
1694
    arguments = new XdmValue*[argument_length];
1695
      
1696
    if (xslt30Processor != nullptr) {
1697
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1698
        if(Z_TYPE_P(val) != nullptr) {
1699
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1700
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1701
        php_printf("num_key %d =>", num_key);
1702
        php_printf("key %d =>", key);
1703
        */
1704
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1705
                zend_object* ooth = Z_OBJ_P(val);
1706
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1707
                if(nobj != nullptr) {
1708
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1709
                            arguments[num_key] = value;
1710
                }
1711
        }
1712
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1713
                zend_object* ooth = Z_OBJ_P(val);
1714
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1715
                if(nobj != nullptr) {
1716
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1717
                            arguments[num_key] = value;
1718
                }
1719
        }
1720
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1721
                zend_object* ooth = Z_OBJ_P(val);
1722
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1723
                if(nobj != nullptr) {
1724
                            XdmValue * value = nobj->xdmValue;
1725
                            arguments[num_key] = value;
1726
                }
1727
        }
1728
        else {//TODO error warning}
1729
         }}else {
1730
                //TODO error warning
1731
        }
1732
      } ZEND_HASH_FOREACH_END();
1733

    
1734

    
1735
        //php_printf(" argument_length= %d",argument_length);
1736
        XdmValue * result = xslt30Processor->callFunctionReturningValue(styleFileName, functionName, arguments, argument_length);
1737
        if(result != nullptr) {
1738
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1739
                RETURN_NULL();
1740
            } else {
1741
                zend_object *ooth =  Z_OBJ_P(return_value);
1742
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
1743
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1744
                assert (vobj != nullptr);
1745
                vobj->xdmValue = result;
1746
            }
1747
        } else {
1748
            if(obj->xslt30Processor->exceptionOccurred()){
1749
                  //TODO
1750
            }
1751
            RETURN_NULL();
1752
        }
1753
    }
1754

    
1755

    
1756
}
1757

    
1758
PHP_METHOD(Xslt30Processor, callFunctionReturningString){
1759
    Xslt30Processor *xslt30Processor;
1760
    HashTable *arr_hash;
1761
    char* functionName;
1762
    zval * arguments_zval;
1763
    zval * val;
1764
    long num_key;
1765
    XdmValue ** arguments = nullptr;
1766
    int argument_length=0;
1767
    zend_string *key;
1768

    
1769
    char * infilename;
1770
    char * styleFileName = nullptr;
1771
    size_t len1, len2;
1772

    
1773
     if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len2, &arguments_zval) == FAILURE) {
1774
        RETURN_NULL();
1775
      }else if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssa", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1776
        RETURN_NULL();
1777
    }
1778

    
1779
    zend_object* pobj = Z_OBJ_P(getThis());
1780
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1781
    xslt30Processor = obj->xslt30Processor;
1782
    arr_hash = Z_ARRVAL_P(arguments_zval);
1783
    argument_length = zend_hash_num_elements(arr_hash);
1784
   
1785
    arguments = new XdmValue*[argument_length];
1786
      
1787
    if (xslt30Processor != nullptr) {
1788
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1789
        if(Z_TYPE_P(val) != nullptr) {
1790
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1791
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1792
        php_printf("num_key %d =>", num_key);
1793
        php_printf("key %d =>", key);
1794
        */
1795
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1796
                zend_object* ooth = Z_OBJ_P(val);
1797
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1798
                if(nobj != nullptr) {
1799
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1800
                            arguments[num_key] = value;
1801
                }
1802
        }
1803
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1804
                zend_object* ooth = Z_OBJ_P(val);
1805
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1806
                if(nobj != nullptr) {
1807
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1808
                            arguments[num_key] = value;
1809
                }
1810
        }
1811
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1812
                zend_object* ooth = Z_OBJ_P(val);
1813
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1814
                if(nobj != nullptr) {
1815
                            XdmValue * value = nobj->xdmValue;
1816
                            arguments[num_key] = value;
1817
                }
1818
        }
1819
        else {//TODO error warning}
1820
         }}else {
1821
                //TODO error warning
1822
        }
1823
      } ZEND_HASH_FOREACH_END();
1824

    
1825
        const char * result = xslt30Processor->callFunctionReturningString(styleFileName, functionName, arguments, argument_length);
1826
        if(result != nullptr) {
1827
            //char *str = estrdup(result);
1828
            _RETURN_STRING(result);
1829
        } else if(xslt30Processor->exceptionOccurred()){
1830
            //TODO: xslt30Processor->checkException();
1831
            const char * errStr = xslt30Processor->getErrorMessage(0);
1832
            if(errStr != nullptr) {
1833
                const char * errorCode = xslt30Processor->getErrorCode(0);
1834
                if(errorCode!=nullptr) {
1835
                    // TODO: throw exception
1836
                }
1837
            }
1838
        }
1839
    }
1840

    
1841

    
1842

    
1843
}
1844

    
1845

    
1846
    PHP_METHOD(Xslt30Processor, callFunctionReturningFile){
1847
    HashTable *arr_hash;
1848
    Xslt30Processor *xslt30Processor;
1849
    char* functionName;
1850
    zval * arguments_zval;
1851
    zval * val;
1852
    long num_key;
1853
    XdmValue ** arguments = nullptr;
1854
    int argument_length=0;
1855
    zend_string *key;
1856

    
1857
    char * outfilename;
1858
    char * styleFileName = nullptr;
1859
    size_t len1, len2, len3;
1860

    
1861

    
1862
    if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "sas", &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
1863
        RETURN_NULL();
1864
    } else if (ZEND_NUM_ARGS()==4 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssas", &styleFileName, &len1, &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
1865
        RETURN_NULL();
1866
    }
1867

    
1868
    zend_object* pobj = Z_OBJ_P(getThis());
1869
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1870
    xslt30Processor = obj->xslt30Processor;
1871
    arr_hash = Z_ARRVAL_P(arguments_zval);
1872
    argument_length = zend_hash_num_elements(arr_hash);
1873
   
1874
    arguments = new XdmValue*[argument_length];
1875
      
1876
    if (xslt30Processor != nullptr) {
1877
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1878
        if(Z_TYPE_P(val) != nullptr) {
1879
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1880
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1881
        php_printf("num_key %d =>", num_key);
1882
        php_printf("key %d =>", key);
1883
        */
1884
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1885
                zend_object* ooth = Z_OBJ_P(val);
1886
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1887
                if(nobj != nullptr) {
1888
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1889
                            arguments[num_key] = value;
1890
                }
1891
        }
1892
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1893
                zend_object* ooth = Z_OBJ_P(val);
1894
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1895
                if(nobj != nullptr) {
1896
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1897
                            arguments[num_key] = value;
1898
                }
1899
        }
1900
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1901
                zend_object* ooth = Z_OBJ_P(val);
1902
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1903
                if(nobj != nullptr) {
1904
                            XdmValue * value = nobj->xdmValue;
1905
                            arguments[num_key] = value;
1906
                }
1907
        }
1908
        else {//TODO error warning}
1909
         }}else {
1910
                //TODO error warning
1911
        }
1912
      } ZEND_HASH_FOREACH_END();
1913

    
1914

    
1915
        xslt30Processor->callFunctionReturningFile(styleFileName, functionName, arguments, argument_length, outfilename);
1916
        if(xslt30Processor->exceptionOccurred()){
1917
            //TODO: xslt30Processor->checkException();
1918
            const char * errStr = xslt30Processor->getErrorMessage(0);
1919
            if(errStr != nullptr) {
1920
                const char * errorCode = xslt30Processor->getErrorCode(0);
1921
            }
1922
        }
1923
    }
1924

    
1925
}
1926

    
1927
    PHP_METHOD(Xslt30Processor, callTemplateReturningValue){
1928

    
1929
  Xslt30Processor *xslt30Processor;
1930
    char* templateName = nullptr;
1931
   
1932
    char * styleFileName = nullptr;
1933
    size_t len1, len2;
1934

    
1935

    
1936
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
1937
        RETURN_NULL();
1938
    } else if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1939
        RETURN_NULL();
1940
    }
1941

    
1942

    
1943
    zend_object* pobj = Z_OBJ_P(getThis());
1944
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1945
    xslt30Processor = obj->xslt30Processor;
1946
      
1947
    if (xslt30Processor != nullptr) {
1948
   
1949

    
1950
        //php_printf(" argument_length= %d",argument_length);
1951
        XdmValue * result = xslt30Processor->callTemplateReturningValue(styleFileName, templateName);
1952
        if(result != nullptr) {
1953
 
1954
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) { 
1955
               RETURN_NULL();
1956
            } else {
1957
                zend_object *ooth =  Z_OBJ_P(return_value);
1958
              
1959
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1960
                assert (vobj != nullptr);
1961
                vobj->xdmValue = result;
1962
                
1963
            }
1964
        } else {
1965
            if(obj->xslt30Processor->exceptionOccurred()){
1966
                  //TODO
1967
            }
1968
            RETURN_NULL();
1969
        }
1970
    }
1971
   }
1972

    
1973

    
1974
    PHP_METHOD(Xslt30Processor, callTemplateReturningString){
1975
    Xslt30Processor *xslt30Processor;
1976
    char* templateName = nullptr;
1977
   
1978
    char * styleFileName = nullptr;
1979
    size_t len1, len2;
1980

    
1981
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
1982
        RETURN_NULL();
1983
    }
1984

    
1985
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1986
        RETURN_NULL();
1987
    }
1988

    
1989
    zend_object* pobj = Z_OBJ_P(getThis());
1990
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1991
    xslt30Processor = obj->xslt30Processor;
1992
      
1993
    if (xslt30Processor != nullptr) {
1994
   
1995

    
1996
        //php_printf(" argument_length= %d",argument_length);
1997
        const char * result = xslt30Processor->callTemplateReturningString(styleFileName, templateName);
1998
        if(result != nullptr) {
1999
            _RETURN_STRING(result); 
2000
        } else {
2001
            if(xslt30Processor->exceptionOccurred()){
2002
            xslt30Processor->checkException();
2003
            const char * errStr = xslt30Processor->getErrorMessage(0);
2004
            if(errStr != nullptr) {
2005
                const char * errorCode = xslt30Processor->getErrorCode(0);
2006
                if(errorCode!=nullptr) {
2007
                    // TODO: throw exception
2008
                }
2009
            }
2010
           }
2011
        }
2012
    }
2013

    
2014
     RETURN_NULL();
2015
    }
2016

    
2017
    PHP_METHOD(Xslt30Processor, callTemplateReturningFile){
2018
   Xslt30Processor *xslt30Processor;
2019
    char* templateName = nullptr;
2020
    char * filename = nullptr;
2021
    char * styleFileName = nullptr;
2022
    size_t len1, len2, len3;
2023

    
2024
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
2025
        RETURN_NULL();
2026
    }
2027

    
2028
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
2029
        RETURN_NULL();
2030
    }
2031

    
2032
    zend_object* pobj = Z_OBJ_P(getThis());
2033
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2034
    xslt30Processor = obj->xslt30Processor;
2035
      
2036
    if (xslt30Processor != nullptr) {
2037
           xslt30Processor->callTemplateReturningFile(styleFileName, templateName, filename);
2038
    }
2039

    
2040
  }
2041

    
2042

    
2043
PHP_METHOD(Xslt30Processor, applyTemplatesReturningValue){
2044
   Xslt30Processor *xslt30Processor;
2045
    char * styleFileName = nullptr;
2046
    size_t len1;
2047

    
2048
    if (ZEND_NUM_ARGS()>0) {
2049

    
2050
      if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &styleFileName, &len1) == FAILURE) {
2051
          RETURN_NULL();
2052
      }
2053
    }
2054

    
2055
    zend_object* pobj = Z_OBJ_P(getThis());
2056
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2057
    xslt30Processor = obj->xslt30Processor;
2058
      
2059
    if (xslt30Processor != nullptr) {
2060
           XdmValue * result = xslt30Processor->applyTemplatesReturningValue(styleFileName);
2061
    
2062
        if(result != nullptr) {
2063
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2064
                RETURN_NULL();
2065
            } else {
2066
                zend_object *ooth =  Z_OBJ_P(return_value);
2067
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2068
                assert (vobj != nullptr);
2069
                vobj->xdmValue = result;
2070
            }
2071
        } else {
2072
            if(obj->xslt30Processor->exceptionOccurred()){
2073
                  //TODO
2074
            }
2075
            RETURN_NULL();
2076
        }
2077

    
2078

    
2079

    
2080
    } else {
2081
     RETURN_NULL();
2082
    }
2083
}
2084

    
2085

    
2086
PHP_METHOD(Xslt30Processor, applyTemplatesReturningString){
2087
 Xslt30Processor *xslt30Processor;
2088

    
2089
    char * styleFileName = nullptr;
2090
    size_t len1;
2091

    
2092

    
2093
    if (ZEND_NUM_ARGS()>0) {
2094
    
2095
            if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &styleFileName, &len1) == FAILURE) {
2096
                RETURN_NULL();
2097
            }
2098
    }
2099

    
2100
    zend_object* pobj = Z_OBJ_P(getThis());
2101
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2102
    xslt30Processor = obj->xslt30Processor;
2103
      
2104
    if (xslt30Processor != nullptr) {
2105
        const char * result = xslt30Processor->applyTemplatesReturningString(styleFileName);
2106
   
2107
        if(result != nullptr) {
2108
            _RETURN_STRING(result); 
2109
        } else {
2110
            if(xslt30Processor->exceptionOccurred()){
2111
            xslt30Processor->checkException();
2112
            const char * errStr = xslt30Processor->getErrorMessage(0);
2113
            if(errStr != nullptr) {
2114
                const char * errorCode = xslt30Processor->getErrorCode(0);
2115
                if(errorCode!=nullptr) {
2116
                    // TODO: throw exception
2117
                }
2118
            }
2119
           }
2120
        }
2121
    }
2122

    
2123
     RETURN_NULL();
2124
   
2125

    
2126

    
2127
}
2128

    
2129

    
2130

    
2131
PHP_METHOD(Xslt30Processor, applyTemplatesReturningFile){
2132
 Xslt30Processor *xslt30Processor;
2133
    char * filename = nullptr;
2134
    char * styleFileName = nullptr;
2135
    size_t len1, len2;
2136

    
2137
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &filename, &len2) == FAILURE) {
2138
          RETURN_NULL();
2139
    }
2140

    
2141
   if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &filename, &len2) == FAILURE) {
2142
          RETURN_NULL();
2143
    }
2144
    
2145

    
2146
    zend_object* pobj = Z_OBJ_P(getThis());
2147
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2148
    xslt30Processor = obj->xslt30Processor;
2149
      
2150
    if (xslt30Processor != nullptr) {
2151
           xslt30Processor->applyTemplatesReturningFile(styleFileName, filename);
2152
    }
2153

    
2154

    
2155

    
2156
}
2157

    
2158

    
2159
/*PHP_METHOD(Xslt30Processor, addPackages){
2160
    HashTable *arr_hash;
2161
    Xslt30Processor *xslt30Processor;
2162
    char* functionName = nullptr;
2163
    zval * arguments_zval;
2164
    zval * val;
2165
    long num_key;
2166
    const char ** arguments = nullptr;
2167
    int argument_length=0;
2168
    zend_string *key;
2169

2170
    char * infilename = nullptr;
2171
    char * styleFileName = nullptr;
2172
    size_t len1, len2;
2173

2174
        if (zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
2175
        RETURN_NULL();
2176
    }
2177

2178
    zend_object* pobj = Z_OBJ_P(getThis());
2179
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2180
    xslt30Processor = obj->xslt30Processor;
2181
    arr_hash = Z_ARRVAL_P(arguments_zval);
2182
    argument_length = zend_hash_num_elements(arr_hash);
2183
   
2184
    arguments = new const char*[argument_length];
2185

2186
  if (xslt30Processor != nullptr) {
2187
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
2188
        if(Z_TYPE_P(val) != nullptr && Z_TYPE_P(val)== IS_STRING) {
2189

2190
                arguments[num_key] = (const char*)Z_STRVAL_P(val);
2191
                     
2192
        } 
2193
    }  ZEND_HASH_FOREACH_END();
2194

2195
        xslt30Processor->addPackages(arguments, argument_length);
2196
        if(xslt30Processor->exceptionOccurred()){
2197
            //TODO: xslt30Processor->checkException();
2198
            const char * errStr = xslt30Processor->getErrorMessage(0);
2199
            if(errStr != nullptr) {
2200
                const char * errorCode = xslt30Processor->getErrorCode(0);
2201
            }
2202
        }
2203
    }
2204
}    */
2205

    
2206

    
2207
    PHP_METHOD(Xslt30Processor,setInitialTemplateParameters){
2208

    
2209
  Xslt30Processor *xslt30Processor;
2210
    HashTable *arr_hash;
2211
    zval * arguments_zval;
2212
    zval * val;
2213
    long num_key;
2214
    XdmValue ** arguments;
2215
    int argument_length=0;
2216
    zend_string *key;
2217

    
2218
    bool tunnel = false;
2219
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
2220
        RETURN_NULL();
2221
    }
2222

    
2223
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ab", &arguments_zval, &tunnel) == FAILURE) {
2224
        RETURN_NULL();
2225
    }
2226

    
2227

    
2228
    zend_object* pobj = Z_OBJ_P(getThis());
2229
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2230
    xslt30Processor = obj->xslt30Processor;
2231
    arr_hash = Z_ARRVAL_P(arguments_zval);
2232
    argument_length = zend_hash_num_elements(arr_hash);
2233
   
2234
    arguments = new XdmValue*[argument_length];
2235
    std::map<std::string,XdmValue*> parameters;
2236
    if (xslt30Processor != nullptr) {
2237
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
2238
        if(Z_TYPE_P(val) != nullptr) {
2239
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
2240
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
2241
        php_printf("num_key %d =>", num_key);
2242
        php_printf("key %d =>", key);
2243
        */
2244
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2245
                zend_object* ooth = Z_OBJ_P(val);
2246
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
2247
                if(nobj != nullptr) {
2248
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
2249
                            parameters[ZSTR_VAL(key)] = value;
2250
                }
2251
        }
2252
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2253
                zend_object* ooth = Z_OBJ_P(val);
2254
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
2255
                if(nobj != nullptr) {
2256
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
2257
                            parameters[ZSTR_VAL(key)] = value;
2258
                }
2259
        }
2260
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
2261
                zend_object* ooth = Z_OBJ_P(val);
2262
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2263
                if(nobj != nullptr) {
2264
                            XdmValue * value = nobj->xdmValue;
2265
                            parameters[ZSTR_VAL(key)] = value;
2266
                }
2267
        }
2268
        else {//TODO error warning}
2269
         }}else {
2270
                //TODO error warning
2271
        }
2272
      } ZEND_HASH_FOREACH_END();
2273

    
2274

    
2275
        //php_printf(" argument_length= %d",argument_length);
2276
        xslt30Processor->setInitialTemplateParameters(parameters, tunnel);
2277
        
2278
    }
2279

    
2280
    }
2281

    
2282

    
2283
PHP_METHOD(Xslt30Processor, setInitialMatchSelection){
2284
   Xslt30Processor *xslt30Processor;
2285
    zval* oth = nullptr;
2286

    
2287
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2288
        RETURN_NULL();
2289
    }
2290

    
2291
    zend_object* pobj = Z_OBJ_P(getThis());
2292
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2293
    xslt30Processor = obj->xslt30Processor;
2294
    if (xslt30Processor != nullptr) {
2295

    
2296
    if(!oth) {
2297
        php_error(E_WARNING, "Error setting source value");
2298
        return;
2299
    } else {
2300
        if(Z_TYPE_P(oth) ==IS_NULL){
2301
                php_error(E_WARNING, "Error setting source value - nullptr found");
2302
                return;
2303
        }
2304

    
2305
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2306
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2307

    
2308
      
2309
      if(strcmp(objName, "Saxon\\XdmValue")==0) {
2310
        zend_object * nobj = Z_OBJ_P(oth);
2311

    
2312
        xdmValue_object* ooth = (xdmValue_object *)((char *)nobj - XtOffsetOf(xdmValue_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2313
        if(ooth != nullptr) {
2314
            XdmValue * value = ooth->xdmValue;
2315
            if(value != nullptr) {
2316
                xslt30Processor->setInitialMatchSelection(value);
2317

    
2318
            }
2319
        }
2320
      } else if(strcmp(objName, "Saxon\\XdmNode")==0) {
2321
        zend_object * nobj = Z_OBJ_P(oth);
2322

    
2323
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2324
        if(ooth != nullptr) {
2325
            XdmNode * value = ooth->xdmNode;
2326
            if(value != nullptr) {
2327
                XdmValue  *valueX = (XdmValue*)value;
2328
                xslt30Processor->setInitialMatchSelection(valueX);
2329

    
2330
            } else {
2331

    
2332
php_error(E_WARNING, "XdmNode - seInitialMatchSelection - cp1");
2333
}
2334
        }
2335
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2336
        zend_object* vvobj = Z_OBJ_P(oth);
2337

    
2338
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2339
        if(ooth != nullptr) {
2340
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2341
            if(value != nullptr) {
2342
                xslt30Processor->setInitialMatchSelection((XdmValue*)value);
2343
            }
2344
        }
2345
      } else {
2346
        //TODO raise warning
2347
        }
2348

    
2349

    
2350
    }
2351
  }
2352

    
2353

    
2354

    
2355

    
2356
}
2357
    
2358

    
2359
PHP_METHOD(Xslt30Processor, setGlobalContextItem)
2360
{
2361
    Xslt30Processor *xslt30Processor;
2362
    zval* oth = nullptr;
2363

    
2364
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2365
        RETURN_NULL();
2366
    }
2367

    
2368
    zend_object* pobj = Z_OBJ_P(getThis());
2369
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2370
    xslt30Processor = obj->xslt30Processor;
2371
    if (xslt30Processor != nullptr) {
2372

    
2373
    if(!oth) {
2374
        php_error(E_WARNING, "Error setting source value");
2375
        return;
2376
    } else {
2377
        if(Z_TYPE_P(oth) ==IS_NULL){
2378
                php_error(E_WARNING, "Error setting source value");
2379
                return;
2380
        }
2381

    
2382
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2383
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2384

    
2385
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2386
        zend_object * nobj = Z_OBJ_P(oth);
2387

    
2388
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2389
        if(ooth != nullptr) {
2390
            XdmNode * value = ooth->xdmNode;
2391
            if(value != nullptr) {
2392
                XdmItem  *valueX = (XdmItem*)value;
2393
                xslt30Processor->setGlobalContextItem(valueX);
2394

    
2395
            }
2396
        }
2397
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2398
        zend_object* vvobj = Z_OBJ_P(oth);
2399
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2400
        if(ooth != nullptr) {
2401
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2402
            if(value != nullptr) {
2403
                xslt30Processor->setGlobalContextItem((XdmItem*)value);
2404
            }
2405
        }
2406
      } else {
2407
        //TODO raise warning
2408
        }
2409

    
2410

    
2411
    }
2412
  }
2413
}
2414

    
2415

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

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

    
2431

    
2432
    }
2433
}
2434

    
2435

    
2436
PHP_METHOD(Xslt30Processor, setInitialMatchSelectionAsFile)
2437
{
2438
    Xslt30Processor *xslt30Processor;
2439
    char * inFilename = nullptr;
2440
    size_t len1;
2441
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2442
        RETURN_NULL();
2443
    }
2444

    
2445
    zend_object* pobj = Z_OBJ_P(getThis());
2446
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2447
    xslt30Processor = obj->xslt30Processor;
2448
    if (xslt30Processor != nullptr && inFilename != nullptr) {
2449
         xslt30Processor->setInitialMatchSelectionAsFile(inFilename);
2450

    
2451

    
2452
    }
2453
}
2454

    
2455

    
2456
PHP_METHOD(Xslt30Processor, transformFileToFile)
2457
{
2458
    Xslt30Processor *xslt30Processor;
2459
    char * outfileName = nullptr;
2460
    char * infilename = nullptr;
2461
    char * styleFileName = nullptr;
2462
    size_t len1, len2, len3;
2463

    
2464
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
2465
        RETURN_NULL();
2466
    }
2467

    
2468
    zend_object* pobj = Z_OBJ_P(getThis());
2469
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2470
    xslt30Processor = obj->xslt30Processor;
2471

    
2472
    if (xslt30Processor != nullptr) {
2473

    
2474
        xslt30Processor->transformFileToFile(infilename, styleFileName, outfileName);
2475
        if(xslt30Processor->exceptionOccurred()) {
2476
               // TODO: throw exception
2477
        }
2478
    }
2479
}
2480

    
2481
PHP_METHOD(Xslt30Processor, transformFileToValue)
2482
{
2483
    Xslt30Processor *xslt30Processor;
2484
    char * infilename = nullptr;
2485
    char * styleFileName = nullptr;
2486
   size_t len1, len2;
2487

    
2488
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2489
        RETURN_NULL();
2490
    }
2491

    
2492
    zend_object* pobj = Z_OBJ_P(getThis());
2493
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2494
    xslt30Processor = obj->xslt30Processor;
2495

    
2496
    if (xslt30Processor != nullptr) {
2497

    
2498
        XdmValue * node = xslt30Processor->transformFileToValue(infilename, styleFileName);
2499
        if(node != nullptr) {
2500
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2501
                RETURN_NULL();
2502
            } else {
2503
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
2504
                zend_object *ooth =  Z_OBJ_P(return_value);
2505
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2506
                assert (vobj != nullptr);
2507
                vobj->xdmValue = node;
2508
            }
2509
        } else {
2510
            if(obj->xslt30Processor->exceptionOccurred()){
2511
                  //TODO
2512
            }
2513
        }
2514
    }else {
2515
        RETURN_NULL();
2516
    }
2517
}
2518

    
2519

    
2520
PHP_METHOD(Xslt30Processor, transformFileToString)
2521
{
2522
    Xslt30Processor *xslt30Processor;
2523
    char * infilename = nullptr;
2524
    char * styleFileName = nullptr;
2525
    size_t len1, len2;
2526

    
2527
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2528
        RETURN_NULL();
2529
    }
2530

    
2531
    zend_object* pobj = Z_OBJ_P(getThis());
2532
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2533
    xslt30Processor = obj->xslt30Processor;
2534

    
2535
    if (xslt30Processor != nullptr) {
2536

    
2537
        const char * result = xslt30Processor->transformFileToString(infilename, styleFileName);
2538
        if(result != nullptr) {
2539
            //char *str = estrdup(result);
2540
            _RETURN_STRING(result);
2541
        } else if(xslt30Processor->exceptionOccurred()){
2542
            //TODO: xslt30Processor->checkException();
2543
            const char * errStr = xslt30Processor->getErrorMessage(0);
2544
            if(errStr != nullptr) {
2545
                const char * errorCode = xslt30Processor->getErrorCode(0);
2546
                if(errorCode!=nullptr) {
2547
                    // TODO: throw exception
2548
                }
2549
            }
2550
        }
2551
    }
2552
}
2553

    
2554

    
2555

    
2556
PHP_METHOD(Xslt30Processor, transformToString)
2557
{
2558
    Xslt30Processor *xslt30Processor;
2559

    
2560
    if (ZEND_NUM_ARGS()>1) {
2561
        WRONG_PARAM_COUNT;
2562
    }
2563

    
2564

    
2565
    zval* oth;
2566
   
2567

    
2568
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2569
        RETURN_NULL();
2570
    }
2571

    
2572

    
2573
    zend_object* pobj = Z_OBJ_P(getThis());
2574
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2575
    xslt30Processor = obj->xslt30Processor;
2576
    if (xslt30Processor != nullptr) {
2577

    
2578

    
2579
     if(ZEND_NUM_ARGS() == 0) {
2580
        const char * result = xslt30Processor->transformToString();
2581
        if(result != nullptr) {
2582
            _RETURN_STRING(result);
2583
            return;
2584

    
2585
        }
2586

    
2587

    
2588
     } else {
2589
        if(!oth) {
2590
            php_error(E_WARNING, "Error setting source value");
2591
            return;
2592
        }
2593

    
2594
            if(Z_TYPE_P(oth) ==IS_NULL){
2595
                    php_error(E_WARNING, "Error setting source value");
2596
                    return;
2597
            }
2598

    
2599
        const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2600
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2601
                zend_object * nobj = Z_OBJ_P(oth);
2602

    
2603
                xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2604
            if(ooth != nullptr) {
2605
                XdmNode * value = ooth->xdmNode;
2606
                if(value != nullptr) {
2607
                        const char * result = xslt30Processor->transformToString(value);
2608
                    if(result != nullptr) {
2609
                        _RETURN_STRING(result);
2610
                    }
2611
                }
2612

    
2613
            }
2614
        }
2615
     }
2616
    }
2617

    
2618
    RETURN_NULL();
2619
}
2620

    
2621
PHP_METHOD(Xslt30Processor, transformToValue)
2622
{
2623
    Xslt30Processor *xslt30Processor;
2624

    
2625
    if (ZEND_NUM_ARGS()>1) {
2626
        WRONG_PARAM_COUNT;
2627
    }
2628

    
2629

    
2630
    zval* oth;
2631
   
2632

    
2633
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2634
        RETURN_NULL();
2635
    }
2636

    
2637
    zend_object* pobj = Z_OBJ_P(getThis());
2638
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2639
    xslt30Processor = obj->xslt30Processor;
2640

    
2641
    if (xslt30Processor != nullptr) {
2642
      if(!oth) {
2643
        php_error(E_WARNING, "Error setting source value");
2644
        return;
2645
      } else {
2646
        XdmValue * node = nullptr;
2647
        if(ZEND_NUM_ARGS() == 0) {
2648
            XdmValue * node = xslt30Processor->transformToValue();
2649

    
2650
        } else {
2651

    
2652
            if(Z_TYPE_P(oth) == IS_NULL){
2653
                php_error(E_WARNING, "Error setting source value");
2654
                return;
2655
            }
2656

    
2657
            const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2658

    
2659
            if(strcmp(objName,"Saxon\\XdmNode")==0) {
2660
                zend_object *nobj = Z_OBJ_P(oth);
2661

    
2662
                xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
2663
                                           XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2664
                if(ooth != nullptr) {
2665
                    XdmNode *value = ooth->xdmNode;
2666
                    if(value != nullptr) {
2667
                        node = xslt30Processor->transformToValue(value);
2668
                    }
2669
                }
2670
            }
2671
        }
2672
        if(node != nullptr) {
2673
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2674
                RETURN_NULL();
2675
            } else {
2676
                zend_object *vvobj =  Z_OBJ_P(return_value);
2677
                        xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2678
                        assert (vobj != nullptr);
2679
                        vobj->xdmValue = node;
2680
                        return;
2681
            }
2682
        }
2683
      }
2684

    
2685

    
2686

    
2687
    } else {
2688
        RETURN_NULL();
2689
    }
2690
}
2691

    
2692
PHP_METHOD(Xslt30Processor, transformToFile)
2693
{
2694
    Xslt30Processor *xslt30Processor;
2695

    
2696
    if (ZEND_NUM_ARGS()>1) {
2697
        WRONG_PARAM_COUNT;
2698
    }
2699

    
2700

    
2701
    zval* oth;
2702
   
2703

    
2704
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2705
        RETURN_NULL();
2706
    }
2707

    
2708
    zend_object* pobj = Z_OBJ_P(getThis());
2709
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2710
    xslt30Processor = obj->xslt30Processor;
2711

    
2712
    if (xslt30Processor != nullptr) {
2713
      if(!oth) {
2714
        php_error(E_WARNING, "Error setting source value");
2715
        return;
2716
      } else {
2717
        if(ZEND_NUM_ARGS() == 0) {
2718
            xslt30Processor->transformToFile();
2719
        } else {
2720
            if(Z_TYPE_P(oth) == mIS_NULL){
2721
                php_error(E_WARNING,"Error setting source value");
2722
                return;
2723
            }
2724

    
2725
            const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2726

    
2727
            if(strcmp(objName,"Saxon\\XdmNode")==0) {
2728
                zend_object *nobj = Z_OBJ_P(oth);
2729

    
2730
                xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
2731
                                           XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2732
                if(ooth != nullptr) {
2733
                    XdmNode *value = ooth->xdmNode;
2734
                    if(value != nullptr) {
2735
                        xslt30Processor->transformToFile(value);
2736
                    }
2737
                }
2738
            }
2739

    
2740
        }
2741
      }
2742
    }
2743
}
2744

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

    
2761

    
2762
PHP_METHOD(Xslt30Processor, compileFromAssociatedFile)
2763
{
2764
    Xslt30Processor *xslt30Processor;
2765
    char * name = nullptr;
2766
    size_t len1;
2767
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2768
        RETURN_NULL();
2769
    }
2770
    zend_object* pobj = Z_OBJ_P(getThis());
2771
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2772
    xslt30Processor = obj->xslt30Processor;
2773
    if (xslt30Processor != nullptr) {
2774
        xslt30Processor->compileFromAssociatedFile(name);
2775
    }
2776
}
2777

    
2778

    
2779
PHP_METHOD(Xslt30Processor, compileFromString)
2780
{
2781
    Xslt30Processor *xslt30Processor;
2782
    char * stylesheetStr;
2783
    size_t len1, myint;
2784
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
2785
        RETURN_NULL();
2786
    }
2787
    zend_object* pobj = Z_OBJ_P(getThis());
2788
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2789
    xslt30Processor = obj->xslt30Processor;
2790
    if (xslt30Processor != nullptr) {
2791
        xslt30Processor->compileFromString(stylesheetStr);
2792
    }
2793
}
2794

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

    
2812
PHP_METHOD(Xslt30Processor, compileFromFileAndSave)
2813
{
2814
    Xslt30Processor *xslt30Processor;
2815
    char * stylesheetFilename = nullptr;
2816
    char * filename = nullptr;
2817
    size_t len1, len2, myint;
2818
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
2819
        RETURN_NULL();
2820
    }
2821
    zend_object* pobj = Z_OBJ_P(getThis());
2822
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2823
    xslt30Processor = obj->xslt30Processor;
2824
    if (xslt30Processor != nullptr) {
2825
        xslt30Processor->compileFromStringAndSave(stylesheetFilename, filename);
2826
    }
2827
}
2828

    
2829

    
2830

    
2831
PHP_METHOD(Xslt30Processor, compileFromValue)
2832
{
2833
    Xslt30Processor *xslt30Processor;
2834
   zval* oth;
2835

    
2836
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
2837
        RETURN_NULL();
2838
    }
2839
    zend_object* pobj = Z_OBJ_P(getThis());
2840
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2841
    xslt30Processor = obj->xslt30Processor;
2842
    if (xslt30Processor != nullptr) {
2843
        zend_object* vvobj = Z_OBJ_P(oth);
2844
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2845
        if(ooth != nullptr) {
2846
            XdmValue * value = ooth->xdmValue;
2847
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
2848
                xslt30Processor->compileFromXdmNode((XdmNode*)(value->getHead()));
2849
            }
2850
        }
2851
    }
2852
}
2853

    
2854

    
2855

    
2856
PHP_METHOD(Xslt30Processor, setResultAsRawValue)
2857
{
2858
    Xslt30Processor *xslt30Processor;
2859
    bool raw = false;
2860

    
2861
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &raw) == 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->setResultAsRawValue(raw);
2870
    }
2871

    
2872
}
2873

    
2874

    
2875

    
2876
PHP_METHOD(Xslt30Processor, setJustInTimeCompilation)
2877
{
2878
    Xslt30Processor *xslt30Processor;
2879
    bool jit = false;
2880
    size_t len1;
2881

    
2882
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
2883
        RETURN_NULL();
2884
    }
2885

    
2886
    zend_object* pobj = Z_OBJ_P(getThis());
2887
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2888
    xslt30Processor = obj->xslt30Processor;
2889
    if (xslt30Processor != nullptr) {
2890
         xslt30Processor->setJustInTimeCompilation(jit);
2891
    }
2892
}
2893

    
2894
PHP_METHOD(Xslt30Processor, setOutputFile)
2895
{
2896
    Xslt30Processor *xslt30Processor;
2897
    char * outputFilename = nullptr;
2898
    size_t len1;
2899

    
2900
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
2901
        RETURN_NULL();
2902
    }
2903

    
2904
    zend_object* pobj = Z_OBJ_P(getThis());
2905
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2906
    xslt30Processor = obj->xslt30Processor;
2907
    if (xslt30Processor != nullptr && outputFilename != nullptr) {
2908

    
2909
         xslt30Processor->setOutputFile(outputFilename);
2910

    
2911

    
2912
    }
2913
}
2914

    
2915

    
2916

    
2917

    
2918
PHP_METHOD(Xslt30Processor, setProperty)
2919
{
2920
    Xslt30Processor *xslt30Processor;
2921
    char * name = nullptr;
2922
    char * value;
2923
    size_t len1, len2, myint;
2924

    
2925
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
2926
        RETURN_NULL();
2927
    }
2928
    zend_object* pobj = Z_OBJ_P(getThis());
2929
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2930
    xslt30Processor = obj->xslt30Processor;
2931
    if (xslt30Processor != nullptr) {
2932
        xslt30Processor->setProperty(name, value);
2933
    }
2934
}
2935

    
2936
PHP_METHOD(Xslt30Processor, setParameter)
2937
{
2938

    
2939
   Xslt30Processor *xslt30Processor;
2940
   char * name;
2941
   zval* oth;
2942
   size_t len1, len2, myint;
2943
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
2944
        RETURN_NULL();
2945
    }
2946
    zend_object* pobj = Z_OBJ_P(getThis());
2947
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2948
    xslt30Processor = obj->xslt30Processor;
2949
    if (xslt30Processor != nullptr) {
2950
        if(Z_TYPE_P(oth) ==IS_NULL){
2951
                php_error(E_WARNING, "Error setting source value - value is nullptr");
2952
                return;
2953
        }
2954

    
2955
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2956
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2957

    
2958
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2959
        zend_object* ooth = Z_OBJ_P(oth);
2960
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
2961
        if(nobj != nullptr) {
2962
            XdmNode * value = nobj->xdmNode;
2963
            if(value != nullptr) {
2964
                xslt30Processor->setParameter(name, (XdmValue *)value);
2965

    
2966
            }
2967
        }
2968
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2969
        zend_object* ooth = Z_OBJ_P(oth);
2970
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2971
        if(vobj != nullptr) {
2972
            XdmValue * value = vobj->xdmValue;
2973
            if(value != nullptr) {
2974

    
2975
                xslt30Processor->setParameter(name, value);
2976
            }
2977
        }
2978

    
2979

    
2980

    
2981
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2982
        zend_object* ooth = Z_OBJ_P(oth);
2983
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
2984
        if(aobj != nullptr) {
2985
            XdmAtomicValue * value = aobj->xdmAtomicValue;
2986
            if(value != nullptr) {
2987
                xslt30Processor->setParameter(name, (XdmValue *)value);
2988
            }
2989
        }
2990

    
2991

    
2992

    
2993
      }
2994

    
2995
    }
2996
}
2997

    
2998
PHP_METHOD(Xslt30Processor, clearParameters)
2999
{
3000
    Xslt30Processor *xslt30Processor;
3001
    if (ZEND_NUM_ARGS()>0) {
3002
        WRONG_PARAM_COUNT;
3003
    }
3004

    
3005
    zend_object* pobj = Z_OBJ_P(getThis());
3006
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3007
    xslt30Processor = obj->xslt30Processor;
3008
    if (xslt30Processor != nullptr) {
3009
        xslt30Processor->clearParameters(true);
3010
    }
3011
}
3012

    
3013
PHP_METHOD(Xslt30Processor, clearProperties)
3014
{
3015
    Xslt30Processor *xslt30Processor;
3016
    if (ZEND_NUM_ARGS()>0) {
3017
        WRONG_PARAM_COUNT;
3018
    }
3019

    
3020
    zend_object* pobj = Z_OBJ_P(getThis());
3021
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3022
    xslt30Processor = obj->xslt30Processor;
3023
    if (xslt30Processor != nullptr) {
3024
        xslt30Processor->clearProperties();
3025
    }
3026
}
3027

    
3028

    
3029
PHP_METHOD(Xslt30Processor, setupXslMessage)
3030
{
3031
    Xslt30Processor *xslt30Processor;
3032
    bool show = false;
3033
    char * filename = nullptr;
3034
    size_t len1;
3035
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename &len1) == FAILURE) {
3036
        RETURN_NULL();
3037
    }
3038

    
3039
    zend_object* pobj = Z_OBJ_P(getThis());
3040
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3041
    xslt30Processor = obj->xslt30Processor;
3042

    
3043
    if (xslt30Processor != nullptr) {
3044

    
3045
            xslt30Processor->setupXslMessage(show, filename);
3046
        }
3047

    
3048
}
3049

    
3050

    
3051

    
3052
PHP_METHOD(Xslt30Processor, exceptionOccurred)
3053
{
3054
    Xslt30Processor *xslt30Processor;
3055
    zend_object* pobj = Z_OBJ_P(getThis());
3056
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3057
    if (ZEND_NUM_ARGS()>0) {
3058
        WRONG_PARAM_COUNT;
3059
    }
3060

    
3061
    xslt30Processor = obj->xslt30Processor;
3062
    if (xslt30Processor != nullptr) {
3063
        bool result = xslt30Processor->exceptionOccurred();
3064
        RETURN_BOOL(result);
3065
    }
3066
    RETURN_BOOL(false);
3067
}
3068

    
3069
PHP_METHOD(Xslt30Processor, getExceptionCount)
3070
{
3071
    Xslt30Processor *xslt30Processor;
3072
    zend_object* pobj = Z_OBJ_P(getThis());
3073
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3074
    if (ZEND_NUM_ARGS()>0) {
3075
        WRONG_PARAM_COUNT;
3076
    }
3077

    
3078
    xslt30Processor = obj->xslt30Processor;
3079
    if (xslt30Processor != nullptr) {
3080
        int count = xslt30Processor->exceptionCount();
3081
        RETURN_LONG(count);
3082
    }
3083
    RETURN_LONG(0);
3084
}
3085

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

    
3106
PHP_METHOD(Xslt30Processor, getErrorMessage)
3107
{
3108
    Xslt30Processor *xslt30Processor;
3109
    long index;
3110
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3111
        RETURN_NULL();
3112
    }
3113
    zend_object* pobj = Z_OBJ_P(getThis());
3114
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3115
    xslt30Processor = obj->xslt30Processor;
3116
    if (xslt30Processor != nullptr) {
3117
        const char * errStr = xslt30Processor->getErrorMessage((int)index);
3118
        if(errStr != nullptr) {
3119
            //char *str = estrdup(errStr);
3120
            _RETURN_STRING(errStr);
3121
        }
3122
    }
3123
    RETURN_NULL();
3124
}
3125
PHP_METHOD(Xslt30Processor, exceptionClear)
3126
{
3127
    Xslt30Processor *xslt30Processor;
3128
    zend_object* pobj = Z_OBJ_P(getThis());
3129
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3130
    xslt30Processor = obj->xslt30Processor;
3131
    if (xslt30Processor != nullptr) {
3132
        xslt30Processor->exceptionClear();
3133
    }
3134
}
3135

    
3136
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
3137

    
3138
void xqueryProcessor_free_storage(zend_object *object)
3139
{
3140
    zend_object_std_dtor(object);
3141
}
3142

    
3143
void xqueryProcessor_destroy_storage(zend_object *object)
3144
{
3145
    zend_objects_destroy_object(object);
3146
}
3147

    
3148
zend_object *xqueryProcessor_create_handler(zend_class_entry *type)
3149
{
3150

    
3151
    xqueryProcessor_object *obj = (xqueryProcessor_object *)ecalloc(1, sizeof(xqueryProcessor_object)+ zend_object_properties_size(type));
3152
    zend_object_std_init(&obj->std, type); 
3153
    object_properties_init(&obj->std, type);
3154
    obj->std.handlers = &xqueryProcessor_object_handlers;
3155

    
3156
    return &obj->std;
3157
}
3158

    
3159
PHP_METHOD(XQueryProcessor, __destruct)
3160
{
3161
    zend_object* pobj = Z_OBJ_P(getThis());
3162
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3163
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
3164
    if(xqueryProcessor != nullptr){
3165
            delete xqueryProcessor;
3166
    }
3167
}
3168

    
3169

    
3170
PHP_METHOD(XQueryProcessor, runQueryToValue)
3171
{
3172
    XQueryProcessor *xqueryProcessor;
3173
    zend_object* pobj = Z_OBJ_P(getThis()); 
3174
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3175

    
3176
    if (ZEND_NUM_ARGS()>0) {
3177
        WRONG_PARAM_COUNT;
3178
    }
3179

    
3180
    xqueryProcessor = obj->xqueryProcessor;
3181

    
3182
    if (xqueryProcessor != nullptr) {
3183
        XdmValue * node = xqueryProcessor->runQueryToValue();
3184
        if(node != nullptr) {
3185
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
3186
                RETURN_NULL();
3187
                return;
3188
            } else {
3189
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
3190
                zend_object *vvobj =  Z_OBJ_P(return_value);
3191
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3192
                assert (vobj != nullptr);
3193
                vobj->xdmValue = node;
3194
                return;
3195
            }
3196
        }
3197
        xqueryProcessor->checkException();//TODO
3198
    } else {
3199
        RETURN_NULL();
3200
    }
3201
}
3202

    
3203
PHP_METHOD(XQueryProcessor, runQueryToString)
3204
{
3205
    XQueryProcessor *xqueryProcessor;
3206
   
3207

    
3208
    if (ZEND_NUM_ARGS()>0) {
3209
        WRONG_PARAM_COUNT;
3210
    }
3211
    zend_object* pobj = Z_OBJ_P(getThis()); 
3212
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3213
    xqueryProcessor = obj->xqueryProcessor;
3214

    
3215
    if (xqueryProcessor != nullptr) {
3216
        const char * result = xqueryProcessor->runQueryToString();
3217
        if(result != nullptr) {
3218
            //char *str = estrdup(result);
3219
            _RETURN_STRING(result);
3220
            return;
3221
        } else {
3222
          xqueryProcessor->checkException(); //TODO
3223
        }
3224
    }
3225
   RETURN_NULL();
3226
}
3227

    
3228
PHP_METHOD(XQueryProcessor, runQueryToFile)
3229
{
3230

    
3231
     char * ofilename;
3232
    size_t len1 =0;
3233
    if (ZEND_NUM_ARGS()!= 1) {
3234
        WRONG_PARAM_COUNT;
3235
    }
3236
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &ofilename, &len1) == FAILURE) {
3237
        RETURN_NULL();
3238
    }
3239
    XQueryProcessor *xqueryProcessor;
3240
    zend_object* pobj = Z_OBJ_P(getThis()); 
3241
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3242

    
3243

    
3244

    
3245
    xqueryProcessor = obj->xqueryProcessor;
3246

    
3247
    if (xqueryProcessor != nullptr) {
3248
        if(ofilename != nullptr) {
3249
                xqueryProcessor->setOutputFile(ofilename);        
3250
        }
3251
        xqueryProcessor->runQueryToFile(); 
3252
    }
3253

    
3254
}
3255

    
3256
PHP_METHOD(XQueryProcessor, setQueryContent)
3257
{
3258
    char * queryStr;
3259
    size_t len1;
3260

    
3261
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &queryStr, &len1) == FAILURE) {
3262
        RETURN_NULL();
3263
    }
3264
    zend_object* pobj = Z_OBJ_P(getThis()); 
3265
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std)); 
3266
    if(queryStr != nullptr) {
3267
      obj->xqueryProcessor->setProperty("qs", queryStr);
3268
   }
3269
}
3270

    
3271
PHP_METHOD(XQueryProcessor, setQueryFile)
3272
{
3273
   char * fileName;
3274
   size_t len1;
3275
    XQueryProcessor *xqueryProcessor;
3276

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

    
3289
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
3290
{
3291
   char * base;
3292
   size_t len1;
3293
    XQueryProcessor *xqueryProcessor;
3294

    
3295
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &base, &len1) == FAILURE) {
3296
        RETURN_NULL();
3297
    }
3298
    if(base != nullptr) {
3299
            zend_object* pobj = Z_OBJ_P(getThis()); 
3300
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3301
            xqueryProcessor = obj->xqueryProcessor;
3302
            xqueryProcessor->setQueryBaseURI(base);
3303
    }
3304
            
3305
}
3306

    
3307
PHP_METHOD(XQueryProcessor, declareNamespace)
3308
{
3309
   char * prefix;
3310
   char * ns;
3311
   size_t len1, len2;
3312
    XQueryProcessor *xqueryProcessor;
3313

    
3314
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
3315
        RETURN_NULL();
3316
    }
3317
    if(prefix != nullptr && ns != 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
            xqueryProcessor->declareNamespace(prefix, ns);
3322
    }
3323
            
3324
}
3325

    
3326

    
3327

    
3328
PHP_METHOD(XQueryProcessor, setContextItem)
3329
{
3330
   char * context;
3331
   int len1;
3332
   zval* oth;
3333
    XQueryProcessor *xqueryProcessor;
3334

    
3335
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &oth) == FAILURE) {
3336
        RETURN_NULL();
3337
    }
3338
    if(oth != nullptr) {
3339
            zend_object* pobj = Z_OBJ_P(getThis()); 
3340
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3341
            xqueryProcessor = obj->xqueryProcessor;
3342
    const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name); 
3343
        
3344
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3345
        zend_object *vvobj =  Z_OBJ_P(oth);
3346
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3347
        //xdmNode_object* ooth = (xdmNode_object*)Z_OBJ_P(oth TSRMLS_CC);
3348
        if(ooth != nullptr) {
3349
            XdmNode * value = ooth->xdmNode;
3350
            if(value != nullptr) {
3351
                xqueryProcessor->setContextItem((XdmItem *)value);
3352
               
3353
                return;
3354
            }
3355
        }
3356
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
3357
        zend_object *vvobj =  Z_OBJ_P(oth);
3358
        xdmItem_object* ooth  = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
3359
        if(ooth != nullptr) {
3360
            XdmItem * value = ooth->xdmItem;
3361
            if(value != nullptr) {
3362
                xqueryProcessor->setContextItem(value);
3363
               
3364
                return;
3365
            }
3366
         }
3367
        
3368

    
3369

    
3370

    
3371
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3372
        zend_object *vvobj =  Z_OBJ_P(oth);
3373
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3374
        if(ooth != nullptr) {
3375
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3376
            if(value != nullptr) {
3377
                
3378
                xqueryProcessor->setContextItem((XdmItem *)value);
3379
      
3380
                return;
3381
            }
3382
        }
3383

    
3384

    
3385

    
3386
      } 
3387

    
3388

    
3389
    }
3390
        //throw exception
3391
        
3392
            
3393
}
3394

    
3395
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
3396
{
3397
   char * cfilename;
3398
   size_t len1;
3399
    XQueryProcessor *xqueryProcessor;
3400

    
3401
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &cfilename, &len1) == FAILURE) {
3402
        RETURN_NULL();
3403
    }
3404
    if(cfilename != nullptr) {
3405
             zend_object* pobj = Z_OBJ_P(getThis()); 
3406
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3407
            xqueryProcessor = obj->xqueryProcessor;
3408
            xqueryProcessor->setContextItemFromFile(cfilename);
3409
    }
3410
            
3411
}
3412

    
3413

    
3414
PHP_METHOD(XQueryProcessor, setProperty)
3415
{
3416
    XQueryProcessor *xqueryProcessor;
3417
    char * name;
3418
    char * value;
3419
    size_t len1, len2, myint;
3420

    
3421
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
3422
        RETURN_NULL();
3423
    }
3424
    zend_object* pobj = Z_OBJ_P(getThis()); 
3425
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3426
    xqueryProcessor = obj->xqueryProcessor;
3427
    if (xqueryProcessor != nullptr) {
3428
        xqueryProcessor->setProperty(name, value);
3429
    }
3430
}
3431

    
3432
PHP_METHOD(XQueryProcessor, setParameter)
3433
{
3434

    
3435
   XQueryProcessor *xqueryProcessor;
3436
   char * name;
3437
   zval* oth;
3438
   size_t len1, len2, myint;        
3439
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
3440
        RETURN_NULL();
3441
    }
3442
    zend_object* pobj = Z_OBJ_P(getThis()); 
3443
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3444
    xqueryProcessor = obj->xqueryProcessor;
3445
    if (xqueryProcessor != nullptr) {
3446
        if(Z_TYPE_P(oth) ==IS_NULL){
3447
                php_error(E_WARNING, "Error setting source value - value is nullptr");
3448
                return;
3449
        }
3450
             const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
3451
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3452
//Z_ADDREF_P(oth);
3453
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3454
        zend_object *vvobj =  Z_OBJ_P(oth);
3455
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3456
        if(ooth != nullptr) {
3457
            XdmNode * value = ooth->xdmNode;
3458
            if(value != nullptr) {
3459
                xqueryProcessor->setParameter(name, (XdmValue *)value);
3460

    
3461
            }
3462
        }
3463
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
3464
        zend_object *vvobj =  Z_OBJ_P(oth);
3465
        xdmValue_object* ooth  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3466
        if(ooth != nullptr) {
3467
            XdmValue * value = ooth->xdmValue;
3468
            if(value != nullptr) {
3469
                
3470
                xqueryProcessor->setParameter(name, value);
3471
            }
3472
        }
3473

    
3474

    
3475

    
3476
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3477
        zend_object *vvobj =  Z_OBJ_P(oth);
3478
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3479
        if(ooth != nullptr) {
3480
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3481
            if(value != nullptr) {
3482
                
3483
                xqueryProcessor->setParameter(name, (XdmValue *)value);
3484
            } 
3485
        }
3486

    
3487

    
3488

    
3489
      }
3490

    
3491
    }
3492
}
3493

    
3494

    
3495

    
3496

    
3497
PHP_METHOD(XQueryProcessor, clearParameters)
3498
{
3499
    XQueryProcessor *xqueryProcessor;
3500
    if (ZEND_NUM_ARGS()>0) {
3501
        WRONG_PARAM_COUNT;
3502
    }
3503

    
3504
    zend_object* pobj = Z_OBJ_P(getThis()); 
3505
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3506
    xqueryProcessor = obj->xqueryProcessor;
3507
    if (xqueryProcessor != nullptr) {
3508
        xqueryProcessor->clearParameters(true);
3509
    }
3510
}
3511

    
3512
PHP_METHOD(XQueryProcessor, clearProperties)
3513
{
3514
    XQueryProcessor *xqueryProcessor;
3515

    
3516
    if (ZEND_NUM_ARGS()>0) {
3517
        WRONG_PARAM_COUNT;
3518
    }
3519

    
3520
    zend_object* pobj = Z_OBJ_P(getThis()); 
3521
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3522
    xqueryProcessor = obj->xqueryProcessor;
3523
    if (xqueryProcessor != nullptr) {
3524
        xqueryProcessor->clearProperties();
3525
    }
3526
}
3527

    
3528
PHP_METHOD(XQueryProcessor, exceptionOccurred)
3529
{
3530
    XQueryProcessor *xqueryProcessor;
3531
    zend_object* pobj = Z_OBJ_P(getThis()); 
3532
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3533
    if (ZEND_NUM_ARGS()>0) {
3534
        WRONG_PARAM_COUNT;
3535
    }
3536

    
3537
    xqueryProcessor = obj->xqueryProcessor;
3538
    if (xqueryProcessor != nullptr) {
3539
        bool result = xqueryProcessor->exceptionOccurred();
3540
        RETURN_BOOL(result);
3541
    }
3542
    RETURN_BOOL(false);
3543
}
3544

    
3545
PHP_METHOD(XQueryProcessor, getExceptionCount)
3546
{
3547
    XQueryProcessor *xqueryProcessor;
3548
     zend_object* pobj = Z_OBJ_P(getThis()); 
3549
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3550
    if (ZEND_NUM_ARGS()>0) {
3551
        WRONG_PARAM_COUNT;
3552
    }
3553

    
3554
    xqueryProcessor = obj->xqueryProcessor;
3555
    if (xqueryProcessor != nullptr) {
3556
        int count = xqueryProcessor->exceptionCount();
3557
        RETURN_LONG(count);
3558
    }
3559
    RETURN_LONG(0);
3560
}
3561

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

    
3582
PHP_METHOD(XQueryProcessor, getErrorMessage)
3583
{
3584
    XQueryProcessor *xqueryProcessor;
3585
    long index;
3586
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3587
        RETURN_NULL();
3588
    }
3589
    zend_object* pobj = Z_OBJ_P(getThis()); 
3590
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3591
    xqueryProcessor = obj->xqueryProcessor;
3592
    if (xqueryProcessor != nullptr) {
3593
        const char * errStr = xqueryProcessor->getErrorMessage((int)index);
3594
        if(errStr != nullptr) {
3595
            //char *str = estrdup(errStr);
3596
            _RETURN_STRING(errStr);
3597
        }
3598
    }
3599
    RETURN_NULL();
3600
}
3601
PHP_METHOD(XQueryProcessor, exceptionClear)
3602
{
3603
    XQueryProcessor *xqueryProcessor;
3604
    zend_object* pobj = Z_OBJ_P(getThis()); 
3605
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3606
    xqueryProcessor = obj->xqueryProcessor;
3607
    if (xqueryProcessor != nullptr) {
3608
        xqueryProcessor->exceptionClear();
3609
    }
3610
}
3611

    
3612
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
3613

    
3614
void xpathProcessor_free_storage(zend_object *object)
3615
{
3616
    zend_object_std_dtor(object);
3617
}
3618

    
3619
void xpathProcessor_destroy_storage(zend_object *object)
3620
{
3621
    zend_objects_destroy_object(object);
3622
}
3623

    
3624
PHP_METHOD(XPathProcessor, __destruct)
3625
{
3626

    
3627
   zend_object* pobj = Z_OBJ_P(getThis()); 
3628
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3629

    
3630

    
3631
   XPathProcessor * xpathProc= obj->xpathProcessor;
3632
    if(xpathProc != nullptr){
3633
            delete xpathProc;
3634
     }
3635

    
3636
   
3637
    
3638
}
3639

    
3640
zend_object *xpathProcessor_create_handler(zend_class_entry *type)
3641
{
3642
    xpathProcessor_object *obj = (xpathProcessor_object *)ecalloc(1, sizeof(xpathProcessor_object)+ zend_object_properties_size(type));
3643
    
3644
    zend_object_std_init(&obj->std, type); 
3645
    
3646
    object_properties_init(&obj->std, type);
3647
    
3648
    obj->std.handlers = &xpathProcessor_object_handlers;
3649

    
3650
    return &obj->std;
3651
}
3652

    
3653

    
3654

    
3655
PHP_METHOD(XPathProcessor, setProperty)
3656
{
3657
    XPathProcessor *xpathProcessor;
3658
    char * name;
3659
    char * value;
3660
    size_t len1, len2;
3661

    
3662
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
3663
        RETURN_NULL();
3664
    }
3665
    zend_object* pobj = Z_OBJ_P(getThis()); 
3666
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3667
    xpathProcessor = obj->xpathProcessor;
3668
    if (xpathProcessor != nullptr) {
3669
        xpathProcessor->setProperty(name, value);
3670
    }
3671
}
3672

    
3673
PHP_METHOD(XPathProcessor, setParameter)
3674
{
3675

    
3676
   XPathProcessor *xpathProcessor;
3677
   char * name;
3678
   zval* oth;
3679
   size_t len1, len2;        
3680
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name, &len2, &oth) == FAILURE) {
3681
        RETURN_NULL();
3682
    }
3683
    zend_object* pobj = Z_OBJ_P(getThis()); 
3684
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3685
    xpathProcessor = obj->xpathProcessor;
3686
    if (xpathProcessor != nullptr) {
3687
            const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
3688
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3689

    
3690
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3691
        
3692
        zend_object* vvobj = Z_OBJ_P(oth);
3693
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3694
        if(ooth != nullptr) {
3695
            XdmNode * value = ooth->xdmNode;
3696
            if(value != nullptr) {
3697
                xpathProcessor->setParameter(name, (XdmValue *)value);
3698

    
3699
            }
3700
        }
3701
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
3702
        
3703
        zend_object* vvobj = Z_OBJ_P(oth);
3704
        xdmValue_object * ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3705
        if(ooth != nullptr) {
3706
            XdmValue * value = ooth->xdmValue;
3707
            if(value != nullptr) {
3708
                
3709
                xpathProcessor->setParameter(name, value);
3710
            }
3711
        }
3712

    
3713

    
3714

    
3715
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3716
        
3717
        zend_object* vvobj = Z_OBJ_P(oth);
3718
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3719
        if(ooth != nullptr) {
3720
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3721
            if(value != nullptr) {
3722
                
3723
                xpathProcessor->setParameter(name, (XdmValue *)value);
3724
            }
3725
        }
3726

    
3727

    
3728

    
3729
      }
3730

    
3731
    }
3732
}
3733

    
3734
PHP_METHOD(XPathProcessor, declareNamespace)
3735
{
3736
   char * prefix;
3737
   char * ns;
3738
   int len1, len2;
3739
   XPathProcessor *xpathProcessor;
3740

    
3741
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
3742
        RETURN_NULL();
3743
    }
3744
    if(prefix != nullptr && ns != nullptr) {
3745
            zend_object* pobj = Z_OBJ_P(getThis()); 
3746
        xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3747
            xpathProcessor = obj->xpathProcessor;
3748
            xpathProcessor->declareNamespace(prefix, ns);
3749
    }
3750
            
3751
}
3752

    
3753

    
3754

    
3755
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
3756

    
3757
    XPathProcessor *xpathProcessor;
3758
    bool allow = false;
3759
    size_t len1;
3760

    
3761
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &allow) == FAILURE) {
3762
        RETURN_NULL();
3763
    }
3764

    
3765
    zend_object* pobj = Z_OBJ_P(getThis());
3766
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3767
    xpathProcessor = obj->xpathProcessor;
3768
    if (xpathProcessor != nullptr) {
3769
            xpathProcessor->setBackwardsCompatible(allow);
3770
         }
3771
}
3772

    
3773
PHP_METHOD(XPathProcessor, setCaching){
3774
    XPathProcessor *xpathProcessor;
3775
    bool isCaching = false;
3776
    size_t len1;
3777

    
3778
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &isCaching) == FAILURE) {
3779
        RETURN_NULL();
3780
    }
3781

    
3782
    zend_object* pobj = Z_OBJ_P(getThis());
3783
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3784
    xpathProcessor = obj->xpathProcessor;
3785
    if (xpathProcessor != nullptr) {
3786
            xpathProcessor->setCaching(isCaching);
3787
         }
3788
}
3789

    
3790
PHP_METHOD(XPathProcessor, importSchemaNamespace){
3791
      char * name;
3792
      int len1;
3793
      XPathProcessor *xpathProcessor;
3794

    
3795
       if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
3796
           RETURN_NULL();
3797
       }
3798
       if(name != nullptr) {
3799
               zend_object* pobj = Z_OBJ_P(getThis());
3800
           xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3801
               xpathProcessor = obj->xpathProcessor;
3802
               xpathProcessor->importSchemaNamespace(name);
3803
       }
3804
}
3805

    
3806
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
3807
{
3808

    
3809
   XPathProcessor *xpathProcessor;
3810
   char * xpathStr;
3811
   zval* oth;
3812
   size_t len1, myint;        
3813
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &xpathStr, &len1) == FAILURE) {
3814
        RETURN_NULL();
3815
    }
3816
    zend_object* pobj = Z_OBJ_P(getThis()); 
3817
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3818
    xpathProcessor = obj->xpathProcessor;
3819
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
3820
        
3821
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
3822
                RETURN_BOOL(result);
3823
    }
3824
}
3825

    
3826
PHP_METHOD(XPathProcessor, evaluate)
3827
{
3828

    
3829
   XPathProcessor *xpathProcessor;
3830
   char * xpathStr;
3831
   zval* oth;
3832
   size_t len1, myint;        
3833
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
3834
        RETURN_NULL();
3835
    }
3836
    zend_object* pobj = Z_OBJ_P(getThis()); 
3837
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3838
    xpathProcessor = obj->xpathProcessor;
3839
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
3840
        
3841
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
3842
        if(node != nullptr) {
3843
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
3844
                RETURN_NULL();
3845
                return;
3846
            } else {
3847
                zend_object* vvobj = Z_OBJ_P(return_value);
3848
                        
3849
                if(node->getType() == XDM_NODE) {
3850
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3851
                                assert (vobj != nullptr);
3852
                                  vobj->xdmNode = (XdmNode *)node;
3853
                        return;
3854

    
3855
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
3856
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3857
                assert (vobj != nullptr);
3858
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
3859
                return;
3860

    
3861
                } else {
3862
                  xdmValue_object * vobj = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3863
                  assert (vobj != nullptr);
3864
                  vobj->xdmValue = node;
3865
                  return;
3866
                }
3867
            }
3868
        }
3869
        xpathProcessor->checkException();//TODO
3870
    } 
3871
    RETURN_NULL();
3872
    
3873
}
3874

    
3875
PHP_METHOD(XPathProcessor, evaluateSingle)
3876
{
3877

    
3878
   XPathProcessor *xpathProcessor;
3879
   char * xpathStr;
3880
   zval* oth;
3881
   size_t len1, myint;        
3882
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
3883
        RETURN_NULL();
3884
    }
3885
    zend_object* pobj = Z_OBJ_P(getThis()); 
3886
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3887
    xpathProcessor = obj->xpathProcessor;
3888

    
3889
    if(xpathStr == nullptr) {
3890
        RETURN_NULL();
3891
        return;
3892
        }
3893

    
3894

    
3895
    if (xpathProcessor != nullptr) {
3896
        
3897
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
3898
        if(node != nullptr) {
3899
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
3900
                RETURN_NULL();
3901
                return;
3902
            } else {
3903
                //struct xdmItem_object* vobj = (struct xdmItem_object *)Z_OBJ_P(return_value TSRMLS_CC);
3904
                zend_object* vvobj = Z_OBJ_P(return_value);
3905
                if(node->getType() == XDM_NODE) {
3906
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3907
                        assert (vobj != nullptr);
3908
                        vobj->xdmNode = (XdmNode *)node;
3909
                        return;
3910

    
3911
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
3912

    
3913
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3914
                assert (vobj != nullptr);
3915
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
3916
                return;
3917

    
3918
                } else {
3919
                        xdmItem_object * vobj = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
3920
                        assert (vobj != nullptr);
3921
                        vobj->xdmItem = node;
3922
                        return;
3923
                }
3924
            }
3925
        } 
3926
        xpathProcessor->checkException();//TODO
3927
    } 
3928
    RETURN_NULL();
3929
}
3930

    
3931
PHP_METHOD(XPathProcessor, setContextItem)
3932
{
3933

    
3934
   XPathProcessor *xpathProcessor;
3935

    
3936
   zval* oth;
3937
        //TODO this should be relaxed to accept item/atomic/node as well as Value
3938

    
3939
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
3940
        RETURN_NULL();
3941
    }
3942
    zend_object* pobj = Z_OBJ_P(getThis()); 
3943
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3944
    xpathProcessor = obj->xpathProcessor;
3945
    if (xpathProcessor != nullptr) {
3946
        if(!oth) {
3947
                php_error(E_WARNING, "Error setting source value");
3948
                return;
3949
         } 
3950
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
3951
        
3952
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
3953
        zend_object* vvobj = Z_OBJ_P(oth);
3954
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3955
        if(ooth != nullptr) {
3956
            XdmNode * value = ooth->xdmNode;
3957
            if(value != nullptr) {
3958
                xpathProcessor->setContextItem((XdmItem *)value);
3959
                value->incrementRefCount();
3960

    
3961
            }
3962
        }
3963
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3964
        zend_object* vvobj = Z_OBJ_P(oth);
3965
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3966
        if(ooth != nullptr) {
3967
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3968
            if(value != nullptr) {
3969
                
3970
                xpathProcessor->setContextItem((XdmItem *)value);
3971
                value->incrementRefCount();
3972
            }
3973
        }
3974
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
3975
        zend_object* vvobj = Z_OBJ_P(oth);
3976
        xdmItem_object * ooth = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
3977
        if(ooth != nullptr) {
3978
            XdmItem * value = ooth->xdmItem;
3979
            if(value != nullptr) {
3980
                
3981
                xpathProcessor->setContextItem(value);
3982
                value->incrementRefCount();
3983
            }
3984
        }
3985

    
3986
      }
3987
    }
3988
}
3989

    
3990
PHP_METHOD(XPathProcessor, setBaseURI)
3991
{
3992

    
3993
   XPathProcessor *xpathProcessor;
3994

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

    
4014
PHP_METHOD(XPathProcessor, setContextFile)
4015
{
4016

    
4017
   XPathProcessor *xpathProcessor;
4018

    
4019
   char * name;
4020
   size_t len1;
4021
        
4022
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4023
        RETURN_NULL();
4024
    }
4025
    zend_object* pobj = Z_OBJ_P(getThis()); 
4026
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4027
    xpathProcessor = obj->xpathProcessor;
4028
    if (xpathProcessor != nullptr) {
4029
        
4030
        if(name != nullptr) {
4031
           
4032
                xpathProcessor->setContextFile(name);
4033
            
4034
        }
4035
    }
4036
}
4037

    
4038
PHP_METHOD(XPathProcessor, clearParameters)
4039
{
4040
    XPathProcessor *xpathProcessor;
4041
    if (ZEND_NUM_ARGS()>0) {
4042
        WRONG_PARAM_COUNT;
4043
    }
4044

    
4045
    zend_object* pobj = Z_OBJ_P(getThis()); 
4046
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4047
    xpathProcessor = obj->xpathProcessor;
4048
    if (xpathProcessor != nullptr) {
4049
        xpathProcessor->clearParameters(true);
4050
    }
4051
}
4052

    
4053
PHP_METHOD(XPathProcessor, clearProperties)
4054
{
4055
     XPathProcessor *xpathProcessor;
4056
    if (ZEND_NUM_ARGS()>0) {
4057
        WRONG_PARAM_COUNT;
4058
    }
4059

    
4060
    zend_object* pobj = Z_OBJ_P(getThis()); 
4061
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4062
    xpathProcessor = obj->xpathProcessor;
4063
    if (xpathProcessor != nullptr) {
4064
        xpathProcessor->clearProperties();
4065
    }
4066
}
4067

    
4068

    
4069
PHP_METHOD(XPathProcessor, exceptionOccurred)
4070
{
4071
   XPathProcessor *xpathProcessor;
4072
    zend_object* pobj = Z_OBJ_P(getThis()); 
4073
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4074
    if (ZEND_NUM_ARGS()>0) {
4075
        WRONG_PARAM_COUNT;
4076
    }
4077

    
4078
    xpathProcessor = obj->xpathProcessor;
4079
    if (xpathProcessor != nullptr) {
4080
        bool result = xpathProcessor->exceptionOccurred();
4081
        RETURN_BOOL(result);
4082
    }
4083
    RETURN_BOOL(false);
4084
}
4085

    
4086
PHP_METHOD(XPathProcessor, getExceptionCount)
4087
{
4088
    XPathProcessor *xpathProcessor;
4089
   zend_object* pobj = Z_OBJ_P(getThis()); 
4090
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4091
    if (ZEND_NUM_ARGS()>0) {
4092
        WRONG_PARAM_COUNT;
4093
    }
4094

    
4095
    xpathProcessor = obj->xpathProcessor;
4096
    if (xpathProcessor != nullptr) {
4097
        int count = xpathProcessor->exceptionCount();
4098
        RETURN_LONG(count);
4099
    }
4100
    RETURN_LONG(0);
4101
}
4102

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

    
4123
PHP_METHOD(XPathProcessor, getErrorMessage)
4124
{
4125
    XPathProcessor *xpathProcessor;
4126
    long index;
4127
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
4128
        RETURN_NULL();
4129
    }
4130
    zend_object* pobj = Z_OBJ_P(getThis()); 
4131
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4132
    xpathProcessor = obj->xpathProcessor;
4133
    if (xpathProcessor != nullptr) {
4134
        const char * errStr = xpathProcessor->getErrorMessage((int)index);
4135
        if(errStr != nullptr) {
4136
            //char *str = estrdup(errStr);
4137
            _RETURN_STRING(errStr);
4138
        }
4139
    }
4140
    RETURN_NULL();
4141
}
4142
PHP_METHOD(XPathProcessor, exceptionClear)
4143
{
4144
    XPathProcessor *xpathProcessor;
4145
    zend_object* pobj = Z_OBJ_P(getThis()); 
4146
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4147
    xpathProcessor = obj->xpathProcessor;
4148
    if (xpathProcessor != nullptr) {
4149
        xpathProcessor->exceptionClear();
4150
    }
4151
}
4152

    
4153
/*     ============== PHP Interface of   SchemaValidator =============== */
4154

    
4155
void schemaValidator_free_storage(zend_object *object)
4156
{
4157
    zend_object_std_dtor(object);
4158
}
4159

    
4160
void schemaValidator_destroy_storage(zend_object *object)
4161
{
4162
    zend_objects_destroy_object(object);
4163
}
4164

    
4165
zend_object *schemaValidator_create_handler(zend_class_entry *type)
4166
{
4167
    zval *tmp;
4168
    zend_object retval;
4169
    schemaValidator_object *obj = (schemaValidator_object *)ecalloc(1, sizeof(schemaValidator_object)+ zend_object_properties_size(type));
4170

    
4171
    zend_object_std_init(&obj->std, type);    
4172
    object_properties_init(&obj->std, type);
4173

    
4174
    obj->std.handlers = &schemaValidator_object_handlers;
4175

    
4176
    return &obj->std;
4177
}
4178

    
4179

    
4180

    
4181
PHP_METHOD(SchemaValidator, __destruct)
4182
{
4183
    zend_object* pobj = Z_OBJ_P(getThis()); 
4184
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4185

    
4186

    
4187
    SchemaValidator * schemaValidator= obj->schemaValidator;
4188
    if(schemaValidator != nullptr) {
4189
            delete schemaValidator;
4190
    }
4191
    
4192
}
4193

    
4194

    
4195

    
4196
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
4197
{
4198
    SchemaValidator *schemaValidator;
4199
    char * name;
4200
    size_t len1;
4201

    
4202
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
4203
        RETURN_NULL();
4204
    }
4205
    zend_object* pobj = Z_OBJ_P(getThis()); 
4206
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4207
    schemaValidator = obj->schemaValidator;
4208
    if (name != nullptr && schemaValidator != nullptr) {
4209
        schemaValidator->registerSchemaFromFile(name);
4210
    }
4211
}
4212

    
4213
PHP_METHOD(SchemaValidator, registerSchemaFromString)
4214
{
4215
    char * schemaStr;
4216
    size_t len1;
4217
    SchemaValidator *schemaValidator;
4218
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &schemaStr, &len1) == FAILURE) {
4219
        RETURN_NULL();
4220
    }
4221
    zend_object* pobj = Z_OBJ_P(getThis()); 
4222
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4223
    schemaValidator = obj->schemaValidator;
4224
    if (schemaStr!= nullptr && schemaValidator != nullptr) {
4225
        schemaValidator->registerSchemaFromString(schemaStr);
4226
    }
4227
}
4228

    
4229
PHP_METHOD(SchemaValidator, validate)
4230
{
4231
    char * name = nullptr;
4232
    size_t len1;
4233
    SchemaValidator *schemaValidator;
4234
    if (ZEND_NUM_ARGS()>1) {
4235
        WRONG_PARAM_COUNT;
4236
    }
4237
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4238
        RETURN_NULL();
4239
    }
4240
    zend_object* pobj = Z_OBJ_P(getThis()); 
4241
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4242
    schemaValidator = obj->schemaValidator;
4243
    if (schemaValidator != nullptr) {
4244
        schemaValidator->validate(name);
4245
    }
4246
}
4247

    
4248
PHP_METHOD(SchemaValidator, validateToNode)
4249
{
4250
    char * name = nullptr;
4251
   size_t len1;
4252
    SchemaValidator *schemaValidator;
4253
    if (ZEND_NUM_ARGS()>1) {
4254
        WRONG_PARAM_COUNT;
4255
    }
4256
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4257
        RETURN_NULL();
4258
    }
4259
    zend_object* pobj = Z_OBJ_P(getThis()); 
4260
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4261
    schemaValidator = obj->schemaValidator;
4262
    if (schemaValidator != nullptr) {
4263
        XdmNode * node = schemaValidator->validateToNode(name);
4264
        if(node != nullptr) {
4265
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4266
                RETURN_NULL();
4267
                return;
4268
            } else {
4269
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
4270
                zend_object* vvobj = Z_OBJ_P(return_value);
4271
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
4272
                assert (vobj != nullptr);
4273
                vobj->xdmNode = node;
4274
                return;
4275
            }
4276
        } 
4277
            schemaValidator->checkException();//TODO
4278
    } 
4279
    RETURN_NULL();
4280
}
4281

    
4282

    
4283
PHP_METHOD(SchemaValidator, getValidationReport)
4284
{
4285

    
4286
    SchemaValidator *schemaValidator;
4287
    if (ZEND_NUM_ARGS()>0) {
4288
        WRONG_PARAM_COUNT;
4289
    }
4290

    
4291
    zend_object* pobj = Z_OBJ_P(getThis()); 
4292
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4293
    schemaValidator = obj->schemaValidator;
4294
    if (schemaValidator != nullptr) {
4295
        XdmNode * node = schemaValidator->getValidationReport();
4296
        if(node != nullptr) {
4297
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4298
                RETURN_NULL();
4299
                return;
4300
            } else {
4301
                zend_object* vvobj = Z_OBJ_P(return_value);
4302
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
4303
                assert (vobj != nullptr);
4304
                vobj->xdmNode = node;
4305
                return;
4306
            }
4307
        } 
4308
            schemaValidator->checkException();//TODO
4309
    } 
4310
    RETURN_NULL();
4311
}
4312

    
4313

    
4314
PHP_METHOD(SchemaValidator, setSourceNode)
4315
{
4316
    SchemaValidator *schemaValidator;
4317

    
4318
    zval* oth;
4319
   
4320

    
4321
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
4322
        RETURN_NULL();
4323
    }
4324
    zend_object* pobj = Z_OBJ_P(getThis()); 
4325
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4326
    schemaValidator = obj->schemaValidator;
4327
    if (schemaValidator != nullptr) {
4328
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
4329
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
4330
        zend_object * nobj = Z_OBJ_P(oth);
4331
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
4332
        if(ooth != nullptr) {
4333
            XdmNode * value = ooth->xdmNode;
4334
            if(value != nullptr) {
4335
                schemaValidator->setSourceNode(value);
4336

    
4337
            }
4338
        }
4339
      
4340
        
4341
      }
4342
    }
4343
}
4344

    
4345
PHP_METHOD(SchemaValidator, setOutputFile)
4346
{
4347
    SchemaValidator *schemaValidator;
4348
    char * name;
4349
    int len1;
4350

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

    
4362

    
4363
PHP_METHOD(SchemaValidator, exportSchema)
4364
{
4365
    SchemaValidator *schemaValidator;
4366
    char * name;
4367
    int len1;
4368

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

    
4380

    
4381
PHP_METHOD(SchemaValidator, setProperty)
4382
{
4383
    SchemaValidator *schemaValidator;
4384
    char * name;
4385
    char * value;
4386
    size_t len1, len2, myint;
4387

    
4388
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
4389
        RETURN_NULL();
4390
    }
4391
    zend_object* pobj = Z_OBJ_P(getThis()); 
4392
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4393
    schemaValidator = obj->schemaValidator;
4394
    if (schemaValidator != nullptr) {
4395
        schemaValidator->setProperty(name, value);
4396
    }
4397
}
4398

    
4399
PHP_METHOD(SchemaValidator, setParameter)
4400
{
4401

    
4402
   SchemaValidator *schemaValidator;
4403
   char * name;
4404
   zval* oth;
4405
   size_t len1, len2, myint;        
4406
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
4407
        RETURN_NULL();
4408
    }
4409
    zend_object* pobj = Z_OBJ_P(getThis()); 
4410
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4411
    schemaValidator = obj->schemaValidator;
4412
    if (schemaValidator != nullptr) {
4413
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
4414
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
4415

    
4416
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
4417
        zend_object * nobj = Z_OBJ_P(oth);
4418

    
4419
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
4420
        if(ooth != nullptr) {
4421
            XdmNode * value = ooth->xdmNode;
4422
            if(value != nullptr) {
4423
                schemaValidator->setParameter(name, (XdmValue *)value);
4424

    
4425
            }
4426
        }
4427
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
4428
        zend_object* vvobj = Z_OBJ_P(oth);
4429
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
4430
        if(ooth != nullptr) {
4431
            XdmValue * value = ooth->xdmValue;
4432
            if(value != nullptr) {
4433
                
4434
                schemaValidator->setParameter(name, value);
4435
            }
4436
        }
4437

    
4438

    
4439

    
4440
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
4441
        zend_object* vvobj = Z_OBJ_P(oth);
4442
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
4443
        if(ooth != nullptr) {
4444
            XdmAtomicValue * value = ooth->xdmAtomicValue;
4445
            if(value != nullptr) {
4446
                
4447
                schemaValidator->setParameter(name, (XdmValue *)value);
4448
            }
4449
        }
4450

    
4451

    
4452

    
4453
      }
4454

    
4455
    }
4456
}
4457

    
4458
PHP_METHOD(SchemaValidator, clearProperties)
4459
{
4460
    SchemaValidator *schemaValidator;
4461
    if (ZEND_NUM_ARGS()>0) {
4462
        WRONG_PARAM_COUNT;
4463
    }
4464

    
4465
    zend_object* pobj = Z_OBJ_P(getThis()); 
4466
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4467
    schemaValidator = obj->schemaValidator;
4468
    if (schemaValidator != nullptr) {
4469
        schemaValidator->clearProperties();
4470
        schemaValidator->exceptionClear();
4471
    }
4472
}
4473

    
4474
PHP_METHOD(SchemaValidator, clearParameters)
4475
{
4476

    
4477
   SchemaValidator *schemaValidator;
4478
    if (ZEND_NUM_ARGS()>0) {
4479
        WRONG_PARAM_COUNT;
4480
    }
4481
    zend_object* pobj = Z_OBJ_P(getThis()); 
4482
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4483
    schemaValidator = obj->schemaValidator;
4484
    if (schemaValidator != nullptr) {
4485
       
4486
                schemaValidator->clearParameters(true);
4487
                schemaValidator->exceptionClear();
4488
        }
4489
    }
4490

    
4491
PHP_METHOD(SchemaValidator, exceptionOccurred)
4492
{
4493
    SchemaValidator *schemaValidator;
4494
    if (ZEND_NUM_ARGS()>0) {
4495
        WRONG_PARAM_COUNT;
4496
    }
4497
    zend_object* pobj = Z_OBJ_P(getThis()); 
4498
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4499
    schemaValidator = obj->schemaValidator;
4500
    if (schemaValidator != nullptr) {
4501
        bool result = schemaValidator->exceptionOccurred();
4502
        RETURN_BOOL(result);
4503
    }
4504
    RETURN_BOOL(false);
4505
}
4506

    
4507
PHP_METHOD(SchemaValidator, getExceptionCount)
4508
{
4509
    SchemaValidator *schemaValidator;
4510

    
4511
    if (ZEND_NUM_ARGS()>0) {
4512
        WRONG_PARAM_COUNT;
4513
    }
4514
    zend_object* pobj = Z_OBJ_P(getThis()); 
4515
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4516
    schemaValidator = obj->schemaValidator;
4517
    if (schemaValidator != nullptr) {
4518
        int count = schemaValidator->exceptionCount();
4519
        RETURN_LONG(count);
4520
    }
4521
    RETURN_LONG(0);
4522
}
4523

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

    
4544
PHP_METHOD(SchemaValidator, getErrorMessage)
4545
{
4546
    SchemaValidator *schemaValidator;
4547
    long index;
4548
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
4549
        RETURN_NULL();
4550
    }
4551
    zend_object* pobj = Z_OBJ_P(getThis()); 
4552
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4553
    schemaValidator = obj->schemaValidator;
4554
    if (schemaValidator != nullptr) {
4555
        const char * errStr = schemaValidator->getErrorMessage((int)index);
4556
        if(errStr != nullptr) {
4557
            //char *str = estrdup(errStr);
4558
            _RETURN_STRING(errStr);
4559
        }
4560
    }
4561
    RETURN_NULL();
4562
}
4563
PHP_METHOD(SchemaValidator, exceptionClear)
4564
{
4565
    SchemaValidator * schemaValidator;
4566
    zend_object* pobj = Z_OBJ_P(getThis()); 
4567
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4568
    schemaValidator = obj->schemaValidator;
4569
    if (schemaValidator != nullptr) {
4570
        schemaValidator->exceptionClear();
4571
    }
4572
}
4573

    
4574
/*     ============== PHP Interface of   XdmValue =============== */
4575
void xdmValue_free_storage(zend_object *object)
4576
{
4577
    zend_object_std_dtor(object);
4578
}
4579

    
4580
zend_object *xdmValue_create_handler(zend_class_entry *type)
4581
{
4582
    zval *tmp;
4583
    zend_object retval;
4584
    xdmValue_object *obj = (xdmValue_object *)ecalloc(1, sizeof(xdmValue_object)+ zend_object_properties_size(type));
4585
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
4586
    object_properties_init(&obj->std, type);
4587
    
4588
    obj->std.handlers = &xdmValue_object_handlers;
4589

    
4590
    return &obj->std;
4591
}
4592

    
4593
void XdmValue_destroy_storage(zend_object *object)
4594
{
4595
    zend_objects_destroy_object(object);
4596
}
4597

    
4598
PHP_METHOD(XdmValue, __construct)
4599
{
4600
    XdmValue *xdmValue = nullptr;
4601
    bool bVal;
4602
    char * sVal;
4603
    int len;
4604
    long iVal;
4605
    double dVal;
4606
    zval *zvalue;
4607

    
4608

    
4609

    
4610
    SaxonProcessor *proc= nullptr;
4611
    //xdmValue_object *obj = (xdmValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
4612
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == SUCCESS) {
4613
        switch (Z_TYPE_P(zvalue)) {
4614
            case IS_FALSE:
4615
            case IS_TRUE:
4616
                bVal = Z_BVAL_P(zvalue);
4617
                xdmValue = new XdmValue(bVal);
4618
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4619
                obj->xdmValue = xdmValue;
4620
            break;
4621
            case IS_LONG:
4622
                iVal = Z_LVAL_P(zvalue);
4623
                xdmValue = new XdmValue((int)iVal);
4624
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4625
                obj->xdmValue = xdmValue;
4626
            break;
4627
            case IS_STRING:
4628
                sVal = Z_STRVAL_P(zvalue);
4629
                len = Z_STRLEN_P(zvalue);
4630
                xdmValue = new XdmValue("string", sVal);
4631
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4632
                obj->xdmValue = xdmValue;
4633
            break;
4634
            case IS_NULL:
4635
                xdmValue = new XdmValue();
4636
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4637
                obj->xdmValue = xdmValue;
4638
            break;
4639
            case IS_DOUBLE:
4640
                // TODO: implement this
4641
                //index = (long)Z_DVAL_P(zvalue);
4642
            //break;
4643
            case IS_ARRAY:
4644
            //break;
4645
            case IS_OBJECT:
4646
            //break;
4647
            default:
4648
                obj = nullptr;
4649
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
4650
        }
4651
    }*/
4652
}
4653

    
4654
PHP_METHOD(XdmValue, __destruct)
4655
{
4656

    
4657
     zend_object *oobj = Z_OBJ_P(getThis());
4658
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4659
    XdmValue * xdmValue= obj->xdmValue;
4660
   if(xdmValue != nullptr) {
4661
            xdmValue->decrementRefCount();
4662
            if(xdmValue!= nullptr && xdmValue->getRefCount()< 1){
4663
                    delete xdmValue;
4664
            } 
4665
    }
4666
}
4667

    
4668
PHP_METHOD(XdmValue, __toString)
4669
    {
4670
             XdmValue *xdmValue;
4671
         zend_object *oobj = Z_OBJ_P(getThis());
4672
         xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4673
         xdmValue = obj->xdmValue;
4674
         if (xdmValue != nullptr) {
4675
                const char * value = xdmValue->toString();
4676
                  if(value != nullptr) {
4677
                      _RETURN_STRING(value);
4678
                   } else {
4679
                   _RETURN_STRING("");
4680

    
4681
                   }
4682
                 }else {
4683
                      _RETURN_STRING("");
4684
              }
4685
    }
4686

    
4687
PHP_METHOD(XdmValue,  getHead){
4688
    XdmValue *xdmValue;
4689
     zend_object *oobj = Z_OBJ_P(getThis());
4690
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4691
    xdmValue = obj->xdmValue;
4692
    if (xdmValue != nullptr) {
4693
        XdmItem * item = xdmValue->getHead();
4694
        if(item != nullptr) {
4695
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
4696
                RETURN_NULL();
4697
              } else {
4698
                item->incrementRefCount();
4699
                zend_object * oobj = Z_OBJ_P(return_value);
4700
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
4701
                assert (vobj != nullptr);
4702
                vobj->xdmItem = item;
4703
                
4704
            }
4705
        } else {
4706
                RETURN_NULL();
4707
        }
4708
        
4709
    } else {
4710
        RETURN_NULL();
4711
    }
4712
}
4713

    
4714

    
4715
PHP_METHOD(XdmValue,  itemAt){
4716
    XdmValue *xdmValue;
4717

    
4718
    long index;
4719
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
4720
        RETURN_NULL();
4721
    }
4722

    
4723
     zend_object *oobj = Z_OBJ_P(getThis());
4724
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4725
    xdmValue = obj->xdmValue;
4726
    if (xdmValue != nullptr) {
4727
        XdmItem * item = xdmValue->itemAt((unsigned int)index);
4728
        if(item != nullptr) {
4729
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
4730
                RETURN_NULL();
4731
                return;
4732
            } else {
4733
                item->incrementRefCount();
4734
                zend_object * oobj = Z_OBJ_P(return_value);
4735
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
4736
               
4737
                assert (vobj != nullptr);
4738
                vobj->xdmItem = item;
4739
                return;
4740
            }
4741
        }
4742
        
4743
    } else {
4744
        RETURN_NULL();
4745
    }
4746
}
4747

    
4748

    
4749
PHP_METHOD(XdmValue,  size){
4750
    XdmValue *xdmValue;
4751
    zend_object *oobj = Z_OBJ_P(getThis());
4752
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4753
    xdmValue = obj->xdmValue;
4754
    int sizei = 0;
4755
    if (xdmValue != nullptr) {
4756
        sizei = xdmValue->size();
4757
    }
4758
     RETURN_LONG(sizei);
4759
}
4760

    
4761

    
4762
PHP_METHOD(XdmValue, addXdmItem){
4763
    XdmValue *xdmValue;
4764
    zval* oth;
4765
           
4766
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
4767
        RETURN_NULL();
4768
    }
4769

    
4770
    xdmValue_object *obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4771
    xdmValue = obj->xdmValue;
4772
    if (xdmValue != nullptr) {
4773
     const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
4774
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
4775

    
4776
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
4777
        zend_object * nobj = Z_OBJ_P(oth);
4778
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
4779
        if(ooth != nullptr) {
4780
            XdmNode * value = ooth->xdmNode;
4781
            if(value != nullptr) {
4782
                xdmValue->addXdmItem((XdmItem *)value);
4783
                return;
4784
            }
4785
        }
4786
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
4787
        zend_object * iobj = Z_OBJ_P(oth);
4788
        xdmItem_object* ooth = (xdmItem_object *)((char *)iobj - XtOffsetOf(xdmItem_object, std));
4789
        if(ooth != nullptr) {
4790
            XdmItem * value = ooth->xdmItem;
4791
            if(value != nullptr) {
4792
                xdmValue->addXdmItem(value);
4793
                return;
4794
            }
4795
        }
4796

    
4797

    
4798

    
4799
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
4800
        zend_object * aobj = Z_OBJ_P(oth);
4801
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)aobj - XtOffsetOf(xdmAtomicValue_object, std));
4802
        if(ooth != nullptr) {
4803
            XdmAtomicValue * value = ooth->xdmAtomicValue;
4804
            if(value != nullptr) {
4805
                xdmValue->addXdmItem((XdmItem *)value);
4806
                return;
4807
            }
4808
        }
4809

    
4810
      } else {
4811
                //TODO exception
4812
        }
4813
    }
4814
}
4815

    
4816

    
4817

    
4818
/*     ============== PHP Interface of   XdmItem =============== */
4819

    
4820
void xdmItem_free_storage(zend_object *object)
4821
{
4822
    zend_object_std_dtor(object);
4823
}
4824

    
4825
zend_object *xdmItem_create_handler(zend_class_entry *type)
4826
{
4827
    zval *tmp;
4828
    zend_object retval;
4829
    xdmItem_object *obj = (xdmItem_object *)ecalloc(1, sizeof(xdmItem_object)+ zend_object_properties_size(type));
4830
    
4831
    object_properties_init(&obj->std, type);
4832
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
4833
    
4834
    obj->std.handlers = &xdmItem_object_handlers;
4835

    
4836
    return &obj->std;
4837
}
4838

    
4839
PHP_METHOD(XdmItem, __construct)
4840
{
4841
    XdmItem *xdmItem = nullptr;
4842
    bool bVal;
4843
    char * sVal;
4844
    int len;
4845
    long iVal;
4846
    double dVal;
4847
    zval *zvalue;
4848

    
4849
    SaxonProcessor *proc= nullptr;
4850
    
4851
   zval *object = getThis();
4852
   
4853
    zend_object * zobj = Z_OBJ_P(object);
4854

    
4855
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4856
    //saxonProc =  obj->saxonProcessor;
4857
 
4858
}
4859

    
4860
void XdmItem_destroy_storage(zend_object *object)
4861
{
4862
    zend_objects_destroy_object(object);
4863
    
4864
}
4865

    
4866
PHP_METHOD(XdmItem, __destruct)
4867
{
4868
     zval *object = getThis();
4869
     zend_object * zobj = Z_OBJ_P(object);
4870

    
4871
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4872

    
4873
    XdmItem * xdmItem= obj->xdmItem;
4874
    xdmItem->decrementRefCount();
4875
    if(xdmItem != nullptr && xdmItem->getRefCount()< 1){
4876
            delete xdmItem;
4877
    }
4878
    
4879
}
4880

    
4881
PHP_METHOD(XdmItem, getStringValue)
4882
{
4883
    XdmItem *xdmItem;
4884
     zval *object = getThis();
4885
    zend_object * zobj = Z_OBJ_P(object);
4886
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4887
    xdmItem = obj->xdmItem;
4888

    
4889
    if (xdmItem != nullptr) {
4890
        const char * valueStr = xdmItem->getStringValue();
4891
        if(valueStr != nullptr) {
4892
            _RETURN_STRING(valueStr);
4893
        }
4894
    }
4895
    RETURN_NULL();
4896
}
4897

    
4898
    /* {{{ __toString()
4899
       Returns the string content */
4900
PHP_METHOD(XdmItem, __toString)
4901
    {
4902
             XdmItem *xdmItem;
4903
         zend_object *oobj = Z_OBJ_P(getThis());
4904
         xdmItem_object* obj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
4905
         xdmItem = obj->xdmItem;
4906
         if (xdmItem != nullptr) {
4907
                const char * value = xdmItem->toString();
4908
                  if(value != nullptr) {
4909
                      _RETURN_STRING(value);
4910
                   } else {
4911
                   _RETURN_STRING("");
4912

    
4913
                   }
4914
                 }else {
4915
                      _RETURN_STRING("");
4916
              }
4917
    }
4918

    
4919
PHP_METHOD(XdmItem, isAtomic)
4920
{
4921
    XdmItem *xdmItem;
4922
    zend_object * zobj = Z_OBJ_P(getThis());
4923
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4924
    xdmItem = obj->xdmItem;
4925

    
4926
    if (xdmItem != nullptr) {
4927
        bool isAtomic = xdmItem->isAtomic();
4928
        RETURN_BOOL(isAtomic);
4929
    }
4930
    RETURN_BOOL(false);
4931
}
4932

    
4933
PHP_METHOD(XdmItem, isNode)
4934
{
4935
    XdmItem *xdmItem;
4936
    zend_object * zobj = Z_OBJ_P(getThis());
4937
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4938
    xdmItem = obj->xdmItem;
4939

    
4940
    if (xdmItem != nullptr && xdmItem->getType() == XDM_NODE) {
4941
        RETURN_TRUE;
4942
    }
4943
    RETURN_FALSE;
4944
}
4945

    
4946
PHP_METHOD(XdmItem, getAtomicValue)
4947
{
4948
    XdmItem *xdmItem;
4949
    zend_object * zobj = Z_OBJ_P(getThis());
4950
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4951
    xdmItem = obj->xdmItem;
4952

    
4953
    if (xdmItem != nullptr) {
4954
          if(!xdmItem->isAtomic()) {
4955
                RETURN_NULL();
4956
                return;
4957
          }
4958
          if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
4959
                RETURN_NULL();
4960
                return;
4961
            } else {
4962
                xdmItem->incrementRefCount();
4963
//Z_ADDREF_P(return_value);
4964
                   zend_object * zobj = Z_OBJ_P(return_value);
4965
                    xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
4966
                //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
4967
                assert (vobj != nullptr);
4968
                vobj->xdmAtomicValue = (XdmAtomicValue *)xdmItem;
4969
                return;
4970
            }
4971
    }
4972
    RETURN_NULL();
4973
}
4974

    
4975
PHP_METHOD(XdmItem, getNodeValue)
4976
{
4977
    XdmItem *xdmItem;
4978
    zend_object * zobj = Z_OBJ_P(getThis());
4979
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4980
    xdmItem = obj->xdmItem;
4981

    
4982
    if (xdmItem != nullptr) {
4983
          if(xdmItem->isAtomic()) {
4984
                RETURN_NULL();
4985
                return;
4986
          }
4987
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4988
                RETURN_NULL();
4989
                return;
4990
            } else {
4991
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
4992
                   zend_object * zobj = Z_OBJ_P(return_value);
4993
                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
4994
                assert (vobj != nullptr);
4995
                vobj->xdmNode = (XdmNode *)xdmItem;
4996
                vobj->xdmNode->incrementRefCount();
4997

    
4998
                return;
4999
            }
5000
    }
5001
    RETURN_NULL();
5002
}
5003

    
5004

    
5005

    
5006
/*     ============== PHP Interface of   XdmNode =============== */
5007

    
5008
void xdmNode_free_storage(zend_object *object)
5009
{
5010
   zend_object_std_dtor(object);
5011

    
5012
    
5013
}
5014

    
5015
zend_object *xdmNode_create_handler(zend_class_entry *type)
5016
{
5017
    zval *tmp;
5018
    zend_object retval;
5019
    xdmNode_object *obj = (xdmNode_object *)ecalloc(1, sizeof(xdmNode_object)+ zend_object_properties_size(type));
5020
    zend_object_std_init(&obj->std, type); /* take care of the