Project

Profile

Help

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

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

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

    
5
#include "php_saxon.h"
6

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

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

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

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

    
42

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

    
46
void SaxonProcessor_free_storage(zend_object *object)
47
{
48

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

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

    
62
    efree(obj);
63
}
64

    
65
void SaxonProcessor_destroy_storage(zend_object *pobj)
66
{
67

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

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

    
81
    
82
}
83

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

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

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

    
96
    return &obj->std;
97
}
98

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

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

    
112

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

    
117

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

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

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

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

    
141
            char* cwd2;
142

    
143
            //php_error(E_WARNING,cwd2);
144

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

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

    
158
          }
159
#endif
160

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

    
165
}
166

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

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

    
181

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

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

    
195

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

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

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

    
238

    
239

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

    
261

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

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

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

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

    
333

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

    
409

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

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

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

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

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

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

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

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

    
478

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

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

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

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

    
506
            xproc_object->xslt30Processor = xslt30Processor;
507

    
508
    }
509
    } else {
510

    
511
        RETURN_NULL();
512
    }
513
}
514

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

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

    
579

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

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

    
600

    
601

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

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

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

    
625

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

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

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

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

    
642
}
643

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

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

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

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

    
672
void XsltProcessor_free_storage(zend_object *object)
673
{
674

    
675
    zend_object_std_dtor(object);
676
}
677

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

    
682
    zend_objects_destroy_object(object);
683
}
684

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

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

    
697
    return &obj->std;
698
}
699

    
700

    
701

    
702
PHP_METHOD(XsltProcessor, __destruct)
703
{
704

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

    
708

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

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

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

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

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

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

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

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

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

    
780

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

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

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

    
796
    if (xsltProcessor != nullptr) {
797

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

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

    
826

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

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

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

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

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

    
874

    
875

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

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

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

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

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

    
943
    }
944

    
945

    
946
    free(sresult);
947

    
948

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

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

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

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

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

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

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

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

    
1002

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

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

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

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

    
1023

    
1024

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

    
1033

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

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

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

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

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

    
1068
    if (xsltProcessor != nullptr) {
1069

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

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

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

    
1102
    if (xsltProcessor != nullptr) {
1103

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

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

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

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

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

    
1180

    
1181

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

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

    
1205

    
1206

    
1207

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

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

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

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

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

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

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

    
1257
        
1258
    }
1259
  }
1260
}
1261

    
1262

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

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

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

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

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

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

    
1302

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

    
1309
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &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 && baseOutputURI != nullptr) {
1317

    
1318
         xsltProcessor->setBaseOutputURI(baseOutputURI);
1319

    
1320

    
1321
    }
1322
}
1323

    
1324

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

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

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

    
1348

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

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

    
1367
PHP_METHOD(XsltProcessor, setParameter)
1368
{
1369

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

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

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

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

    
1410

    
1411

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

    
1422

    
1423

    
1424
      }
1425

    
1426
    }
1427
}
1428

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

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

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

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

    
1459

    
1460

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

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

    
1475
    if (xsltProcessor != nullptr) {
1476

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

    
1480
}
1481

    
1482

    
1483

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

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

    
1501

    
1502

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

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

    
1552

    
1553

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

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

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

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

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

    
1574
    return &obj->std;
1575
}
1576

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

    
1587

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

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

    
1598
    xqueryProcessor = obj->xqueryProcessor;
1599

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

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

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

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

    
1646
PHP_METHOD(XQueryProcessor, runQueryToFile)
1647
{
1648

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

    
1661

    
1662

    
1663
    xqueryProcessor = obj->xqueryProcessor;
1664

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

    
1672
}
1673

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

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

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

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

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

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

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

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

    
1744

    
1745

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

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

    
1787

    
1788

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

    
1802

    
1803

    
1804
      } 
1805

    
1806

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

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

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

    
1831

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

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

    
1850
PHP_METHOD(XQueryProcessor, setParameter)
1851
{
1852

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

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

    
1892

    
1893

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

    
1905

    
1906

    
1907
      }
1908

    
1909
    }
1910
}
1911

    
1912

    
1913

    
1914

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

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

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

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

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

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

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

    
1963

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

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

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

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

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

    
2025
PHP_METHOD(XPathProcessor, __destruct)
2026
{
2027

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

    
2031

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

    
2037
   
2038
    
2039
}
2040

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

    
2051
    return &obj->std;
2052
}
2053

    
2054

    
2055

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

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

    
2074
PHP_METHOD(XPathProcessor, setParameter)
2075
{
2076

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

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

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

    
2114

    
2115

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

    
2128

    
2129

    
2130
      }
2131

    
2132
    }
2133
}
2134

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

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

    
2154

    
2155

    
2156
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
2157

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

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

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

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

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

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

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

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

    
2207
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
2208
{
2209

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

    
2227
PHP_METHOD(XPathProcessor, evaluate)
2228
{
2229

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

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

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

    
2276
PHP_METHOD(XPathProcessor, evaluateSingle)
2277
{
2278

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

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

    
2295

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

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

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

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

    
2332
PHP_METHOD(XPathProcessor, setContextItem)
2333
{
2334

    
2335
   XPathProcessor *xpathProcessor;
2336

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

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

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

    
2387
      }
2388
    }
2389
}
2390

    
2391
PHP_METHOD(XPathProcessor, setBaseURI)
2392
{
2393

    
2394
   XPathProcessor *xpathProcessor;
2395

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

    
2415
PHP_METHOD(XPathProcessor, setContextFile)
2416
{
2417

    
2418
   XPathProcessor *xpathProcessor;
2419

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

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

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

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

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

    
2469

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

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

    
2487

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

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

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

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

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

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

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

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

    
2561
    return &obj->std;
2562
}
2563

    
2564

    
2565

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

    
2571

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

    
2579

    
2580

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

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

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

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

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

    
2667

    
2668
PHP_METHOD(SchemaValidator, getValidationReport)
2669
{
2670

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

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

    
2698

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

    
2703
    zval* oth;
2704
   
2705

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

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

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

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

    
2747

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

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

    
2765

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

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

    
2784
PHP_METHOD(SchemaValidator, setParameter)
2785
{
2786

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

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

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

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

    
2823

    
2824

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

    
2836

    
2837

    
2838
      }
2839

    
2840
    }
2841
}
2842

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

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

    
2859
PHP_METHOD(SchemaValidator, clearParameters)
2860
{
2861

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

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

    
2892

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

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

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

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

    
2959
    return &obj->std;
2960
}
2961

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

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

    
2977

    
2978

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

    
3023
PHP_METHOD(XdmValue, __destruct)
3024
{
3025

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

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

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

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

    
3083

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

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

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

    
3117

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

    
3130

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

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

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

    
3166

    
3167

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

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

    
3185

    
3186

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

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

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

    
3205
    return &obj->std;
3206
}
3207

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3373

    
3374

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

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

    
3381
    
3382
}
3383

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

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

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

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

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

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

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

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

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

    
3447

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

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

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

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

    
3478

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

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

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

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

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

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

    
3534
PHP_METHOD(XdmNode, isAtomic)
3535
{
3536

    
3537
    RETURN_FALSE;
3538
}
3539

    
3540

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

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

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

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

    
3568
} 
3569

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

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

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

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

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

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

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

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

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

    
3678
}
3679

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

    
3701

    
3702
}
3703

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

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

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

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

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

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

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

    
3727
    return &obj->std;
3728
}
3729

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

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

    
3742
}
3743

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

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

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

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

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

    
3768

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

    
3777

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

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

    
3787

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

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

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

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

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

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

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

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

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

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

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

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

    
3858

    
3859

    
3860

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

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

    
3882

    
3883
PHP_METHOD(XdmAtomicValue, isAtomic)
3884
{
3885

    
3886
    RETURN_TRUE;
3887
}
3888

    
3889

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

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

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

    
3901

    
3902
// =============================================================
3903

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

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

    
3954

    
3955

    
3956

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

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

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

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

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

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

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

    
4078
PHP_MINIT_FUNCTION(saxon)
4079
{
4080

    
4081

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

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

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

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

    
4112
    INIT_CLASS_ENTRY(ce, "Saxon\\XSLTExecutable", XsltExecutable_methods);
4113
    xsltExecutable_object = zend_register_internal_class(&ce);
4114
    xsltExecutable_ce->create_object = xslt30Processor_create_handler;
4115
    memcpy(&xsltExecutable_object_handlers, zend_get_std_object_handlers(), sizeof(xsltExecutable_object_handlers));
4116
    xsltExecutable_object_handlers.offset = XtOffsetOf(xsltExecutable_object, std);
4117
    xsltExecutable_object_handlers.free_obj = XsltExcutable_free_storage;
4118
    xsltExecutable_object_handlers.dtor_obj = XsltExcutable_destroy_storage;
4119

    
4120
    INIT_CLASS_ENTRY(ce, "Saxon\\XQueryProcessor", XQueryProcessor_methods);
4121
    xqueryProcessor_ce = zend_register_internal_class(&ce);
4122
    xqueryProcessor_ce->create_object = xqueryProcessor_create_handler;
4123
    memcpy(&xqueryProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xqueryProcessor_object_handlers));
4124
    xqueryProcessor_object_handlers.offset = XtOffsetOf(xqueryProcessor_object, std);
4125
    xqueryProcessor_object_handlers.free_obj = xqueryProcessor_free_storage;
4126
    xqueryProcessor_object_handlers.dtor_obj = xqueryProcessor_destroy_storage;    
4127

    
4128
        //xqueryProcessor_object_handlers.clone_obj = nullptr;
4129

    
4130
    INIT_CLASS_ENTRY(ce, "Saxon\\XPathProcessor", XPathProcessor_methods);
4131
    xpathProcessor_ce = zend_register_internal_class(&ce);
4132
    xpathProcessor_ce->create_object = xpathProcessor_create_handler;
4133
    memcpy(&xpathProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xpathProcessor_object_handlers));
4134
    xpathProcessor_object_handlers.offset = XtOffsetOf(xpathProcessor_object, std);
4135
    xpathProcessor_object_handlers.free_obj = xpathProcessor_free_storage;
4136
    xpathProcessor_object_handlers.dtor_obj = xpathProcessor_destroy_storage; 
4137
    //xpathProcessor_object_handlers.clone_obj = nullptr;
4138

    
4139
    INIT_CLASS_ENTRY(ce, "Saxon\\SchemaValidator", SchemaValidator_methods);
4140
    schemaValidator_ce = zend_register_internal_class(&ce);
4141
    schemaValidator_ce->create_object = schemaValidator_create_handler;
4142
    memcpy(&schemaValidator_object_handlers, zend_get_std_object_handlers(), sizeof(schemaValidator_object_handlers));
4143
    schemaValidator_object_handlers.offset = XtOffsetOf(schemaValidator_object, std);
4144
    schemaValidator_object_handlers.free_obj = schemaValidator_free_storage;
4145
    schemaValidator_object_handlers.dtor_obj = schemaValidator_destroy_storage; 
4146
    //schemaValidator_object_handlers.clone_obj = nullptr;
4147

    
4148
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmValue", xdmValue_methods);
4149
    xdmValue_ce = zend_register_internal_class(&ce);
4150
    xdmValue_ce->create_object = xdmValue_create_handler;
4151
    memcpy(&xdmValue_object_handlers, zend_get_std_object_handlers(), sizeof(xdmValue_object_handlers));
4152
    xdmValue_object_handlers.offset = XtOffsetOf(xdmValue_object, std);
4153
    xdmValue_object_handlers.free_obj = xdmValue_free_storage;
4154
    xdmValue_object_handlers.dtor_obj = XdmValue_destroy_storage;
4155
    //xdmValue_object_handlers.clone_obj = nullptr;
4156

    
4157
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmItem", xdmItem_methods);
4158
    xdmItem_ce = zend_register_internal_class(&ce);
4159
    xdmItem_ce->create_object = xdmItem_create_handler;
4160
    memcpy(&xdmItem_object_handlers, zend_get_std_object_handlers(), sizeof(xdmItem_object_handlers));
4161
    xdmItem_object_handlers.offset = XtOffsetOf(xdmItem_object, std);
4162
    xdmItem_object_handlers.free_obj = xdmItem_free_storage;
4163
    xdmItem_object_handlers.dtor_obj = XdmItem_destroy_storage;
4164
    //xdmItem_object_handlers.clone_obj = nullptr;
4165

    
4166
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmNode", xdmNode_methods);
4167
    xdmNode_ce = zend_register_internal_class(&ce);
4168
    xdmNode_ce->create_object = xdmNode_create_handler;
4169
    memcpy(&xdmNode_object_handlers, zend_get_std_object_handlers(), sizeof(xdmNode_object_handlers));
4170
    xdmNode_object_handlers.offset = XtOffsetOf(xdmNode_object, std);
4171
    xdmNode_object_handlers.free_obj = xdmNode_free_storage;
4172
    xdmNode_object_handlers.dtor_obj = XdmNode_destroy_storage;
4173
 
4174
    //xdmNode_object_handlers.clone_obj = nullptr;
4175

    
4176
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmAtomicValue", xdmAtomicValue_methods);
4177
    xdmAtomicValue_ce = zend_register_internal_class(&ce);
4178
    xdmAtomicValue_ce->create_object = xdmAtomicValue_create_handler;
4179
    memcpy(&xdmAtomicValue_object_handlers, zend_get_std_object_handlers(), sizeof(xdmAtomicValue_object_handlers));
4180
    xdmAtomicValue_object_handlers.offset = XtOffsetOf(xdmAtomicValue_object, std);
4181
    xdmAtomicValue_object_handlers.free_obj = xdmAtomicValue_free_storage;
4182
    xdmAtomicValue_object_handlers.dtor_obj = XdmAtomicValue_destroy_storage;
4183
    //REGISTER_INI_ENTRIES();
4184
    return SUCCESS;
4185
}
4186

    
4187
PHP_MINFO_FUNCTION(saxon)
4188
{
4189
    php_info_print_table_start();
4190
    php_info_print_table_header(2, "saxonc", "enabled");
4191
    php_info_print_table_row(2, "Saxon/C EXT version", "1.3");
4192
    php_info_print_table_row(2, "Saxon", "10.4");
4193
    php_info_print_table_row(2, "Excelsior JET", "15.3 MP1");
4194
    php_info_print_table_end();
4195
    DISPLAY_INI_ENTRIES();
4196
}
4197

    
4198
PHP_MSHUTDOWN_FUNCTION(saxon) {
4199
//std::cerr<<"MSHUTDOWN called -start"<<std::endl;
4200
//SaxonProcessor *  proc = new SaxonProcessor();
4201
 SaxonProcessor::release();   
4202
//delete proc;
4203
 UNREGISTER_INI_ENTRIES();
4204
   
4205
    return SUCCESS;
4206
}
4207

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

    
4214
PHP_RINIT_FUNCTION(saxon) {
4215
    //SaxonProcessor::release();
4216
    //std::cerr<<"RINIT called -start"<<std::endl;
4217
    return SUCCESS;
4218
}
4219

    
4220
zend_module_entry saxon_module_entry = {
4221
#if ZEND_MODULE_API_NO >= 20010901
4222
    STANDARD_MODULE_HEADER,
4223
#endif
4224
    PHP_SAXON_EXTNAME,
4225
    nullptr,        /* Functions */
4226
    PHP_MINIT(saxon),        /* MINIT */
4227
    PHP_MSHUTDOWN(saxon),        /* MSHUTDOWN */
4228
    nullptr,        /* RINIT */
4229
    nullptr,        /* RSHUTDOWN */
4230
    PHP_MINFO(saxon),        /* MINFO */
4231
#if ZEND_MODULE_API_NO >= 20010901
4232
    PHP_SAXON_EXTVER,
4233
#endif
4234
    STANDARD_MODULE_PROPERTIES
4235
};
4236

    
4237
#ifdef COMPILE_DL_SAXONC
4238
#ifdef ZTS
4239
ZEND_TSRMLS_CACHE_DEFINE()
4240
#endif
4241
ZEND_GET_MODULE(saxonc)
4242
#endif
4243

    
(5-5/8)