Project

Profile

Help

Bug #4371 ยป php7_saxon.cpp

O'Neil Delpratt, 2020-05-12 15:49

 
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
    saxonProcessor_object *obj;
47
        
48
        obj =  (saxonProcessor_object *)((char *)object - XtOffsetOf(saxonProcessor_object, std));
49

    
50
 SaxonProcessor * saxonProc= obj->saxonProcessor;
51
    if(saxonProc != NULL) {    
52
        delete saxonProc;
53
    }
54
 zend_object_std_dtor(object);
55

    
56
   // efree(obj);
57
}
58

    
59
void SaxonProcessor_destroy_storage(zend_object *pobj)
60
{
61

    
62
        //php_error(E_WARNING,"_destroy_Storage called php-saxonProc");
63
          //  saxonProcessor_object *obj;
64
        //zend_object* pobj = Z_OBJ_P(getThis()); 
65
 /*  saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
66

67
    SaxonProcessor * saxonProc= obj->saxonProcessor;
68
    if(saxonProc != NULL) {
69
        SaxonProcessor::release();    
70
        delete saxonProc;
71
    }*/
72
        
73
    zend_objects_destroy_object(pobj);
74

    
75
    
76
}
77

    
78
zend_object *saxonProcessor_create_handler(zend_class_entry *type)
79
{
80
    zval *tmp;
81
    zend_object retval;
82
    saxonProcessor_object *obj = (saxonProcessor_object *)ecalloc(1, sizeof(saxonProcessor_object) + zend_object_properties_size(type));
83
 
84

    
85
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
86
    object_properties_init(&obj->std, type);
87

    
88
    obj->std.handlers = &saxonProcessor_object_handlers;
89

    
90
    return &obj->std;
91
}
92

    
93
PHP_METHOD(SaxonProcessor, __construct)
94
{
95
    if (ZEND_NUM_ARGS()>2) {
96
        WRONG_PARAM_COUNT;
97
    }
98

    
99
    char * cwdi = NULL;
100
   bool license = false;
101
    size_t len1;
102
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS(), "b", &license) == FAILURE) {
103
        RETURN_NULL();
104
    } 
105

    
106

    
107
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS(), "bs", &license, &cwdi, &len1) == FAILURE) {
108
        RETURN_NULL();
109
    }
110

    
111

    
112
    zval *object = getThis();
113
    SaxonProcessor * saxonProc = NULL;
114
    zend_object * zobj = Z_OBJ_P(object);
115

    
116
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)zobj - XtOffsetOf(saxonProcessor_object, std));
117

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

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

    
135
            char* cwd2;
136

    
137
            //php_error(E_WARNING,cwd2);
138

    
139
            saxonProc->setcwd(cwd);
140
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
141
#else
142
            char cwd[256];
143

    
144
            VCWD_GETCWD(cwd, sizeof(cwd));
145
            if(cwd == NULL) {
146
             //php_error(E_WARNING,"cwd is nullXXXXXXXXXXXXXXXXXXXXXXX");
147
           }else {
148
           //  php_error(E_WARNING,cwd);
149
 
150
            saxonProc->setcwd(cwd);
151

    
152
          }
153
#endif
154

    
155
    } else {
156
        saxonProc->setcwd(cwdi);
157
    }
158

    
159
}
160

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

    
168
    SaxonProcessor * saxonProc= obj->saxonProcessor;
169
    if(saxonProc != NULL) {
170
        //SaxonProcessor::release();    
171
        //delete saxonProc;
172
    }
173
}
174

    
175

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

    
183
    SaxonProcessor * saxonProc= obj->saxonProcessor;
184
    if(saxonProc != NULL) {
185
        SaxonProcessor::release();    
186
    }
187
}
188

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

    
210

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

    
225
                RETURN_TRUE;
226
         }
227
    }
228
    RETURN_FALSE;
229
}
230

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

    
253

    
254

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

    
276

    
277
PHP_METHOD(SaxonProcessor, parseXmlFromString)
278
{
279
    SaxonProcessor * saxonProcessor;
280
    char * source;
281
    size_t len1;
282

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

    
311
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
312
{
313
    SaxonProcessor * saxonProcessor;
314
    char * source;
315
    size_t len1;
316

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

    
348

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

    
424

    
425
PHP_METHOD(SaxonProcessor, newXPathProcessor)
426
{
427
   
428
    if (ZEND_NUM_ARGS()>0) {
429
        WRONG_PARAM_COUNT;
430
    }
431
    SaxonProcessor * proc;
432
    XPathProcessor * xpathProcessor = NULL;
433

    
434
    zend_object* pobj = Z_OBJ_P(getThis()); 
435
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
436

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

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

    
467
      zend_object* pobj = Z_OBJ_P(getThis()); 
468
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
469

    
470
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
471
    assert (obj != NULL);
472
    proc = obj->saxonProcessor;
473

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

    
486
    }
487
    } else {
488
       
489
        RETURN_NULL();
490
    }
491
}
492

    
493

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

    
504
      zend_object* pobj = Z_OBJ_P(getThis());
505
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
506

    
507
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
508
    assert (obj != NULL);
509
    proc = obj->saxonProcessor;
510

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

    
521
            xproc_object->xslt30Processor = xslt30Processor;
522

    
523
    }
524
    } else {
525

    
526
        RETURN_NULL();
527
    }
528
}
529

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

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

    
594

    
595
PHP_METHOD(SaxonProcessor, version)
596
{
597
    SaxonProcessor *saxonProcessor;
598

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

    
615

    
616

    
617
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
618
{
619
    SaxonProcessor *saxonProcessor;
620
    char * name;
621
    char * value;
622
    size_t len1, len2;
623
    if (ZEND_NUM_ARGS()!= 2) {
624
        WRONG_PARAM_COUNT;
625
    }
626

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

    
633
    saxonProcessor = obj->saxonProcessor;
634
    if (saxonProcessor != NULL && name != NULL && value != NULL) {
635
        saxonProcessor->setConfigurationProperty(name, value);
636
    }
637
    
638
}
639

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

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

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

    
666
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
667

    
668
void XsltProcessor_free_storage(zend_object *object)
669
{
670

    
671
    zend_object_std_dtor(object);
672
}
673

    
674
void XsltProcessor_destroy_storage(zend_object *object)
675
{
676
    xsltProcessor_object *obj;
677

    
678
    zend_objects_destroy_object(object);
679
}
680

    
681
zend_object * xsltProcessor_create_handler(zend_class_entry *type)
682
{
683
   
684

    
685
    xsltProcessor_object *obj = (xsltProcessor_object *)ecalloc(1, sizeof(xsltProcessor_object)+ zend_object_properties_size(type));
686
   
687
    
688
   zend_object_std_init(&obj->std,type);
689
    object_properties_init(&obj->std, type);
690
    
691
    obj->std.handlers = &xsltProcessor_object_handlers;
692

    
693
    return &obj->std;
694
}
695

    
696

    
697

    
698
PHP_METHOD(XsltProcessor, __destruct)
699
{
700

    
701
    zend_object* pobj = Z_OBJ_P(getThis()); 
702
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
703

    
704

    
705
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
706
    if(xsltProcessor != NULL){
707
            delete xsltProcessor;
708
     }
709
 
710
    
711
}
712

    
713
PHP_METHOD(XsltProcessor, transformFileToFile)
714
{
715
    XsltProcessor *xsltProcessor;
716
    char * outfileName;
717
    char * infilename;
718
    char * styleFileName;
719
    size_t len1, len2, len3;
720

    
721
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
722
        RETURN_NULL();
723
    }
724

    
725
    zend_object* pobj = Z_OBJ_P(getThis()); 
726
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
727
    xsltProcessor = obj->xsltProcessor;
728
 
729
    if (xsltProcessor != NULL) {
730

    
731
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
732
        if(xsltProcessor->exceptionOccurred()) {
733
               // TODO: throw exception
734
        }
735
    }
736
}
737

    
738
PHP_METHOD(XsltProcessor, transformFileToValue)
739
{
740
    XsltProcessor *xsltProcessor;
741
    char * infilename;
742
    char * styleFileName;
743
   size_t len1, len2;
744

    
745
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
746
        RETURN_NULL();
747
    }
748

    
749
    zend_object* pobj = Z_OBJ_P(getThis()); 
750
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
751
    xsltProcessor = obj->xsltProcessor;
752
    
753
    if (xsltProcessor != NULL) {
754

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

    
776

    
777
PHP_METHOD(XsltProcessor, transformFileToString)
778
{
779
    XsltProcessor *xsltProcessor;
780
    char * infilename;
781
    char * styleFileName;
782
    size_t len1, len2;
783

    
784
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
785
        RETURN_NULL();
786
    }
787

    
788
    zend_object* pobj = Z_OBJ_P(getThis()); 
789
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
790
    xsltProcessor = obj->xsltProcessor;
791

    
792
    if (xsltProcessor != NULL) {
793

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

    
811
/*enum saxonTypeEnum
812
{
813
        enumNode,
814
        enumString,
815
        enumInteger,
816
        enumDouble,
817
        enumFloat,
818
        enumBool,
819
        enumArrXdmValue
820
};*/
821

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

    
864
        for(int i=0; i<argLength;i++){
865

    
866
                jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
867
                jobject argObj = senv->GetObjectArrayElement(arguments, i);
868

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

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

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

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

    
943
}
944

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

    
954
                params[i] = *php_argv[i]._val; }
955

    
956
        //std::cerr<<"phpNative called cp3-1"<<std::endl;
957
        //note: no implicit type conversion.
958

    
959
        zval *argvv = NULL;//xparams;
960
        zval* callOnObj = NULL;
961
        //MAKE_STD_ZVAL(function_name);
962
        //nativeString[nativeStrLen] = '\0';
963

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

    
971
        if(Z_TYPE(retval) ==0){
972
                zend_error(E_ERROR, "Function returned null");
973
        }
974

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

    
1014
                      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1015
                
1016
                        zend_vobj2 =  Z_OBJ_P(&retval);
1017
                        ooth = (xdmNode_object *)((char *)zend_vobj2 - XtOffsetOf(xdmNode_object, std));
1018

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

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

    
1041

    
1042

    
1043
PHP_METHOD(XsltProcessor, transformToString)
1044
{
1045
    XsltProcessor *xsltProcessor;
1046
 
1047
    if (ZEND_NUM_ARGS()>0) {
1048
        WRONG_PARAM_COUNT;
1049
    }
1050

    
1051

    
1052
    zend_object* pobj = Z_OBJ_P(getThis()); 
1053
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1054
    xsltProcessor = obj->xsltProcessor;
1055
    if (xsltProcessor != NULL) {
1056

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

    
1074
PHP_METHOD(XsltProcessor, transformToValue)
1075
{
1076
    XsltProcessor *xsltProcessor;
1077

    
1078
    if (ZEND_NUM_ARGS()>0) {
1079
        WRONG_PARAM_COUNT;
1080
    }
1081

    
1082
    zend_object* pobj = Z_OBJ_P(getThis()); 
1083
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1084
    xsltProcessor = obj->xsltProcessor;
1085

    
1086
    if (xsltProcessor != NULL) {
1087

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

    
1108
PHP_METHOD(XsltProcessor, transformToFile)
1109
{
1110
    XsltProcessor *xsltProcessor;
1111
 
1112
    if (ZEND_NUM_ARGS()>0) {
1113
        WRONG_PARAM_COUNT;
1114
    }
1115

    
1116
    zend_object* pobj = Z_OBJ_P(getThis()); 
1117
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1118
    xsltProcessor = obj->xsltProcessor;
1119

    
1120
    if (xsltProcessor != NULL) {
1121

    
1122
        xsltProcessor->transformToFile();
1123
        if(xsltProcessor->exceptionOccurred()) {
1124
           //TODO
1125
            const char * exStr = xsltProcessor->checkException();
1126
        }
1127
    } else {
1128
        RETURN_NULL();
1129
    }
1130
}
1131

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

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

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

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

    
1198

    
1199

    
1200
PHP_METHOD(XsltProcessor, compileFromValue)
1201
{
1202
    XsltProcessor *xsltProcessor;
1203
   zval* oth;
1204

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

    
1223

    
1224

    
1225

    
1226
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1227
{
1228
    XsltProcessor *xsltProcessor;
1229
    zval* oth = NULL;
1230

    
1231
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1232
        RETURN_NULL();
1233
    }
1234

    
1235
    zend_object* pobj = Z_OBJ_P(getThis()); 
1236
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1237
    xsltProcessor = obj->xsltProcessor;
1238
    if (xsltProcessor != NULL) {
1239

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

    
1252
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1253
        zend_object * nobj = Z_OBJ_P(oth);
1254

    
1255
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1256
        if(ooth != NULL) {
1257
            XdmNode * value = ooth->xdmNode;
1258
            if(value != NULL) {        
1259
                
1260
                xsltProcessor->setSourceFromXdmNode(value);
1261

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

    
1275
        
1276
    }
1277
  }
1278
}
1279

    
1280

    
1281
PHP_METHOD(XsltProcessor, setJustInTimeCompilation)
1282
{
1283
    XsltProcessor *xsltProcessor;
1284
    bool jit = false;
1285
    size_t len1;
1286

    
1287
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
1288
        RETURN_NULL();
1289
    }
1290

    
1291
    zend_object* pobj = Z_OBJ_P(getThis());
1292
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1293
    xsltProcessor = obj->xsltProcessor;
1294
    if (xsltProcessor != NULL) {
1295
         xsltProcessor->setJustInTimeCompilation(jit);
1296
    }
1297
}
1298

    
1299
PHP_METHOD(XsltProcessor, setOutputFile)
1300
{
1301
    XsltProcessor *xsltProcessor;
1302
    char * outputFilename;
1303
    size_t len1;
1304

    
1305
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
1306
        RETURN_NULL();
1307
    }
1308

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

    
1320
int size_t2int(size_t val) {
1321
    return (val <= INT_MAX) ? (int)((ssize_t)val) : -1;
1322
}
1323

    
1324
PHP_METHOD(XsltProcessor, setSourceFromFile)
1325
{
1326
    XsltProcessor *xsltProcessor;
1327
    char * inFilename;
1328
    size_t len1;
1329
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
1330
        RETURN_NULL();
1331
    }
1332

    
1333
    zend_object* pobj = Z_OBJ_P(getThis()); 
1334
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1335
    xsltProcessor = obj->xsltProcessor;
1336
    if (xsltProcessor != NULL && inFilename != NULL) {
1337
         xsltProcessor->setSourceFromFile(inFilename);
1338
            
1339
        
1340
    }
1341
}
1342

    
1343

    
1344
PHP_METHOD(XsltProcessor, setProperty)
1345
{
1346
    XsltProcessor *xsltProcessor;
1347
    char * name;
1348
    char * value;
1349
    size_t len1, len2, myint;
1350

    
1351
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
1352
        RETURN_NULL();
1353
    }
1354
    zend_object* pobj = Z_OBJ_P(getThis()); 
1355
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1356
    xsltProcessor = obj->xsltProcessor;
1357
    if (xsltProcessor != NULL) {
1358
        xsltProcessor->setProperty(name, value);
1359
    }
1360
}
1361

    
1362
PHP_METHOD(XsltProcessor, setParameter)
1363
{
1364

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

    
1381
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1382
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1383

    
1384
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1385
        zend_object* ooth = Z_OBJ_P(oth);
1386
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1387
        if(nobj != NULL) {
1388
            XdmNode * value = nobj->xdmNode;
1389
            if(value != NULL) {        
1390
                xsltProcessor->setParameter(name, (XdmValue *)value);
1391

    
1392
            }
1393
        }
1394
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1395
        zend_object* ooth = Z_OBJ_P(oth);
1396
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1397
        if(vobj != NULL) {
1398
            XdmValue * value = vobj->xdmValue;
1399
            if(value != NULL) {
1400
                
1401
                xsltProcessor->setParameter(name, value);
1402
            }
1403
        }
1404

    
1405

    
1406

    
1407
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1408
        zend_object* ooth = Z_OBJ_P(oth);
1409
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1410
        if(aobj != NULL) {
1411
            XdmAtomicValue * value = aobj->xdmAtomicValue;
1412
            if(value != NULL) {
1413
                xsltProcessor->setParameter(name, (XdmValue *)value);
1414
            }
1415
        }
1416

    
1417

    
1418

    
1419
      }
1420

    
1421
    }
1422
}
1423

    
1424
PHP_METHOD(XsltProcessor, clearParameters)
1425
{
1426
    XsltProcessor *xsltProcessor;
1427
    if (ZEND_NUM_ARGS()>0) {
1428
        WRONG_PARAM_COUNT;
1429
    }
1430

    
1431
    zend_object* pobj = Z_OBJ_P(getThis()); 
1432
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1433
    xsltProcessor = obj->xsltProcessor;
1434
    if (xsltProcessor != NULL) {
1435
        xsltProcessor->clearParameters(true);
1436
    }
1437
}
1438

    
1439
PHP_METHOD(XsltProcessor, clearProperties)
1440
{
1441
    XsltProcessor *xsltProcessor;
1442
    if (ZEND_NUM_ARGS()>0) {
1443
        WRONG_PARAM_COUNT;
1444
    }
1445

    
1446
    zend_object* pobj = Z_OBJ_P(getThis()); 
1447
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1448
    xsltProcessor = obj->xsltProcessor;
1449
    if (xsltProcessor != NULL) {
1450
        xsltProcessor->clearProperties();
1451
    }
1452
}
1453

    
1454

    
1455

    
1456
PHP_METHOD(XsltProcessor, getXslMessages)
1457
{
1458
    XsltProcessor *xsltProcessor;
1459

    
1460
    if (ZEND_NUM_ARGS()>0) {
1461
        WRONG_PARAM_COUNT;
1462
    }
1463

    
1464
    zend_object* pobj = Z_OBJ_P(getThis());
1465
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1466
    xsltProcessor = obj->xsltProcessor;
1467

    
1468
    if (xsltProcessor != NULL) {
1469

    
1470
        XdmValue * values = xsltProcessor->getXslMessages();
1471
        if(values != NULL) {
1472
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1473
                RETURN_NULL();
1474
            } else {
1475
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value);
1476
                zend_object *vvobj =  Z_OBJ_P(return_value);
1477
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1478

    
1479

    
1480
                assert (vobj != NULL);
1481
                vobj->xdmValue = values;
1482
            }
1483
        } else if(xsltProcessor->exceptionOccurred()){
1484
            xsltProcessor->checkException();
1485
            RETURN_NULL();
1486
        }
1487
    } else {
1488
        RETURN_NULL();
1489
    }
1490
}
1491

    
1492

    
1493

    
1494
PHP_METHOD(XsltProcessor, exceptionOccurred)
1495
{
1496
    XsltProcessor *xsltProcessor;
1497
    zend_object* pobj = Z_OBJ_P(getThis()); 
1498
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1499
    if (ZEND_NUM_ARGS()>0) {
1500
        WRONG_PARAM_COUNT;
1501
    }
1502

    
1503
    xsltProcessor = obj->xsltProcessor;
1504
    if (xsltProcessor != NULL) {
1505
        bool result = xsltProcessor->exceptionOccurred();
1506
        RETURN_BOOL(result);
1507
    }
1508
    RETURN_BOOL(false);
1509
}
1510

    
1511
PHP_METHOD(XsltProcessor, getExceptionCount)
1512
{
1513
    XsltProcessor *xsltProcessor;
1514
    zend_object* pobj = Z_OBJ_P(getThis()); 
1515
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1516
    if (ZEND_NUM_ARGS()>0) {
1517
        WRONG_PARAM_COUNT;
1518
    }
1519

    
1520
    xsltProcessor = obj->xsltProcessor;
1521
    if (xsltProcessor != NULL) {
1522
        int count = xsltProcessor->exceptionCount();
1523
        RETURN_LONG(count);
1524
    }
1525
    RETURN_LONG(0);
1526
}
1527

    
1528
PHP_METHOD(XsltProcessor, getErrorCode)
1529
{
1530
    XsltProcessor *xsltProcessor;
1531
    long index;
1532
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1533
        RETURN_NULL();
1534
    }
1535
    zend_object* pobj = Z_OBJ_P(getThis()); 
1536
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1537
    xsltProcessor = obj->xsltProcessor;
1538
    if (xsltProcessor != NULL) {
1539
        const char * errCode = xsltProcessor->getErrorCode((int)index);
1540
        if(errCode != NULL) {
1541
            //char *str = estrdup(errCode);
1542
            _RETURN_STRING(errCode);
1543
        }
1544
    }
1545
    RETURN_NULL();
1546
}
1547

    
1548
PHP_METHOD(XsltProcessor, getErrorMessage)
1549
{
1550
    XsltProcessor *xsltProcessor;
1551
    long index;
1552
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1553
        RETURN_NULL();
1554
    }
1555
    zend_object* pobj = Z_OBJ_P(getThis()); 
1556
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1557
    xsltProcessor = obj->xsltProcessor;
1558
    if (xsltProcessor != NULL) {
1559
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1560
        if(errStr != NULL) {
1561
            //char *str = estrdup(errStr);
1562
            _RETURN_STRING(errStr);
1563
        }
1564
    }
1565
    RETURN_NULL();
1566
}
1567
PHP_METHOD(XsltProcessor, exceptionClear)
1568
{
1569
    XsltProcessor *xsltProcessor;
1570
    zend_object* pobj = Z_OBJ_P(getThis()); 
1571
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1572
    xsltProcessor = obj->xsltProcessor;
1573
    if (xsltProcessor != NULL) {
1574
        xsltProcessor->exceptionClear();
1575
    }
1576
}
1577

    
1578

    
1579

    
1580
/*     ============== XSLT30: PHP Interface of  Xslt30Processor class =============== */
1581

    
1582
void Xslt30Processor_free_storage(zend_object *object)
1583
{
1584

    
1585
    zend_object_std_dtor(object);
1586

    
1587
}
1588

    
1589
void Xslt30Processor_destroy_storage(zend_object *object)
1590
{
1591
    xslt30Processor_object *obj;
1592

    
1593
    zend_objects_destroy_object(object);
1594
}
1595

    
1596
zend_object * xslt30Processor_create_handler(zend_class_entry *type)
1597
{
1598

    
1599

    
1600
    xslt30Processor_object *obj = (xslt30Processor_object *)ecalloc(1, sizeof(xslt30Processor_object)+ zend_object_properties_size(type));
1601

    
1602

    
1603
   zend_object_std_init(&obj->std,type);
1604
    object_properties_init(&obj->std, type);
1605

    
1606
    obj->std.handlers = &xslt30Processor_object_handlers;
1607

    
1608
    return &obj->std;
1609
}
1610

    
1611

    
1612

    
1613
PHP_METHOD(Xslt30Processor, __destruct)
1614
{
1615

    
1616
    zend_object* pobj = Z_OBJ_P(getThis());
1617
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1618

    
1619

    
1620
    Xslt30Processor * xslt30Processor= obj->xslt30Processor;
1621
    if(xslt30Processor != NULL){
1622
            delete xslt30Processor;
1623
     }
1624

    
1625

    
1626
}
1627

    
1628

    
1629

    
1630
PHP_METHOD(Xslt30Processor, callFunctionReturningValue)
1631
{
1632
//arguments: const char * stylesheetFilename, const char* functionName, XdmValue * arguments, int argument_length
1633

    
1634
    Xslt30Processor *xslt30Processor;
1635
    HashTable *arr_hash;
1636
    char* functionName;
1637
    zval * arguments_zval;
1638
    zval * val;
1639
    long num_key;
1640
    XdmValue ** arguments = NULL;
1641
    int argument_length=0;
1642
    zend_string *key;
1643

    
1644
    char * infilename;
1645
    char * styleFileName = NULL;
1646
    size_t len1, len2;
1647

    
1648
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len2, &arguments_zval) == FAILURE) {
1649
        RETURN_NULL();
1650
    } else if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssa", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1651
        RETURN_NULL();
1652
    }
1653

    
1654
    zend_object* pobj = Z_OBJ_P(getThis());
1655
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1656
    xslt30Processor = obj->xslt30Processor;
1657
    arr_hash = Z_ARRVAL_P(arguments_zval);
1658
    argument_length = zend_hash_num_elements(arr_hash);
1659
   
1660
    arguments = new XdmValue*[argument_length];
1661
      
1662
    if (xslt30Processor != NULL) {
1663
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1664
        if(Z_TYPE_P(val) != NULL) {
1665
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1666
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1667
        php_printf("num_key %d =>", num_key);
1668
        php_printf("key %d =>", key);
1669
        */
1670
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1671
                zend_object* ooth = Z_OBJ_P(val);
1672
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1673
                if(nobj != NULL) {
1674
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1675
                            arguments[num_key] = value;
1676
                }
1677
        }
1678
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1679
                zend_object* ooth = Z_OBJ_P(val);
1680
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1681
                if(nobj != NULL) {
1682
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1683
                            arguments[num_key] = value;
1684
                }
1685
        }
1686
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1687
                zend_object* ooth = Z_OBJ_P(val);
1688
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1689
                if(nobj != NULL) {
1690
                            XdmValue * value = nobj->xdmValue;
1691
                            arguments[num_key] = value;
1692
                }
1693
        }
1694
        else {//TODO error warning}
1695
         }}else {
1696
                //TODO error warning
1697
        }
1698
      } ZEND_HASH_FOREACH_END();
1699

    
1700

    
1701
        //php_printf(" argument_length= %d",argument_length);
1702
        XdmValue * result = xslt30Processor->callFunctionReturningValue(styleFileName, functionName, arguments, argument_length);
1703
        if(result != NULL) {
1704
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1705
                RETURN_NULL();
1706
            } else {
1707
                zend_object *ooth =  Z_OBJ_P(return_value);
1708
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
1709
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1710
                assert (vobj != NULL);
1711
                vobj->xdmValue = result;
1712
            }
1713
        } else {
1714
            if(obj->xslt30Processor->exceptionOccurred()){
1715
                  //TODO
1716
            }
1717
            RETURN_NULL();
1718
        }
1719
    }
1720

    
1721

    
1722
}
1723

    
1724
PHP_METHOD(Xslt30Processor, callFunctionReturningString){
1725
    Xslt30Processor *xslt30Processor;
1726
    HashTable *arr_hash;
1727
    char* functionName;
1728
    zval * arguments_zval;
1729
    zval * val;
1730
    long num_key;
1731
    XdmValue ** arguments = NULL;
1732
    int argument_length=0;
1733
    zend_string *key;
1734

    
1735
    char * infilename;
1736
    char * styleFileName = NULL;
1737
    size_t len1, len2;
1738

    
1739
     if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len2, &arguments_zval) == FAILURE) {
1740
        RETURN_NULL();
1741
      }else if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssa", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1742
        RETURN_NULL();
1743
    }
1744

    
1745
    zend_object* pobj = Z_OBJ_P(getThis());
1746
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1747
    xslt30Processor = obj->xslt30Processor;
1748
    arr_hash = Z_ARRVAL_P(arguments_zval);
1749
    argument_length = zend_hash_num_elements(arr_hash);
1750
   
1751
    arguments = new XdmValue*[argument_length];
1752
      
1753
    if (xslt30Processor != NULL) {
1754
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1755
        if(Z_TYPE_P(val) != NULL) {
1756
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1757
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1758
        php_printf("num_key %d =>", num_key);
1759
        php_printf("key %d =>", key);
1760
        */
1761
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1762
                zend_object* ooth = Z_OBJ_P(val);
1763
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1764
                if(nobj != NULL) {
1765
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1766
                            arguments[num_key] = value;
1767
                }
1768
        }
1769
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1770
                zend_object* ooth = Z_OBJ_P(val);
1771
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1772
                if(nobj != NULL) {
1773
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1774
                            arguments[num_key] = value;
1775
                }
1776
        }
1777
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1778
                zend_object* ooth = Z_OBJ_P(val);
1779
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1780
                if(nobj != NULL) {
1781
                            XdmValue * value = nobj->xdmValue;
1782
                            arguments[num_key] = value;
1783
                }
1784
        }
1785
        else {//TODO error warning}
1786
         }}else {
1787
                //TODO error warning
1788
        }
1789
      } ZEND_HASH_FOREACH_END();
1790

    
1791
        const char * result = xslt30Processor->callFunctionReturningString(styleFileName, functionName, arguments, argument_length);
1792
        if(result != NULL) {
1793
            //char *str = estrdup(result);
1794
            _RETURN_STRING(result);
1795
        } else if(xslt30Processor->exceptionOccurred()){
1796
            //TODO: xslt30Processor->checkException();
1797
            const char * errStr = xslt30Processor->getErrorMessage(0);
1798
            if(errStr != NULL) {
1799
                const char * errorCode = xslt30Processor->getErrorCode(0);
1800
                if(errorCode!=NULL) {
1801
                    // TODO: throw exception
1802
                }
1803
            }
1804
        }
1805
    }
1806

    
1807

    
1808

    
1809
}
1810

    
1811

    
1812
    PHP_METHOD(Xslt30Processor, callFunctionReturningFile){
1813
    HashTable *arr_hash;
1814
    Xslt30Processor *xslt30Processor;
1815
    char* functionName;
1816
    zval * arguments_zval;
1817
    zval * val;
1818
    long num_key;
1819
    XdmValue ** arguments = NULL;
1820
    int argument_length=0;
1821
    zend_string *key;
1822

    
1823
    char * outfilename;
1824
    char * styleFileName = NULL;
1825
    size_t len1, len2, len3;
1826

    
1827

    
1828
    if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "sas", &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
1829
        RETURN_NULL();
1830
    } else if (ZEND_NUM_ARGS()==4 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssas", &styleFileName, &len1, &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
1831
        RETURN_NULL();
1832
    }
1833

    
1834
    zend_object* pobj = Z_OBJ_P(getThis());
1835
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1836
    xslt30Processor = obj->xslt30Processor;
1837
    arr_hash = Z_ARRVAL_P(arguments_zval);
1838
    argument_length = zend_hash_num_elements(arr_hash);
1839
   
1840
    arguments = new XdmValue*[argument_length];
1841
      
1842
    if (xslt30Processor != NULL) {
1843
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1844
        if(Z_TYPE_P(val) != NULL) {
1845
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1846
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1847
        php_printf("num_key %d =>", num_key);
1848
        php_printf("key %d =>", key);
1849
        */
1850
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1851
                zend_object* ooth = Z_OBJ_P(val);
1852
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1853
                if(nobj != NULL) {
1854
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1855
                            arguments[num_key] = value;
1856
                }
1857
        }
1858
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1859
                zend_object* ooth = Z_OBJ_P(val);
1860
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1861
                if(nobj != NULL) {
1862
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1863
                            arguments[num_key] = value;
1864
                }
1865
        }
1866
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1867
                zend_object* ooth = Z_OBJ_P(val);
1868
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1869
                if(nobj != NULL) {
1870
                            XdmValue * value = nobj->xdmValue;
1871
                            arguments[num_key] = value;
1872
                }
1873
        }
1874
        else {//TODO error warning}
1875
         }}else {
1876
                //TODO error warning
1877
        }
1878
      } ZEND_HASH_FOREACH_END();
1879

    
1880

    
1881
        xslt30Processor->callFunctionReturningFile(styleFileName, functionName, arguments, argument_length, outfilename);
1882
        if(xslt30Processor->exceptionOccurred()){
1883
            //TODO: xslt30Processor->checkException();
1884
            const char * errStr = xslt30Processor->getErrorMessage(0);
1885
            if(errStr != NULL) {
1886
                const char * errorCode = xslt30Processor->getErrorCode(0);
1887
            }
1888
        }
1889
    }
1890

    
1891
}
1892

    
1893
    PHP_METHOD(Xslt30Processor, callTemplateReturningValue){
1894

    
1895
  Xslt30Processor *xslt30Processor;
1896
    char* templateName = NULL;
1897
   
1898
    char * styleFileName = NULL;
1899
    size_t len1, len2;
1900

    
1901

    
1902
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
1903
        RETURN_NULL();
1904
    } else if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1905
        RETURN_NULL();
1906
    }
1907

    
1908

    
1909
    zend_object* pobj = Z_OBJ_P(getThis());
1910
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1911
    xslt30Processor = obj->xslt30Processor;
1912
      
1913
    if (xslt30Processor != NULL) {
1914
   
1915

    
1916
        //php_printf(" argument_length= %d",argument_length);
1917
        XdmValue * result = xslt30Processor->callTemplateReturningValue(styleFileName, templateName);
1918
        if(result != NULL) {
1919
 
1920
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) { 
1921
               RETURN_NULL();
1922
            } else {
1923
                zend_object *ooth =  Z_OBJ_P(return_value);
1924
              
1925
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1926
                assert (vobj != NULL);
1927
                vobj->xdmValue = result;
1928
                
1929
            }
1930
        } else {
1931
            if(obj->xslt30Processor->exceptionOccurred()){
1932
                  //TODO
1933
            }
1934
            RETURN_NULL();
1935
        }
1936
    }
1937
   }
1938

    
1939

    
1940
    PHP_METHOD(Xslt30Processor, callTemplateReturningString){
1941
    Xslt30Processor *xslt30Processor;
1942
    char* templateName = NULL;
1943
   
1944
    char * styleFileName = NULL;
1945
    size_t len1, len2;
1946

    
1947
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
1948
        RETURN_NULL();
1949
    }
1950

    
1951
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1952
        RETURN_NULL();
1953
    }
1954

    
1955
    zend_object* pobj = Z_OBJ_P(getThis());
1956
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1957
    xslt30Processor = obj->xslt30Processor;
1958
      
1959
    if (xslt30Processor != NULL) {
1960
   
1961

    
1962
        //php_printf(" argument_length= %d",argument_length);
1963
        const char * result = xslt30Processor->callTemplateReturningString(styleFileName, templateName);
1964
        if(result != NULL) {
1965
            _RETURN_STRING(result); 
1966
        } else {
1967
            if(xslt30Processor->exceptionOccurred()){
1968
            xslt30Processor->checkException();
1969
            const char * errStr = xslt30Processor->getErrorMessage(0);
1970
            if(errStr != NULL) {
1971
                const char * errorCode = xslt30Processor->getErrorCode(0);
1972
                if(errorCode!=NULL) {
1973
                    // TODO: throw exception
1974
                }
1975
            }
1976
           }
1977
        }
1978
    }
1979

    
1980
     RETURN_NULL();
1981
    }
1982

    
1983
    PHP_METHOD(Xslt30Processor, callTemplateReturningFile){
1984
   Xslt30Processor *xslt30Processor;
1985
    char* templateName = NULL;
1986
    char * filename = NULL;
1987
    char * styleFileName = NULL;
1988
    size_t len1, len2, len3;
1989

    
1990
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
1991
        RETURN_NULL();
1992
    }
1993

    
1994
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1995
        RETURN_NULL();
1996
    }
1997

    
1998
    zend_object* pobj = Z_OBJ_P(getThis());
1999
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2000
    xslt30Processor = obj->xslt30Processor;
2001
      
2002
    if (xslt30Processor != NULL) {
2003
           xslt30Processor->callTemplateReturningFile(styleFileName, templateName, filename);
2004
    }
2005

    
2006
  }
2007

    
2008

    
2009
PHP_METHOD(Xslt30Processor, applyTemplatesReturningValue){
2010
   Xslt30Processor *xslt30Processor;
2011
    char * styleFileName = NULL;
2012
    size_t len1;
2013

    
2014
    if (ZEND_NUM_ARGS()>0) {
2015

    
2016
      if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &styleFileName, &len1) == FAILURE) {
2017
          RETURN_NULL();
2018
      }
2019
    }
2020

    
2021
    zend_object* pobj = Z_OBJ_P(getThis());
2022
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2023
    xslt30Processor = obj->xslt30Processor;
2024
      
2025
    if (xslt30Processor != NULL) {
2026
           XdmValue * result = xslt30Processor->applyTemplatesReturningValue(styleFileName);
2027
    
2028
        if(result != NULL) {
2029
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2030
                RETURN_NULL();
2031
            } else {
2032
                zend_object *ooth =  Z_OBJ_P(return_value);
2033
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2034
                assert (vobj != NULL);
2035
                vobj->xdmValue = result;
2036
            }
2037
        } else {
2038
            if(obj->xslt30Processor->exceptionOccurred()){
2039
                  //TODO
2040
            }
2041
            RETURN_NULL();
2042
        }
2043

    
2044

    
2045

    
2046
    } else {
2047
     RETURN_NULL();
2048
    }
2049
}
2050

    
2051

    
2052
PHP_METHOD(Xslt30Processor, applyTemplatesReturningString){
2053
 Xslt30Processor *xslt30Processor;
2054

    
2055
    char * styleFileName = NULL;
2056
    size_t len1;
2057

    
2058

    
2059
    if (ZEND_NUM_ARGS()>0) {
2060
    
2061
            if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &styleFileName, &len1) == FAILURE) {
2062
                RETURN_NULL();
2063
            }
2064
    }
2065

    
2066
    zend_object* pobj = Z_OBJ_P(getThis());
2067
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2068
    xslt30Processor = obj->xslt30Processor;
2069
      
2070
    if (xslt30Processor != NULL) {
2071
        const char * result = xslt30Processor->applyTemplatesReturningString(styleFileName);
2072
   
2073
        if(result != NULL) {
2074
            _RETURN_STRING(result); 
2075
        } else {
2076
            if(xslt30Processor->exceptionOccurred()){
2077
            xslt30Processor->checkException();
2078
            const char * errStr = xslt30Processor->getErrorMessage(0);
2079
            if(errStr != NULL) {
2080
                const char * errorCode = xslt30Processor->getErrorCode(0);
2081
                if(errorCode!=NULL) {
2082
                    // TODO: throw exception
2083
                }
2084
            }
2085
           }
2086
        }
2087
    }
2088

    
2089
     RETURN_NULL();
2090
   
2091

    
2092

    
2093
}
2094

    
2095

    
2096

    
2097
PHP_METHOD(Xslt30Processor, applyTemplatesReturningFile){
2098
 Xslt30Processor *xslt30Processor;
2099
    char * filename = NULL;
2100
    char * styleFileName = NULL;
2101
    size_t len1, len2;
2102

    
2103
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &filename, &len2) == FAILURE) {
2104
          RETURN_NULL();
2105
    }
2106

    
2107
   if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &filename, &len2) == FAILURE) {
2108
          RETURN_NULL();
2109
    }
2110
    
2111

    
2112
    zend_object* pobj = Z_OBJ_P(getThis());
2113
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2114
    xslt30Processor = obj->xslt30Processor;
2115
      
2116
    if (xslt30Processor != NULL) {
2117
           xslt30Processor->applyTemplatesReturningFile(styleFileName, filename);
2118
    }
2119

    
2120

    
2121

    
2122
}
2123

    
2124

    
2125
PHP_METHOD(Xslt30Processor, addPackages){
2126
    HashTable *arr_hash;
2127
    Xslt30Processor *xslt30Processor;
2128
    char* functionName = NULL;
2129
    zval * arguments_zval;
2130
    zval * val;
2131
    long num_key;
2132
    const char ** arguments = NULL;
2133
    int argument_length=0;
2134
    zend_string *key;
2135

    
2136
    char * infilename = NULL;
2137
    char * styleFileName = NULL;
2138
    size_t len1, len2;
2139

    
2140
        if (zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
2141
        RETURN_NULL();
2142
    }
2143

    
2144
    zend_object* pobj = Z_OBJ_P(getThis());
2145
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2146
    xslt30Processor = obj->xslt30Processor;
2147
    arr_hash = Z_ARRVAL_P(arguments_zval);
2148
    argument_length = zend_hash_num_elements(arr_hash);
2149
   
2150
    arguments = new const char*[argument_length];
2151

    
2152
  if (xslt30Processor != NULL) {
2153
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
2154
        if(Z_TYPE_P(val) != NULL && Z_TYPE_P(val)== IS_STRING) {
2155
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
2156
        php_printf("num_key %d =>", num_key);
2157
        php_printf("key %d =>", key);
2158
        */
2159
                arguments[num_key] = (const char*)Z_STRVAL_P(val);
2160
                     
2161
        } 
2162
    }  ZEND_HASH_FOREACH_END();
2163

    
2164
        xslt30Processor->addPackages(arguments, argument_length);
2165
        if(xslt30Processor->exceptionOccurred()){
2166
            //TODO: xslt30Processor->checkException();
2167
            const char * errStr = xslt30Processor->getErrorMessage(0);
2168
            if(errStr != NULL) {
2169
                const char * errorCode = xslt30Processor->getErrorCode(0);
2170
            }
2171
        }
2172
    }
2173
}
2174

    
2175

    
2176
    PHP_METHOD(Xslt30Processor,setInitialTemplateParameters){
2177

    
2178
  Xslt30Processor *xslt30Processor;
2179
    HashTable *arr_hash;
2180
    zval * arguments_zval;
2181
    zval * val;
2182
    long num_key;
2183
    XdmValue ** arguments;
2184
    int argument_length=0;
2185
    zend_string *key;
2186

    
2187
    bool tunnel = false;
2188
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
2189
        RETURN_NULL();
2190
    }
2191

    
2192
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ab", &arguments_zval, &tunnel) == FAILURE) {
2193
        RETURN_NULL();
2194
    }
2195

    
2196

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

    
2243

    
2244
        //php_printf(" argument_length= %d",argument_length);
2245
        xslt30Processor->setInitialTemplateParameters(parameters, tunnel);
2246
        
2247
    }
2248

    
2249
    }
2250

    
2251

    
2252
PHP_METHOD(Xslt30Processor, setInitialMatchSelection){
2253
   Xslt30Processor *xslt30Processor;
2254
    zval* oth = NULL;
2255

    
2256
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2257
        RETURN_NULL();
2258
    }
2259

    
2260
    zend_object* pobj = Z_OBJ_P(getThis());
2261
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2262
    xslt30Processor = obj->xslt30Processor;
2263
    if (xslt30Processor != NULL) {
2264

    
2265
    if(!oth) {
2266
        php_error(E_WARNING, "Error setting source value");
2267
        return;
2268
    } else {
2269
        if(Z_TYPE_P(oth) ==IS_NULL){
2270
                php_error(E_WARNING, "Error setting source value - NULL found");
2271
                return;
2272
        }
2273

    
2274
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2275
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2276

    
2277
      
2278
      if(strcmp(objName, "Saxon\\XdmValue")==0) {
2279
        zend_object * nobj = Z_OBJ_P(oth);
2280

    
2281
        xdmValue_object* ooth = (xdmValue_object *)((char *)nobj - XtOffsetOf(xdmValue_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2282
        if(ooth != NULL) {
2283
            XdmValue * value = ooth->xdmValue;
2284
            if(value != NULL) {
2285
                xslt30Processor->setInitialMatchSelection(value);
2286

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

    
2292
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2293
        if(ooth != NULL) {
2294
            XdmNode * value = ooth->xdmNode;
2295
            if(value != NULL) {
2296
                XdmValue  *valueX = (XdmValue*)value;
2297
                xslt30Processor->setInitialMatchSelection(valueX);
2298

    
2299
            } else {
2300

    
2301
php_error(E_WARNING, "XdmNode - seInitialMatchSelection - cp1");
2302
}
2303
        }
2304
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2305
        zend_object* vvobj = Z_OBJ_P(oth);
2306

    
2307
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2308
        if(ooth != NULL) {
2309
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2310
            if(value != NULL) {
2311
                xslt30Processor->setInitialMatchSelection((XdmValue*)value);
2312
            }
2313
        }
2314
      } else {
2315
        //TODO raise warning
2316
        }
2317

    
2318

    
2319
    }
2320
  }
2321

    
2322

    
2323

    
2324

    
2325
}
2326
    
2327

    
2328
PHP_METHOD(Xslt30Processor, setGlobalContextItem)
2329
{
2330
    Xslt30Processor *xslt30Processor;
2331
    zval* oth = NULL;
2332

    
2333
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2334
        RETURN_NULL();
2335
    }
2336

    
2337
    zend_object* pobj = Z_OBJ_P(getThis());
2338
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2339
    xslt30Processor = obj->xslt30Processor;
2340
    if (xslt30Processor != NULL) {
2341

    
2342
    if(!oth) {
2343
        php_error(E_WARNING, "Error setting source value");
2344
        return;
2345
    } else {
2346
        if(Z_TYPE_P(oth) ==IS_NULL){
2347
                php_error(E_WARNING, "Error setting source value");
2348
                return;
2349
        }
2350

    
2351
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2352
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2353

    
2354
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2355
        zend_object * nobj = Z_OBJ_P(oth);
2356

    
2357
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2358
        if(ooth != NULL) {
2359
            XdmNode * value = ooth->xdmNode;
2360
            if(value != NULL) {
2361
                XdmItem  *valueX = (XdmItem*)value;
2362
                xslt30Processor->setGlobalContextItem(valueX);
2363

    
2364
            }
2365
        }
2366
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2367
        zend_object* vvobj = Z_OBJ_P(oth);
2368
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2369
        if(ooth != NULL) {
2370
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2371
            if(value != NULL) {
2372
                xslt30Processor->setGlobalContextItem((XdmItem*)value);
2373
            }
2374
        }
2375
      } else {
2376
        //TODO raise warning
2377
        }
2378

    
2379

    
2380
    }
2381
  }
2382
}
2383

    
2384

    
2385
PHP_METHOD(Xslt30Processor, setGlobalContextFromFile)
2386
{
2387
    Xslt30Processor *xslt30Processor;
2388
    char * inFilename = NULL;
2389
    size_t len1;
2390
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2391
        RETURN_NULL();
2392
    }
2393

    
2394
    zend_object* pobj = Z_OBJ_P(getThis());
2395
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2396
    xslt30Processor = obj->xslt30Processor;
2397
    if (xslt30Processor != NULL && inFilename != NULL) {
2398
         xslt30Processor->setGlobalContextFromFile(inFilename);
2399

    
2400

    
2401
    }
2402
}
2403

    
2404

    
2405
PHP_METHOD(Xslt30Processor, setInitialMatchSelectionAsFile)
2406
{
2407
    Xslt30Processor *xslt30Processor;
2408
    char * inFilename = NULL;
2409
    size_t len1;
2410
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2411
        RETURN_NULL();
2412
    }
2413

    
2414
    zend_object* pobj = Z_OBJ_P(getThis());
2415
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2416
    xslt30Processor = obj->xslt30Processor;
2417
    if (xslt30Processor != NULL && inFilename != NULL) {
2418
         xslt30Processor->setInitialMatchSelectionAsFile(inFilename);
2419

    
2420

    
2421
    }
2422
}
2423

    
2424

    
2425
PHP_METHOD(Xslt30Processor, transformFileToFile)
2426
{
2427
    Xslt30Processor *xslt30Processor;
2428
    char * outfileName = NULL;
2429
    char * infilename = NULL;
2430
    char * styleFileName = NULL;
2431
    size_t len1, len2, len3;
2432

    
2433
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
2434
        RETURN_NULL();
2435
    }
2436

    
2437
    zend_object* pobj = Z_OBJ_P(getThis());
2438
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2439
    xslt30Processor = obj->xslt30Processor;
2440

    
2441
    if (xslt30Processor != NULL) {
2442

    
2443
        xslt30Processor->transformFileToFile(infilename, styleFileName, outfileName);
2444
        if(xslt30Processor->exceptionOccurred()) {
2445
               // TODO: throw exception
2446
        }
2447
    }
2448
}
2449

    
2450
PHP_METHOD(Xslt30Processor, transformFileToValue)
2451
{
2452
    Xslt30Processor *xslt30Processor;
2453
    char * infilename = NULL;
2454
    char * styleFileName = NULL;
2455
   size_t len1, len2;
2456

    
2457
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2458
        RETURN_NULL();
2459
    }
2460

    
2461
    zend_object* pobj = Z_OBJ_P(getThis());
2462
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2463
    xslt30Processor = obj->xslt30Processor;
2464

    
2465
    if (xslt30Processor != NULL) {
2466

    
2467
        XdmValue * node = xslt30Processor->transformFileToValue(infilename, styleFileName);
2468
        if(node != NULL) {
2469
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2470
                RETURN_NULL();
2471
            } else {
2472
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
2473
                zend_object *ooth =  Z_OBJ_P(return_value);
2474
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2475
                assert (vobj != NULL);
2476
                vobj->xdmValue = node;
2477
            }
2478
        } else {
2479
            if(obj->xslt30Processor->exceptionOccurred()){
2480
                  //TODO
2481
            }
2482
        }
2483
    }else {
2484
        RETURN_NULL();
2485
    }
2486
}
2487

    
2488

    
2489
PHP_METHOD(Xslt30Processor, transformFileToString)
2490
{
2491
    Xslt30Processor *xslt30Processor;
2492
    char * infilename = NULL;
2493
    char * styleFileName = NULL;
2494
    size_t len1, len2;
2495

    
2496
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2497
        RETURN_NULL();
2498
    }
2499

    
2500
    zend_object* pobj = Z_OBJ_P(getThis());
2501
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2502
    xslt30Processor = obj->xslt30Processor;
2503

    
2504
    if (xslt30Processor != NULL) {
2505

    
2506
        const char * result = xslt30Processor->transformFileToString(infilename, styleFileName);
2507
        if(result != NULL) {
2508
            //char *str = estrdup(result);
2509
            _RETURN_STRING(result);
2510
        } else if(xslt30Processor->exceptionOccurred()){
2511
            //TODO: xslt30Processor->checkException();
2512
            const char * errStr = xslt30Processor->getErrorMessage(0);
2513
            if(errStr != NULL) {
2514
                const char * errorCode = xslt30Processor->getErrorCode(0);
2515
                if(errorCode!=NULL) {
2516
                    // TODO: throw exception
2517
                }
2518
            }
2519
        }
2520
    }
2521
}
2522

    
2523

    
2524

    
2525
PHP_METHOD(Xslt30Processor, transformToString)
2526
{
2527
    Xslt30Processor *xslt30Processor;
2528

    
2529
    if (ZEND_NUM_ARGS()>1) {
2530
        WRONG_PARAM_COUNT;
2531
    }
2532

    
2533

    
2534
    zval* oth;
2535
   
2536

    
2537
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2538
        RETURN_NULL();
2539
    }
2540

    
2541

    
2542
    zend_object* pobj = Z_OBJ_P(getThis());
2543
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2544
    xslt30Processor = obj->xslt30Processor;
2545
    if (xslt30Processor != NULL) {
2546

    
2547
      if(!oth) {
2548
        php_error(E_WARNING, "Error setting source value");
2549
        return;
2550
      } else {
2551
        if(Z_TYPE_P(oth) ==IS_NULL){
2552
                php_error(E_WARNING, "Error setting source value");
2553
                return;
2554
        }
2555
        
2556
        const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2557
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2558
          zend_object * nobj = Z_OBJ_P(oth);
2559

    
2560
          xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2561
          if(ooth != NULL) {
2562
            XdmNode * value = ooth->xdmNode;
2563
            if(value != NULL) {
2564
                const char * result = xslt30Processor->transformToString(value);
2565
                if(result != NULL) {
2566
                  _RETURN_STRING(result);
2567
                } else if(xslt30Processor->exceptionOccurred()){
2568
                   xslt30Processor->checkException(); 
2569
                }
2570
            }
2571

    
2572
          }
2573
        }
2574
}}
2575
    RETURN_NULL();
2576
}
2577

    
2578
PHP_METHOD(Xslt30Processor, transformToValue)
2579
{
2580
    Xslt30Processor *xslt30Processor;
2581

    
2582
    if (ZEND_NUM_ARGS()>1) {
2583
        WRONG_PARAM_COUNT;
2584
    }
2585

    
2586

    
2587
    zval* oth;
2588
   
2589

    
2590
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2591
        RETURN_NULL();
2592
    }
2593

    
2594
    zend_object* pobj = Z_OBJ_P(getThis());
2595
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2596
    xslt30Processor = obj->xslt30Processor;
2597

    
2598
    if (xslt30Processor != NULL) {
2599
      if(!oth) {
2600
        php_error(E_WARNING, "Error setting source value");
2601
        return;
2602
      } else {
2603
        if(Z_TYPE_P(oth) ==IS_NULL){
2604
                php_error(E_WARNING, "Error setting source value");
2605
                return;
2606
        }
2607
        
2608
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2609
     
2610
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2611
        zend_object * nobj = Z_OBJ_P(oth);
2612

    
2613
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2614
        if(ooth != NULL) {
2615
            XdmNode * value = ooth->xdmNode;
2616
            if(value != NULL) {
2617
                
2618
                XdmValue * node = xslt30Processor->transformToValue(value);
2619
                if(node != NULL) {
2620
                  if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2621
                    RETURN_NULL();
2622
                  } else {
2623
                    zend_object *vvobj =  Z_OBJ_P(return_value);
2624
                    xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2625
                    assert (vobj != NULL);
2626
                    vobj->xdmValue = node;
2627
                  }
2628
               } else if(xslt30Processor->exceptionOccurred()){
2629
                 xslt30Processor->checkException();
2630
                 RETURN_NULL();
2631
               }
2632
            }
2633
         }
2634
       }
2635

    
2636
 }   } else {
2637
        RETURN_NULL();
2638
    }
2639
}
2640

    
2641
PHP_METHOD(Xslt30Processor, transformToFile)
2642
{
2643
    Xslt30Processor *xslt30Processor;
2644

    
2645
    if (ZEND_NUM_ARGS()>1) {
2646
        WRONG_PARAM_COUNT;
2647
    }
2648

    
2649

    
2650
    zval* oth;
2651
   
2652

    
2653
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2654
        RETURN_NULL();
2655
    }
2656

    
2657
    zend_object* pobj = Z_OBJ_P(getThis());
2658
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2659
    xslt30Processor = obj->xslt30Processor;
2660

    
2661
    if (xslt30Processor != NULL) {
2662
      if(!oth) {
2663
        php_error(E_WARNING, "Error setting source value");
2664
        return;
2665
      } else {
2666
        if(Z_TYPE_P(oth) ==IS_NULL){
2667
                php_error(E_WARNING, "Error setting source value");
2668
                return;
2669
        }
2670
        
2671
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2672

    
2673
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2674
        zend_object * nobj = Z_OBJ_P(oth);
2675

    
2676
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2677
        if(ooth != NULL) {
2678
            XdmNode * value = ooth->xdmNode;
2679
            if(value != NULL) {
2680
                
2681
                xslt30Processor->transformToFile(value);
2682
                if(xslt30Processor->exceptionOccurred()) {
2683
                   //TODO
2684
                   const char * exStr = xslt30Processor->checkException();
2685
                }
2686
            }
2687
        }
2688
      }
2689

    
2690
    }
2691
   }
2692
 else {
2693
        RETURN_NULL();
2694
    }
2695
}
2696

    
2697
PHP_METHOD(Xslt30Processor, compileFromFile)
2698
{
2699
    Xslt30Processor *xslt30Processor;
2700
    char * name = NULL;
2701
    size_t len1;
2702
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2703
        RETURN_NULL();
2704
    }
2705
    zend_object* pobj = Z_OBJ_P(getThis());
2706
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2707
    xslt30Processor = obj->xslt30Processor;
2708
    if (xslt30Processor != NULL) {
2709
        xslt30Processor->compileFromFile(name);
2710
    }
2711
}
2712

    
2713

    
2714
PHP_METHOD(Xslt30Processor, compileFromAssociatedFile)
2715
{
2716
    Xslt30Processor *xslt30Processor;
2717
    char * name = NULL;
2718
    size_t len1;
2719
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2720
        RETURN_NULL();
2721
    }
2722
    zend_object* pobj = Z_OBJ_P(getThis());
2723
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2724
    xslt30Processor = obj->xslt30Processor;
2725
    if (xslt30Processor != NULL) {
2726
        xslt30Processor->compileFromAssociatedFile(name);
2727
    }
2728
}
2729

    
2730

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

    
2747
PHP_METHOD(Xslt30Processor, compileFromStringAndSave)
2748
{
2749
    Xslt30Processor *xslt30Processor;
2750
    char * stylesheetStr;
2751
    char * filename = NULL;
2752
    size_t len1, len2, myint;
2753
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetStr, filename, &len1, &len2) == FAILURE) {
2754
        RETURN_NULL();
2755
    }
2756
    zend_object* pobj = Z_OBJ_P(getThis());
2757
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2758
    xslt30Processor = obj->xslt30Processor;
2759
    if (xslt30Processor != NULL) {
2760
        xslt30Processor->compileFromStringAndSave(stylesheetStr, filename);
2761
    }
2762
}
2763

    
2764
PHP_METHOD(Xslt30Processor, compileFromFileAndSave)
2765
{
2766
    Xslt30Processor *xslt30Processor;
2767
    char * stylesheetFilename = NULL;
2768
    char * filename = NULL;
2769
    size_t len1, len2, myint;
2770
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
2771
        RETURN_NULL();
2772
    }
2773
    zend_object* pobj = Z_OBJ_P(getThis());
2774
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2775
    xslt30Processor = obj->xslt30Processor;
2776
    if (xslt30Processor != NULL) {
2777
        xslt30Processor->compileFromStringAndSave(stylesheetFilename, filename);
2778
    }
2779
}
2780

    
2781

    
2782

    
2783
PHP_METHOD(Xslt30Processor, compileFromValue)
2784
{
2785
    Xslt30Processor *xslt30Processor;
2786
   zval* oth;
2787

    
2788
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
2789
        RETURN_NULL();
2790
    }
2791
    zend_object* pobj = Z_OBJ_P(getThis());
2792
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2793
    xslt30Processor = obj->xslt30Processor;
2794
    if (xslt30Processor != NULL) {
2795
        zend_object* vvobj = Z_OBJ_P(oth);
2796
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2797
        if(ooth != NULL) {
2798
            XdmValue * value = ooth->xdmValue;
2799
            if(value != NULL && value->size() == 1 && (value->getHead())->getType() == 3) {
2800
                xslt30Processor->compileFromXdmNode((XdmNode*)(value->getHead()));
2801
            }
2802
        }
2803
    }
2804
}
2805

    
2806

    
2807

    
2808
PHP_METHOD(Xslt30Processor, setResultAsRawValue)
2809
{
2810
    Xslt30Processor *xslt30Processor;
2811
    bool raw = false;
2812

    
2813
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &raw) == FAILURE) {
2814
        RETURN_NULL();
2815
    }
2816

    
2817
    zend_object* pobj = Z_OBJ_P(getThis());
2818
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2819
    xslt30Processor = obj->xslt30Processor;
2820
    if (xslt30Processor != NULL) {
2821
         xslt30Processor->setResultAsRawValue(raw);
2822
    }
2823

    
2824
}
2825

    
2826

    
2827

    
2828
PHP_METHOD(Xslt30Processor, setJustInTimeCompilation)
2829
{
2830
    Xslt30Processor *xslt30Processor;
2831
    bool jit = false;
2832
    size_t len1;
2833

    
2834
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
2835
        RETURN_NULL();
2836
    }
2837

    
2838
    zend_object* pobj = Z_OBJ_P(getThis());
2839
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2840
    xslt30Processor = obj->xslt30Processor;
2841
    if (xslt30Processor != NULL) {
2842
         xslt30Processor->setJustInTimeCompilation(jit);
2843
    }
2844
}
2845

    
2846
PHP_METHOD(Xslt30Processor, setOutputFile)
2847
{
2848
    Xslt30Processor *xslt30Processor;
2849
    char * outputFilename = NULL;
2850
    size_t len1;
2851

    
2852
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
2853
        RETURN_NULL();
2854
    }
2855

    
2856
    zend_object* pobj = Z_OBJ_P(getThis());
2857
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2858
    xslt30Processor = obj->xslt30Processor;
2859
    if (xslt30Processor != NULL && outputFilename != NULL) {
2860

    
2861
         xslt30Processor->setOutputFile(outputFilename);
2862

    
2863

    
2864
    }
2865
}
2866

    
2867

    
2868

    
2869

    
2870
PHP_METHOD(Xslt30Processor, setProperty)
2871
{
2872
    Xslt30Processor *xslt30Processor;
2873
    char * name = NULL;
2874
    char * value;
2875
    size_t len1, len2, myint;
2876

    
2877
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
2878
        RETURN_NULL();
2879
    }
2880
    zend_object* pobj = Z_OBJ_P(getThis());
2881
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2882
    xslt30Processor = obj->xslt30Processor;
2883
    if (xslt30Processor != NULL) {
2884
        xslt30Processor->setProperty(name, value);
2885
    }
2886
}
2887

    
2888
PHP_METHOD(Xslt30Processor, setParameter)
2889
{
2890

    
2891
   Xslt30Processor *xslt30Processor;
2892
   char * name;
2893
   zval* oth;
2894
   size_t len1, len2, myint;
2895
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
2896
        RETURN_NULL();
2897
    }
2898
    zend_object* pobj = Z_OBJ_P(getThis());
2899
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2900
    xslt30Processor = obj->xslt30Processor;
2901
    if (xslt30Processor != NULL) {
2902
        if(Z_TYPE_P(oth) ==IS_NULL){
2903
                php_error(E_WARNING, "Error setting source value - value is null");
2904
                return;
2905
        }
2906

    
2907
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2908
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2909

    
2910
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2911
        zend_object* ooth = Z_OBJ_P(oth);
2912
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
2913
        if(nobj != NULL) {
2914
            XdmNode * value = nobj->xdmNode;
2915
            if(value != NULL) {
2916
                xslt30Processor->setParameter(name, (XdmValue *)value);
2917

    
2918
            }
2919
        }
2920
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2921
        zend_object* ooth = Z_OBJ_P(oth);
2922
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2923
        if(vobj != NULL) {
2924
            XdmValue * value = vobj->xdmValue;
2925
            if(value != NULL) {
2926

    
2927
                xslt30Processor->setParameter(name, value);
2928
            }
2929
        }
2930

    
2931

    
2932

    
2933
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2934
        zend_object* ooth = Z_OBJ_P(oth);
2935
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
2936
        if(aobj != NULL) {
2937
            XdmAtomicValue * value = aobj->xdmAtomicValue;
2938
            if(value != NULL) {
2939
                xslt30Processor->setParameter(name, (XdmValue *)value);
2940
            }
2941
        }
2942

    
2943

    
2944

    
2945
      }
2946

    
2947
    }
2948
}
2949

    
2950
PHP_METHOD(Xslt30Processor, clearParameters)
2951
{
2952
    Xslt30Processor *xslt30Processor;
2953
    if (ZEND_NUM_ARGS()>0) {
2954
        WRONG_PARAM_COUNT;
2955
    }
2956

    
2957
    zend_object* pobj = Z_OBJ_P(getThis());
2958
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2959
    xslt30Processor = obj->xslt30Processor;
2960
    if (xslt30Processor != NULL) {
2961
        xslt30Processor->clearParameters(true);
2962
    }
2963
}
2964

    
2965
PHP_METHOD(Xslt30Processor, clearProperties)
2966
{
2967
    Xslt30Processor *xslt30Processor;
2968
    if (ZEND_NUM_ARGS()>0) {
2969
        WRONG_PARAM_COUNT;
2970
    }
2971

    
2972
    zend_object* pobj = Z_OBJ_P(getThis());
2973
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2974
    xslt30Processor = obj->xslt30Processor;
2975
    if (xslt30Processor != NULL) {
2976
        xslt30Processor->clearProperties();
2977
    }
2978
}
2979

    
2980

    
2981

    
2982
PHP_METHOD(Xslt30Processor, getXslMessages)
2983
{
2984
    Xslt30Processor *xslt30Processor;
2985

    
2986
    if (ZEND_NUM_ARGS()>0) {
2987
        WRONG_PARAM_COUNT;
2988
    }
2989

    
2990
    zend_object* pobj = Z_OBJ_P(getThis());
2991
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2992
    xslt30Processor = obj->xslt30Processor;
2993

    
2994
    if (xslt30Processor != NULL) {
2995

    
2996
        XdmValue * values = xslt30Processor->getXslMessages();
2997
        if(values != NULL) {
2998
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2999
                RETURN_NULL();
3000
            } else {
3001
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value);
3002
                zend_object *vvobj =  Z_OBJ_P(return_value);
3003
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3004

    
3005

    
3006
                assert (vobj != NULL);
3007
                vobj->xdmValue = values;
3008
            }
3009
        } else if(xslt30Processor->exceptionOccurred()){
3010
            xslt30Processor->checkException();
3011
            RETURN_NULL();
3012
        }
3013
    } else {
3014
        RETURN_NULL();
3015
    }
3016
}
3017

    
3018

    
3019

    
3020
PHP_METHOD(Xslt30Processor, exceptionOccurred)
3021
{
3022
    Xslt30Processor *xslt30Processor;
3023
    zend_object* pobj = Z_OBJ_P(getThis());
3024
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3025
    if (ZEND_NUM_ARGS()>0) {
3026
        WRONG_PARAM_COUNT;
3027
    }
3028

    
3029
    xslt30Processor = obj->xslt30Processor;
3030
    if (xslt30Processor != NULL) {
3031
        bool result = xslt30Processor->exceptionOccurred();
3032
        RETURN_BOOL(result);
3033
    }
3034
    RETURN_BOOL(false);
3035
}
3036

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

    
3046
    xslt30Processor = obj->xslt30Processor;
3047
    if (xslt30Processor != NULL) {
3048
        int count = xslt30Processor->exceptionCount();
3049
        RETURN_LONG(count);
3050
    }
3051
    RETURN_LONG(0);
3052
}
3053

    
3054
PHP_METHOD(Xslt30Processor, getErrorCode)
3055
{
3056
    Xslt30Processor *xslt30Processor;
3057
    long index;
3058
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3059
        RETURN_NULL();
3060
    }
3061
    zend_object* pobj = Z_OBJ_P(getThis());
3062
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3063
    xslt30Processor = obj->xslt30Processor;
3064
    if (xslt30Processor != NULL) {
3065
        const char * errCode = xslt30Processor->getErrorCode((int)index);
3066
        if(errCode != NULL) {
3067
            //char *str = estrdup(errCode);
3068
            _RETURN_STRING(errCode);
3069
        }
3070
    }
3071
    RETURN_NULL();
3072
}
3073

    
3074
PHP_METHOD(Xslt30Processor, getErrorMessage)
3075
{
3076
    Xslt30Processor *xslt30Processor;
3077
    long index;
3078
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3079
        RETURN_NULL();
3080
    }
3081
    zend_object* pobj = Z_OBJ_P(getThis());
3082
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3083
    xslt30Processor = obj->xslt30Processor;
3084
    if (xslt30Processor != NULL) {
3085
        const char * errStr = xslt30Processor->getErrorMessage((int)index);
3086
        if(errStr != NULL) {
3087
            //char *str = estrdup(errStr);
3088
            _RETURN_STRING(errStr);
3089
        }
3090
    }
3091
    RETURN_NULL();
3092
}
3093
PHP_METHOD(Xslt30Processor, exceptionClear)
3094
{
3095
    Xslt30Processor *xslt30Processor;
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
        xslt30Processor->exceptionClear();
3101
    }
3102
}
3103

    
3104
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
3105

    
3106
void xqueryProcessor_free_storage(zend_object *object)
3107
{
3108
    zend_object_std_dtor(object);
3109
}
3110

    
3111
void xqueryProcessor_destroy_storage(zend_object *object)
3112
{
3113
    zend_objects_destroy_object(object);
3114
}
3115

    
3116
zend_object *xqueryProcessor_create_handler(zend_class_entry *type)
3117
{
3118

    
3119
    xqueryProcessor_object *obj = (xqueryProcessor_object *)ecalloc(1, sizeof(xqueryProcessor_object)+ zend_object_properties_size(type));
3120
    zend_object_std_init(&obj->std, type); 
3121
    object_properties_init(&obj->std, type);
3122
    obj->std.handlers = &xqueryProcessor_object_handlers;
3123

    
3124
    return &obj->std;
3125
}
3126

    
3127
PHP_METHOD(XQueryProcessor, __destruct)
3128
{
3129
    zend_object* pobj = Z_OBJ_P(getThis());
3130
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3131
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
3132
    if(xqueryProcessor != NULL){
3133
            delete xqueryProcessor;
3134
    }
3135
}
3136

    
3137

    
3138
PHP_METHOD(XQueryProcessor, runQueryToValue)
3139
{
3140
    XQueryProcessor *xqueryProcessor;
3141
    zend_object* pobj = Z_OBJ_P(getThis()); 
3142
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3143

    
3144
    if (ZEND_NUM_ARGS()>0) {
3145
        WRONG_PARAM_COUNT;
3146
    }
3147

    
3148
    xqueryProcessor = obj->xqueryProcessor;
3149

    
3150
    if (xqueryProcessor != NULL) {
3151
        XdmValue * node = xqueryProcessor->runQueryToValue();
3152
        if(node != NULL) {
3153
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
3154
                RETURN_NULL();
3155
                return;
3156
            } else {
3157
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
3158
                zend_object *vvobj =  Z_OBJ_P(return_value);
3159
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3160
                assert (vobj != NULL);
3161
                vobj->xdmValue = node;
3162
                return;
3163
            }
3164
        }
3165
        xqueryProcessor->checkException();//TODO
3166
    } else {
3167
        RETURN_NULL();
3168
    }
3169
}
3170

    
3171
PHP_METHOD(XQueryProcessor, runQueryToString)
3172
{
3173
    XQueryProcessor *xqueryProcessor;
3174
   
3175

    
3176
    if (ZEND_NUM_ARGS()>0) {
3177
        WRONG_PARAM_COUNT;
3178
    }
3179
    zend_object* pobj = Z_OBJ_P(getThis()); 
3180
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3181
    xqueryProcessor = obj->xqueryProcessor;
3182

    
3183
    if (xqueryProcessor != NULL) {
3184
        const char * result = xqueryProcessor->runQueryToString();
3185
        if(result != NULL) {
3186
            //char *str = estrdup(result);
3187
            _RETURN_STRING(result);
3188
            return;
3189
        } else {
3190
          xqueryProcessor->checkException(); //TODO
3191
        }
3192
    }
3193
   RETURN_NULL();
3194
}
3195

    
3196
PHP_METHOD(XQueryProcessor, runQueryToFile)
3197
{
3198

    
3199
     char * ofilename;
3200
    size_t len1 =0;
3201
    if (ZEND_NUM_ARGS()!= 1) {
3202
        WRONG_PARAM_COUNT;
3203
    }
3204
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &ofilename, &len1) == FAILURE) {
3205
        RETURN_NULL();
3206
    }
3207
    XQueryProcessor *xqueryProcessor;
3208
    zend_object* pobj = Z_OBJ_P(getThis()); 
3209
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3210

    
3211

    
3212

    
3213
    xqueryProcessor = obj->xqueryProcessor;
3214

    
3215
    if (xqueryProcessor != NULL) {
3216
        if(ofilename != NULL) {
3217
                xqueryProcessor->setOutputFile(ofilename);        
3218
        }
3219
        xqueryProcessor->runQueryToFile(); 
3220
    }
3221

    
3222
}
3223

    
3224
PHP_METHOD(XQueryProcessor, setQueryContent)
3225
{
3226
    char * queryStr;
3227
    size_t len1;
3228

    
3229
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &queryStr, &len1) == FAILURE) {
3230
        RETURN_NULL();
3231
    }
3232
    zend_object* pobj = Z_OBJ_P(getThis()); 
3233
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std)); 
3234
    if(queryStr != NULL) { 
3235
      obj->xqueryProcessor->setProperty("qs", queryStr);
3236
   }
3237
}
3238

    
3239
PHP_METHOD(XQueryProcessor, setQueryFile)
3240
{
3241
   char * fileName;
3242
   size_t len1;
3243
    XQueryProcessor *xqueryProcessor;
3244

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

    
3257
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
3258
{
3259
   char * base;
3260
   size_t len1;
3261
    XQueryProcessor *xqueryProcessor;
3262

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

    
3275
PHP_METHOD(XQueryProcessor, declareNamespace)
3276
{
3277
   char * prefix;
3278
   char * ns;
3279
   size_t len1, len2;
3280
    XQueryProcessor *xqueryProcessor;
3281

    
3282
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
3283
        RETURN_NULL();
3284
    }
3285
    if(prefix != NULL && ns != NULL) {
3286
            zend_object* pobj = Z_OBJ_P(getThis()); 
3287
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3288
            xqueryProcessor = obj->xqueryProcessor;
3289
            xqueryProcessor->declareNamespace(prefix, ns);
3290
    }
3291
            
3292
}
3293

    
3294

    
3295

    
3296
PHP_METHOD(XQueryProcessor, setContextItem)
3297
{
3298
   char * context;
3299
   int len1;
3300
   zval* oth;
3301
    XQueryProcessor *xqueryProcessor;
3302

    
3303
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &oth) == FAILURE) {
3304
        RETURN_NULL();
3305
    }
3306
    if(oth != NULL) {
3307
            zend_object* pobj = Z_OBJ_P(getThis()); 
3308
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3309
            xqueryProcessor = obj->xqueryProcessor;
3310
    const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name); 
3311
        
3312
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3313
        zend_object *vvobj =  Z_OBJ_P(oth);
3314
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3315
        //xdmNode_object* ooth = (xdmNode_object*)Z_OBJ_P(oth TSRMLS_CC);
3316
        if(ooth != NULL) {
3317
            XdmNode * value = ooth->xdmNode;
3318
            if(value != NULL) {        
3319
                xqueryProcessor->setContextItem((XdmItem *)value);
3320
               
3321
                return;
3322
            }
3323
        }
3324
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
3325
        zend_object *vvobj =  Z_OBJ_P(oth);
3326
        xdmItem_object* ooth  = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
3327
        if(ooth != NULL) {
3328
            XdmItem * value = ooth->xdmItem;
3329
            if(value != NULL) {        
3330
                xqueryProcessor->setContextItem(value);
3331
               
3332
                return;
3333
            }
3334
         }
3335
        
3336

    
3337

    
3338

    
3339
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3340
        zend_object *vvobj =  Z_OBJ_P(oth);
3341
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3342
        if(ooth != NULL) {
3343
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3344
            if(value != NULL) {
3345
                
3346
                xqueryProcessor->setContextItem((XdmItem *)value);
3347
      
3348
                return;
3349
            }
3350
        }
3351

    
3352

    
3353

    
3354
      } 
3355

    
3356

    
3357
    }
3358
        //throw exception
3359
        
3360
            
3361
}
3362

    
3363
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
3364
{
3365
   char * cfilename;
3366
   size_t len1;
3367
    XQueryProcessor *xqueryProcessor;
3368

    
3369
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &cfilename, &len1) == FAILURE) {
3370
        RETURN_NULL();
3371
    }
3372
    if(cfilename != NULL) {
3373
             zend_object* pobj = Z_OBJ_P(getThis()); 
3374
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3375
            xqueryProcessor = obj->xqueryProcessor;
3376
            xqueryProcessor->setContextItemFromFile(cfilename);
3377
    }
3378
            
3379
}
3380

    
3381

    
3382
PHP_METHOD(XQueryProcessor, setProperty)
3383
{
3384
    XQueryProcessor *xqueryProcessor;
3385
    char * name;
3386
    char * value;
3387
    size_t len1, len2, myint;
3388

    
3389
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
3390
        RETURN_NULL();
3391
    }
3392
    zend_object* pobj = Z_OBJ_P(getThis()); 
3393
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3394
    xqueryProcessor = obj->xqueryProcessor;
3395
    if (xqueryProcessor != NULL) {
3396
        xqueryProcessor->setProperty(name, value);
3397
    }
3398
}
3399

    
3400
PHP_METHOD(XQueryProcessor, setParameter)
3401
{
3402

    
3403
   XQueryProcessor *xqueryProcessor;
3404
   char * name;
3405
   zval* oth;
3406
   size_t len1, len2, myint;        
3407
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
3408
        RETURN_NULL();
3409
    }
3410
    zend_object* pobj = Z_OBJ_P(getThis()); 
3411
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3412
    xqueryProcessor = obj->xqueryProcessor;
3413
    if (xqueryProcessor != NULL) {
3414
        if(Z_TYPE_P(oth) ==IS_NULL){
3415
                php_error(E_WARNING, "Error setting source value - value is null");
3416
                return;
3417
        }
3418
             const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
3419
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3420
//Z_ADDREF_P(oth);
3421
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3422
        zend_object *vvobj =  Z_OBJ_P(oth);
3423
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3424
        if(ooth != NULL) {
3425
            XdmNode * value = ooth->xdmNode;
3426
            if(value != NULL) {        
3427
                xqueryProcessor->setParameter(name, (XdmValue *)value);
3428

    
3429
            }
3430
        }
3431
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
3432
        zend_object *vvobj =  Z_OBJ_P(oth);
3433
        xdmValue_object* ooth  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3434
        if(ooth != NULL) {
3435
            XdmValue * value = ooth->xdmValue;
3436
            if(value != NULL) {
3437
                
3438
                xqueryProcessor->setParameter(name, value);
3439
            }
3440
        }
3441

    
3442

    
3443

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

    
3455

    
3456

    
3457
      }
3458

    
3459
    }
3460
}
3461

    
3462

    
3463

    
3464

    
3465
PHP_METHOD(XQueryProcessor, clearParameters)
3466
{
3467
    XQueryProcessor *xqueryProcessor;
3468
    if (ZEND_NUM_ARGS()>0) {
3469
        WRONG_PARAM_COUNT;
3470
    }
3471

    
3472
    zend_object* pobj = Z_OBJ_P(getThis()); 
3473
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3474
    xqueryProcessor = obj->xqueryProcessor;
3475
    if (xqueryProcessor != NULL) {
3476
        xqueryProcessor->clearParameters(true);
3477
    }
3478
}
3479

    
3480
PHP_METHOD(XQueryProcessor, clearProperties)
3481
{
3482
    XQueryProcessor *xqueryProcessor;
3483

    
3484
    if (ZEND_NUM_ARGS()>0) {
3485
        WRONG_PARAM_COUNT;
3486
    }
3487

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

    
3496
PHP_METHOD(XQueryProcessor, exceptionOccurred)
3497
{
3498
    XQueryProcessor *xqueryProcessor;
3499
    zend_object* pobj = Z_OBJ_P(getThis()); 
3500
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3501
    if (ZEND_NUM_ARGS()>0) {
3502
        WRONG_PARAM_COUNT;
3503
    }
3504

    
3505
    xqueryProcessor = obj->xqueryProcessor;
3506
    if (xqueryProcessor != NULL) {
3507
        bool result = xqueryProcessor->exceptionOccurred();
3508
        RETURN_BOOL(result);
3509
    }
3510
    RETURN_BOOL(false);
3511
}
3512

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

    
3522
    xqueryProcessor = obj->xqueryProcessor;
3523
    if (xqueryProcessor != NULL) {
3524
        int count = xqueryProcessor->exceptionCount();
3525
        RETURN_LONG(count);
3526
    }
3527
    RETURN_LONG(0);
3528
}
3529

    
3530
PHP_METHOD(XQueryProcessor, getErrorCode)
3531
{
3532
    XQueryProcessor *xqueryProcessor;
3533
    long index;
3534
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3535
        RETURN_NULL();
3536
    }
3537
    zend_object* pobj = Z_OBJ_P(getThis()); 
3538
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3539
    xqueryProcessor = obj->xqueryProcessor;
3540
    if (xqueryProcessor != NULL) {
3541
        const char * errCode = xqueryProcessor->getErrorCode((int)index);
3542
        if(errCode != NULL) {
3543
            //char *str = estrdup(errCode);
3544
            _RETURN_STRING(errCode);
3545
        }
3546
    }
3547
    RETURN_NULL();
3548
}
3549

    
3550
PHP_METHOD(XQueryProcessor, getErrorMessage)
3551
{
3552
    XQueryProcessor *xqueryProcessor;
3553
    long index;
3554
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3555
        RETURN_NULL();
3556
    }
3557
    zend_object* pobj = Z_OBJ_P(getThis()); 
3558
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
3559
    xqueryProcessor = obj->xqueryProcessor;
3560
    if (xqueryProcessor != NULL) {
3561
        const char * errStr = xqueryProcessor->getErrorMessage((int)index);
3562
        if(errStr != NULL) {
3563
            //char *str = estrdup(errStr);
3564
            _RETURN_STRING(errStr);
3565
        }
3566
    }
3567
    RETURN_NULL();
3568
}
3569
PHP_METHOD(XQueryProcessor, exceptionClear)
3570
{
3571
    XQueryProcessor *xqueryProcessor;
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
        xqueryProcessor->exceptionClear();
3577
    }
3578
}
3579

    
3580
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
3581

    
3582
void xpathProcessor_free_storage(zend_object *object)
3583
{
3584
    zend_object_std_dtor(object);
3585
}
3586

    
3587
void xpathProcessor_destroy_storage(zend_object *object)
3588
{
3589
    zend_objects_destroy_object(object);
3590
}
3591

    
3592
PHP_METHOD(XPathProcessor, __destruct)
3593
{
3594

    
3595
   zend_object* pobj = Z_OBJ_P(getThis()); 
3596
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3597

    
3598

    
3599
   XPathProcessor * xpathProc= obj->xpathProcessor;
3600
    if(xpathProc != NULL){
3601
            delete xpathProc;
3602
     }
3603

    
3604
   
3605
    
3606
}
3607

    
3608
zend_object *xpathProcessor_create_handler(zend_class_entry *type)
3609
{
3610
    xpathProcessor_object *obj = (xpathProcessor_object *)ecalloc(1, sizeof(xpathProcessor_object)+ zend_object_properties_size(type));
3611
    
3612
    zend_object_std_init(&obj->std, type); 
3613
    
3614
    object_properties_init(&obj->std, type);
3615
    
3616
    obj->std.handlers = &xpathProcessor_object_handlers;
3617

    
3618
    return &obj->std;
3619
}
3620

    
3621

    
3622

    
3623
PHP_METHOD(XPathProcessor, setProperty)
3624
{
3625
    XPathProcessor *xpathProcessor;
3626
    char * name;
3627
    char * value;
3628
    size_t len1, len2;
3629

    
3630
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
3631
        RETURN_NULL();
3632
    }
3633
    zend_object* pobj = Z_OBJ_P(getThis()); 
3634
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3635
    xpathProcessor = obj->xpathProcessor;
3636
    if (xpathProcessor != NULL) {
3637
        xpathProcessor->setProperty(name, value);
3638
    }
3639
}
3640

    
3641
PHP_METHOD(XPathProcessor, setParameter)
3642
{
3643

    
3644
   XPathProcessor *xpathProcessor;
3645
   char * name;
3646
   zval* oth;
3647
   size_t len1, len2;        
3648
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name, &len2, &oth) == FAILURE) {
3649
        RETURN_NULL();
3650
    }
3651
    zend_object* pobj = Z_OBJ_P(getThis()); 
3652
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3653
    xpathProcessor = obj->xpathProcessor;
3654
    if (xpathProcessor != NULL) {
3655
            const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
3656
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3657

    
3658
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3659
        
3660
        zend_object* vvobj = Z_OBJ_P(oth);
3661
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3662
        if(ooth != NULL) {
3663
            XdmNode * value = ooth->xdmNode;
3664
            if(value != NULL) {        
3665
                xpathProcessor->setParameter(name, (XdmValue *)value);
3666

    
3667
            }
3668
        }
3669
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
3670
        
3671
        zend_object* vvobj = Z_OBJ_P(oth);
3672
        xdmValue_object * ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3673
        if(ooth != NULL) {
3674
            XdmValue * value = ooth->xdmValue;
3675
            if(value != NULL) {
3676
                
3677
                xpathProcessor->setParameter(name, value);
3678
            }
3679
        }
3680

    
3681

    
3682

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

    
3695

    
3696

    
3697
      }
3698

    
3699
    }
3700
}
3701

    
3702
PHP_METHOD(XPathProcessor, declareNamespace)
3703
{
3704
   char * prefix;
3705
   char * ns;
3706
   int len1, len2;
3707
   XPathProcessor *xpathProcessor;
3708

    
3709
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
3710
        RETURN_NULL();
3711
    }
3712
    if(prefix != NULL && ns != NULL) {
3713
            zend_object* pobj = Z_OBJ_P(getThis()); 
3714
        xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3715
            xpathProcessor = obj->xpathProcessor;
3716
            xpathProcessor->declareNamespace(prefix, ns);
3717
    }
3718
            
3719
}
3720

    
3721

    
3722

    
3723
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
3724

    
3725
    XPathProcessor *xpathProcessor;
3726
    bool allow = false;
3727
    size_t len1;
3728

    
3729
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &allow) == FAILURE) {
3730
        RETURN_NULL();
3731
    }
3732

    
3733
    zend_object* pobj = Z_OBJ_P(getThis());
3734
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3735
    xpathProcessor = obj->xpathProcessor;
3736
    if (xpathProcessor != NULL) {
3737
            xpathProcessor->setBackwardsCompatible(allow);
3738
         }
3739
}
3740

    
3741
PHP_METHOD(XPathProcessor, setCaching){
3742
    XPathProcessor *xpathProcessor;
3743
    bool isCaching = false;
3744
    size_t len1;
3745

    
3746
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &isCaching) == FAILURE) {
3747
        RETURN_NULL();
3748
    }
3749

    
3750
    zend_object* pobj = Z_OBJ_P(getThis());
3751
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3752
    xpathProcessor = obj->xpathProcessor;
3753
    if (xpathProcessor != NULL) {
3754
            xpathProcessor->setCaching(isCaching);
3755
         }
3756
}
3757

    
3758
PHP_METHOD(XPathProcessor, importSchemaNamespace){
3759
      char * name;
3760
      int len1;
3761
      XPathProcessor *xpathProcessor;
3762

    
3763
       if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
3764
           RETURN_NULL();
3765
       }
3766
       if(name != NULL) {
3767
               zend_object* pobj = Z_OBJ_P(getThis());
3768
           xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3769
               xpathProcessor = obj->xpathProcessor;
3770
               xpathProcessor->importSchemaNamespace(name);
3771
       }
3772
}
3773

    
3774
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
3775
{
3776

    
3777
   XPathProcessor *xpathProcessor;
3778
   char * xpathStr;
3779
   zval* oth;
3780
   size_t len1, myint;        
3781
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &xpathStr, &len1) == FAILURE) {
3782
        RETURN_NULL();
3783
    }
3784
    zend_object* pobj = Z_OBJ_P(getThis()); 
3785
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3786
    xpathProcessor = obj->xpathProcessor;
3787
    if (xpathProcessor != NULL && xpathStr != NULL) {
3788
        
3789
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
3790
                RETURN_BOOL(result);
3791
    }
3792
}
3793

    
3794
PHP_METHOD(XPathProcessor, evaluate)
3795
{
3796

    
3797
   XPathProcessor *xpathProcessor;
3798
   char * xpathStr;
3799
   zval* oth;
3800
   size_t len1, myint;        
3801
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
3802
        RETURN_NULL();
3803
    }
3804
    zend_object* pobj = Z_OBJ_P(getThis()); 
3805
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3806
    xpathProcessor = obj->xpathProcessor;
3807
    if (xpathProcessor != NULL && xpathStr != NULL) {
3808
        
3809
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
3810
        if(node != NULL) {
3811
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
3812
                RETURN_NULL();
3813
                return;
3814
            } else {
3815
                zend_object* vvobj = Z_OBJ_P(return_value);
3816
                        
3817
                if(node->getType() == XDM_NODE) {
3818
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3819
                                assert (vobj != NULL);
3820
                                  vobj->xdmNode = (XdmNode *)node;
3821
                        return;
3822

    
3823
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
3824
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3825
                assert (vobj != NULL);
3826
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
3827
                return;
3828

    
3829
                } else {
3830
                  xdmValue_object * vobj = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
3831
                  assert (vobj != NULL);
3832
                  vobj->xdmValue = node;
3833
                  return;
3834
                }
3835
            }
3836
        }
3837
        xpathProcessor->checkException();//TODO
3838
    } 
3839
    RETURN_NULL();
3840
    
3841
}
3842

    
3843
PHP_METHOD(XPathProcessor, evaluateSingle)
3844
{
3845

    
3846
   XPathProcessor *xpathProcessor;
3847
   char * xpathStr;
3848
   zval* oth;
3849
   size_t len1, myint;        
3850
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
3851
        RETURN_NULL();
3852
    }
3853
    zend_object* pobj = Z_OBJ_P(getThis()); 
3854
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3855
    xpathProcessor = obj->xpathProcessor;
3856

    
3857
    if(xpathStr == NULL) { 
3858
        RETURN_NULL();        
3859
        return;
3860
        }
3861

    
3862

    
3863
    if (xpathProcessor != NULL) {
3864
        
3865
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
3866
        if(node != NULL) {
3867
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
3868
                RETURN_NULL();
3869
                return;
3870
            } else {
3871
                //struct xdmItem_object* vobj = (struct xdmItem_object *)Z_OBJ_P(return_value TSRMLS_CC);
3872
                zend_object* vvobj = Z_OBJ_P(return_value);
3873
                if(node->getType() == XDM_NODE) {
3874
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3875
                        assert (vobj != NULL);
3876
                        vobj->xdmNode = (XdmNode *)node;
3877
                        return;
3878

    
3879
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
3880

    
3881
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3882
                assert (vobj != NULL);
3883
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
3884
                return;
3885

    
3886
                } else {
3887
                        xdmItem_object * vobj = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
3888
                        assert (vobj != NULL);
3889
                        vobj->xdmItem = node;
3890
                        return;
3891
                }
3892
            }
3893
        } 
3894
        xpathProcessor->checkException();//TODO
3895
    } 
3896
    RETURN_NULL();
3897
}
3898

    
3899
PHP_METHOD(XPathProcessor, setContextItem)
3900
{
3901

    
3902
   XPathProcessor *xpathProcessor;
3903

    
3904
   zval* oth;
3905
        //TODO this should be relaxed to accept item/atomic/node as well as Value
3906

    
3907
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
3908
        RETURN_NULL();
3909
    }
3910
    zend_object* pobj = Z_OBJ_P(getThis()); 
3911
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3912
    xpathProcessor = obj->xpathProcessor;
3913
    if (xpathProcessor != NULL) {
3914
        if(!oth) {
3915
                php_error(E_WARNING, "Error setting source value");
3916
                return;
3917
         } 
3918
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
3919
        
3920
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
3921
        zend_object* vvobj = Z_OBJ_P(oth);
3922
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
3923
        if(ooth != NULL) {
3924
            XdmNode * value = ooth->xdmNode;
3925
            if(value != NULL) {        
3926
                xpathProcessor->setContextItem((XdmItem *)value);
3927
                value->incrementRefCount();
3928

    
3929
            }
3930
        }
3931
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3932
        zend_object* vvobj = Z_OBJ_P(oth);
3933
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
3934
        if(ooth != NULL) {
3935
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3936
            if(value != NULL) {
3937
                
3938
                xpathProcessor->setContextItem((XdmItem *)value);
3939
                value->incrementRefCount();
3940
            }
3941
        }
3942
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
3943
        zend_object* vvobj = Z_OBJ_P(oth);
3944
        xdmItem_object * ooth = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
3945
        if(ooth != NULL) {
3946
            XdmItem * value = ooth->xdmItem;
3947
            if(value != NULL) {
3948
                
3949
                xpathProcessor->setContextItem(value);
3950
                value->incrementRefCount();
3951
            }
3952
        }
3953

    
3954
      }
3955
    }
3956
}
3957

    
3958
PHP_METHOD(XPathProcessor, setBaseURI)
3959
{
3960

    
3961
   XPathProcessor *xpathProcessor;
3962

    
3963
   char * uriStr;
3964
   size_t len1;
3965
        
3966
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &uriStr, &len1) == FAILURE) {
3967
        RETURN_NULL();
3968
    }
3969
    zend_object* pobj = Z_OBJ_P(getThis()); 
3970
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3971
    xpathProcessor = obj->xpathProcessor;
3972
    if (xpathProcessor != NULL) {
3973
        
3974
        if(uriStr != NULL) {
3975
           
3976
                xpathProcessor->setBaseURI(uriStr);
3977
            
3978
        }
3979
    }
3980
}
3981

    
3982
PHP_METHOD(XPathProcessor, setContextFile)
3983
{
3984

    
3985
   XPathProcessor *xpathProcessor;
3986

    
3987
   char * name;
3988
   size_t len1;
3989
        
3990
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
3991
        RETURN_NULL();
3992
    }
3993
    zend_object* pobj = Z_OBJ_P(getThis()); 
3994
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
3995
    xpathProcessor = obj->xpathProcessor;
3996
    if (xpathProcessor != NULL) {
3997
        
3998
        if(name != NULL) {
3999
           
4000
                xpathProcessor->setContextFile(name);
4001
            
4002
        }
4003
    }
4004
}
4005

    
4006
PHP_METHOD(XPathProcessor, clearParameters)
4007
{
4008
    XPathProcessor *xpathProcessor;
4009
    if (ZEND_NUM_ARGS()>0) {
4010
        WRONG_PARAM_COUNT;
4011
    }
4012

    
4013
    zend_object* pobj = Z_OBJ_P(getThis()); 
4014
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4015
    xpathProcessor = obj->xpathProcessor;
4016
    if (xpathProcessor != NULL) {
4017
        xpathProcessor->clearParameters(true);
4018
    }
4019
}
4020

    
4021
PHP_METHOD(XPathProcessor, clearProperties)
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->clearProperties();
4033
    }
4034
}
4035

    
4036

    
4037
PHP_METHOD(XPathProcessor, exceptionOccurred)
4038
{
4039
   XPathProcessor *xpathProcessor;
4040
    zend_object* pobj = Z_OBJ_P(getThis()); 
4041
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4042
    if (ZEND_NUM_ARGS()>0) {
4043
        WRONG_PARAM_COUNT;
4044
    }
4045

    
4046
    xpathProcessor = obj->xpathProcessor;
4047
    if (xpathProcessor != NULL) {
4048
        bool result = xpathProcessor->exceptionOccurred();
4049
        RETURN_BOOL(result);
4050
    }
4051
    RETURN_BOOL(false);
4052
}
4053

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

    
4063
    xpathProcessor = obj->xpathProcessor;
4064
    if (xpathProcessor != NULL) {
4065
        int count = xpathProcessor->exceptionCount();
4066
        RETURN_LONG(count);
4067
    }
4068
    RETURN_LONG(0);
4069
}
4070

    
4071
PHP_METHOD(XPathProcessor, getErrorCode)
4072
{
4073
    XPathProcessor *xpathProcessor;
4074
    long index;
4075
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
4076
        RETURN_NULL();
4077
    }
4078
    zend_object* pobj = Z_OBJ_P(getThis()); 
4079
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4080
    xpathProcessor = obj->xpathProcessor;
4081
    if (xpathProcessor != NULL) {
4082
        const char * errCode = xpathProcessor->getErrorCode((int)index);
4083
        if(errCode != NULL) {
4084
           // char *str = estrdup(errCode);
4085
            _RETURN_STRING(errCode);
4086
        }
4087
    }
4088
    RETURN_NULL();
4089
}
4090

    
4091
PHP_METHOD(XPathProcessor, getErrorMessage)
4092
{
4093
    XPathProcessor *xpathProcessor;
4094
    long index;
4095
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
4096
        RETURN_NULL();
4097
    }
4098
    zend_object* pobj = Z_OBJ_P(getThis()); 
4099
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
4100
    xpathProcessor = obj->xpathProcessor;
4101
    if (xpathProcessor != NULL) {
4102
        const char * errStr = xpathProcessor->getErrorMessage((int)index);
4103
        if(errStr != NULL) {
4104
            //char *str = estrdup(errStr);
4105
            _RETURN_STRING(errStr);
4106
        }
4107
    }
4108
    RETURN_NULL();
4109
}
4110
PHP_METHOD(XPathProcessor, exceptionClear)
4111
{
4112
    XPathProcessor *xpathProcessor;
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
        xpathProcessor->exceptionClear();
4118
    }
4119
}
4120

    
4121
/*     ============== PHP Interface of   SchemaValidator =============== */
4122

    
4123
void schemaValidator_free_storage(zend_object *object)
4124
{
4125
    zend_object_std_dtor(object);
4126
}
4127

    
4128
void schemaValidator_destroy_storage(zend_object *object)
4129
{
4130
    zend_objects_destroy_object(object);
4131
}
4132

    
4133
zend_object *schemaValidator_create_handler(zend_class_entry *type)
4134
{
4135
    zval *tmp;
4136
    zend_object retval;
4137
    schemaValidator_object *obj = (schemaValidator_object *)ecalloc(1, sizeof(schemaValidator_object)+ zend_object_properties_size(type));
4138

    
4139
    zend_object_std_init(&obj->std, type);    
4140
    object_properties_init(&obj->std, type);
4141

    
4142
    obj->std.handlers = &schemaValidator_object_handlers;
4143

    
4144
    return &obj->std;
4145
}
4146

    
4147

    
4148

    
4149
PHP_METHOD(SchemaValidator, __destruct)
4150
{
4151
    zend_object* pobj = Z_OBJ_P(getThis()); 
4152
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4153

    
4154

    
4155
    SchemaValidator * schemaValidator= obj->schemaValidator;
4156
    if(schemaValidator != NULL) {
4157
            delete schemaValidator;
4158
    }
4159
    
4160
}
4161

    
4162

    
4163

    
4164
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
4165
{
4166
    SchemaValidator *schemaValidator;
4167
    char * name;
4168
    size_t len1;
4169

    
4170
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
4171
        RETURN_NULL();
4172
    }
4173
    zend_object* pobj = Z_OBJ_P(getThis()); 
4174
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4175
    schemaValidator = obj->schemaValidator;
4176
    if (name != NULL && schemaValidator != NULL) {
4177
        schemaValidator->registerSchemaFromFile(name);
4178
    }
4179
}
4180

    
4181
PHP_METHOD(SchemaValidator, registerSchemaFromString)
4182
{
4183
    char * schemaStr;
4184
    size_t len1;
4185
    SchemaValidator *schemaValidator;
4186
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &schemaStr, &len1) == FAILURE) {
4187
        RETURN_NULL();
4188
    }
4189
    zend_object* pobj = Z_OBJ_P(getThis()); 
4190
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4191
    schemaValidator = obj->schemaValidator;
4192
    if (schemaStr!= NULL && schemaValidator != NULL) {
4193
        schemaValidator->registerSchemaFromString(schemaStr);
4194
    }
4195
}
4196

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

    
4216
PHP_METHOD(SchemaValidator, validateToNode)
4217
{
4218
    char * name = NULL;
4219
   size_t len1;
4220
    SchemaValidator *schemaValidator;
4221
    if (ZEND_NUM_ARGS()>1) {
4222
        WRONG_PARAM_COUNT;
4223
    }
4224
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4225
        RETURN_NULL();
4226
    }
4227
    zend_object* pobj = Z_OBJ_P(getThis()); 
4228
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4229
    schemaValidator = obj->schemaValidator;
4230
    if (schemaValidator != NULL) {
4231
        XdmNode * node = schemaValidator->validateToNode(name);
4232
        if(node != NULL) {
4233
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4234
                RETURN_NULL();
4235
                return;
4236
            } else {
4237
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
4238
                zend_object* vvobj = Z_OBJ_P(return_value);
4239
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
4240
                assert (vobj != NULL);
4241
                vobj->xdmNode = node;
4242
                return;
4243
            }
4244
        } 
4245
            schemaValidator->checkException();//TODO
4246
    } 
4247
    RETURN_NULL();
4248
}
4249

    
4250

    
4251
PHP_METHOD(SchemaValidator, getValidationReport)
4252
{
4253

    
4254
    SchemaValidator *schemaValidator;
4255
    if (ZEND_NUM_ARGS()>0) {
4256
        WRONG_PARAM_COUNT;
4257
    }
4258

    
4259
    zend_object* pobj = Z_OBJ_P(getThis()); 
4260
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4261
    schemaValidator = obj->schemaValidator;
4262
    if (schemaValidator != NULL) {
4263
        XdmNode * node = schemaValidator->getValidationReport();
4264
        if(node != NULL) {
4265
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4266
                RETURN_NULL();
4267
                return;
4268
            } else {
4269
                zend_object* vvobj = Z_OBJ_P(return_value);
4270
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
4271
                assert (vobj != NULL);
4272
                vobj->xdmNode = node;
4273
                return;
4274
            }
4275
        } 
4276
            schemaValidator->checkException();//TODO
4277
    } 
4278
    RETURN_NULL();
4279
}
4280

    
4281

    
4282
PHP_METHOD(SchemaValidator, setSourceNode)
4283
{
4284
    SchemaValidator *schemaValidator;
4285

    
4286
    zval* oth;
4287
   
4288

    
4289
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
4290
        RETURN_NULL();
4291
    }
4292
    zend_object* pobj = Z_OBJ_P(getThis()); 
4293
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4294
    schemaValidator = obj->schemaValidator;
4295
    if (schemaValidator != NULL) {
4296
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
4297
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
4298
        zend_object * nobj = Z_OBJ_P(oth);
4299
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
4300
        if(ooth != NULL) {
4301
            XdmNode * value = ooth->xdmNode;
4302
            if(value != NULL) {        
4303
                schemaValidator->setSourceNode(value);
4304

    
4305
            }
4306
        }
4307
      
4308
        
4309
      }
4310
    }
4311
}
4312

    
4313
PHP_METHOD(SchemaValidator, setOutputFile)
4314
{
4315
    SchemaValidator *schemaValidator;
4316
    char * name;
4317
    int len1;
4318

    
4319
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
4320
        RETURN_NULL();
4321
    }
4322
    zend_object* pobj = Z_OBJ_P(getThis()); 
4323
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4324
    schemaValidator = obj->schemaValidator;
4325
    if (schemaValidator != NULL) {
4326
        schemaValidator->setOutputFile(name);
4327
    }
4328
}
4329

    
4330

    
4331
PHP_METHOD(SchemaValidator, setProperty)
4332
{
4333
    SchemaValidator *schemaValidator;
4334
    char * name;
4335
    char * value;
4336
    size_t len1, len2, myint;
4337

    
4338
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
4339
        RETURN_NULL();
4340
    }
4341
    zend_object* pobj = Z_OBJ_P(getThis()); 
4342
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4343
    schemaValidator = obj->schemaValidator;
4344
    if (schemaValidator != NULL) {
4345
        schemaValidator->setProperty(name, value);
4346
    }
4347
}
4348

    
4349
PHP_METHOD(SchemaValidator, setParameter)
4350
{
4351

    
4352
   SchemaValidator *schemaValidator;
4353
   char * name;
4354
   zval* oth;
4355
   size_t len1, len2, myint;        
4356
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
4357
        RETURN_NULL();
4358
    }
4359
    zend_object* pobj = Z_OBJ_P(getThis()); 
4360
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4361
    schemaValidator = obj->schemaValidator;
4362
    if (schemaValidator != NULL) {
4363
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
4364
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
4365

    
4366
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
4367
        zend_object * nobj = Z_OBJ_P(oth);
4368

    
4369
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
4370
        if(ooth != NULL) {
4371
            XdmNode * value = ooth->xdmNode;
4372
            if(value != NULL) {        
4373
                schemaValidator->setParameter(name, (XdmValue *)value);
4374

    
4375
            }
4376
        }
4377
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
4378
        zend_object* vvobj = Z_OBJ_P(oth);
4379
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
4380
        if(ooth != NULL) {
4381
            XdmValue * value = ooth->xdmValue;
4382
            if(value != NULL) {
4383
                
4384
                schemaValidator->setParameter(name, value);
4385
            }
4386
        }
4387

    
4388

    
4389

    
4390
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
4391
        zend_object* vvobj = Z_OBJ_P(oth);
4392
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
4393
        if(ooth != NULL) {
4394
            XdmAtomicValue * value = ooth->xdmAtomicValue;
4395
            if(value != NULL) {
4396
                
4397
                schemaValidator->setParameter(name, (XdmValue *)value);
4398
            }
4399
        }
4400

    
4401

    
4402

    
4403
      }
4404

    
4405
    }
4406
}
4407

    
4408
PHP_METHOD(SchemaValidator, clearProperties)
4409
{
4410
    SchemaValidator *schemaValidator;
4411
    if (ZEND_NUM_ARGS()>0) {
4412
        WRONG_PARAM_COUNT;
4413
    }
4414

    
4415
    zend_object* pobj = Z_OBJ_P(getThis()); 
4416
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4417
    schemaValidator = obj->schemaValidator;
4418
    if (schemaValidator != NULL) {
4419
        schemaValidator->clearProperties();
4420
        schemaValidator->exceptionClear();
4421
    }
4422
}
4423

    
4424
PHP_METHOD(SchemaValidator, clearParameters)
4425
{
4426

    
4427
   SchemaValidator *schemaValidator;
4428
    if (ZEND_NUM_ARGS()>0) {
4429
        WRONG_PARAM_COUNT;
4430
    }
4431
    zend_object* pobj = Z_OBJ_P(getThis()); 
4432
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4433
    schemaValidator = obj->schemaValidator;
4434
    if (schemaValidator != NULL) {
4435
       
4436
                schemaValidator->clearParameters(true);
4437
                schemaValidator->exceptionClear();
4438
        }
4439
    }
4440

    
4441
PHP_METHOD(SchemaValidator, exceptionOccurred)
4442
{
4443
    SchemaValidator *schemaValidator;
4444
    if (ZEND_NUM_ARGS()>0) {
4445
        WRONG_PARAM_COUNT;
4446
    }
4447
    zend_object* pobj = Z_OBJ_P(getThis()); 
4448
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4449
    schemaValidator = obj->schemaValidator;
4450
    if (schemaValidator != NULL) {
4451
        bool result = schemaValidator->exceptionOccurred();
4452
        RETURN_BOOL(result);
4453
    }
4454
    RETURN_BOOL(false);
4455
}
4456

    
4457
PHP_METHOD(SchemaValidator, getExceptionCount)
4458
{
4459
    SchemaValidator *schemaValidator;
4460

    
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
        int count = schemaValidator->exceptionCount();
4469
        RETURN_LONG(count);
4470
    }
4471
    RETURN_LONG(0);
4472
}
4473

    
4474
PHP_METHOD(SchemaValidator, getErrorCode)
4475
{
4476
    SchemaValidator *schemaValidator;
4477
    long index;
4478
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
4479
        RETURN_NULL();
4480
    }
4481
    zend_object* pobj = Z_OBJ_P(getThis()); 
4482
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4483
    schemaValidator = obj->schemaValidator;
4484
    if (schemaValidator != NULL) {
4485
        const char * errCode = schemaValidator->getErrorCode((int)index);
4486
        if(errCode != NULL) {
4487
            //char *str = estrdup(errCode);
4488
            _RETURN_STRING(errCode);
4489
        }
4490
    }
4491
    RETURN_NULL();
4492
}
4493

    
4494
PHP_METHOD(SchemaValidator, getErrorMessage)
4495
{
4496
    SchemaValidator *schemaValidator;
4497
    long index;
4498
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
4499
        RETURN_NULL();
4500
    }
4501
    zend_object* pobj = Z_OBJ_P(getThis()); 
4502
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4503
    schemaValidator = obj->schemaValidator;
4504
    if (schemaValidator != NULL) {
4505
        const char * errStr = schemaValidator->getErrorMessage((int)index);
4506
        if(errStr != NULL) {
4507
            //char *str = estrdup(errStr);
4508
            _RETURN_STRING(errStr);
4509
        }
4510
    }
4511
    RETURN_NULL();
4512
}
4513
PHP_METHOD(SchemaValidator, exceptionClear)
4514
{
4515
    SchemaValidator * schemaValidator;
4516
    zend_object* pobj = Z_OBJ_P(getThis()); 
4517
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
4518
    schemaValidator = obj->schemaValidator;
4519
    if (schemaValidator != NULL) {
4520
        schemaValidator->exceptionClear();
4521
    }
4522
}
4523

    
4524
/*     ============== PHP Interface of   XdmValue =============== */
4525
void xdmValue_free_storage(zend_object *object)
4526
{
4527
    zend_object_std_dtor(object);
4528
}
4529

    
4530
zend_object *xdmValue_create_handler(zend_class_entry *type)
4531
{
4532
    zval *tmp;
4533
    zend_object retval;
4534
    xdmValue_object *obj = (xdmValue_object *)ecalloc(1, sizeof(xdmValue_object)+ zend_object_properties_size(type));
4535
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
4536
    object_properties_init(&obj->std, type);
4537
    
4538
    obj->std.handlers = &xdmValue_object_handlers;
4539

    
4540
    return &obj->std;
4541
}
4542

    
4543
void XdmValue_destroy_storage(zend_object *object)
4544
{
4545
    zend_objects_destroy_object(object);
4546
}
4547

    
4548
PHP_METHOD(XdmValue, __construct)
4549
{
4550
    XdmValue *xdmValue = NULL;
4551
    bool bVal;
4552
    char * sVal;
4553
    int len;
4554
    long iVal;
4555
    double dVal;
4556
    zval *zvalue;
4557

    
4558

    
4559

    
4560
    SaxonProcessor *proc= NULL;
4561
    //xdmValue_object *obj = (xdmValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
4562
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == SUCCESS) {
4563
        switch (Z_TYPE_P(zvalue)) {
4564
            case IS_FALSE:
4565
            case IS_TRUE:
4566
                bVal = Z_BVAL_P(zvalue);
4567
                xdmValue = new XdmValue(bVal);
4568
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4569
                obj->xdmValue = xdmValue;
4570
            break;
4571
            case IS_LONG:
4572
                iVal = Z_LVAL_P(zvalue);
4573
                xdmValue = new XdmValue((int)iVal);
4574
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4575
                obj->xdmValue = xdmValue;
4576
            break;
4577
            case IS_STRING:
4578
                sVal = Z_STRVAL_P(zvalue);
4579
                len = Z_STRLEN_P(zvalue);
4580
                xdmValue = new XdmValue("string", sVal);
4581
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4582
                obj->xdmValue = xdmValue;
4583
            break;
4584
            case IS_NULL:
4585
                xdmValue = new XdmValue();
4586
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4587
                obj->xdmValue = xdmValue;
4588
            break;
4589
            case IS_DOUBLE:
4590
                // TODO: implement this
4591
                //index = (long)Z_DVAL_P(zvalue);
4592
            //break;
4593
            case IS_ARRAY:
4594
            //break;
4595
            case IS_OBJECT:
4596
            //break;
4597
            default:
4598
                obj = NULL;
4599
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
4600
        }
4601
    }*/
4602
}
4603

    
4604
PHP_METHOD(XdmValue, __destruct)
4605
{
4606

    
4607
     zend_object *oobj = Z_OBJ_P(getThis());
4608
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4609
    XdmValue * xdmValue= obj->xdmValue;
4610
   if(xdmValue != NULL) {
4611
            xdmValue->decrementRefCount();
4612
            if(xdmValue!= NULL && xdmValue->getRefCount()< 1){
4613
                    delete xdmValue;
4614
            } 
4615
    }
4616
}
4617

    
4618
PHP_METHOD(XdmValue, __toString)
4619
    {
4620
             XdmValue *xdmValue;
4621
         zend_object *oobj = Z_OBJ_P(getThis());
4622
         xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4623
         xdmValue = obj->xdmValue;
4624
         if (xdmValue != NULL) {
4625
                const char * value = xdmValue->toString();
4626
                  if(value != NULL) {
4627
                      _RETURN_STRING(value);
4628
                   } else {
4629
                   _RETURN_STRING("");
4630

    
4631
                   }
4632
                 }else {
4633
                      _RETURN_STRING("");
4634
              }
4635
    }
4636

    
4637
PHP_METHOD(XdmValue,  getHead){
4638
    XdmValue *xdmValue;
4639
     zend_object *oobj = Z_OBJ_P(getThis());
4640
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4641
    xdmValue = obj->xdmValue;
4642
    if (xdmValue != NULL) {
4643
        XdmItem * item = xdmValue->getHead();
4644
        if(item != NULL) {
4645
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
4646
                RETURN_NULL();
4647
              } else {
4648
                item->incrementRefCount();
4649
                zend_object * oobj = Z_OBJ_P(return_value);
4650
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
4651
                assert (vobj != NULL);
4652
                vobj->xdmItem = item;
4653
                
4654
            }
4655
        } else {
4656
                RETURN_NULL();
4657
        }
4658
        
4659
    } else {
4660
        RETURN_NULL();
4661
    }
4662
}
4663

    
4664

    
4665
PHP_METHOD(XdmValue,  itemAt){
4666
    XdmValue *xdmValue;
4667

    
4668
    long index;
4669
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
4670
        RETURN_NULL();
4671
    }
4672

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

    
4698

    
4699
PHP_METHOD(XdmValue,  size){
4700
    XdmValue *xdmValue;
4701
    zend_object *oobj = Z_OBJ_P(getThis());
4702
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
4703
    xdmValue = obj->xdmValue;
4704
    int sizei = 0;
4705
    if (xdmValue != NULL) {
4706
        sizei = xdmValue->size();
4707
    }
4708
     RETURN_LONG(sizei);
4709
}
4710

    
4711

    
4712
PHP_METHOD(XdmValue, addXdmItem){
4713
    XdmValue *xdmValue;
4714
    zval* oth;
4715
           
4716
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
4717
        RETURN_NULL();
4718
    }
4719

    
4720
    xdmValue_object *obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
4721
    xdmValue = obj->xdmValue;
4722
    if (xdmValue != NULL) {
4723
     const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
4724
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
4725

    
4726
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
4727
        zend_object * nobj = Z_OBJ_P(oth);
4728
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
4729
        if(ooth != NULL) {
4730
            XdmNode * value = ooth->xdmNode;
4731
            if(value != NULL) {        
4732
                xdmValue->addXdmItem((XdmItem *)value);
4733
                return;
4734
            }
4735
        }
4736
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
4737
        zend_object * iobj = Z_OBJ_P(oth);
4738
        xdmItem_object* ooth = (xdmItem_object *)((char *)iobj - XtOffsetOf(xdmItem_object, std));
4739
        if(ooth != NULL) {
4740
            XdmItem * value = ooth->xdmItem;
4741
            if(value != NULL) {
4742
                xdmValue->addXdmItem(value);
4743
                return;
4744
            }
4745
        }
4746

    
4747

    
4748

    
4749
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
4750
        zend_object * aobj = Z_OBJ_P(oth);
4751
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)aobj - XtOffsetOf(xdmAtomicValue_object, std));
4752
        if(ooth != NULL) {
4753
            XdmAtomicValue * value = ooth->xdmAtomicValue;
4754
            if(value != NULL) {
4755
                xdmValue->addXdmItem((XdmItem *)value);
4756
                return;
4757
            }
4758
        }
4759

    
4760
      } else {
4761
                //TODO exception
4762
        }
4763
    }
4764
}
4765

    
4766

    
4767

    
4768
/*     ============== PHP Interface of   XdmItem =============== */
4769

    
4770
void xdmItem_free_storage(zend_object *object)
4771
{
4772
    zend_object_std_dtor(object);
4773
}
4774

    
4775
zend_object *xdmItem_create_handler(zend_class_entry *type)
4776
{
4777
    zval *tmp;
4778
    zend_object retval;
4779
    xdmItem_object *obj = (xdmItem_object *)ecalloc(1, sizeof(xdmItem_object)+ zend_object_properties_size(type));
4780
    
4781
    object_properties_init(&obj->std, type);
4782
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
4783
    
4784
    obj->std.handlers = &xdmItem_object_handlers;
4785

    
4786
    return &obj->std;
4787
}
4788

    
4789
PHP_METHOD(XdmItem, __construct)
4790
{
4791
    XdmItem *xdmItem = NULL;
4792
    bool bVal;
4793
    char * sVal;
4794
    int len;
4795
    long iVal;
4796
    double dVal;
4797
    zval *zvalue;
4798

    
4799
    SaxonProcessor *proc= NULL;
4800
    
4801
   zval *object = getThis();
4802
   
4803
    zend_object * zobj = Z_OBJ_P(object);
4804

    
4805
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4806
    //saxonProc =  obj->saxonProcessor;
4807
 
4808
}
4809

    
4810
void XdmItem_destroy_storage(zend_object *object)
4811
{
4812
    zend_objects_destroy_object(object);
4813
    
4814
}
4815

    
4816
PHP_METHOD(XdmItem, __destruct)
4817
{
4818
     zval *object = getThis();
4819
     zend_object * zobj = Z_OBJ_P(object);
4820

    
4821
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4822

    
4823
    XdmItem * xdmItem= obj->xdmItem;
4824
    xdmItem->decrementRefCount();
4825
    if(xdmItem != NULL && xdmItem->getRefCount()< 1){
4826
            delete xdmItem;
4827
    }
4828
    
4829
}
4830

    
4831
PHP_METHOD(XdmItem, getStringValue)
4832
{
4833
    XdmItem *xdmItem;
4834
     zval *object = getThis();
4835
    zend_object * zobj = Z_OBJ_P(object);
4836
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4837
    xdmItem = obj->xdmItem;
4838

    
4839
    if (xdmItem != NULL) {
4840
        const char * valueStr = xdmItem->getStringValue();
4841
        if(valueStr != NULL) {
4842
            _RETURN_STRING(valueStr);
4843
        }
4844
    }
4845
    RETURN_NULL();
4846
}
4847

    
4848
    /* {{{ __toString()
4849
       Returns the string content */
4850
PHP_METHOD(XdmItem, __toString)
4851
    {
4852
             XdmItem *xdmItem;
4853
         zend_object *oobj = Z_OBJ_P(getThis());
4854
         xdmItem_object* obj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
4855
         xdmItem = obj->xdmItem;
4856
         if (xdmItem != NULL) {
4857
                const char * value = xdmItem->toString();
4858
                  if(value != NULL) {
4859
                      _RETURN_STRING(value);
4860
                   } else {
4861
                   _RETURN_STRING("");
4862

    
4863
                   }
4864
                 }else {
4865
                      _RETURN_STRING("");
4866
              }
4867
    }
4868

    
4869
PHP_METHOD(XdmItem, isAtomic)
4870
{
4871
    XdmItem *xdmItem;
4872
    zend_object * zobj = Z_OBJ_P(getThis());
4873
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4874
    xdmItem = obj->xdmItem;
4875

    
4876
    if (xdmItem != NULL) {
4877
        bool isAtomic = xdmItem->isAtomic();
4878
        RETURN_BOOL(isAtomic);
4879
    }
4880
    RETURN_BOOL(false);
4881
}
4882

    
4883
PHP_METHOD(XdmItem, isNode)
4884
{
4885
    XdmItem *xdmItem;
4886
    zend_object * zobj = Z_OBJ_P(getThis());
4887
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
4888
    xdmItem = obj->xdmItem;
4889

    
4890
    if (xdmItem != NULL && xdmItem->getType() == XDM_NODE) {
4891
        RETURN_TRUE;
4892
    }
4893
    RETURN_FALSE;
4894
}
4895

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

    
4903
    if (xdmItem != NULL) {
4904
          if(!xdmItem->isAtomic()) {
4905
                RETURN_NULL();
4906
                return;
4907
          }
4908
          if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
4909
                RETURN_NULL();
4910
                return;
4911
            } else {
4912
                xdmItem->incrementRefCount();
4913
//Z_ADDREF_P(return_value);
4914
                   zend_object * zobj = Z_OBJ_P(return_value);
4915
                    xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
4916
                //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
4917
                assert (vobj != NULL);
4918
                vobj->xdmAtomicValue = (XdmAtomicValue *)xdmItem;
4919
                return;
4920
            }
4921
    }
4922
    RETURN_NULL();
4923
}
4924

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

    
4932
    if (xdmItem != NULL) {
4933
          if(xdmItem->isAtomic()) {
4934
                RETURN_NULL();
4935
                return;
4936
          }
4937
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4938
                RETURN_NULL();
4939
                return;
4940
            } else {
4941
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
4942
                   zend_object * zobj = Z_OBJ_P(return_value);
4943
                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
4944
                assert (vobj != NULL);
4945
                vobj->xdmNode = (XdmNode *)xdmItem;
4946
                vobj->xdmNode->incrementRefCount();
4947

    
4948
                return;
4949
            }
4950
    }
4951
    RETURN_NULL();
4952
}
4953

    
4954

    
4955

    
4956
/*     ============== PHP Interface of   XdmNode =============== */
4957

    
4958
void xdmNode_free_storage(zend_object *object)
4959
{
4960
   zend_object_std_dtor(object);
4961

    
4962
    
4963
}
4964

    
4965
zend_object *xdmNode_create_handler(zend_class_entry *type)
4966
{
4967
    zval *tmp;
4968
    zend_object retval;
4969
    xdmNode_object *obj = (xdmNode_object *)ecalloc(1, sizeof(xdmNode_object)+ zend_object_properties_size(type));
4970
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
4971
    object_properties_init(&obj->std, type);
4972
    obj->std.handlers = &xdmNode_object_handlers;
4973
        
4974
    return &obj->std;
4975
}
4976

    
4977
PHP_METHOD(XdmNode, __construct)
4978
{
4979
    //xdmNode_object *obj = (xdmNode_object *) Z_OBJ_P(getThis() TSRMLS_CC);
4980
}
4981

    
4982
void XdmNode_destroy_storage(zend_object *object)
4983
{
4984
 
4985
 zend_objects_destroy_object(object);
4986
   
4987
}
4988

    
4989
PHP_METHOD(XdmNode, __destruct)
4990
{
4991
    zval *object = getThis();
4992
     zend_object * zobj = Z_OBJ_P(object);
4993

    
4994
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
4995

    
4996
    if(obj != NULL) {
4997
    XdmNode * xdmNode= obj->xdmNode;
4998
    if(xdmNode != NULL) {
4999
            xdmNode->decrementRefCount();
5000
            if(xdmNode->getRefCount()< 1){
5001
                    delete xdmNode;
5002
            } 
5003
    }
5004
    }
5005
}
5006

    
5007
PHP_METHOD(XdmNode, getStringValue)
5008
{
5009
    XdmNode *xdmNode;
5010
    zval *object = getThis();
5011
    zend_object * zobj = Z_OBJ_P(object);
5012

    
5013
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
5014
    xdmNode = obj->xdmNode;
5015

    
5016
   
5017
    if (xdmNode != NULL) {
5018
        const char * valueStr = xdmNode->getStringValue();
5019
        if(valueStr != NULL) {
5020
            _RETURN_STRING(valueStr);
5021
            return;
5022
        }
5023
    } 
5024
    RETURN_NULL(); 
5025
    
5026
}
5027

    
5028

    
5029
    /* {{{ __toString()
5030
       Returns the string content */
5031
PHP_METHOD(XdmNode, __toString)
5032
    {
5033
             XdmNode *xdmNode;
5034
         zend_object *oobj = Z_OBJ_P(getThis());
5035
         xdmNode_object* obj = (xdmNode_object *)((char *)oobj - XtOffsetOf(xdmNode_object, std));
5036
         xdmNode = obj->xdmNode;
5037
         if (xdmNode != NULL) {
5038
                const char * value = xdmNode->toString();
5039
                  if(value != NULL) {
5040
                      _RETURN_STRING(value);
5041
                   } else {
5042
                   _RETURN_STRING("");
5043

    
5044
                   }
5045
                 }else {
5046