Project

Profile

Help

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

he / latest9.9 / hec / Saxon.C.API / php7_saxon.cpp @ 1117bc69

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

    
5
#include "php_saxon.h"
6

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

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

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

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

    
44
void SaxonProcessor_free_storage(zend_object *object)
45
{
46

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

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

    
60
    efree(obj);
61
}
62

    
63
void SaxonProcessor_destroy_storage(zend_object *pobj)
64
{
65

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

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

    
79
    
80
}
81

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

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

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

    
94
    return &obj->std;
95
}
96

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

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

    
110

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

    
115

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

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

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

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

    
139
            char* cwd2;
140

    
141
            //php_error(E_WARNING,cwd2);
142

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

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

    
156
          }
157
#endif
158

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

    
163
}
164

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

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

    
179

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

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

    
193
PHP_METHOD(SaxonProcessor, setResourcesDirectory)
194
{
195
    SaxonProcessor *saxonProcessor;
196
    char * dirStr;
197
    size_t len;
198
    
199
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &dirStr, &len) == FAILURE) {
200
        RETURN_NULL();
201
    }
202
    
203
    zend_object* pobj = Z_OBJ_P(getThis()); 
204
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
205
    saxonProcessor = obj->saxonProcessor;
206
    if (saxonProcessor != NULL) {
207
       
208
        if(dirStr != NULL) {
209
            saxonProcessor->setResourcesDirectory(dirStr);
210
        }
211
    }
212
}
213

    
214

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

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

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

    
257

    
258

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

    
280

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

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

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

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

    
352

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

    
428

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

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

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

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

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

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

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

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

    
497

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

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

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

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

    
525
            xproc_object->xslt30Processor = xslt30Processor;
526

    
527
    }
528
    } else {
529

    
530
        RETURN_NULL();
531
    }
532
}
533

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

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

    
598

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

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

    
619

    
620

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

    
631
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
632
        RETURN_NULL();
633
    }
634
    zend_object* pobj = Z_OBJ_P(getThis()); 
635
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
636

    
637
    saxonProcessor = obj->saxonProcessor;
638
    if (saxonProcessor != NULL && name != NULL && value != NULL) {
639
        saxonProcessor->setConfigurationProperty(name, value);
640
    }
641
    
642
}
643

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

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

    
661
    saxonProcessor = obj->saxonProcessor;
662
    if (saxonProcessor != NULL && libName != NULL) {
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 != NULL){
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 != NULL) {
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 != NULL) {
758

    
759
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
760
        if(node != NULL) {
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 != NULL);
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 != NULL) {
797

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

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

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

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

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

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

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

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

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

    
947
}
948

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

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

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

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

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

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

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

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

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

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

    
1045

    
1046

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

    
1055

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

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

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

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

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

    
1090
    if (xsltProcessor != NULL) {
1091

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

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

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

    
1124
    if (xsltProcessor != NULL) {
1125

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

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

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

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

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

    
1202

    
1203

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

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

    
1227

    
1228

    
1229

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

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

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

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

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

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

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

    
1279
        
1280
    }
1281
  }
1282
}
1283

    
1284

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

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

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

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

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

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

    
1324

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

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

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

    
1340
         xsltProcessor->setBaseOutputURI(baseOutputURI);
1341

    
1342

    
1343
    }
1344
}
1345

    
1346

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

    
1351
PHP_METHOD(XsltProcessor, setSourceFromFile)
1352
{
1353
    XsltProcessor *xsltProcessor;
1354
    char * inFilename;
1355
    size_t len1;
1356
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
1357
        RETURN_NULL();
1358
    }
1359

    
1360
    zend_object* pobj = Z_OBJ_P(getThis()); 
1361
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1362
    xsltProcessor = obj->xsltProcessor;
1363
    if (xsltProcessor != NULL && inFilename != NULL) {
1364
         xsltProcessor->setSourceFromFile(inFilename);
1365
            
1366
        
1367
    }
1368
}
1369

    
1370

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

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

    
1389
PHP_METHOD(XsltProcessor, setParameter)
1390
{
1391

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

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

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

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

    
1432

    
1433

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

    
1444

    
1445

    
1446
      }
1447

    
1448
    }
1449
}
1450

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

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

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

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

    
1481

    
1482

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

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

    
1497
    if (xsltProcessor != NULL) {
1498

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

    
1502
}
1503

    
1504

    
1505

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

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

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

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

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

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

    
1590

    
1591

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

    
1594
void Xslt30Processor_free_storage(zend_object *object)
1595
{
1596

    
1597
    zend_object_std_dtor(object);
1598

    
1599
}
1600

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

    
1605
    zend_objects_destroy_object(object);
1606
}
1607

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

    
1611

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

    
1614

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

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

    
1620
    return &obj->std;
1621
}
1622

    
1623

    
1624

    
1625
PHP_METHOD(Xslt30Processor, __destruct)
1626
{
1627

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

    
1631

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

    
1637

    
1638
}
1639

    
1640

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

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

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

    
1656
         xslt30Processor->setBaseOutputURI(baseOutputURI);
1657

    
1658

    
1659
    }
1660
}
1661

    
1662

    
1663

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

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

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

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

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

    
1734

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

    
1755

    
1756
}
1757

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

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

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

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

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

    
1841

    
1842

    
1843
}
1844

    
1845

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

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

    
1861

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

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

    
1914

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

    
1925
}
1926

    
1927
    PHP_METHOD(Xslt30Processor, callTemplateReturningValue){
1928

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

    
1935

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

    
1942

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

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

    
1973

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

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

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

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

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

    
2014
     RETURN_NULL();
2015
    }
2016

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

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

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

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

    
2040
  }
2041

    
2042

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

    
2048
    if (ZEND_NUM_ARGS()>0) {
2049

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

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

    
2078

    
2079

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

    
2085

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

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

    
2092

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

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

    
2123
     RETURN_NULL();
2124
   
2125

    
2126

    
2127
}
2128

    
2129

    
2130

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

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

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

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

    
2154

    
2155

    
2156
}
2157

    
2158

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

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

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

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

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

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

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

    
2206

    
2207
    PHP_METHOD(Xslt30Processor,setInitialTemplateParameters){
2208

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

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

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

    
2227

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

    
2274

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

    
2280
    }
2281

    
2282

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

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

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

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

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

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

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

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

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

    
2330
            } else {
2331

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

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

    
2349

    
2350
    }
2351
  }
2352

    
2353

    
2354

    
2355

    
2356
}
2357
    
2358

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

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

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

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

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

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

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

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

    
2410

    
2411
    }
2412
  }
2413
}
2414

    
2415

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

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

    
2431

    
2432
    }
2433
}
2434

    
2435

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

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

    
2451

    
2452
    }
2453
}
2454

    
2455

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

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

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

    
2472
    if (xslt30Processor != NULL) {
2473

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

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

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

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

    
2496
    if (xslt30Processor != NULL) {
2497

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

    
2519

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

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

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

    
2535
    if (xslt30Processor != NULL) {
2536

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

    
2554

    
2555

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

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

    
2564

    
2565
    zval* oth;
2566
   
2567

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

    
2572

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

    
2578
      if(!oth) {
2579
        php_error(E_WARNING, "Error setting source value");
2580
        return;
2581
      } else {
2582
        if(Z_TYPE_P(oth) ==IS_NULL){
2583
                php_error(E_WARNING, "Error setting source value");
2584
                return;
2585
        }
2586
        
2587
        const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2588
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2589
          zend_object * nobj = Z_OBJ_P(oth);
2590

    
2591
          xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2592
          if(ooth != NULL) {
2593
            XdmNode * value = ooth->xdmNode;
2594
            if(value != NULL) {
2595
                const char * result = xslt30Processor->transformToString(value);
2596
                if(result != NULL) {
2597
                  _RETURN_STRING(result);
2598
                } else if(xslt30Processor->exceptionOccurred()){
2599
                   xslt30Processor->checkException(); 
2600
                }
2601
            }
2602

    
2603
          }
2604
        }
2605
}}
2606
    RETURN_NULL();
2607
}
2608

    
2609
PHP_METHOD(Xslt30Processor, transformToValue)
2610
{
2611
    Xslt30Processor *xslt30Processor;
2612

    
2613
    if (ZEND_NUM_ARGS()>1) {
2614
        WRONG_PARAM_COUNT;
2615
    }
2616

    
2617

    
2618
    zval* oth;
2619
   
2620

    
2621
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2622
        RETURN_NULL();
2623
    }
2624

    
2625
    zend_object* pobj = Z_OBJ_P(getThis());
2626
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2627
    xslt30Processor = obj->xslt30Processor;
2628

    
2629
    if (xslt30Processor != NULL) {
2630
      if(!oth) {
2631
        php_error(E_WARNING, "Error setting source value");
2632
        return;
2633
      } else {
2634
        if(Z_TYPE_P(oth) ==IS_NULL){
2635
                php_error(E_WARNING, "Error setting source value");
2636
                return;
2637
        }
2638
        
2639
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2640
     
2641
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2642
        zend_object * nobj = Z_OBJ_P(oth);
2643

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

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

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

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

    
2680

    
2681
    zval* oth;
2682
   
2683

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

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

    
2692
    if (xslt30Processor != NULL) {
2693
      if(!oth) {
2694
        php_error(E_WARNING, "Error setting source value");
2695
        return;
2696
      } else {
2697
        if(Z_TYPE_P(oth) ==IS_NULL){
2698
                php_error(E_WARNING, "Error setting source value");
2699
                return;
2700
        }
2701
        
2702
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2703

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

    
2707
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2708
        if(ooth != NULL) {
2709
            XdmNode * value = ooth->xdmNode;
2710
            if(value != NULL) {
2711
                
2712
                xslt30Processor->transformToFile(value);
2713
                if(xslt30Processor->exceptionOccurred()) {
2714
                   //TODO
2715
                   const char * exStr = xslt30Processor->checkException();
2716
                }
2717
            }
2718
        }
2719
      }
2720

    
2721
    }
2722
   }
2723
 else {
2724
        RETURN_NULL();
2725
    }
2726
}
2727

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

    
2744

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

    
2761

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

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

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

    
2812

    
2813

    
2814
PHP_METHOD(Xslt30Processor, compileFromValue)
2815
{
2816
    Xslt30Processor *xslt30Processor;
2817
   zval* oth;
2818

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

    
2837

    
2838

    
2839
PHP_METHOD(Xslt30Processor, setResultAsRawValue)
2840
{
2841
    Xslt30Processor *xslt30Processor;
2842
    bool raw = false;
2843

    
2844
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &raw) == FAILURE) {
2845
        RETURN_NULL();
2846
    }
2847

    
2848
    zend_object* pobj = Z_OBJ_P(getThis());
2849
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2850
    xslt30Processor = obj->xslt30Processor;
2851
    if (xslt30Processor != NULL) {
2852
         xslt30Processor->setResultAsRawValue(raw);
2853
    }
2854

    
2855
}
2856

    
2857

    
2858

    
2859
PHP_METHOD(Xslt30Processor, setJustInTimeCompilation)
2860
{
2861
    Xslt30Processor *xslt30Processor;
2862
    bool jit = false;
2863
    size_t len1;
2864

    
2865
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
2866
        RETURN_NULL();
2867
    }
2868

    
2869
    zend_object* pobj = Z_OBJ_P(getThis());
2870
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2871
    xslt30Processor = obj->xslt30Processor;
2872
    if (xslt30Processor != NULL) {
2873
         xslt30Processor->setJustInTimeCompilation(jit);
2874
    }
2875
}
2876

    
2877
PHP_METHOD(Xslt30Processor, setOutputFile)
2878
{
2879
    Xslt30Processor *xslt30Processor;
2880
    char * outputFilename = NULL;
2881
    size_t len1;
2882

    
2883
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
2884
        RETURN_NULL();
2885
    }
2886

    
2887
    zend_object* pobj = Z_OBJ_P(getThis());
2888
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2889
    xslt30Processor = obj->xslt30Processor;
2890
    if (xslt30Processor != NULL && outputFilename != NULL) {
2891

    
2892
         xslt30Processor->setOutputFile(outputFilename);
2893

    
2894

    
2895
    }
2896
}
2897

    
2898

    
2899

    
2900

    
2901
PHP_METHOD(Xslt30Processor, setProperty)
2902
{
2903
    Xslt30Processor *xslt30Processor;
2904
    char * name = NULL;
2905
    char * value;
2906
    size_t len1, len2, myint;
2907

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

    
2919
PHP_METHOD(Xslt30Processor, setParameter)
2920
{
2921

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

    
2938
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2939
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2940

    
2941
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2942
        zend_object* ooth = Z_OBJ_P(oth);
2943
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
2944
        if(nobj != NULL) {
2945
            XdmNode * value = nobj->xdmNode;
2946
            if(value != NULL) {
2947
                xslt30Processor->setParameter(name, (XdmValue *)value);
2948

    
2949
            }
2950
        }
2951
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2952
        zend_object* ooth = Z_OBJ_P(oth);
2953
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2954
        if(vobj != NULL) {
2955
            XdmValue * value = vobj->xdmValue;
2956
            if(value != NULL) {
2957

    
2958
                xslt30Processor->setParameter(name, value);
2959
            }
2960
        }
2961

    
2962

    
2963

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

    
2974

    
2975

    
2976
      }
2977

    
2978
    }
2979
}
2980

    
2981
PHP_METHOD(Xslt30Processor, clearParameters)
2982
{
2983
    Xslt30Processor *xslt30Processor;
2984
    if (ZEND_NUM_ARGS()>0) {
2985
        WRONG_PARAM_COUNT;
2986
    }
2987

    
2988
    zend_object* pobj = Z_OBJ_P(getThis());
2989
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2990
    xslt30Processor = obj->xslt30Processor;
2991
    if (xslt30Processor != NULL) {
2992
        xslt30Processor->clearParameters(true);
2993
    }
2994
}
2995

    
2996
PHP_METHOD(Xslt30Processor, clearProperties)
2997
{
2998
    Xslt30Processor *xslt30Processor;
2999
    if (ZEND_NUM_ARGS()>0) {
3000
        WRONG_PARAM_COUNT;
3001
    }
3002

    
3003
    zend_object* pobj = Z_OBJ_P(getThis());
3004
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3005
    xslt30Processor = obj->xslt30Processor;
3006
    if (xslt30Processor != NULL) {
3007
        xslt30Processor->clearProperties();
3008
    }
3009
}
3010

    
3011

    
3012
PHP_METHOD(Xslt30Processor, setupXslMessage)
3013
{
3014
    Xslt30Processor *xslt30Processor;
3015
    bool show = false;
3016
    char * filename = NULL;
3017
    size_t len1;
3018
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename &len1) == FAILURE) {
3019
        RETURN_NULL();
3020
    }
3021

    
3022
    zend_object* pobj = Z_OBJ_P(getThis());
3023
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3024
    xslt30Processor = obj->xslt30Processor;
3025

    
3026
    if (xslt30Processor != NULL) {
3027

    
3028
            xslt30Processor->setupXslMessage(show, filename);
3029
        }
3030

    
3031
}
3032

    
3033

    
3034

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

    
3044
    xslt30Processor = obj->xslt30Processor;
3045
    if (xslt30Processor != NULL) {
3046
        bool result = xslt30Processor->exceptionOccurred();
3047
        RETURN_BOOL(result);
3048
    }
3049
    RETURN_BOOL(false);
3050
}
3051

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

    
3061
    xslt30Processor = obj->xslt30Processor;
3062
    if (xslt30Processor != NULL) {
3063
        int count = xslt30Processor->exceptionCount();
3064
        RETURN_LONG(count);
3065
    }
3066
    RETURN_LONG(0);
3067
}
3068

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

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

    
3119
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
3120

    
3121
void xqueryProcessor_free_storage(zend_object *object)
3122
{
3123
    zend_object_std_dtor(object);
3124
}
3125

    
3126
void xqueryProcessor_destroy_storage(zend_object *object)
3127
{
3128
    zend_objects_destroy_object(object);
3129
}
3130

    
3131
zend_object *xqueryProcessor_create_handler(zend_class_entry *type)
3132
{
3133

    
3134
    xqueryProcessor_object *obj = (xqueryProcessor_object *)ecalloc(1, sizeof(xqueryProcessor_object)+ zend_object_properties_size(type));
3135
    zend_object_std_init(&obj->std, type); 
3136
    object_properties_init(&obj->std, type);
3137
    obj->std.handlers = &xqueryProcessor_object_handlers;
3138

    
3139
    return &obj->std;
3140
}
3141

    
3142
PHP_METHOD(XQueryProcessor, __destruct)
3143
{
3144
    zend_object* pobj = Z_OBJ_P(getThis());
3145
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3146
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
3147
    if(xqueryProcessor != NULL){
3148
            delete xqueryProcessor;
3149
    }
3150
}
3151

    
3152

    
3153
PHP_METHOD(XQueryProcessor, runQueryToValue)
3154
{
3155
    XQueryProcessor *xqueryProcessor;
3156
    zend_object* pobj = Z_OBJ_P(getThis()); 
3157
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3158

    
3159
    if (ZEND_NUM_ARGS()>0) {
3160
        WRONG_PARAM_COUNT;
3161
    }
3162

    
3163
    xqueryProcessor = obj->xqueryProcessor;
3164

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

    
3186
PHP_METHOD(XQueryProcessor, runQueryToString)
3187
{
3188
    XQueryProcessor *xqueryProcessor;
3189
   
3190

    
3191
    if (ZEND_NUM_ARGS()>0) {
3192
        WRONG_PARAM_COUNT;
3193
    }
3194
    zend_object* pobj = Z_OBJ_P(getThis()); 
3195
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3196
    xqueryProcessor = obj->xqueryProcessor;
3197

    
3198
    if (xqueryProcessor != NULL) {
3199
        const char * result = xqueryProcessor->runQueryToString();
3200
        if(result != NULL) {
3201
            //char *str = estrdup(result);
3202
            _RETURN_STRING(result);
3203
            return;
3204
        } else {
3205
          xqueryProcessor->checkException(); //TODO
3206
        }
3207
    }
3208
   RETURN_NULL();
3209
}
3210

    
3211
PHP_METHOD(XQueryProcessor, runQueryToFile)
3212
{
3213

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

    
3226

    
3227

    
3228
    xqueryProcessor = obj->xqueryProcessor;
3229

    
3230
    if (xqueryProcessor != NULL) {
3231
        if(ofilename != NULL) {
3232
                xqueryProcessor->setOutputFile(ofilename);        
3233
        }
3234
        xqueryProcessor->runQueryToFile(); 
3235
    }
3236

    
3237
}
3238

    
3239
PHP_METHOD(XQueryProcessor, setQueryContent)
3240
{
3241
    char * queryStr;
3242
    size_t len1;
3243

    
3244
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &queryStr, &len1) == FAILURE) {
3245
        RETURN_NULL();
3246
    }
3247
    zend_object* pobj = Z_OBJ_P(getThis()); 
3248
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std)); 
3249
    if(queryStr != NULL) { 
3250
      obj->xqueryProcessor->setProperty("qs", queryStr);
3251
   }
3252
}
3253

    
3254
PHP_METHOD(XQueryProcessor, setQueryFile)
3255
{
3256
   char * fileName;
3257
   size_t len1;
3258
    XQueryProcessor *xqueryProcessor;
3259

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

    
3272
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
3273
{
3274
   char * base;
3275
   size_t len1;
3276
    XQueryProcessor *xqueryProcessor;
3277

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

    
3290
PHP_METHOD(XQueryProcessor, declareNamespace)
3291
{
3292
   char * prefix;
3293
   char * ns;
3294
   size_t len1, len2;
3295
    XQueryProcessor *xqueryProcessor;
3296

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

    
3309

    
3310

    
3311
PHP_METHOD(XQueryProcessor, setContextItem)
3312
{
3313
   char * context;
3314
   int len1;
3315
   zval* oth;
3316
    XQueryProcessor *xqueryProcessor;
3317

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

    
3352

    
3353

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

    
3367

    
3368

    
3369
      } 
3370

    
3371

    
3372
    }
3373
        //throw exception
3374
        
3375
            
3376
}
3377

    
3378
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
3379
{
3380
   char * cfilename;
3381
   size_t len1;
3382
    XQueryProcessor *xqueryProcessor;
3383

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

    
3396

    
3397
PHP_METHOD(XQueryProcessor, setProperty)
3398
{
3399
    XQueryProcessor *xqueryProcessor;
3400
    char * name;
3401
    char * value;
3402
    size_t len1, len2, myint;
3403

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

    
3415
PHP_METHOD(XQueryProcessor, setParameter)
3416
{
3417

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

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

    
3457

    
3458

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

    
3470

    
3471

    
3472
      }
3473

    
3474
    }
3475
}
3476

    
3477

    
3478

    
3479

    
3480
PHP_METHOD(XQueryProcessor, clearParameters)
3481
{
3482
    XQueryProcessor *xqueryProcessor;
3483
    if (ZEND_NUM_ARGS()>0) {
3484
        WRONG_PARAM_COUNT;
3485
    }
3486

    
3487
    zend_object* pobj = Z_OBJ_P(getThis()); 
3488
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3489
    xqueryProcessor = obj->xqueryProcessor;
3490
    if (xqueryProcessor != NULL) {
3491
        xqueryProcessor->clearParameters(true);
3492
    }
3493
}
3494

    
3495
PHP_METHOD(XQueryProcessor, clearProperties)
3496
{
3497
    XQueryProcessor *xqueryProcessor;
3498

    
3499
    if (ZEND_NUM_ARGS()>0) {
3500
        WRONG_PARAM_COUNT;
3501
    }
3502

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

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

    
3520
    xqueryProcessor = obj->xqueryProcessor;
3521
    if (xqueryProcessor != NULL) {
3522
        bool result = xqueryProcessor->exceptionOccurred();
3523
        RETURN_BOOL(result);
3524
    }
3525
    RETURN_BOOL(false);
3526
}
3527

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

    
3537
    xqueryProcessor = obj->xqueryProcessor;
3538
    if (xqueryProcessor != NULL) {
3539
        int count = xqueryProcessor->exceptionCount();
3540
        RETURN_LONG(count);
3541
    }
3542
    RETURN_LONG(0);
3543
}
3544

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

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

    
3595
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
3596

    
3597
void xpathProcessor_free_storage(zend_object *object)
3598
{
3599
    zend_object_std_dtor(object);
3600
}
3601

    
3602
void xpathProcessor_destroy_storage(zend_object *object)
3603
{
3604
    zend_objects_destroy_object(object);
3605
}
3606

    
3607
PHP_METHOD(XPathProcessor, __destruct)
3608
{
3609

    
3610
   zend_object* pobj = Z_OBJ_P(getThis()); 
3611
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3612

    
3613

    
3614
   XPathProcessor * xpathProc= obj->xpathProcessor;
3615
    if(xpathProc != NULL){
3616
            delete xpathProc;
3617
     }
3618

    
3619
   
3620
    
3621
}
3622

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

    
3633
    return &obj->std;
3634
}
3635

    
3636

    
3637

    
3638
PHP_METHOD(XPathProcessor, setProperty)
3639
{
3640
    XPathProcessor *xpathProcessor;
3641
    char * name;
3642
    char * value;
3643
    size_t len1, len2;
3644

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

    
3656
PHP_METHOD(XPathProcessor, setParameter)
3657
{
3658

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

    
3673
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3674
        
3675
        zend_object* vvobj = Z_OBJ_P(oth);
3676
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3677
        if(ooth != NULL) {
3678
            XdmNode * value = ooth->xdmNode;
3679
            if(value != NULL) {        
3680
                xpathProcessor->setParameter(name, (XdmValue *)value);
3681

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

    
3696

    
3697

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

    
3710

    
3711

    
3712
      }
3713

    
3714
    }
3715
}
3716

    
3717
PHP_METHOD(XPathProcessor, declareNamespace)
3718
{
3719
   char * prefix;
3720
   char * ns;
3721
   int len1, len2;
3722
   XPathProcessor *xpathProcessor;
3723

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

    
3736

    
3737

    
3738
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
3739

    
3740
    XPathProcessor *xpathProcessor;
3741
    bool allow = false;
3742
    size_t len1;
3743

    
3744
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &allow) == FAILURE) {
3745
        RETURN_NULL();
3746
    }
3747

    
3748
    zend_object* pobj = Z_OBJ_P(getThis());
3749
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3750
    xpathProcessor = obj->xpathProcessor;
3751
    if (xpathProcessor != NULL) {
3752
            xpathProcessor->setBackwardsCompatible(allow);
3753
         }
3754
}
3755

    
3756
PHP_METHOD(XPathProcessor, setCaching){
3757
    XPathProcessor *xpathProcessor;
3758
    bool isCaching = false;
3759
    size_t len1;
3760

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

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

    
3773
PHP_METHOD(XPathProcessor, importSchemaNamespace){
3774
      char * name;
3775
      int len1;
3776
      XPathProcessor *xpathProcessor;
3777

    
3778
       if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
3779
           RETURN_NULL();
3780
       }
3781
       if(name != NULL) {
3782
               zend_object* pobj = Z_OBJ_P(getThis());
3783
           xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3784
               xpathProcessor = obj->xpathProcessor;
3785
               xpathProcessor->importSchemaNamespace(name);
3786
       }
3787
}
3788

    
3789
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
3790
{
3791

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

    
3809
PHP_METHOD(XPathProcessor, evaluate)
3810
{
3811

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

    
3838
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
3839
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3840
                assert (vobj != NULL);
3841
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
3842
                return;
3843

    
3844
                } else {
3845
                  xdmValue_object * vobj = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3846
                  assert (vobj != NULL);
3847
                  vobj->xdmValue = node;
3848
                  return;
3849
                }
3850
            }
3851
        }
3852
        xpathProcessor->checkException();//TODO
3853
    } 
3854
    RETURN_NULL();
3855
    
3856
}
3857

    
3858
PHP_METHOD(XPathProcessor, evaluateSingle)
3859
{
3860

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

    
3872
    if(xpathStr == NULL) { 
3873
        RETURN_NULL();        
3874
        return;
3875
        }
3876

    
3877

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

    
3894
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
3895

    
3896
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3897
                assert (vobj != NULL);
3898
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
3899
                return;
3900

    
3901
                } else {
3902
                        xdmItem_object * vobj = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
3903
                        assert (vobj != NULL);
3904
                        vobj->xdmItem = node;
3905
                        return;
3906
                }
3907
            }
3908
        } 
3909
        xpathProcessor->checkException();//TODO
3910
    } 
3911
    RETURN_NULL();
3912
}
3913

    
3914
PHP_METHOD(XPathProcessor, setContextItem)
3915
{
3916

    
3917
   XPathProcessor *xpathProcessor;
3918

    
3919
   zval* oth;
3920
        //TODO this should be relaxed to accept item/atomic/node as well as Value
3921

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

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

    
3969
      }
3970
    }
3971
}
3972

    
3973
PHP_METHOD(XPathProcessor, setBaseURI)
3974
{
3975

    
3976
   XPathProcessor *xpathProcessor;
3977

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

    
3997
PHP_METHOD(XPathProcessor, setContextFile)
3998
{
3999

    
4000
   XPathProcessor *xpathProcessor;
4001

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

    
4021
PHP_METHOD(XPathProcessor, clearParameters)
4022
{
4023
    XPathProcessor *xpathProcessor;
4024
    if (ZEND_NUM_ARGS()>0) {
4025
        WRONG_PARAM_COUNT;
4026
    }
4027

    
4028
    zend_object* pobj = Z_OBJ_P(getThis()); 
4029
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4030
    xpathProcessor = obj->xpathProcessor;
4031
    if (xpathProcessor != NULL) {
4032
        xpathProcessor->clearParameters(true);
4033
    }
4034
}
4035

    
4036
PHP_METHOD(XPathProcessor, clearProperties)
4037
{
4038
     XPathProcessor *xpathProcessor;
4039
    if (ZEND_NUM_ARGS()>0) {
4040
        WRONG_PARAM_COUNT;
4041
    }
4042

    
4043
    zend_object* pobj = Z_OBJ_P(getThis()); 
4044
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4045
    xpathProcessor = obj->xpathProcessor;
4046
    if (xpathProcessor != NULL) {
4047
        xpathProcessor->clearProperties();
4048
    }
4049
}
4050

    
4051

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

    
4061
    xpathProcessor = obj->xpathProcessor;
4062
    if (xpathProcessor != NULL) {
4063
        bool result = xpathProcessor->exceptionOccurred();
4064
        RETURN_BOOL(result);
4065
    }
4066
    RETURN_BOOL(false);
4067
}
4068

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

    
4078
    xpathProcessor = obj->xpathProcessor;
4079
    if (xpathProcessor != NULL) {
4080
        int count = xpathProcessor->exceptionCount();
4081
        RETURN_LONG(count);
4082
    }
4083
    RETURN_LONG(0);
4084
}
4085

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

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

    
4136
/*     ============== PHP Interface of   SchemaValidator =============== */
4137

    
4138
void schemaValidator_free_storage(zend_object *object)
4139
{
4140
    zend_object_std_dtor(object);
4141
}
4142

    
4143
void schemaValidator_destroy_storage(zend_object *object)
4144
{
4145
    zend_objects_destroy_object(object);
4146
}
4147

    
4148
zend_object *schemaValidator_create_handler(zend_class_entry *type)
4149
{
4150
    zval *tmp;
4151
    zend_object retval;
4152
    schemaValidator_object *obj = (schemaValidator_object *)ecalloc(1, sizeof(schemaValidator_object)+ zend_object_properties_size(type));
4153

    
4154
    zend_object_std_init(&obj->std, type);    
4155
    object_properties_init(&obj->std, type);
4156

    
4157
    obj->std.handlers = &schemaValidator_object_handlers;
4158

    
4159
    return &obj->std;
4160
}
4161

    
4162

    
4163

    
4164
PHP_METHOD(SchemaValidator, __destruct)
4165
{
4166
    zend_object* pobj = Z_OBJ_P(getThis()); 
4167
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4168

    
4169

    
4170
    SchemaValidator * schemaValidator= obj->schemaValidator;
4171
    if(schemaValidator != NULL) {
4172
            delete schemaValidator;
4173
    }
4174
    
4175
}
4176

    
4177

    
4178

    
4179
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
4180
{
4181
    SchemaValidator *schemaValidator;
4182
    char * name;
4183
    size_t len1;
4184

    
4185
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
4186
        RETURN_NULL();
4187
    }
4188
    zend_object* pobj = Z_OBJ_P(getThis()); 
4189
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4190
    schemaValidator = obj->schemaValidator;
4191
    if (name != NULL && schemaValidator != NULL) {
4192
        schemaValidator->registerSchemaFromFile(name);
4193
    }
4194
}
4195

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

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

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

    
4265

    
4266
PHP_METHOD(SchemaValidator, getValidationReport)
4267
{
4268

    
4269
    SchemaValidator *schemaValidator;
4270
    if (ZEND_NUM_ARGS()>0) {
4271
        WRONG_PARAM_COUNT;
4272
    }
4273

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

    
4296

    
4297
PHP_METHOD(SchemaValidator, setSourceNode)
4298
{
4299
    SchemaValidator *schemaValidator;
4300

    
4301
    zval* oth;
4302
   
4303

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

    
4320
            }
4321
        }
4322
      
4323
        
4324
      }
4325
    }
4326
}
4327

    
4328
PHP_METHOD(SchemaValidator, setOutputFile)
4329
{
4330
    SchemaValidator *schemaValidator;
4331
    char * name;
4332
    int len1;
4333

    
4334
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4335
        RETURN_NULL();
4336
    }
4337
    zend_object* pobj = Z_OBJ_P(getThis()); 
4338
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4339
    schemaValidator = obj->schemaValidator;
4340
    if (schemaValidator != NULL) {
4341
        schemaValidator->setOutputFile(name);
4342
    }
4343
}
4344

    
4345

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

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

    
4363

    
4364
PHP_METHOD(SchemaValidator, setProperty)
4365
{
4366
    SchemaValidator *schemaValidator;
4367
    char * name;
4368
    char * value;
4369
    size_t len1, len2, myint;
4370

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

    
4382
PHP_METHOD(SchemaValidator, setParameter)
4383
{
4384

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

    
4399
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
4400
        zend_object * nobj = Z_OBJ_P(oth);
4401

    
4402
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
4403
        if(ooth != NULL) {
4404
            XdmNode * value = ooth->xdmNode;
4405
            if(value != NULL) {        
4406
                schemaValidator->setParameter(name, (XdmValue *)value);
4407

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

    
4421

    
4422

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

    
4434

    
4435

    
4436
      }
4437

    
4438
    }
4439
}
4440

    
4441
PHP_METHOD(SchemaValidator, clearProperties)
4442
{
4443
    SchemaValidator *schemaValidator;
4444
    if (ZEND_NUM_ARGS()>0) {
4445
        WRONG_PARAM_COUNT;
4446
    }
4447

    
4448
    zend_object* pobj = Z_OBJ_P(getThis()); 
4449
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4450
    schemaValidator = obj->schemaValidator;
4451
    if (schemaValidator != NULL) {
4452
        schemaValidator->clearProperties();
4453
        schemaValidator->exceptionClear();
4454
    }
4455
}
4456

    
4457
PHP_METHOD(SchemaValidator, clearParameters)
4458
{
4459

    
4460
   SchemaValidator *schemaValidator;
4461
    if (ZEND_NUM_ARGS()>0) {
4462
        WRONG_PARAM_COUNT;
4463
    }
4464
    zend_object* pobj = Z_OBJ_P(getThis()); 
4465
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4466
    schemaValidator = obj->schemaValidator;
4467
    if (schemaValidator != NULL) {
4468
       
4469
                schemaValidator->clearParameters(true);
4470
                schemaValidator->exceptionClear();
4471
        }
4472
    }
4473

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

    
4490
PHP_METHOD(SchemaValidator, getExceptionCount)
4491
{
4492
    SchemaValidator *schemaValidator;
4493

    
4494
    if (ZEND_NUM_ARGS()>0) {
4495
        WRONG_PARAM_COUNT;
4496
    }
4497
    zend_object* pobj = Z_OBJ_P(getThis()); 
4498
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4499
    schemaValidator = obj->schemaValidator;
4500
    if (schemaValidator != NULL) {
4501
        int count = schemaValidator->exceptionCount();
4502
        RETURN_LONG(count);
4503
    }
4504
    RETURN_LONG(0);
4505
}
4506

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

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

    
4557
/*     ============== PHP Interface of   XdmValue =============== */
4558
void xdmValue_free_storage(zend_object *object)
4559
{
4560
    zend_object_std_dtor(object);
4561
}
4562

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

    
4573
    return &obj->std;
4574
}
4575

    
4576
void XdmValue_destroy_storage(zend_object *object)
4577
{
4578
    zend_objects_destroy_object(object);
4579
}
4580

    
4581
PHP_METHOD(XdmValue, __construct)
4582
{
4583
    XdmValue *xdmValue = NULL;
4584
    bool bVal;
4585
    char * sVal;
4586
    int len;
4587
    long iVal;
4588
    double dVal;
4589
    zval *zvalue;
4590

    
4591

    
4592

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

    
4637
PHP_METHOD(XdmValue, __destruct)
4638
{
4639

    
4640
     zend_object *oobj = Z_OBJ_P(getThis());
4641
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4642
    XdmValue * xdmValue= obj->xdmValue;
4643
   if(xdmValue != NULL) {
4644
            xdmValue->decrementRefCount();
4645
            if(xdmValue!= NULL && xdmValue->getRefCount()< 1){
4646
                    delete xdmValue;
4647
            } 
4648
    }
4649
}
4650

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

    
4664
                   }
4665
                 }else {
4666
                      _RETURN_STRING("");
4667
              }
4668
    }
4669

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

    
4697

    
4698
PHP_METHOD(XdmValue,  itemAt){
4699
    XdmValue *xdmValue;
4700

    
4701
    long index;
4702
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
4703
        RETURN_NULL();
4704
    }
4705

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

    
4731

    
4732
PHP_METHOD(XdmValue,  size){
4733
    XdmValue *xdmValue;
4734
    zend_object *oobj = Z_OBJ_P(getThis());
4735
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4736
    xdmValue = obj->xdmValue;
4737
    int sizei = 0;
4738
    if (xdmValue != NULL) {
4739
        sizei = xdmValue->size();
4740
    }
4741
     RETURN_LONG(sizei);
4742
}
4743

    
4744

    
4745
PHP_METHOD(XdmValue, addXdmItem){
4746
    XdmValue *xdmValue;
4747
    zval* oth;
4748
           
4749
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
4750
        RETURN_NULL();
4751
    }
4752

    
4753
    xdmValue_object *obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4754
    xdmValue = obj->xdmValue;
4755
    if (xdmValue != NULL) {
4756
     const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
4757
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
4758

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

    
4780

    
4781

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

    
4793
      } else {
4794
                //TODO exception
4795
        }
4796
    }
4797
}
4798

    
4799

    
4800

    
4801
/*     ============== PHP Interface of   XdmItem =============== */
4802

    
4803
void xdmItem_free_storage(zend_object *object)
4804
{
4805
    zend_object_std_dtor(object);
4806
}
4807

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

    
4819
    return &obj->std;
4820
}
4821

    
4822
PHP_METHOD(XdmItem, __construct)
4823
{
4824
    XdmItem *xdmItem = NULL;
4825
    bool bVal;
4826
    char * sVal;
4827
    int len;
4828
    long iVal;
4829
    double dVal;
4830
    zval *zvalue;
4831

    
4832
    SaxonProcessor *proc= NULL;
4833
    
4834
   zval *object = getThis();
4835
   
4836
    zend_object * zobj = Z_OBJ_P(object);
4837

    
4838
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4839
    //saxonProc =  obj->saxonProcessor;
4840
 
4841
}
4842

    
4843
void XdmItem_destroy_storage(zend_object *object)
4844
{
4845
    zend_objects_destroy_object(object);
4846
    
4847
}
4848

    
4849
PHP_METHOD(XdmItem, __destruct)
4850
{
4851
     zval *object = getThis();
4852
     zend_object * zobj = Z_OBJ_P(object);
4853

    
4854
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4855

    
4856
    XdmItem * xdmItem= obj->xdmItem;
4857
    xdmItem->decrementRefCount();
4858
    if(xdmItem != NULL && xdmItem->getRefCount()< 1){
4859
            delete xdmItem;
4860
    }
4861
    
4862
}
4863

    
4864
PHP_METHOD(XdmItem, getStringValue)
4865
{
4866
    XdmItem *xdmItem;
4867
     zval *object = getThis();
4868
    zend_object * zobj = Z_OBJ_P(object);
4869
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4870
    xdmItem = obj->xdmItem;
4871

    
4872
    if (xdmItem != NULL) {
4873
        const char * valueStr = xdmItem->getStringValue();
4874
        if(valueStr != NULL) {
4875
            _RETURN_STRING(valueStr);
4876
        }
4877
    }
4878
    RETURN_NULL();
4879
}
4880

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

    
4896
                   }
4897
                 }else {
4898
                      _RETURN_STRING("");
4899
              }
4900
    }
4901

    
4902
PHP_METHOD(XdmItem, isAtomic)
4903
{
4904
    XdmItem *xdmItem;
4905
    zend_object * zobj = Z_OBJ_P(getThis());
4906
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4907
    xdmItem = obj->xdmItem;
4908

    
4909
    if (xdmItem != NULL) {
4910
        bool isAtomic = xdmItem->isAtomic();
4911
        RETURN_BOOL(isAtomic);
4912
    }
4913
    RETURN_BOOL(false);
4914
}
4915

    
4916
PHP_METHOD(XdmItem, isNode)
4917
{
4918
    XdmItem *xdmItem;
4919
    zend_object * zobj = Z_OBJ_P(getThis());
4920
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4921
    xdmItem = obj->xdmItem;
4922

    
4923
    if (xdmItem != NULL && xdmItem->getType() == XDM_NODE) {
4924
        RETURN_TRUE;
4925
    }
4926
    RETURN_FALSE;
4927
}
4928

    
4929
PHP_METHOD(XdmItem, getAtomicValue)
4930
{
4931
    XdmItem *xdmItem;
4932
    zend_object * zobj = Z_OBJ_P(getThis());
4933
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4934
    xdmItem = obj->xdmItem;
4935

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

    
4958
PHP_METHOD(XdmItem, getNodeValue)
4959
{
4960
    XdmItem *xdmItem;
4961
    zend_object * zobj = Z_OBJ_P(getThis());
4962
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4963
    xdmItem = obj->xdmItem;
4964

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

    
4981
                return;
4982
            }
4983
    }
4984
    RETURN_NULL();
4985
}
4986

    
4987

    
4988

    
4989
/*     ============== PHP Interface of   XdmNode =============== */
4990

    
4991
void xdmNode_free_storage(zend_object *object)
4992
{
4993
   zend_object_std_dtor(object);
4994

    
4995
    
4996
}
4997

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

    
5010
PHP_METHOD(XdmNode, __construct)
5011
{
5012
    //xdmNode_object *obj = (xdmNode_object *) Z_OBJ_P(getThis() TSRMLS_CC);
5013
}
5014

    
5015
void XdmNode_destroy_storage(zend_object *object)
5016
{
5017
 
5018
 zend_objects_destroy_object(object);
5019
   
5020
}
5021

    
5022
PHP_METHOD(XdmNode, __destruct)
5023
{
5024
    zval *object = getThis();
5025
     zend_object * zobj = Z_OBJ_P(object);
5026

    
5027
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
5028