Project

Profile

Help

Bug #4274 » php7_saxon.cpp

O'Neil Delpratt, 2019-08-14 00:15

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

    
5
#include "php_saxon.h"
6

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

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

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

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

    
42
void SaxonProcessor_free_storage(zend_object *object)
43
{
44
         //std::cerr<<"saxonProc free storage function call"<<std::endl;
45
  /*  saxonProcessor_object *obj;
46
        
47
        obj =  (saxonProcessor_object *)((char *)object - XtOffsetOf(saxonProcessor_object, std));
48

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

    
55
   // efree(obj);
56
}
57

    
58
void SaxonProcessor_destroy_storage(zend_object *object)
59
{
60
         //std::cerr<<"destroy storage call saxonProc"<<std::endl;
61
    saxonProcessor_object *obj;
62
        
63
        
64
    zend_objects_destroy_object(object);
65

    
66
    
67
}
68

    
69
zend_object *saxonProcessor_create_handler(zend_class_entry *type)
70
{
71
    zval *tmp;
72
    zend_object retval;
73
    saxonProcessor_object *obj = (saxonProcessor_object *)ecalloc(1, sizeof(saxonProcessor_object) + zend_object_properties_size(type));
74
 
75

    
76
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
77
    object_properties_init(&obj->std, type);
78

    
79
    obj->std.handlers = &saxonProcessor_object_handlers;
80

    
81
    return &obj->std;
82
}
83

    
84
PHP_METHOD(SaxonProcessor, __construct)
85
{
86
    if (ZEND_NUM_ARGS()>2) {
87
        WRONG_PARAM_COUNT;
88
    }
89

    
90
    char * cwdi = NULL;
91
   bool license = false;
92
    size_t len1;
93
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS(), "b", &license) == FAILURE) {
94
        RETURN_NULL();
95
    } 
96

    
97

    
98
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS(), "bs", &license, &cwdi, &len1) == FAILURE) {
99
        RETURN_NULL();
100
    }
101
//std::cerr<<"SaxonProcessorConstructor cp0"<<std::endl;
102

    
103
    zval *object = getThis();
104
    SaxonProcessor * saxonProc = NULL;
105
    zend_object * zobj = Z_OBJ_P(object);
106

    
107
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)zobj - XtOffsetOf(saxonProcessor_object, std));
108

    
109
        saxonProc = new SaxonProcessor(true); //TODO: add license flag to PHP function argument
110
                
111
    
112
        obj->saxonProcessor = saxonProc;
113
//std::cerr<<"SaxonProcessorConstructor cp1"<<std::endl;
114
    if(cwdi==NULL) {
115
//std::cerr<<"SaxonProcessorConstructor cp1-1"<<std::endl;
116
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
117
            TCHAR s[256];
118

    
119
            // --
120
            DWORD a = GetCurrentDirectory(256, s);
121
            const size_t newsize = wcslen(s)*2;
122
            char* cwd = new char[newsize];
123
            wcstombs_s(0, cwd, newsize, s, _TRUNCATE);
124
            // -- code above returns the apache installtion directory as the CWD
125

    
126
            char* cwd2;
127

    
128
            //php_error(E_WARNING,cwd2);
129

    
130
            saxonProc->setcwd(cwd);
131
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
132
#else
133
            char cwd[256];
134

    
135
            VCWD_GETCWD(cwd, sizeof(cwd));
136
            if(cwd == NULL) {
137
             //php_error(E_WARNING,"cwd is nullXXXXXXXXXXXXXXXXXXXXXXX");
138
           }else {
139
           //  php_error(E_WARNING,cwd);
140
//std::cerr<<"SaxonProcessorConstructor cp2YYYYYYY cwd:"<<cwd<<std::endl;
141
 
142
            saxonProc->setcwd(cwd);
143

    
144
          }
145
#endif
146

    
147
    } else {
148
        saxonProc->setcwd(cwdi);
149
    }
150

    
151
}
152

    
153
PHP_METHOD(SaxonProcessor, __destruct)
154
{
155
    
156
        zend_object* pobj = Z_OBJ_P(getThis()); 
157
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
158

    
159
    SaxonProcessor * saxonProc= obj->saxonProcessor;
160
    if(saxonProc != NULL) {    
161
        delete saxonProc;
162
    }
163
}
164

    
165
PHP_METHOD(SaxonProcessor, setResourcesDirectory)
166
{
167
    SaxonProcessor *saxonProcessor;
168
    char * dirStr;
169
    size_t len;
170
    
171
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &dirStr, &len) == FAILURE) {
172
        RETURN_NULL();
173
    }
174
    
175
    zend_object* pobj = Z_OBJ_P(getThis()); 
176
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
177
    saxonProcessor = obj->saxonProcessor;
178
    if (saxonProcessor != NULL) {
179
       
180
        if(dirStr != NULL) {
181
            saxonProcessor->setResourcesDirectory(dirStr);
182
        }
183
    }
184
}
185

    
186
PHP_METHOD(SaxonProcessor, setCatalog)
187
{
188
    SaxonProcessor *saxonProcessor;
189
    char * catalogFile;
190
    size_t len;
191
    bool trace = false;
192
    
193
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sb", &catalogFile, &len, &trace) == FAILURE) {
194
        RETURN_NULL();
195
    }
196
    
197
    zend_object* pobj = Z_OBJ_P(getThis()); 
198
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
199
    saxonProcessor = obj->saxonProcessor;
200
    if (saxonProcessor != NULL) {
201
       
202
        if(catalogFile != NULL) {
203
            saxonProcessor->setCatalog(catalogFile, trace);
204
        }
205
    }
206
}
207

    
208

    
209

    
210

    
211
PHP_METHOD(SaxonProcessor, setcwd)
212
{
213
    SaxonProcessor *saxonProcessor;
214
    char * cwdStr;
215
    size_t len;
216
    
217
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &cwdStr, &len) == FAILURE) {
218
        RETURN_NULL();
219
    }
220
    
221
    zend_object* pobj = Z_OBJ_P(getThis()); 
222
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
223
    saxonProcessor = obj->saxonProcessor;
224
    if (saxonProcessor != NULL) {
225
        
226
        if(cwdStr != NULL) {
227
            saxonProcessor->setcwd(cwdStr);
228
        }
229
    }
230
}
231

    
232

    
233
PHP_METHOD(SaxonProcessor, parseXmlFromString)
234
{
235
    SaxonProcessor * saxonProcessor;
236
    char * source;
237
    size_t len1;
238

    
239
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
240
        RETURN_NULL();
241
    }
242
    zend_object* pobj = Z_OBJ_P(getThis()); 
243
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
244
    assert (obj != NULL);
245
    saxonProcessor = obj->saxonProcessor;
246
    if (saxonProcessor != NULL) {
247
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
248
        if(node != NULL) {
249
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
250
                RETURN_NULL();
251
            } else {
252
                zend_object* vobj = Z_OBJ_P(return_value);
253
                 xdmNode_object * xdmNObj = (xdmNode_object *)((char *)vobj - XtOffsetOf(xdmNode_object, std));
254
                assert (xdmNObj != NULL);
255
                xdmNObj->xdmNode = node;
256
            }
257
        } else {
258
            if(obj->saxonProcessor->exceptionOccurred()){
259
                //TODO throw exception
260
            }
261
        }
262
    } else {
263
        RETURN_NULL();
264
    }
265
}
266

    
267
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
268
{
269
    SaxonProcessor * saxonProcessor;
270
    char * source;
271
    size_t len1;
272

    
273
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
274
        RETURN_NULL();
275
    }
276
    zend_object* pobj = Z_OBJ_P(getThis()); 
277
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
278
    assert (obj != NULL);
279
    saxonProcessor = obj->saxonProcessor;
280
    if (saxonProcessor != NULL) {
281
        XdmNode* node = saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
282
        if(node != NULL) {
283
      
284
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
285
                RETURN_NULL();
286
            } else {
287
          
288
            zend_object* vvobj = Z_OBJ_P(return_value);
289
            xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
290
                
291
                assert (vobj != NULL);
292
                vobj->xdmNode = node;
293
            }
294
        } else {
295
           // obj->xsltProcessor->checkException();//TODO
296
        }
297
    } else {
298
  //  std::cerr<<"parseXmlFromFile cp2"<<std::endl;
299
        RETURN_NULL();
300
    }
301
   // std::cerr<<"parseXmlFromFile cp3"<<std::endl;
302
}
303

    
304

    
305
PHP_METHOD(SaxonProcessor, createAtomicValue)
306
{
307
    XdmAtomicValue * xdmValue = NULL;
308
    SaxonProcessor * proc;
309
    char * source;
310
    int len1;
311
    zval *zvalue;
312
    bool bVal;
313
    char * sVal;
314
    int len;
315
    long iVal;
316
    double dVal;
317
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == 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
    proc = obj->saxonProcessor;
324
    assert (proc != NULL);
325
    if (proc != NULL) {
326
        switch (Z_TYPE_P(zvalue)) {
327
            case IS_FALSE:
328
            xdmValue = proc->makeBooleanValue(false);
329
            case IS_TRUE:
330
                xdmValue = proc->makeBooleanValue(true);
331
            break;
332
            case IS_LONG:
333
                iVal = Z_LVAL_P(zvalue);
334
                 xdmValue = proc->makeIntegerValue((int)iVal);
335
            break;
336
            case IS_STRING:
337
                sVal = Z_STRVAL_P(zvalue);
338
                len = Z_STRLEN_P(zvalue);
339
                
340
                xdmValue = proc->makeStringValue((const char*)sVal);
341
                //efree(sVal);
342
            break;
343
            case IS_NULL:
344
                xdmValue = new XdmAtomicValue();
345
            break;
346
            case IS_DOUBLE:
347
                dVal = (double)Z_DVAL_P(zvalue);
348
                xdmValue = proc->makeDoubleValue((double)iVal);
349
                break;
350
            case IS_ARRAY:
351
                // TODO: Should not be expected. Do this some other way
352
                //break;
353
            case IS_OBJECT:
354
                // TODO: implement this
355
                //break;
356
            default:
357
                obj = NULL;
358
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC); 
359
                RETURN_NULL();
360
        }
361
//std::cerr<<"createAtomicValue cp0"<<std::endl;
362
        if(xdmValue == NULL) {
363
            RETURN_NULL();
364
        }
365
        if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
366
            RETURN_NULL();
367
        } else {
368
            //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value);
369
             zend_object* vvobj = Z_OBJ_P(return_value);
370
           xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
371
            assert (vobj != NULL);
372
            vobj->xdmAtomicValue = xdmValue;
373
        }
374
    } else {
375
       
376
        RETURN_NULL();
377
    }
378
}
379

    
380

    
381
PHP_METHOD(SaxonProcessor, newXPathProcessor)
382
{
383
   
384
    if (ZEND_NUM_ARGS()>0) {
385
        WRONG_PARAM_COUNT;
386
    }
387
    SaxonProcessor * proc;
388
    XPathProcessor * xpathProcessor = NULL;
389

    
390
    zend_object* pobj = Z_OBJ_P(getThis()); 
391
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
392

    
393
    assert (obj != NULL);
394
    proc = obj->saxonProcessor;
395
    assert (proc != NULL);
396
    if (proc != NULL) {
397
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
398
            RETURN_NULL();
399
        } else {
400
          // struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)Z_OBJ_P(return_value TSRMLS_CC);
401
           zend_object* vvobj = Z_OBJ_P(return_value);
402
           xpathProcessor_object * vobj = (xpathProcessor_object *)((char *)vvobj - XtOffsetOf(xpathProcessor_object, std));
403
            assert (vobj != NULL);
404
            xpathProcessor = proc->newXPathProcessor();
405
            vobj->xpathProcessor = xpathProcessor;
406
        }
407
    } else {
408
       
409
        RETURN_NULL();
410
    }
411
}
412

    
413
PHP_METHOD(SaxonProcessor, newXsltProcessor)
414
{
415
//std::cerr<<"SaxonProcessor newXsltproc point 1"<<std::endl;
416
    //php_error(E_WARNING,"new xsltProc 1");
417
    if (ZEND_NUM_ARGS()>0) {
418
        WRONG_PARAM_COUNT;
419
    }
420
    SaxonProcessor * proc;
421
    XsltProcessor * xsltProcessor = NULL;
422

    
423
      zend_object* pobj = Z_OBJ_P(getThis()); 
424
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
425

    
426
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
427
    assert (obj != NULL);
428
    proc = obj->saxonProcessor;
429

    
430
    assert (proc != NULL);
431
    if (proc != NULL) {
432
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
433
            RETURN_NULL();
434
        } else {
435
        xsltProcessor = proc->newXsltProcessor();
436
           zend_object* vobj = Z_OBJ_P(return_value);
437
           xsltProcessor_object * xproc_object = (xsltProcessor_object *)((char *)vobj - XtOffsetOf(xsltProcessor_object, std));
438
            assert (vobj != NULL);
439
            
440
            xproc_object->xsltProcessor = xsltProcessor;
441

    
442
    }
443
    } else {
444
       
445
        RETURN_NULL();
446
    }
447
}
448

    
449
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
450
{
451
   
452
    if (ZEND_NUM_ARGS()>0) {
453
        WRONG_PARAM_COUNT;
454
    }
455
    SaxonProcessor * proc;
456
    XQueryProcessor * xqueryProcessor = NULL;
457
     zend_object* pobj = Z_OBJ_P(getThis()); 
458
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
459
    assert (obj != NULL);
460
    proc = obj->saxonProcessor;
461
    assert (proc != NULL);
462
    if (proc != NULL) {
463
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
464
            RETURN_NULL();
465
        } else {
466
          xqueryProcessor = proc->newXQueryProcessor();
467
          zend_object* vvobj = Z_OBJ_P(return_value);
468
           xqueryProcessor_object * vobj = (xqueryProcessor_object *)((char *)vvobj - XtOffsetOf(xqueryProcessor_object, std));
469
            assert (vvobj != NULL);
470
            
471
            vobj->xqueryProcessor = xqueryProcessor;
472
     }
473
    } else {
474
       
475
        RETURN_NULL();
476
    }
477
}
478

    
479
PHP_METHOD(SaxonProcessor, newSchemaValidator)
480
{
481
   
482
    if (ZEND_NUM_ARGS()>0) {
483
        WRONG_PARAM_COUNT;
484
    }
485
    SaxonProcessor * proc;
486
    SchemaValidator * schemaValidator = NULL;
487
   
488
    zend_object* pobj = Z_OBJ_P(getThis()); 
489
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
490
    assert (obj != NULL);
491
    proc = obj->saxonProcessor;
492
    assert (proc != NULL);
493
    if (proc != NULL) {
494
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
495
            RETURN_NULL();
496
        } else {
497
           //struct schemaValidator_object* vobj = (struct schemaValidator_object *)Z_OBJ_P(return_value TSRMLS_CC);
498
           zend_object* vvobj = Z_OBJ_P(return_value);
499
           schemaValidator_object * vobj = (schemaValidator_object *)((char *)vvobj - XtOffsetOf(schemaValidator_object, std));
500
            assert (vobj != NULL);
501
            schemaValidator = proc->newSchemaValidator();
502
            if(schemaValidator == NULL){
503
                RETURN_NULL();
504
            }
505
            vobj->schemaValidator = schemaValidator;
506
        }
507
    } else {
508
       
509
        RETURN_NULL();
510
    }
511
}
512

    
513

    
514
PHP_METHOD(SaxonProcessor, version)
515
{
516
    SaxonProcessor *saxonProcessor;
517

    
518
   
519
    if (ZEND_NUM_ARGS()>0) {
520
        WRONG_PARAM_COUNT;
521
    }
522
    zend_object* pobj = Z_OBJ_P(getThis()); 
523
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
524
    saxonProcessor = obj->saxonProcessor;
525
    if (saxonProcessor != NULL) {
526
        const char * verStr = saxonProcessor->version();
527
        //char *str = estrdup(saxonProcessor->version());
528
        _RETURN_STRING(verStr);
529
//efree(verStr);
530
    }
531
    RETURN_NULL();
532
}
533

    
534

    
535
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
536
{
537
    SaxonProcessor *saxonProcessor;
538
    char * name;
539
    char * value;
540
    size_t len1, len2;
541
    if (ZEND_NUM_ARGS()!= 2) {
542
        WRONG_PARAM_COUNT;
543
    }
544

    
545
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
546
        RETURN_NULL();
547
    }
548
    zend_object* pobj = Z_OBJ_P(getThis()); 
549
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
550

    
551
    saxonProcessor = obj->saxonProcessor;
552
    if (saxonProcessor != NULL && name != NULL && value != NULL) {
553
        saxonProcessor->setConfigurationProperty(name, value);
554
    }
555
    
556
}
557

    
558
PHP_METHOD(SaxonProcessor, registerPHPFunctions)
559
{
560
    SaxonProcessor *saxonProcessor;
561
    char * libName;
562
    size_t len1;
563
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
564
    if (ZEND_NUM_ARGS()!= 1) {
565
        WRONG_PARAM_COUNT;
566
    }
567

    
568
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &libName, &len1) == FAILURE) {
569
        RETURN_NULL();
570
    }
571
//std::cerr<<"checkpoint in registerPHPFunction cp2"<<std::endl;
572
    zend_object* pobj = Z_OBJ_P(getThis()); 
573
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
574

    
575
    saxonProcessor = obj->saxonProcessor;
576
    if (saxonProcessor != NULL && libName != NULL) {
577
        saxonProcessor->setConfigurationProperty("extc", libName);
578
    }
579
saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PHPFunction",
580
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
581
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
582
}
583

    
584
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
585

    
586
void XsltProcessor_free_storage(zend_object *object)
587
{
588

    
589
    zend_object_std_dtor(object);
590
}
591

    
592
void XsltProcessor_destroy_storage(zend_object *object)
593
{
594
    xsltProcessor_object *obj;
595

    
596
    zend_objects_destroy_object(object);
597
}
598

    
599
zend_object * xsltProcessor_create_handler(zend_class_entry *type)
600
{
601
   
602

    
603
    xsltProcessor_object *obj = (xsltProcessor_object *)ecalloc(1, sizeof(xsltProcessor_object)+ zend_object_properties_size(type));
604
   
605
    
606
   zend_object_std_init(&obj->std,type);
607
    object_properties_init(&obj->std, type);
608
    
609
    obj->std.handlers = &xsltProcessor_object_handlers;
610

    
611
    return &obj->std;
612
}
613

    
614

    
615

    
616
PHP_METHOD(XsltProcessor, __destruct)
617
{
618

    
619
    zend_object* pobj = Z_OBJ_P(getThis()); 
620
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
621

    
622

    
623
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
624
    if(xsltProcessor != NULL){
625
            delete xsltProcessor;
626
     }
627
 
628
    
629
}
630

    
631
PHP_METHOD(XsltProcessor, transformFileToFile)
632
{
633
    XsltProcessor *xsltProcessor;
634
    char * outfileName;
635
    char * infilename;
636
    char * styleFileName;
637
    size_t len1, len2, len3;
638

    
639
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
640
        RETURN_NULL();
641
    }
642

    
643
    zend_object* pobj = Z_OBJ_P(getThis()); 
644
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
645
    xsltProcessor = obj->xsltProcessor;
646
 
647
    if (xsltProcessor != NULL) {
648

    
649
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
650
        if(xsltProcessor->exceptionOccurred()) {
651
               // TODO: throw exception
652
        }
653
    }
654
}
655

    
656
PHP_METHOD(XsltProcessor, transformFileToValue)
657
{
658
    XsltProcessor *xsltProcessor;
659
    char * infilename;
660
    char * styleFileName;
661
   size_t len1, len2;
662

    
663
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
664
        RETURN_NULL();
665
    }
666

    
667
    zend_object* pobj = Z_OBJ_P(getThis()); 
668
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
669
    xsltProcessor = obj->xsltProcessor;
670
    
671
    if (xsltProcessor != NULL) {
672

    
673
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
674
        if(node != NULL) {
675
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
676
                RETURN_NULL();
677
            } else {
678
                struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
679
                assert (vobj != NULL);
680
                vobj->xdmValue = node;
681
            }
682
        } else {
683
            if(obj->xsltProcessor->exceptionOccurred()){
684
                  //TODO
685
            }
686
        }
687
    }else {
688
        RETURN_NULL();
689
    }
690
}
691

    
692

    
693
PHP_METHOD(XsltProcessor, transformFileToString)
694
{
695
    XsltProcessor *xsltProcessor;
696
    char * infilename;
697
    char * styleFileName;
698
    size_t len1, len2;
699

    
700
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
701
        RETURN_NULL();
702
    }
703

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

    
708
    if (xsltProcessor != NULL) {
709

    
710
        const char * result = xsltProcessor->transformFileToString(infilename, styleFileName);
711
        if(result != NULL) {
712
            //char *str = estrdup(result);
713
            _RETURN_STRING(result);
714
        } else if(xsltProcessor->exceptionOccurred()){
715
            //TODO: xsltProcessor->checkException();
716
            const char * errStr = xsltProcessor->getErrorMessage(0);
717
            if(errStr != NULL) {
718
                const char * errorCode = xsltProcessor->getErrorCode(0);
719
                if(errorCode!=NULL) {
720
                    // TODO: throw exception
721
                }
722
            }
723
        }
724
    }
725
}
726

    
727
/*enum saxonTypeEnum
728
{
729
        enumNode,
730
        enumString,
731
        enumInteger,
732
        enumDouble,
733
        enumFloat,
734
        enumBool,
735
        enumArrXdmValue
736
};*/
737

    
738
jobject JNICALL phpNativeCall
739
  (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
740
        JNIEnv *senv = SaxonProcessor::sxn_environ->env;
741
//        std::cerr<<"phpNative called"<<std::endl;
742
        char *nativeString = (char *)senv->GetStringUTFChars(funcName, NULL);
743
        string nativeString2 = string(nativeString);
744
        if(nativeString == NULL) {
745
                return NULL;        
746
        }
747
        int nativeStrLen = strlen(nativeString);
748
//std::cerr<<"phpNative called. nativeString="<<nativeString<<", length="<<nativeStrLen<<std::endl;
749
        zval function_name;
750
        zval retval;
751
        
752
        int argLength = 0;
753
        zvalArr * php_argv= NULL;
754
        if(arguments != NULL) {
755
                argLength = (int)senv->GetArrayLength(arguments);
756
                php_argv = new zvalArr[argLength];
757
        }
758
        zval *params;
759
        if(argLength>0) {
760
                //(*params) = (zval**)malloc(sizeof(zval*) * argLength);
761
                params =  new zval[argLength];
762
        } else {
763
                params = NULL;
764
        }
765
        std::map<std::string, saxonTypeEnum> typeMap;
766
        typeMap["node"] = enumNode;
767
        typeMap["string"] = enumString;
768
        typeMap["integer"] = enumInteger;
769
        typeMap["double"] = enumDouble;
770
        typeMap["float"] = enumFloat;
771
        typeMap["boolean"] = enumBool;
772
        typeMap["[xdmvalue"] = enumArrXdmValue;
773
        sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
774
        SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
775
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
776
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
777
                
778
//std::cerr<<"phpNative called cp2"<<std::endl;
779

    
780
        for(int i=0; i<argLength;i++){
781

    
782
                jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
783
                jobject argObj = senv->GetObjectArrayElement(arguments, i);
784

    
785
                const char * str = senv->GetStringUTFChars(argType,NULL);
786
                const char *stri = NULL;
787
                double dnumber = 0;
788
                long lnumber = 0;
789
                bool bvalue = false;
790
                float fnumber = 0;
791
                
792

    
793
         
794
                struct xdmNode_object* vobj;
795
                zend_object* zend_vobj;
796
                XdmNode * node = NULL;
797
                std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
798
                if (it != typeMap.end()){
799
                        switch (it->second)
800
                        {
801
                                case enumNode:
802
                                        if(!nprocessor->proc){
803
                                                nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
804
                                        }
805
                                        if (object_init_ex(php_argv[i]._val, xdmNode_ce) != SUCCESS) {
806
                                                //error
807
                                                
808
                                                //php_error(E_WARNING,"error phpNative xdmNode creation failed");
809
                                                    break;
810
                                        } 
811
                                        node = new XdmNode(argObj);
812
                                        node->setProcessor(nprocessor);
813

    
814
                                        //MAKE_STD_ZVAL(php_argv[i]._val);
815
                                        zend_vobj = Z_OBJ_P(php_argv[i]._val);
816
                                           vobj = (xdmNode_object *)((char *)zend_vobj - XtOffsetOf(xdmNode_object, std));
817
                                            assert (vobj != NULL);
818
            
819
                                        vobj->xdmNode = node;
820
                                        break;
821
                                case enumString:
822
                                        stri = senv->GetStringUTFChars((jstring)argObj, NULL);
823
                                        //ZVAL_STRING(php_argv[i]._val);
824
                                        _ZVAL_STRING(php_argv[i]._val, stri);
825
                                        break;
826
                                case enumInteger:
827
                                        sresult->xdmvalue = argObj; 
828
                                        lnumber = getLongValue(*SaxonProcessor::sxn_environ, *sresult, 0);
829

    
830
                                        //MAKE_STD_ZVAL(php_argv[i]._val);
831
                                        ZVAL_LONG(php_argv[i]._val, lnumber);                                        
832
                                        break;
833
                                case enumDouble:
834
                                        sresult->xdmvalue = argObj; 
835
                                        dnumber = getDoubleValue(*SaxonProcessor::sxn_environ, *sresult, 0);
836
                                        //MAKE_STD_ZVAL(php_argv[i]._val);
837
                                        ZVAL_DOUBLE(php_argv[i]._val, dnumber);
838
                                        break;
839
                                case enumFloat:
840
                                        sresult->xdmvalue = argObj; 
841
                                        fnumber = getFloatValue(*SaxonProcessor::sxn_environ, *sresult, 0);
842
                                        //MAKE_STD_ZVAL(php_argv[i]._val);
843
                                        ZVAL_DOUBLE(php_argv[i]._val, fnumber);                                        
844
                                        break;
845
                                case enumBool:
846
                                        sresult->xdmvalue = argObj; 
847
                                        bvalue = getBooleanValue(*SaxonProcessor::sxn_environ, *sresult);
848
                                        //MAKE_STD_ZVAL(php_argv[i]._val);
849
                                        ZVAL_BOOL(php_argv[i]._val, bvalue);                                                
850
                                        break;
851
                                case enumArrXdmValue:
852
                                        //TODO - not currently supported
853
                                        argLength--;
854
                                        break;
855
                        }
856
                        senv->ReleaseStringUTFChars(argType, str);
857
                } 
858

    
859
}
860

    
861
        //TODO should free sresult but it causes memory corruption        
862
                
863
// array of zvals to execute
864
    
865
//std::cerr<<"phpNative called cp3"<<std::endl;
866
 
867
            // convert all the values
868
            for(int i = 0; i < argLength; i++) { 
869

    
870
                params[i] = *php_argv[i]._val; }
871

    
872
        //std::cerr<<"phpNative called cp3-1"<<std::endl;
873
        //note: no implicit type conversion.
874

    
875
        zval *argvv = NULL;//xparams;
876
        zval* callOnObj = NULL;
877
        //MAKE_STD_ZVAL(function_name);
878
        //nativeString[nativeStrLen] = '\0';
879

    
880
        ZVAL_STRING(&function_name, nativeString);
881
//std::cerr<<"phpNative called cp3-2, argumentLen="<<argLength<<std::endl;
882
        if(call_user_function_ex(CG(function_table), (zval*)callOnObj, &function_name, &retval, argLength, params, 0, NULL) != SUCCESS)
883
        {
884
            zend_error(E_ERROR, "Function call failed");
885
        }
886

    
887
        if(Z_TYPE(retval) ==0){
888
                zend_error(E_ERROR, "Function returned null");
889
        }
890

    
891
        char * sVal = NULL;
892
        int len = 0;
893
        jobject obj = NULL;
894
//TODO handle XdmValue wrapped object
895
const char * objName = NULL;
896
xdmNode_object* ooth = NULL;
897
zend_object* zend_vobj2;
898
bool bVal;
899
        switch (Z_TYPE_P(&retval)) {
900
            case IS_FALSE:
901
                obj= booleanValue(*SaxonProcessor::sxn_environ, false);
902
                break;
903
            case IS_TRUE:
904
                obj= booleanValue(*SaxonProcessor::sxn_environ, true);
905
                break;
906
            
907
            case IS_LONG:
908
                obj= longValue(*SaxonProcessor::sxn_environ, Z_LVAL_P(&retval));
909
                break;
910
            case IS_STRING:
911
                sVal = Z_STRVAL_P(&retval);
912
                len = Z_STRLEN_P(&retval);
913
                obj = getJavaStringValue(*SaxonProcessor::sxn_environ,estrndup(sVal, len)); 
914
                break;
915
            break;
916
            case IS_NULL:
917
                
918
                    break;
919
            case IS_DOUBLE:
920
                obj = doubleValue(*SaxonProcessor::sxn_environ, (double)Z_DVAL_P(&retval));                
921
                 break;
922
            
923
            case IS_ARRAY:
924
            //break;
925
            case IS_OBJECT:
926
                
927
                    objName =ZSTR_VAL(Z_OBJCE_P(&retval)->name);
928
      
929

    
930
                      if(strcmp(objName, "Saxon\\XdmNode")==0) {
931
                
932
                        zend_vobj2 =  Z_OBJ_P(&retval);
933
                        ooth = (xdmNode_object *)((char *)zend_vobj2 - XtOffsetOf(xdmNode_object, std));
934

    
935
                        if(ooth != NULL) {
936
                                    obj = ooth->xdmNode->getUnderlyingValue();
937
                        }
938
                      }
939
                break;
940
            default:
941
                obj = NULL;
942
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
943
        }
944

    
945
        //zend_printf("We have %i as type<br>", retval->type);
946
        //*return_value = *retval;
947
        //zval_copy_ctor(return_value);
948
        //zval_ptr_dtor(&retval);
949
        /*int cstrlen = Z_STRLEN_P(retval);
950
        char * str = estrndup(Z_STRVAL_P(retval), cstrlen);
951
        
952
        jstring jstrBuf = SaxonProcessor::sxn_environ->env->NewStringUTF(str);*/
953
        zval_ptr_dtor(&retval);
954
        return obj;
955
}
956

    
957

    
958

    
959
PHP_METHOD(XsltProcessor, transformToString)
960
{
961
    XsltProcessor *xsltProcessor;
962
 
963
    if (ZEND_NUM_ARGS()>0) {
964
        WRONG_PARAM_COUNT;
965
    }
966
////
967
/*zval *function_name;
968
zval *retval;
969

970
char * str = "userFunction";
971

972

973
MAKE_STD_ZVAL(function_name);
974
_ZVAL_STRING(function_name, str);
975
if(call_user_function_ex(CG(function_table), NULL, function_name, &retval, 0, NULL, 0, NULL TSRMLS_CC) != SUCCESS)
976
{
977
    zend_error(E_ERROR, "Function call failed");
978
}
979

980
if(Z_TYPE(*retval) ==0){
981
zend_error(E_ERROR, "DATAYYY is NULL");
982
}else {
983
str = Z_STRVAL_P(retval);
984
zend_printf("DATAYYY= %i <br>", str);
985
} 
986

987
zend_printf("We have %i as type<br>", retval->type);
988
*return_value = *retval;
989
zval_copy_ctor(return_value);
990
zval_ptr_dtor(&retval);*/
991

    
992

    
993
////
994

    
995
    zend_object* pobj = Z_OBJ_P(getThis()); 
996
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
997
    xsltProcessor = obj->xsltProcessor;
998
    if (xsltProcessor != NULL) {
999

    
1000
        const char * result = xsltProcessor->transformToString();
1001
        if(result != NULL) {
1002
            _RETURN_STRING(result);
1003
        } else if(xsltProcessor->exceptionOccurred()){
1004
            xsltProcessor->checkException();
1005
            const char * errStr = xsltProcessor->getErrorMessage(0);
1006
            if(errStr != NULL) {
1007
                const char * errorCode = xsltProcessor->getErrorCode(0);
1008
                if(errorCode!=NULL) {
1009
                    // TODO: throw exception
1010
                }
1011
            }
1012
        }
1013
    }
1014
    RETURN_NULL();
1015
}
1016

    
1017
PHP_METHOD(XsltProcessor, transformToValue)
1018
{
1019
    XsltProcessor *xsltProcessor;
1020

    
1021
    if (ZEND_NUM_ARGS()>0) {
1022
        WRONG_PARAM_COUNT;
1023
    }
1024

    
1025
    zend_object* pobj = Z_OBJ_P(getThis()); 
1026
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1027
    xsltProcessor = obj->xsltProcessor;
1028

    
1029
    if (xsltProcessor != NULL) {
1030

    
1031
        XdmValue * node = xsltProcessor->transformToValue();
1032
        if(node != NULL) {
1033
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1034
                RETURN_NULL();
1035
            } else {
1036
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value);
1037
                zend_object *vvobj =  Z_OBJ_P(return_value);
1038
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1039

    
1040
                        
1041
                assert (vobj != NULL);
1042
                vobj->xdmValue = node;
1043
            }
1044
        } else if(xsltProcessor->exceptionOccurred()){
1045
            xsltProcessor->checkException();
1046
            RETURN_NULL();
1047
        }
1048
    } else {
1049
        RETURN_NULL();
1050
    }
1051
}
1052

    
1053
PHP_METHOD(XsltProcessor, transformToFile)
1054
{
1055
    XsltProcessor *xsltProcessor;
1056
 
1057
    if (ZEND_NUM_ARGS()>0) {
1058
        WRONG_PARAM_COUNT;
1059
    }
1060

    
1061
    zend_object* pobj = Z_OBJ_P(getThis()); 
1062
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1063
    xsltProcessor = obj->xsltProcessor;
1064

    
1065
    if (xsltProcessor != NULL) {
1066

    
1067
        xsltProcessor->transformToFile();
1068
        if(xsltProcessor->exceptionOccurred()) {
1069
           //TODO
1070
            const char * exStr = xsltProcessor->checkException();
1071
        }
1072
    } else {
1073
        RETURN_NULL();
1074
    }
1075
}
1076

    
1077
PHP_METHOD(XsltProcessor, compileFromFile)
1078
{
1079
    XsltProcessor *xsltProcessor;
1080
    char * name;
1081
    size_t len1;
1082
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
1083
        RETURN_NULL();
1084
    }
1085
    zend_object* pobj = Z_OBJ_P(getThis()); 
1086
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1087
    xsltProcessor = obj->xsltProcessor;
1088
    if (xsltProcessor != NULL) {
1089
        xsltProcessor->compileFromFile(name);
1090
    }
1091
}
1092

    
1093
PHP_METHOD(XsltProcessor, compileFromString)
1094
{
1095
    XsltProcessor *xsltProcessor;
1096
    char * stylesheetStr;
1097
    size_t len1, myint;
1098
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
1099
        RETURN_NULL();
1100
    }
1101
    zend_object* pobj = Z_OBJ_P(getThis()); 
1102
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1103
    xsltProcessor = obj->xsltProcessor;
1104
    if (xsltProcessor != NULL) {
1105
        xsltProcessor->compileFromString(stylesheetStr);
1106
    }
1107
}
1108

    
1109
PHP_METHOD(XsltProcessor, compileFromStringAndSave)
1110
{
1111
    XsltProcessor *xsltProcessor;
1112
    char * stylesheetStr;
1113
    char * filename;
1114
    size_t len1, len2, myint;
1115
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetStr, filename, &len1, &len2) == FAILURE) {
1116
        RETURN_NULL();
1117
    }
1118
    zend_object* pobj = Z_OBJ_P(getThis()); 
1119
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1120
    xsltProcessor = obj->xsltProcessor;
1121
    if (xsltProcessor != NULL) {
1122
        xsltProcessor->compileFromStringAndSave(stylesheetStr, filename);
1123
    }
1124
}
1125

    
1126
PHP_METHOD(XsltProcessor, compileFromFileAndSave)
1127
{
1128
    XsltProcessor *xsltProcessor;
1129
    char * stylesheetFilename;
1130
    char * filename;
1131
    size_t len1, len2, myint;
1132
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
1133
        RETURN_NULL();
1134
    }
1135
    zend_object* pobj = Z_OBJ_P(getThis()); 
1136
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1137
    xsltProcessor = obj->xsltProcessor;
1138
    if (xsltProcessor != NULL) {
1139
        xsltProcessor->compileFromStringAndSave(stylesheetFilename, filename);
1140
    }
1141
}
1142

    
1143
PHP_METHOD(XsltProcessor, compileFromValue)
1144
{
1145
    XsltProcessor *xsltProcessor;
1146
   zval* oth;
1147

    
1148
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
1149
        RETURN_NULL();
1150
    }
1151
    zend_object* pobj = Z_OBJ_P(getThis()); 
1152
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1153
    xsltProcessor = obj->xsltProcessor;
1154
    if (xsltProcessor != NULL) {
1155
        zend_object* vvobj = Z_OBJ_P(oth);
1156
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1157
        if(ooth != NULL) {
1158
            XdmValue * value = ooth->xdmValue;
1159
            if(value != NULL && value->size() == 1 && (value->getHead())->getType() == 3) {
1160
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1161
            }
1162
        }
1163
    }
1164
}
1165

    
1166

    
1167

    
1168

    
1169
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1170
{
1171
    XsltProcessor *xsltProcessor;
1172
    zval* oth = NULL;
1173

    
1174
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1175
        RETURN_NULL();
1176
    }
1177

    
1178
    zend_object* pobj = Z_OBJ_P(getThis()); 
1179
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1180
    xsltProcessor = obj->xsltProcessor;
1181
    if (xsltProcessor != NULL) {
1182

    
1183
    if(!oth) {
1184
        php_error(E_WARNING, "Error setting source value");
1185
        return;
1186
    } else {
1187
        if(Z_TYPE_P(oth) ==IS_NULL){
1188
                php_error(E_WARNING, "Error setting source value");
1189
                return;
1190
        }
1191
        
1192
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1193
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1194

    
1195
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1196
        zend_object * nobj = Z_OBJ_P(oth);
1197

    
1198
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1199
        if(ooth != NULL) {
1200
            XdmNode * value = ooth->xdmNode;
1201
            if(value != NULL) {        
1202
                XdmItem  *valueX = (XdmItem*)value;
1203
                xsltProcessor->setSourceFromXdmValue(valueX);
1204

    
1205
            }
1206
        }
1207
      } else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1208
        zend_object* vvobj = Z_OBJ_P(oth);
1209
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1210
        if(ooth != NULL) {
1211
            XdmValue * value = ooth->xdmValue;
1212
            if(value != NULL) {
1213
                xsltProcessor->setSourceFromXdmValue((XdmItem*)value);
1214
            }
1215
        }
1216
      }  
1217

    
1218
        
1219
    }
1220
  }
1221
}
1222

    
1223
PHP_METHOD(XsltProcessor, setOutputFile)
1224
{
1225
    XsltProcessor *xsltProcessor;
1226
    char * outputFilename;
1227
    size_t len1;
1228

    
1229
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
1230
        RETURN_NULL();
1231
    }
1232

    
1233
    zend_object* pobj = Z_OBJ_P(getThis()); 
1234
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1235
    xsltProcessor = obj->xsltProcessor;
1236
    if (xsltProcessor != NULL && outputFilename != NULL) {
1237
        
1238
         xsltProcessor->setOutputFile(outputFilename);
1239
            
1240
        
1241
    }
1242
}
1243

    
1244
int size_t2int(size_t val) {
1245
    return (val <= INT_MAX) ? (int)((ssize_t)val) : -1;
1246
}
1247

    
1248
PHP_METHOD(XsltProcessor, setSourceFromFile)
1249
{
1250
    XsltProcessor *xsltProcessor;
1251
    char * inFilename;
1252
    size_t len1;
1253
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
1254
        RETURN_NULL();
1255
    }
1256

    
1257
    zend_object* pobj = Z_OBJ_P(getThis()); 
1258
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1259
    xsltProcessor = obj->xsltProcessor;
1260
    if (xsltProcessor != NULL && inFilename != NULL) {
1261
         xsltProcessor->setSourceFromFile(inFilename);
1262
            
1263
        
1264
    }
1265
}
1266

    
1267

    
1268
PHP_METHOD(XsltProcessor, setProperty)
1269
{
1270
    XsltProcessor *xsltProcessor;
1271
    char * name;
1272
    char * value;
1273
    size_t len1, len2, myint;
1274

    
1275
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
1276
        RETURN_NULL();
1277
    }
1278
    zend_object* pobj = Z_OBJ_P(getThis()); 
1279
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1280
    xsltProcessor = obj->xsltProcessor;
1281
    if (xsltProcessor != NULL) {
1282
        xsltProcessor->setProperty(name, value);
1283
    }
1284
}
1285

    
1286
PHP_METHOD(XsltProcessor, setParameter)
1287
{
1288

    
1289
   XsltProcessor *xsltProcessor;
1290
   char * name;
1291
   zval* oth;
1292
   size_t len1, len2, myint;        
1293
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1294
        RETURN_NULL();
1295
    }
1296
    zend_object* pobj = Z_OBJ_P(getThis()); 
1297
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1298
    xsltProcessor = obj->xsltProcessor;
1299
    if (xsltProcessor != NULL) {
1300
        if(Z_TYPE_P(oth) ==IS_NULL){
1301
                php_error(E_WARNING, "Error setting source value - value is null");
1302
                return;
1303
        }
1304

    
1305
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1306
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1307

    
1308
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1309
        zend_object* ooth = Z_OBJ_P(oth);
1310
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1311
        if(nobj != NULL) {
1312
            XdmNode * value = nobj->xdmNode;
1313
            if(value != NULL) {        
1314
                xsltProcessor->setParameter(name, (XdmValue *)value);
1315

    
1316
            }
1317
        }
1318
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1319
        zend_object* ooth = Z_OBJ_P(oth);
1320
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1321
        if(vobj != NULL) {
1322
            XdmValue * value = vobj->xdmValue;
1323
            if(value != NULL) {
1324
                
1325
                xsltProcessor->setParameter(name, value);
1326
            }
1327
        }
1328

    
1329

    
1330

    
1331
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1332
        zend_object* ooth = Z_OBJ_P(oth);
1333
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1334
        if(aobj != NULL) {
1335
            XdmAtomicValue * value = aobj->xdmAtomicValue;
1336
            if(value != NULL) {
1337
                xsltProcessor->setParameter(name, (XdmValue *)value);
1338
            }
1339
        }
1340

    
1341

    
1342

    
1343
      }
1344

    
1345
    }
1346
}
1347

    
1348
PHP_METHOD(XsltProcessor, clearParameters)
1349
{
1350
    XsltProcessor *xsltProcessor;
1351
    if (ZEND_NUM_ARGS()>0) {
1352
        WRONG_PARAM_COUNT;
1353
    }
1354

    
1355
    zend_object* pobj = Z_OBJ_P(getThis()); 
1356
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1357
    xsltProcessor = obj->xsltProcessor;
1358
    if (xsltProcessor != NULL) {
1359
        xsltProcessor->clearParameters(true);
1360
    }
1361
}
1362

    
1363
PHP_METHOD(XsltProcessor, clearProperties)
1364
{
1365
    XsltProcessor *xsltProcessor;
1366
    if (ZEND_NUM_ARGS()>0) {
1367
        WRONG_PARAM_COUNT;
1368
    }
1369

    
1370
    zend_object* pobj = Z_OBJ_P(getThis()); 
1371
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1372
    xsltProcessor = obj->xsltProcessor;
1373
    if (xsltProcessor != NULL) {
1374
        xsltProcessor->clearProperties();
1375
    }
1376
}
1377

    
1378
PHP_METHOD(XsltProcessor, exceptionOccurred)
1379
{
1380
    XsltProcessor *xsltProcessor;
1381
    zend_object* pobj = Z_OBJ_P(getThis()); 
1382
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1383
    if (ZEND_NUM_ARGS()>0) {
1384
        WRONG_PARAM_COUNT;
1385
    }
1386

    
1387
    xsltProcessor = obj->xsltProcessor;
1388
    if (xsltProcessor != NULL) {
1389
        bool result = xsltProcessor->exceptionOccurred();
1390
        RETURN_BOOL(result);
1391
    }
1392
    RETURN_BOOL(false);
1393
}
1394

    
1395
PHP_METHOD(XsltProcessor, getExceptionCount)
1396
{
1397
    XsltProcessor *xsltProcessor;
1398
    zend_object* pobj = Z_OBJ_P(getThis()); 
1399
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1400
    if (ZEND_NUM_ARGS()>0) {
1401
        WRONG_PARAM_COUNT;
1402
    }
1403

    
1404
    xsltProcessor = obj->xsltProcessor;
1405
    if (xsltProcessor != NULL) {
1406
        int count = xsltProcessor->exceptionCount();
1407
        RETURN_LONG(count);
1408
    }
1409
    RETURN_LONG(0);
1410
}
1411

    
1412
PHP_METHOD(XsltProcessor, getErrorCode)
1413
{
1414
    XsltProcessor *xsltProcessor;
1415
    long index;
1416
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1417
        RETURN_NULL();
1418
    }
1419
    zend_object* pobj = Z_OBJ_P(getThis()); 
1420
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1421
    xsltProcessor = obj->xsltProcessor;
1422
    if (xsltProcessor != NULL) {
1423
        const char * errCode = xsltProcessor->getErrorCode((int)index);
1424
        if(errCode != NULL) {
1425
            //char *str = estrdup(errCode);
1426
            _RETURN_STRING(errCode);
1427
        }
1428
    }
1429
    RETURN_NULL();
1430
}
1431

    
1432
PHP_METHOD(XsltProcessor, getErrorMessage)
1433
{
1434
    XsltProcessor *xsltProcessor;
1435
    long index;
1436
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1437
        RETURN_NULL();
1438
    }
1439
    zend_object* pobj = Z_OBJ_P(getThis()); 
1440
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1441
    xsltProcessor = obj->xsltProcessor;
1442
    if (xsltProcessor != NULL) {
1443
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1444
        if(errStr != NULL) {
1445
            //char *str = estrdup(errStr);
1446
            _RETURN_STRING(errStr);
1447
        }
1448
    }
1449
    RETURN_NULL();
1450
}
1451
PHP_METHOD(XsltProcessor, exceptionClear)
1452
{
1453
    XsltProcessor *xsltProcessor;
1454
    zend_object* pobj = Z_OBJ_P(getThis()); 
1455
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1456
    xsltProcessor = obj->xsltProcessor;
1457
    if (xsltProcessor != NULL) {
1458
        xsltProcessor->exceptionClear();
1459
    }
1460
}
1461

    
1462

    
1463

    
1464

    
1465
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
1466

    
1467
void xqueryProcessor_free_storage(zend_object *object)
1468
{
1469
    zend_object_std_dtor(object);
1470
}
1471

    
1472
void xqueryProcessor_destroy_storage(zend_object *object)
1473
{
1474
    zend_objects_destroy_object(object);
1475
}
1476

    
1477
zend_object *xqueryProcessor_create_handler(zend_class_entry *type)
1478
{
1479

    
1480
    xqueryProcessor_object *obj = (xqueryProcessor_object *)ecalloc(1, sizeof(xqueryProcessor_object)+ zend_object_properties_size(type));
1481
    zend_object_std_init(&obj->std, type); 
1482
    object_properties_init(&obj->std, type);
1483
    obj->std.handlers = &xqueryProcessor_object_handlers;
1484

    
1485
    return &obj->std;
1486
}
1487

    
1488
PHP_METHOD(XQueryProcessor, __destruct)
1489
{
1490
    zend_object* pobj = Z_OBJ_P(getThis());
1491
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1492
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
1493
    if(xqueryProcessor != NULL){
1494
            delete xqueryProcessor;
1495
    }
1496
}
1497

    
1498

    
1499
PHP_METHOD(XQueryProcessor, runQueryToValue)
1500
{
1501
    XQueryProcessor *xqueryProcessor;
1502
    zend_object* pobj = Z_OBJ_P(getThis()); 
1503
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1504

    
1505
    if (ZEND_NUM_ARGS()>0) {
1506
        WRONG_PARAM_COUNT;
1507
    }
1508

    
1509
    xqueryProcessor = obj->xqueryProcessor;
1510

    
1511
    if (xqueryProcessor != NULL) {
1512
        XdmValue * node = xqueryProcessor->runQueryToValue();
1513
        if(node != NULL) {
1514
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1515
                RETURN_NULL();
1516
                return;
1517
            } else {
1518
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
1519
                zend_object *vvobj =  Z_OBJ_P(return_value);
1520
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1521
                assert (vobj != NULL);
1522
                vobj->xdmValue = node;
1523
                return;
1524
            }
1525
        }
1526
        xqueryProcessor->checkException();//TODO
1527
    } else {
1528
        RETURN_NULL();
1529
    }
1530
}
1531

    
1532
PHP_METHOD(XQueryProcessor, runQueryToString)
1533
{
1534
    XQueryProcessor *xqueryProcessor;
1535
   
1536

    
1537
    if (ZEND_NUM_ARGS()>0) {
1538
        WRONG_PARAM_COUNT;
1539
    }
1540
    zend_object* pobj = Z_OBJ_P(getThis()); 
1541
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1542
    xqueryProcessor = obj->xqueryProcessor;
1543

    
1544
    if (xqueryProcessor != NULL) {
1545
        const char * result = xqueryProcessor->runQueryToString();
1546
        if(result != NULL) {
1547
            //char *str = estrdup(result);
1548
            _RETURN_STRING(result);
1549
            return;
1550
        } else {
1551
          xqueryProcessor->checkException(); //TODO
1552
        }
1553
    }
1554
   RETURN_NULL();
1555
}
1556

    
1557
PHP_METHOD(XQueryProcessor, runQueryToFile)
1558
{
1559

    
1560
     char * ofilename;
1561
    size_t len1 =0;
1562
    if (ZEND_NUM_ARGS()!= 1) {
1563
        WRONG_PARAM_COUNT;
1564
    }
1565
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &ofilename, &len1) == FAILURE) {
1566
        RETURN_NULL();
1567
    }
1568
    XQueryProcessor *xqueryProcessor;
1569
    zend_object* pobj = Z_OBJ_P(getThis()); 
1570
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1571

    
1572

    
1573

    
1574
    xqueryProcessor = obj->xqueryProcessor;
1575

    
1576
    if (xqueryProcessor != NULL) {
1577
        if(ofilename != NULL) {
1578
                xqueryProcessor->setOutputFile(ofilename);        
1579
        }
1580
        xqueryProcessor->runQueryToFile(); 
1581
    }
1582

    
1583
}
1584

    
1585
PHP_METHOD(XQueryProcessor, setQueryContent)
1586
{
1587
    char * queryStr;
1588
    size_t len1;
1589

    
1590
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &queryStr, &len1) == FAILURE) {
1591
        RETURN_NULL();
1592
    }
1593
    zend_object* pobj = Z_OBJ_P(getThis()); 
1594
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std)); 
1595
    if(queryStr != NULL) { 
1596
      obj->xqueryProcessor->setProperty("qs", queryStr);
1597
   }
1598
}
1599

    
1600
PHP_METHOD(XQueryProcessor, setQueryFile)
1601
{
1602
   char * fileName;
1603
   size_t len1;
1604
    XQueryProcessor *xqueryProcessor;
1605

    
1606
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fileName, &len1) == FAILURE) {
1607
        RETURN_NULL();
1608
    }
1609
    if(fileName != NULL) {
1610
            zend_object* pobj = Z_OBJ_P(getThis()); 
1611
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1612
            xqueryProcessor = obj->xqueryProcessor;
1613
            xqueryProcessor->setQueryFile(fileName);
1614
    }
1615
            
1616
}
1617

    
1618
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
1619
{
1620
   char * base;
1621
   size_t len1;
1622
    XQueryProcessor *xqueryProcessor;
1623

    
1624
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &base, &len1) == FAILURE) {
1625
        RETURN_NULL();
1626
    }
1627
    if(base != NULL) {
1628
            zend_object* pobj = Z_OBJ_P(getThis()); 
1629
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1630
            xqueryProcessor = obj->xqueryProcessor;
1631
            xqueryProcessor->setQueryBaseURI(base);
1632
    }
1633
            
1634
}
1635

    
1636
PHP_METHOD(XQueryProcessor, declareNamespace)
1637
{
1638
   char * prefix;
1639
   char * ns;
1640
   size_t len1, len2;
1641
    XQueryProcessor *xqueryProcessor;
1642

    
1643
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
1644
        RETURN_NULL();
1645
    }
1646
    if(prefix != NULL && ns != NULL) {
1647
            zend_object* pobj = Z_OBJ_P(getThis()); 
1648
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1649
            xqueryProcessor = obj->xqueryProcessor;
1650
            xqueryProcessor->declareNamespace(prefix, ns);
1651
    }
1652
            
1653
}
1654

    
1655

    
1656

    
1657
PHP_METHOD(XQueryProcessor, setContextItem)
1658
{
1659
   char * context;
1660
   int len1;
1661
   zval* oth;
1662
    XQueryProcessor *xqueryProcessor;
1663

    
1664
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &oth) == FAILURE) {
1665
        RETURN_NULL();
1666
    }
1667
    if(oth != NULL) {
1668
            zend_object* pobj = Z_OBJ_P(getThis()); 
1669
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1670
            xqueryProcessor = obj->xqueryProcessor;
1671
    const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name); 
1672
        
1673
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1674
        zend_object *vvobj =  Z_OBJ_P(oth);
1675
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
1676
        //xdmNode_object* ooth = (xdmNode_object*)Z_OBJ_P(oth TSRMLS_CC);
1677
        if(ooth != NULL) {
1678
            XdmNode * value = ooth->xdmNode;
1679
            if(value != NULL) {        
1680
                xqueryProcessor->setContextItem((XdmItem *)value);
1681
               
1682
                return;
1683
            }
1684
        }
1685
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
1686
        zend_object *vvobj =  Z_OBJ_P(oth);
1687
        xdmItem_object* ooth  = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
1688
        if(ooth != NULL) {
1689
            XdmItem * value = ooth->xdmItem;
1690
            if(value != NULL) {        
1691
                xqueryProcessor->setContextItem(value);
1692
               
1693
                return;
1694
            }
1695
         }
1696
        
1697

    
1698

    
1699

    
1700
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1701
        zend_object *vvobj =  Z_OBJ_P(oth);
1702
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
1703
        if(ooth != NULL) {
1704
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1705
            if(value != NULL) {
1706
                
1707
                xqueryProcessor->setContextItem((XdmItem *)value);
1708
      
1709
                return;
1710
            }
1711
        }
1712

    
1713

    
1714

    
1715
      } 
1716

    
1717

    
1718
    }
1719
        //throw exception
1720
        
1721
            
1722
}
1723

    
1724
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
1725
{
1726
   char * cfilename;
1727
   size_t len1;
1728
    XQueryProcessor *xqueryProcessor;
1729

    
1730
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &cfilename, &len1) == FAILURE) {
1731
        RETURN_NULL();
1732
    }
1733
    if(cfilename != NULL) {
1734
             zend_object* pobj = Z_OBJ_P(getThis()); 
1735
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1736
            xqueryProcessor = obj->xqueryProcessor;
1737
            xqueryProcessor->setContextItemFromFile(cfilename);
1738
    }
1739
            
1740
}
1741

    
1742

    
1743
PHP_METHOD(XQueryProcessor, setProperty)
1744
{
1745
    XQueryProcessor *xqueryProcessor;
1746
    char * name;
1747
    char * value;
1748
    size_t len1, len2, myint;
1749

    
1750
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
1751
        RETURN_NULL();
1752
    }
1753
    zend_object* pobj = Z_OBJ_P(getThis()); 
1754
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1755
    xqueryProcessor = obj->xqueryProcessor;
1756
    if (xqueryProcessor != NULL) {
1757
        xqueryProcessor->setProperty(name, value);
1758
    }
1759
}
1760

    
1761
PHP_METHOD(XQueryProcessor, setParameter)
1762
{
1763

    
1764
   XQueryProcessor *xqueryProcessor;
1765
   char * name;
1766
   zval* oth;
1767
   size_t len1, len2, myint;        
1768
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1769
        RETURN_NULL();
1770
    }
1771
    zend_object* pobj = Z_OBJ_P(getThis()); 
1772
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1773
    xqueryProcessor = obj->xqueryProcessor;
1774
    if (xqueryProcessor != NULL) {
1775
        if(Z_TYPE_P(oth) ==IS_NULL){
1776
                php_error(E_WARNING, "Error setting source value - value is null");
1777
                return;
1778
        }
1779
             const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1780
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1781
//Z_ADDREF_P(oth);
1782
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1783
        zend_object *vvobj =  Z_OBJ_P(oth);
1784
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
1785
        if(ooth != NULL) {
1786
            XdmNode * value = ooth->xdmNode;
1787
            if(value != NULL) {        
1788
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1789

    
1790
            }
1791
        }
1792
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1793
        zend_object *vvobj =  Z_OBJ_P(oth);
1794
        xdmValue_object* ooth  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1795
        if(ooth != NULL) {
1796
            XdmValue * value = ooth->xdmValue;
1797
            if(value != NULL) {
1798
                
1799
                xqueryProcessor->setParameter(name, value);
1800
            }
1801
        }
1802

    
1803

    
1804

    
1805
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1806
        zend_object *vvobj =  Z_OBJ_P(oth);
1807
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
1808
        if(ooth != NULL) {
1809
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1810
            if(value != NULL) {
1811
                
1812
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1813
            } 
1814
        }
1815

    
1816

    
1817

    
1818
      }
1819

    
1820
    }
1821
}
1822

    
1823

    
1824

    
1825

    
1826
PHP_METHOD(XQueryProcessor, clearParameters)
1827
{
1828
    XQueryProcessor *xqueryProcessor;
1829
    if (ZEND_NUM_ARGS()>0) {
1830
        WRONG_PARAM_COUNT;
1831
    }
1832

    
1833
    zend_object* pobj = Z_OBJ_P(getThis()); 
1834
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1835
    xqueryProcessor = obj->xqueryProcessor;
1836
    if (xqueryProcessor != NULL) {
1837
        xqueryProcessor->clearParameters(true);
1838
    }
1839
}
1840

    
1841
PHP_METHOD(XQueryProcessor, clearProperties)
1842
{
1843
    XQueryProcessor *xqueryProcessor;
1844

    
1845
    if (ZEND_NUM_ARGS()>0) {
1846
        WRONG_PARAM_COUNT;
1847
    }
1848

    
1849
    zend_object* pobj = Z_OBJ_P(getThis()); 
1850
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1851
    xqueryProcessor = obj->xqueryProcessor;
1852
    if (xqueryProcessor != NULL) {
1853
        xqueryProcessor->clearProperties();
1854
    }
1855
}
1856

    
1857
PHP_METHOD(XQueryProcessor, exceptionOccurred)
1858
{
1859
    XQueryProcessor *xqueryProcessor;
1860
    zend_object* pobj = Z_OBJ_P(getThis()); 
1861
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1862
    if (ZEND_NUM_ARGS()>0) {
1863
        WRONG_PARAM_COUNT;
1864
    }
1865

    
1866
    xqueryProcessor = obj->xqueryProcessor;
1867
    if (xqueryProcessor != NULL) {
1868
        bool result = xqueryProcessor->exceptionOccurred();
1869
        RETURN_BOOL(result);
1870
    }
1871
    RETURN_BOOL(false);
1872
}
1873

    
1874
PHP_METHOD(XQueryProcessor, getExceptionCount)
1875
{
1876
    XQueryProcessor *xqueryProcessor;
1877
     zend_object* pobj = Z_OBJ_P(getThis()); 
1878
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1879
    if (ZEND_NUM_ARGS()>0) {
1880
        WRONG_PARAM_COUNT;
1881
    }
1882

    
1883
    xqueryProcessor = obj->xqueryProcessor;
1884
    if (xqueryProcessor != NULL) {
1885
        int count = xqueryProcessor->exceptionCount();
1886
        RETURN_LONG(count);
1887
    }
1888
    RETURN_LONG(0);
1889
}
1890

    
1891
PHP_METHOD(XQueryProcessor, getErrorCode)
1892
{
1893
    XQueryProcessor *xqueryProcessor;
1894
    long index;
1895
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1896
        RETURN_NULL();
1897
    }
1898
    zend_object* pobj = Z_OBJ_P(getThis()); 
1899
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1900
    xqueryProcessor = obj->xqueryProcessor;
1901
    if (xqueryProcessor != NULL) {
1902
        const char * errCode = xqueryProcessor->getErrorCode((int)index);
1903
        if(errCode != NULL) {
1904
            //char *str = estrdup(errCode);
1905
            _RETURN_STRING(errCode);
1906
        }
1907
    }
1908
    RETURN_NULL();
1909
}
1910

    
1911
PHP_METHOD(XQueryProcessor, getErrorMessage)
1912
{
1913
    XQueryProcessor *xqueryProcessor;
1914
    long index;
1915
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1916
        RETURN_NULL();
1917
    }
1918
    zend_object* pobj = Z_OBJ_P(getThis()); 
1919
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1920
    xqueryProcessor = obj->xqueryProcessor;
1921
    if (xqueryProcessor != NULL) {
1922
        const char * errStr = xqueryProcessor->getErrorMessage((int)index);
1923
        if(errStr != NULL) {
1924
            //char *str = estrdup(errStr);
1925
            _RETURN_STRING(errStr);
1926
        }
1927
    }
1928
    RETURN_NULL();
1929
}
1930
PHP_METHOD(XQueryProcessor, exceptionClear)
1931
{
1932
    XQueryProcessor *xqueryProcessor;
1933
    zend_object* pobj = Z_OBJ_P(getThis()); 
1934
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1935
    xqueryProcessor = obj->xqueryProcessor;
1936
    if (xqueryProcessor != NULL) {
1937
        xqueryProcessor->exceptionClear();
1938
    }
1939
}
1940

    
1941
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
1942

    
1943
void xpathProcessor_free_storage(zend_object *object)
1944
{
1945
    zend_object_std_dtor(object);
1946
}
1947

    
1948
void xpathProcessor_destroy_storage(zend_object *object)
1949
{
1950
    zend_objects_destroy_object(object);
1951
}
1952

    
1953
PHP_METHOD(XPathProcessor, __destruct)
1954
{
1955

    
1956
   zend_object* pobj = Z_OBJ_P(getThis()); 
1957
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
1958

    
1959

    
1960
   XPathProcessor * xpathProc= obj->xpathProcessor;
1961
    if(xpathProc != NULL){
1962
            delete xpathProc;
1963
     }
1964

    
1965
   
1966
    
1967
}
1968

    
1969
zend_object *xpathProcessor_create_handler(zend_class_entry *type)
1970
{
1971
    xpathProcessor_object *obj = (xpathProcessor_object *)ecalloc(1, sizeof(xpathProcessor_object)+ zend_object_properties_size(type));
1972
    
1973
    zend_object_std_init(&obj->std, type); 
1974
    
1975
    object_properties_init(&obj->std, type);
1976
    
1977
    obj->std.handlers = &xpathProcessor_object_handlers;
1978

    
1979
    return &obj->std;
1980
}
1981

    
1982

    
1983

    
1984
PHP_METHOD(XPathProcessor, setProperty)
1985
{
1986
    XPathProcessor *xpathProcessor;
1987
    char * name;
1988
    char * value;
1989
    size_t len1, len2;
1990

    
1991
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
1992
        RETURN_NULL();
1993
    }
1994
    zend_object* pobj = Z_OBJ_P(getThis()); 
1995
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
1996
    xpathProcessor = obj->xpathProcessor;
1997
    if (xpathProcessor != NULL) {
1998
        xpathProcessor->setProperty(name, value);
1999
    }
2000
}
2001

    
2002
PHP_METHOD(XPathProcessor, setParameter)
2003
{
2004

    
2005
   XPathProcessor *xpathProcessor;
2006
   char * name;
2007
   zval* oth;
2008
   size_t len1, len2;        
2009
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name, &len2, &oth) == FAILURE) {
2010
        RETURN_NULL();
2011
    }
2012
    zend_object* pobj = Z_OBJ_P(getThis()); 
2013
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2014
    xpathProcessor = obj->xpathProcessor;
2015
    if (xpathProcessor != NULL) {
2016
            const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2017
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2018

    
2019
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2020
        
2021
        zend_object* vvobj = Z_OBJ_P(oth);
2022
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2023
        if(ooth != NULL) {
2024
            XdmNode * value = ooth->xdmNode;
2025
            if(value != NULL) {        
2026
                xpathProcessor->setParameter(name, (XdmValue *)value);
2027

    
2028
            }
2029
        }
2030
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2031
        
2032
        zend_object* vvobj = Z_OBJ_P(oth);
2033
        xdmValue_object * ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2034
        if(ooth != NULL) {
2035
            XdmValue * value = ooth->xdmValue;
2036
            if(value != NULL) {
2037
                
2038
                xpathProcessor->setParameter(name, value);
2039
            }
2040
        }
2041

    
2042

    
2043

    
2044
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2045
        
2046
        zend_object* vvobj = Z_OBJ_P(oth);
2047
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2048
        if(ooth != NULL) {
2049
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2050
            if(value != NULL) {
2051
                
2052
                xpathProcessor->setParameter(name, (XdmValue *)value);
2053
            }
2054
        }
2055

    
2056

    
2057

    
2058
      }
2059

    
2060
    }
2061
}
2062

    
2063
PHP_METHOD(XPathProcessor, declareNamespace)
2064
{
2065
   char * prefix;
2066
   char * ns;
2067
   int len1, len2;
2068
   XPathProcessor *xpathProcessor;
2069

    
2070
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
2071
        RETURN_NULL();
2072
    }
2073
    if(prefix != NULL && ns != NULL) {
2074
            zend_object* pobj = Z_OBJ_P(getThis()); 
2075
        xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2076
            xpathProcessor = obj->xpathProcessor;
2077
            xpathProcessor->declareNamespace(prefix, ns);
2078
    }
2079
            
2080
}
2081

    
2082
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
2083
{
2084

    
2085
   XPathProcessor *xpathProcessor;
2086
   char * xpathStr;
2087
   zval* oth;
2088
   size_t len1, myint;        
2089
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &xpathStr, &len1) == FAILURE) {
2090
        RETURN_NULL();
2091
    }
2092
    zend_object* pobj = Z_OBJ_P(getThis()); 
2093
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2094
    xpathProcessor = obj->xpathProcessor;
2095
    if (xpathProcessor != NULL && xpathStr != NULL) {
2096
        
2097
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
2098
                RETURN_BOOL(result);
2099
    }
2100
}
2101

    
2102
PHP_METHOD(XPathProcessor, evaluate)
2103
{
2104

    
2105
   XPathProcessor *xpathProcessor;
2106
   char * xpathStr;
2107
   zval* oth;
2108
   size_t len1, myint;        
2109
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
2110
        RETURN_NULL();
2111
    }
2112
    zend_object* pobj = Z_OBJ_P(getThis()); 
2113
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2114
    xpathProcessor = obj->xpathProcessor;
2115
    if (xpathProcessor != NULL && xpathStr != NULL) {
2116
        
2117
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
2118
        if(node != NULL) {
2119
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2120
                RETURN_NULL();
2121
                return;
2122
            } else {
2123

    
2124
                zend_object* vvobj = Z_OBJ_P(return_value);
2125
                xdmValue_object * vobj = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2126
                assert (vobj != NULL);
2127
                vobj->xdmValue = node;
2128
                return;
2129
            }
2130
        }
2131
        xpathProcessor->checkException();//TODO
2132
    } 
2133
    RETURN_NULL();
2134
    
2135
}
2136

    
2137
PHP_METHOD(XPathProcessor, evaluateSingle)
2138
{
2139

    
2140
   XPathProcessor *xpathProcessor;
2141
   char * xpathStr;
2142
   zval* oth;
2143
   size_t len1, myint;        
2144
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
2145
        RETURN_NULL();
2146
    }
2147
    zend_object* pobj = Z_OBJ_P(getThis()); 
2148
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2149
    xpathProcessor = obj->xpathProcessor;
2150

    
2151
    if(xpathStr == NULL) { 
2152
        RETURN_NULL();        
2153
        return;
2154
        }
2155

    
2156

    
2157
    if (xpathProcessor != NULL) {
2158
        
2159
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
2160
        if(node != NULL) {
2161
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2162
                RETURN_NULL();
2163
                return;
2164
            } else {
2165
                //struct xdmItem_object* vobj = (struct xdmItem_object *)Z_OBJ_P(return_value TSRMLS_CC);
2166
                zend_object* vvobj = Z_OBJ_P(return_value);
2167
                xdmItem_object * vobj = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
2168
                assert (vobj != NULL);
2169
                vobj->xdmItem = node;
2170
                return;
2171
            }
2172
        } 
2173
        xpathProcessor->checkException();//TODO
2174
    } 
2175
    RETURN_NULL();
2176
}
2177

    
2178
PHP_METHOD(XPathProcessor, setContextItem)
2179
{
2180

    
2181
   XPathProcessor *xpathProcessor;
2182

    
2183
   zval* oth;
2184
        //TODO this should be relaxed to accept item/atomic/node as well as Value
2185

    
2186
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2187
        RETURN_NULL();
2188
    }
2189
    zend_object* pobj = Z_OBJ_P(getThis()); 
2190
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2191
    xpathProcessor = obj->xpathProcessor;
2192
    if (xpathProcessor != NULL) {
2193
        if(!oth) {
2194
                php_error(E_WARNING, "Error setting source value");
2195
                return;
2196
         } 
2197
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2198
        
2199
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
2200
        zend_object* vvobj = Z_OBJ_P(oth);
2201
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2202
        if(ooth != NULL) {
2203
            XdmNode * value = ooth->xdmNode;
2204
            if(value != NULL) {        
2205
                xpathProcessor->setContextItem((XdmItem *)value);
2206
                value->incrementRefCount();
2207

    
2208
            }
2209
        }
2210
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2211
        zend_object* vvobj = Z_OBJ_P(oth);
2212
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2213
        if(ooth != NULL) {
2214
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2215
            if(value != NULL) {
2216
                
2217
                xpathProcessor->setContextItem((XdmItem *)value);
2218
                value->incrementRefCount();
2219
            }
2220
        }
2221
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
2222
        zend_object* vvobj = Z_OBJ_P(oth);
2223
        xdmItem_object * ooth = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
2224
        if(ooth != NULL) {
2225
            XdmItem * value = ooth->xdmItem;
2226
            if(value != NULL) {
2227
                
2228
                xpathProcessor->setContextItem(value);
2229
                value->incrementRefCount();
2230
            }
2231
        }
2232

    
2233
      }
2234
    }
2235
}
2236

    
2237
PHP_METHOD(XPathProcessor, setBaseURI)
2238
{
2239

    
2240
   XPathProcessor *xpathProcessor;
2241

    
2242
   char * uriStr;
2243
   size_t len1;
2244
        
2245
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &uriStr, &len1) == FAILURE) {
2246
        RETURN_NULL();
2247
    }
2248
    zend_object* pobj = Z_OBJ_P(getThis()); 
2249
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2250
    xpathProcessor = obj->xpathProcessor;
2251
    if (xpathProcessor != NULL) {
2252
        
2253
        if(uriStr != NULL) {
2254
           
2255
                xpathProcessor->setBaseURI(uriStr);
2256
            
2257
        }
2258
    }
2259
}
2260

    
2261
PHP_METHOD(XPathProcessor, setContextFile)
2262
{
2263

    
2264
   XPathProcessor *xpathProcessor;
2265

    
2266
   char * name;
2267
   size_t len1;
2268
        
2269
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2270
        RETURN_NULL();
2271
    }
2272
    zend_object* pobj = Z_OBJ_P(getThis()); 
2273
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2274
    xpathProcessor = obj->xpathProcessor;
2275
    if (xpathProcessor != NULL) {
2276
        
2277
        if(name != NULL) {
2278
           
2279
                xpathProcessor->setContextFile(name);
2280
            
2281
        }
2282
    }
2283
}
2284

    
2285
PHP_METHOD(XPathProcessor, clearParameters)
2286
{
2287
    XPathProcessor *xpathProcessor;
2288
    if (ZEND_NUM_ARGS()>0) {
2289
        WRONG_PARAM_COUNT;
2290
    }
2291

    
2292
    zend_object* pobj = Z_OBJ_P(getThis()); 
2293
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2294
    xpathProcessor = obj->xpathProcessor;
2295
    if (xpathProcessor != NULL) {
2296
        xpathProcessor->clearParameters(true);
2297
    }
2298
}
2299

    
2300
PHP_METHOD(XPathProcessor, clearProperties)
2301
{
2302
     XPathProcessor *xpathProcessor;
2303
    if (ZEND_NUM_ARGS()>0) {
2304
        WRONG_PARAM_COUNT;
2305
    }
2306

    
2307
    zend_object* pobj = Z_OBJ_P(getThis()); 
2308
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2309
    xpathProcessor = obj->xpathProcessor;
2310
    if (xpathProcessor != NULL) {
2311
        xpathProcessor->clearProperties();
2312
    }
2313
}
2314

    
2315

    
2316
PHP_METHOD(XPathProcessor, exceptionOccurred)
2317
{
2318
   XPathProcessor *xpathProcessor;
2319
    zend_object* pobj = Z_OBJ_P(getThis()); 
2320
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2321
    if (ZEND_NUM_ARGS()>0) {
2322
        WRONG_PARAM_COUNT;
2323
    }
2324

    
2325
    xpathProcessor = obj->xpathProcessor;
2326
    if (xpathProcessor != NULL) {
2327
        bool result = xpathProcessor->exceptionOccurred();
2328
        RETURN_BOOL(result);
2329
    }
2330
    RETURN_BOOL(false);
2331
}
2332

    
2333
PHP_METHOD(XPathProcessor, getExceptionCount)
2334
{
2335
    XPathProcessor *xpathProcessor;
2336
   zend_object* pobj = Z_OBJ_P(getThis()); 
2337
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2338
    if (ZEND_NUM_ARGS()>0) {
2339
        WRONG_PARAM_COUNT;
2340
    }
2341

    
2342
    xpathProcessor = obj->xpathProcessor;
2343
    if (xpathProcessor != NULL) {
2344
        int count = xpathProcessor->exceptionCount();
2345
        RETURN_LONG(count);
2346
    }
2347
    RETURN_LONG(0);
2348
}
2349

    
2350
PHP_METHOD(XPathProcessor, getErrorCode)
2351
{
2352
    XPathProcessor *xpathProcessor;
2353
    long index;
2354
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
2355
        RETURN_NULL();
2356
    }
2357
    zend_object* pobj = Z_OBJ_P(getThis()); 
2358
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2359
    xpathProcessor = obj->xpathProcessor;
2360
    if (xpathProcessor != NULL) {
2361
        const char * errCode = xpathProcessor->getErrorCode((int)index);
2362
        if(errCode != NULL) {
2363
           // char *str = estrdup(errCode);
2364
            _RETURN_STRING(errCode);
2365
        }
2366
    }
2367
    RETURN_NULL();
2368
}
2369

    
2370
PHP_METHOD(XPathProcessor, getErrorMessage)
2371
{
2372
    XPathProcessor *xpathProcessor;
2373
    long index;
2374
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
2375
        RETURN_NULL();
2376
    }
2377
    zend_object* pobj = Z_OBJ_P(getThis()); 
2378
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2379
    xpathProcessor = obj->xpathProcessor;
2380
    if (xpathProcessor != NULL) {
2381
        const char * errStr = xpathProcessor->getErrorMessage((int)index);
2382
        if(errStr != NULL) {
2383
            //char *str = estrdup(errStr);
2384
            _RETURN_STRING(errStr);
2385
        }
2386
    }
2387
    RETURN_NULL();
2388
}
2389
PHP_METHOD(XPathProcessor, exceptionClear)
2390
{
2391
    XPathProcessor *xpathProcessor;
2392
    zend_object* pobj = Z_OBJ_P(getThis()); 
2393
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2394
    xpathProcessor = obj->xpathProcessor;
2395
    if (xpathProcessor != NULL) {
2396
        xpathProcessor->exceptionClear();
2397
    }
2398
}
2399

    
2400
/*     ============== PHP Interface of   SchemaValidator =============== */
2401

    
2402
void schemaValidator_free_storage(zend_object *object)
2403
{
2404
    zend_object_std_dtor(object);
2405
}
2406

    
2407
void schemaValidator_destroy_storage(zend_object *object)
2408
{
2409
    zend_objects_destroy_object(object);
2410
}
2411

    
2412
zend_object *schemaValidator_create_handler(zend_class_entry *type)
2413
{
2414
    zval *tmp;
2415
    zend_object retval;
2416
    schemaValidator_object *obj = (schemaValidator_object *)ecalloc(1, sizeof(schemaValidator_object)+ zend_object_properties_size(type));
2417

    
2418
    zend_object_std_init(&obj->std, type);    
2419
    object_properties_init(&obj->std, type);
2420

    
2421
    obj->std.handlers = &schemaValidator_object_handlers;
2422

    
2423
    return &obj->std;
2424
}
2425

    
2426

    
2427

    
2428
PHP_METHOD(SchemaValidator, __destruct)
2429
{
2430
    zend_object* pobj = Z_OBJ_P(getThis()); 
2431
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2432

    
2433

    
2434
    SchemaValidator * schemaValidator= obj->schemaValidator;
2435
    if(schemaValidator != NULL) {
2436
            delete schemaValidator;
2437
    }
2438
    
2439
}
2440

    
2441

    
2442

    
2443
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
2444
{
2445
    SchemaValidator *schemaValidator;
2446
    char * name;
2447
    size_t len1;
2448

    
2449
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2450
        RETURN_NULL();
2451
    }
2452
    zend_object* pobj = Z_OBJ_P(getThis()); 
2453
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2454
    schemaValidator = obj->schemaValidator;
2455
    if (name != NULL && schemaValidator != NULL) {
2456
        schemaValidator->registerSchemaFromFile(name);
2457
    }
2458
}
2459

    
2460
PHP_METHOD(SchemaValidator, registerSchemaFromString)
2461
{
2462
    char * schemaStr;
2463
    size_t len1;
2464
    SchemaValidator *schemaValidator;
2465
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &schemaStr, &len1) == FAILURE) {
2466
        RETURN_NULL();
2467
    }
2468
    zend_object* pobj = Z_OBJ_P(getThis()); 
2469
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2470
    schemaValidator = obj->schemaValidator;
2471
    if (schemaStr!= NULL && schemaValidator != NULL) {
2472
        schemaValidator->registerSchemaFromString(schemaStr);
2473
    }
2474
}
2475

    
2476
PHP_METHOD(SchemaValidator, validate)
2477
{
2478
    char * name = NULL;
2479
    size_t len1;
2480
    SchemaValidator *schemaValidator;
2481
    if (ZEND_NUM_ARGS()>1) {
2482
        WRONG_PARAM_COUNT;
2483
    }
2484
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2485
        RETURN_NULL();
2486
    }
2487
    zend_object* pobj = Z_OBJ_P(getThis()); 
2488
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2489
    schemaValidator = obj->schemaValidator;
2490
    if (schemaValidator != NULL) {
2491
        schemaValidator->validate(name);
2492
    }
2493
}
2494

    
2495
PHP_METHOD(SchemaValidator, validateToNode)
2496
{
2497
    char * name = NULL;
2498
   size_t len1;
2499
    SchemaValidator *schemaValidator;
2500
    if (ZEND_NUM_ARGS()>1) {
2501
        WRONG_PARAM_COUNT;
2502
    }
2503
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2504
        RETURN_NULL();
2505
    }
2506
    zend_object* pobj = Z_OBJ_P(getThis()); 
2507
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2508
    schemaValidator = obj->schemaValidator;
2509
    if (schemaValidator != NULL) {
2510
        XdmNode * node = schemaValidator->validateToNode(name);
2511
        if(node != NULL) {
2512
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2513
                RETURN_NULL();
2514
                return;
2515
            } else {
2516
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
2517
                zend_object* vvobj = Z_OBJ_P(return_value);
2518
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2519
                assert (vobj != NULL);
2520
                vobj->xdmNode = node;
2521
                return;
2522
            }
2523
        } 
2524
            schemaValidator->checkException();//TODO
2525
    } 
2526
    RETURN_NULL();
2527
}
2528

    
2529

    
2530
PHP_METHOD(SchemaValidator, getValidationReport)
2531
{
2532

    
2533
    SchemaValidator *schemaValidator;
2534
    if (ZEND_NUM_ARGS()>0) {
2535
        WRONG_PARAM_COUNT;
2536
    }
2537

    
2538
    zend_object* pobj = Z_OBJ_P(getThis()); 
2539
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2540
    schemaValidator = obj->schemaValidator;
2541
    if (schemaValidator != NULL) {
2542
        XdmNode * node = schemaValidator->getValidationReport();
2543
        if(node != NULL) {
2544
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2545
                RETURN_NULL();
2546
                return;
2547
            } else {
2548
                zend_object* vvobj = Z_OBJ_P(return_value);
2549
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2550
                assert (vobj != NULL);
2551
                vobj->xdmNode = node;
2552
                return;
2553
            }
2554
        } 
2555
            schemaValidator->checkException();//TODO
2556
    } 
2557
    RETURN_NULL();
2558
}
2559

    
2560

    
2561
PHP_METHOD(SchemaValidator, setSourceNode)
2562
{
2563
    SchemaValidator *schemaValidator;
2564

    
2565
    zval* oth;
2566
   
2567

    
2568
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2569
        RETURN_NULL();
2570
    }
2571
    zend_object* pobj = Z_OBJ_P(getThis()); 
2572
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2573
    schemaValidator = obj->schemaValidator;
2574
    if (schemaValidator != NULL) {
2575
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2576
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2577
        zend_object * nobj = Z_OBJ_P(oth);
2578
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
2579
        if(ooth != NULL) {
2580
            XdmNode * value = ooth->xdmNode;
2581
            if(value != NULL) {        
2582
                schemaValidator->setSourceNode(value);
2583

    
2584
            }
2585
        }
2586
      
2587
        
2588
      }
2589
    }
2590
}
2591

    
2592
PHP_METHOD(SchemaValidator, setOutputFile)
2593
{
2594
    SchemaValidator *schemaValidator;
2595
    char * name;
2596
    int len1;
2597

    
2598
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2599
        RETURN_NULL();
2600
    }
2601
    zend_object* pobj = Z_OBJ_P(getThis()); 
2602
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2603
    schemaValidator = obj->schemaValidator;
2604
    if (schemaValidator != NULL) {
2605
        schemaValidator->setOutputFile(name);
2606
    }
2607
}
2608

    
2609

    
2610
PHP_METHOD(SchemaValidator, setProperty)
2611
{
2612
    SchemaValidator *schemaValidator;
2613
    char * name;
2614
    char * value;
2615
    size_t len1, len2, myint;
2616

    
2617
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
2618
        RETURN_NULL();
2619
    }
2620
    zend_object* pobj = Z_OBJ_P(getThis()); 
2621
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2622
    schemaValidator = obj->schemaValidator;
2623
    if (schemaValidator != NULL) {
2624
        schemaValidator->setProperty(name, value);
2625
    }
2626
}
2627

    
2628
PHP_METHOD(SchemaValidator, setParameter)
2629
{
2630

    
2631
   SchemaValidator *schemaValidator;
2632
   char * name;
2633
   zval* oth;
2634
   size_t len1, len2, myint;        
2635
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
2636
        RETURN_NULL();
2637
    }
2638
    zend_object* pobj = Z_OBJ_P(getThis()); 
2639
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2640
    schemaValidator = obj->schemaValidator;
2641
    if (schemaValidator != NULL) {
2642
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2643
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2644

    
2645
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2646
        zend_object * nobj = Z_OBJ_P(oth);
2647

    
2648
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
2649
        if(ooth != NULL) {
2650
            XdmNode * value = ooth->xdmNode;
2651
            if(value != NULL) {        
2652
                schemaValidator->setParameter(name, (XdmValue *)value);
2653

    
2654
            }
2655
        }
2656
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2657
        zend_object* vvobj = Z_OBJ_P(oth);
2658
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2659
        if(ooth != NULL) {
2660
            XdmValue * value = ooth->xdmValue;
2661
            if(value != NULL) {
2662
                
2663
                schemaValidator->setParameter(name, value);
2664
            }
2665
        }
2666

    
2667

    
2668

    
2669
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2670
        zend_object* vvobj = Z_OBJ_P(oth);
2671
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2672
        if(ooth != NULL) {
2673
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2674
            if(value != NULL) {
2675
                
2676
                schemaValidator->setParameter(name, (XdmValue *)value);
2677
            }
2678
        }
2679

    
2680

    
2681

    
2682
      }
2683

    
2684
    }
2685
}
2686

    
2687
PHP_METHOD(SchemaValidator, clearProperties)
2688
{
2689
    SchemaValidator *schemaValidator;
2690
    if (ZEND_NUM_ARGS()>0) {
2691
        WRONG_PARAM_COUNT;
2692
    }
2693

    
2694
    zend_object* pobj = Z_OBJ_P(getThis()); 
2695
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2696
    schemaValidator = obj->schemaValidator;
2697
    if (schemaValidator != NULL) {
2698
        schemaValidator->clearProperties();
2699
        schemaValidator->exceptionClear();
2700
    }
2701
}
2702

    
2703
PHP_METHOD(SchemaValidator, clearParameters)
2704
{
2705

    
2706
   SchemaValidator *schemaValidator;
2707
    if (ZEND_NUM_ARGS()>0) {
2708
        WRONG_PARAM_COUNT;
2709
    }
2710
    zend_object* pobj = Z_OBJ_P(getThis()); 
2711
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2712
    schemaValidator = obj->schemaValidator;
2713
    if (schemaValidator != NULL) {
2714
       
2715
                schemaValidator->clearParameters(true);
2716
                schemaValidator->exceptionClear();
2717
        }
2718
    }
2719

    
2720
PHP_METHOD(SchemaValidator, exceptionOccurred)
2721
{
2722
    SchemaValidator *schemaValidator;
2723
    if (ZEND_NUM_ARGS()>0) {
2724
        WRONG_PARAM_COUNT;
2725
    }
2726
    zend_object* pobj = Z_OBJ_P(getThis()); 
2727
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2728
    schemaValidator = obj->schemaValidator;
2729
    if (schemaValidator != NULL) {
2730
        bool result = schemaValidator->exceptionOccurred();
2731
        RETURN_BOOL(result);
2732
    }
2733
    RETURN_BOOL(false);
2734
}
2735

    
2736
PHP_METHOD(SchemaValidator, getExceptionCount)
2737
{
2738
    SchemaValidator *schemaValidator;
2739

    
2740
    if (ZEND_NUM_ARGS()>0) {
2741
        WRONG_PARAM_COUNT;
2742
    }
2743
    zend_object* pobj = Z_OBJ_P(getThis()); 
2744
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2745
    schemaValidator = obj->schemaValidator;
2746
    if (schemaValidator != NULL) {
2747
        int count = schemaValidator->exceptionCount();
2748
        RETURN_LONG(count);
2749
    }
2750
    RETURN_LONG(0);
2751
}
2752

    
2753
PHP_METHOD(SchemaValidator, getErrorCode)
2754
{
2755
    SchemaValidator *schemaValidator;
2756
    long index;
2757
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
2758
        RETURN_NULL();
2759
    }
2760
    zend_object* pobj = Z_OBJ_P(getThis()); 
2761
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2762
    schemaValidator = obj->schemaValidator;
2763
    if (schemaValidator != NULL) {
2764
        const char * errCode = schemaValidator->getErrorCode((int)index);
2765
        if(errCode != NULL) {
2766
            //char *str = estrdup(errCode);
2767
            _RETURN_STRING(errCode);
2768
        }
2769
    }
2770
    RETURN_NULL();
2771
}
2772

    
2773
PHP_METHOD(SchemaValidator, getErrorMessage)
2774
{
2775
    SchemaValidator *schemaValidator;
2776
    long index;
2777
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
2778
        RETURN_NULL();
2779
    }
2780
    zend_object* pobj = Z_OBJ_P(getThis()); 
2781
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2782
    schemaValidator = obj->schemaValidator;
2783
    if (schemaValidator != NULL) {
2784
        const char * errStr = schemaValidator->getErrorMessage((int)index);
2785
        if(errStr != NULL) {
2786
            //char *str = estrdup(errStr);
2787
            _RETURN_STRING(errStr);
2788
        }
2789
    }
2790
    RETURN_NULL();
2791
}
2792
PHP_METHOD(SchemaValidator, exceptionClear)
2793
{
2794
    SchemaValidator * schemaValidator;
2795
    zend_object* pobj = Z_OBJ_P(getThis()); 
2796
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2797
    schemaValidator = obj->schemaValidator;
2798
    if (schemaValidator != NULL) {
2799
        schemaValidator->exceptionClear();
2800
    }
2801
}
2802

    
2803
/*     ============== PHP Interface of   XdmValue =============== */
2804
void xdmValue_free_storage(zend_object *object)
2805
{
2806
    zend_object_std_dtor(object);
2807
}
2808

    
2809
zend_object *xdmValue_create_handler(zend_class_entry *type)
2810
{
2811
    zval *tmp;
2812
    zend_object retval;
2813
    xdmValue_object *obj = (xdmValue_object *)ecalloc(1, sizeof(xdmValue_object)+ zend_object_properties_size(type));
2814
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
2815
    object_properties_init(&obj->std, type);
2816
    
2817
    obj->std.handlers = &xdmValue_object_handlers;
2818

    
2819
    return &obj->std;
2820
}
2821

    
2822
void XdmValue_destroy_storage(zend_object *object)
2823
{
2824
    zend_objects_destroy_object(object);
2825
}
2826

    
2827
PHP_METHOD(XdmValue, __construct)
2828
{
2829
    XdmValue *xdmValue = NULL;
2830
    bool bVal;
2831
    char * sVal;
2832
    int len;
2833
    long iVal;
2834
    double dVal;
2835
    zval *zvalue;
2836

    
2837

    
2838

    
2839
    SaxonProcessor *proc= NULL;
2840
    //xdmValue_object *obj = (xdmValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
2841
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == SUCCESS) {
2842
        switch (Z_TYPE_P(zvalue)) {
2843
            case IS_FALSE:
2844
            case IS_TRUE:
2845
                bVal = Z_BVAL_P(zvalue);
2846
                xdmValue = new XdmValue(bVal);
2847
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2848
                obj->xdmValue = xdmValue;
2849
            break;
2850
            case IS_LONG:
2851
                iVal = Z_LVAL_P(zvalue);
2852
                xdmValue = new XdmValue((int)iVal);
2853
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2854
                obj->xdmValue = xdmValue;
2855
            break;
2856
            case IS_STRING:
2857
                sVal = Z_STRVAL_P(zvalue);
2858
                len = Z_STRLEN_P(zvalue);
2859
                xdmValue = new XdmValue("string", sVal);
2860
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2861
                obj->xdmValue = xdmValue;
2862
            break;
2863
            case IS_NULL:
2864
                xdmValue = new XdmValue();
2865
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2866
                obj->xdmValue = xdmValue;
2867
            break;
2868
            case IS_DOUBLE:
2869
                // TODO: implement this
2870
                //index = (long)Z_DVAL_P(zvalue);
2871
            //break;
2872
            case IS_ARRAY:
2873
            //break;
2874
            case IS_OBJECT:
2875
            //break;
2876
            default:
2877
                obj = NULL;
2878
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
2879
        }
2880
    }*/
2881
}
2882

    
2883
PHP_METHOD(XdmValue, __destruct)
2884
{
2885

    
2886
     zend_object *oobj = Z_OBJ_P(getThis());
2887
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
2888
    XdmValue * xdmValue= obj->xdmValue;
2889
   if(xdmValue != NULL) {
2890
            xdmValue->decrementRefCount();
2891
            if(xdmValue!= NULL && xdmValue->getRefCount()< 1){
2892
                    delete xdmValue;
2893
            } 
2894
    }
2895
    
2896
}
2897

    
2898
PHP_METHOD(XdmValue,  getHead){
2899
    XdmValue *xdmValue;
2900
     zend_object *oobj = Z_OBJ_P(getThis());
2901
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
2902
    xdmValue = obj->xdmValue;
2903
    if (xdmValue != NULL) {
2904
        XdmItem * item = xdmValue->getHead();
2905
        if(item != NULL) {
2906
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2907
                RETURN_NULL();
2908
                return;
2909
            } else {
2910
                zend_object * oobj = Z_OBJ_P(return_value);
2911
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
2912
                assert (vobj != NULL);
2913
                vobj->xdmItem = item;
2914
                return;
2915
            }
2916
        }
2917
        
2918
    } else {
2919
        RETURN_NULL();
2920
    }
2921
}
2922

    
2923

    
2924
PHP_METHOD(XdmValue,  itemAt){
2925
    XdmValue *xdmValue;
2926

    
2927
    long index;
2928
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
2929
        RETURN_NULL();
2930
    }
2931

    
2932
     zend_object *oobj = Z_OBJ_P(getThis());
2933
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
2934
    xdmValue = obj->xdmValue;
2935
    if (xdmValue != NULL) {
2936
        XdmItem * item = xdmValue->itemAt((unsigned int)index);
2937
        if(item != NULL) {
2938
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2939
                RETURN_NULL();
2940
                return;
2941
            } else {
2942
                item->incrementRefCount();
2943
                zend_object * oobj = Z_OBJ_P(return_value);
2944
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
2945
               
2946
                assert (vobj != NULL);
2947
                vobj->xdmItem = item;
2948
                return;
2949
            }
2950
        }
2951
        
2952
    } else {
2953
        RETURN_NULL();
2954
    }
2955
}
2956

    
2957

    
2958
PHP_METHOD(XdmValue,  size){
2959
    XdmValue *xdmValue;
2960
    zend_object *oobj = Z_OBJ_P(getThis());
2961
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
2962
    xdmValue = obj->xdmValue;
2963
    int sizei = 0;
2964
    if (xdmValue != NULL) {
2965
        sizei = xdmValue->size();
2966
    }
2967
     RETURN_LONG(sizei);
2968
}
2969

    
2970

    
2971
PHP_METHOD(XdmValue, addXdmItem){
2972
    XdmValue *xdmValue;
2973
    zval* oth;
2974
           
2975
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2976
        RETURN_NULL();
2977
    }
2978

    
2979
    xdmValue_object *obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2980
    xdmValue = obj->xdmValue;
2981
    if (xdmValue != NULL) {
2982
     const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2983
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2984

    
2985
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2986
        zend_object * nobj = Z_OBJ_P(oth);
2987
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
2988
        if(ooth != NULL) {
2989
            XdmNode * value = ooth->xdmNode;
2990
            if(value != NULL) {        
2991
                xdmValue->addXdmItem((XdmItem *)value);
2992
                return;
2993
            }
2994
        }
2995
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
2996
        zend_object * iobj = Z_OBJ_P(oth);
2997
        xdmItem_object* ooth = (xdmItem_object *)((char *)iobj - XtOffsetOf(xdmItem_object, std));
2998
        if(ooth != NULL) {
2999
            XdmItem * value = ooth->xdmItem;
3000
            if(value != NULL) {
3001
                xdmValue->addXdmItem(value);
3002
                return;
3003
            }
3004
        }
3005

    
3006

    
3007

    
3008
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3009
        zend_object * aobj = Z_OBJ_P(oth);
3010
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)aobj - XtOffsetOf(xdmAtomicValue_object, std));
3011
        if(ooth != NULL) {
3012
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3013
            if(value != NULL) {
3014
                xdmValue->addXdmItem((XdmItem *)value);
3015
                return;
3016
            }
3017
        }
3018

    
3019
      } else {
3020
                //TODO exception
3021
        }
3022
    }
3023
}
3024

    
3025

    
3026

    
3027
/*     ============== PHP Interface of   XdmItem =============== */
3028

    
3029
void xdmItem_free_storage(zend_object *object)
3030
{
3031
    zend_object_std_dtor(object);
3032
}
3033

    
3034
zend_object *xdmItem_create_handler(zend_class_entry *type)
3035
{
3036
    zval *tmp;
3037
    zend_object retval;
3038
    xdmItem_object *obj = (xdmItem_object *)ecalloc(1, sizeof(xdmItem_object)+ zend_object_properties_size(type));
3039
    
3040
    object_properties_init(&obj->std, type);
3041
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
3042
    
3043
    obj->std.handlers = &xdmItem_object_handlers;
3044

    
3045
    return &obj->std;
3046
}
3047

    
3048
PHP_METHOD(XdmItem, __construct)
3049
{
3050
    XdmItem *xdmItem = NULL;
3051
    bool bVal;
3052
    char * sVal;
3053
    int len;
3054
    long iVal;
3055
    double dVal;
3056
    zval *zvalue;
3057

    
3058
    SaxonProcessor *proc= NULL;
3059
    
3060
   zval *object = getThis();
3061
   
3062
    zend_object * zobj = Z_OBJ_P(object);
3063

    
3064
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3065
    //saxonProc =  obj->saxonProcessor;
3066
 
3067
}
3068

    
3069
void XdmItem_destroy_storage(zend_object *object)
3070
{
3071
    zend_objects_destroy_object(object);
3072
    
3073
}
3074

    
3075
PHP_METHOD(XdmItem, __destruct)
3076
{
3077
     zval *object = getThis();
3078
     zend_object * zobj = Z_OBJ_P(object);
3079

    
3080
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3081

    
3082
    XdmItem * xdmItem= obj->xdmItem;
3083
    xdmItem->decrementRefCount();
3084
    if(xdmItem != NULL && xdmItem->getRefCount()< 1){
3085
            delete xdmItem;
3086
    }
3087
    
3088
}
3089

    
3090
PHP_METHOD(XdmItem, getStringValue)
3091
{
3092
    XdmItem *xdmItem;
3093
     zval *object = getThis();
3094
    zend_object * zobj = Z_OBJ_P(object);
3095
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3096
    xdmItem = obj->xdmItem;
3097

    
3098

    
3099
    if (xdmItem != NULL) {
3100
        const char * valueStr = xdmItem->getStringValue(NULL);
3101
        if(valueStr != NULL) {
3102
            _RETURN_STRING(valueStr);
3103
        }
3104
    }
3105
    RETURN_NULL();
3106
}
3107

    
3108
PHP_METHOD(XdmItem, isAtomic)
3109
{
3110
    XdmItem *xdmItem;
3111
    zend_object * zobj = Z_OBJ_P(getThis());
3112
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3113
    xdmItem = obj->xdmItem;
3114

    
3115
    if (xdmItem != NULL) {
3116
        bool isAtomic = xdmItem->isAtomic();
3117
        RETURN_BOOL(isAtomic);
3118
    }
3119
    RETURN_BOOL(false);
3120
}
3121

    
3122
PHP_METHOD(XdmItem, isNode)
3123
{
3124
    XdmItem *xdmItem;
3125
    zend_object * zobj = Z_OBJ_P(getThis());
3126
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3127
    xdmItem = obj->xdmItem;
3128

    
3129
    if (xdmItem != NULL && xdmItem->getType() == XDM_NODE) {
3130
        RETURN_TRUE;
3131
    }
3132
    RETURN_FALSE;
3133
}
3134

    
3135
PHP_METHOD(XdmItem, getAtomicValue)
3136
{
3137
    XdmItem *xdmItem;
3138
    zend_object * zobj = Z_OBJ_P(getThis());
3139
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3140
    xdmItem = obj->xdmItem;
3141

    
3142
    if (xdmItem != NULL) {
3143
          if(!xdmItem->isAtomic()) {
3144
                RETURN_NULL();
3145
                return;
3146
          }
3147
          if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
3148
                RETURN_NULL();
3149
                return;
3150
            } else {
3151
                xdmItem->incrementRefCount();
3152
//Z_ADDREF_P(return_value);
3153
                   zend_object * zobj = Z_OBJ_P(return_value);
3154
                    xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3155
                //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
3156
                assert (vobj != NULL);
3157
                vobj->xdmAtomicValue = (XdmAtomicValue *)xdmItem;
3158
                return;
3159
            }
3160
    }
3161
    RETURN_NULL();
3162
}
3163

    
3164
PHP_METHOD(XdmItem, getNodeValue)
3165
{
3166
    XdmItem *xdmItem;
3167
    zend_object * zobj = Z_OBJ_P(getThis());
3168
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3169
    xdmItem = obj->xdmItem;
3170

    
3171
    if (xdmItem != NULL) {
3172
          if(xdmItem->isAtomic()) {
3173
                RETURN_NULL();
3174
                return;
3175
          }
3176
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3177
                RETURN_NULL();
3178
                return;
3179
            } else {
3180
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
3181
                   zend_object * zobj = Z_OBJ_P(return_value);
3182
                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3183
                assert (vobj != NULL);
3184
                vobj->xdmNode = (XdmNode *)xdmItem;
3185
                vobj->xdmNode->incrementRefCount();
3186

    
3187
                return;
3188
            }
3189
    }
3190
    RETURN_NULL();
3191
}
3192

    
3193

    
3194

    
3195
/*     ============== PHP Interface of   XdmNode =============== */
3196

    
3197
void xdmNode_free_storage(zend_object *object)
3198
{
3199
   zend_object_std_dtor(object);
3200

    
3201
    
3202
}
3203

    
3204
zend_object *xdmNode_create_handler(zend_class_entry *type)
3205
{
3206
    zval *tmp;
3207
    zend_object retval;
3208
    xdmNode_object *obj = (xdmNode_object *)ecalloc(1, sizeof(xdmNode_object)+ zend_object_properties_size(type));
3209
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
3210
    object_properties_init(&obj->std, type);
3211
    obj->std.handlers = &xdmNode_object_handlers;
3212
        
3213
    return &obj->std;
3214
}
3215

    
3216
PHP_METHOD(XdmNode, __construct)
3217
{
3218
    //xdmNode_object *obj = (xdmNode_object *) Z_OBJ_P(getThis() TSRMLS_CC);
3219
}
3220

    
3221
void XdmNode_destroy_storage(zend_object *object)
3222
{
3223
 
3224
 zend_objects_destroy_object(object);
3225
   
3226
}
3227

    
3228
PHP_METHOD(XdmNode, __destruct)
3229
{
3230
    zval *object = getThis();
3231
     zend_object * zobj = Z_OBJ_P(object);
3232

    
3233
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3234

    
3235
    if(obj != NULL) {
3236
    XdmNode * xdmNode= obj->xdmNode;
3237
    if(xdmNode != NULL) {
3238
            xdmNode->decrementRefCount();
3239
            if(xdmNode->getRefCount()< 1){
3240
                    delete xdmNode;
3241
            } 
3242
    }
3243
    }
3244
}
3245

    
3246
PHP_METHOD(XdmNode, getStringValue)
3247
{
3248
    XdmNode *xdmNode;
3249
    zval *object = getThis();
3250
    zend_object * zobj = Z_OBJ_P(object);
3251

    
3252
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3253
    xdmNode = obj->xdmNode;
3254

    
3255
   
3256
    if (xdmNode != NULL) {
3257
        const char * valueStr = xdmNode->getStringValue(NULL);
3258
        if(valueStr != NULL) {
3259
            _RETURN_STRING(valueStr);
3260
            return;
3261
        }
3262
    } 
3263
    RETURN_NULL(); 
3264
    
3265
}
3266

    
3267
PHP_METHOD(XdmNode, getNodeName)
3268
{
3269
    XdmNode *xdmNode;
3270
    zend_object * zobj = Z_OBJ_P(getThis());
3271
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3272
    xdmNode = obj->xdmNode;
3273
    xdmNode = obj->xdmNode;
3274

    
3275
    if (xdmNode != NULL) {
3276
        const char * valueStr = xdmNode->getNodeName();
3277
        if(valueStr != NULL) {
3278
            //char *str = estrdup(valueStr);
3279
            _RETURN_STRING(valueStr);
3280
        }
3281
    } 
3282
    RETURN_NULL(); 
3283
}
3284

    
3285
PHP_METHOD(XdmNode, getNodeKind)
3286
{
3287
    XdmNode *xdmNode;
3288
    zend_object * zobj = Z_OBJ_P(getThis());
3289
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3290
    xdmNode = obj->xdmNode;
3291

    
3292
    int nodeKind = 0;
3293
    if (xdmNode != NULL) {
3294
        nodeKind = xdmNode->getNodeKind();
3295
        
3296
    }
3297
     RETURN_LONG(nodeKind);
3298
}
3299

    
3300
PHP_METHOD(XdmNode, isAtomic)
3301
{
3302

    
3303
    RETURN_FALSE;
3304
}
3305

    
3306

    
3307
PHP_METHOD(XdmNode,  getChildCount){
3308
    XdmNode *xdmNode;
3309
    zend_object * zobj = Z_OBJ_P(getThis());
3310
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3311
    xdmNode = obj->xdmNode;
3312

    
3313
    int nodeChildCount = 0;
3314
    if (xdmNode != NULL) {
3315
        nodeChildCount = xdmNode->getChildCount();
3316
        
3317
    }
3318
     RETURN_LONG(nodeChildCount);
3319
}   
3320

    
3321
PHP_METHOD(XdmNode,  getAttributeCount){
3322
    XdmNode *xdmNode;
3323
    zend_object * zobj = Z_OBJ_P(getThis());
3324
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3325
    xdmNode = obj->xdmNode;
3326

    
3327
    int nodeAttrCount = 0;
3328
    if (xdmNode != NULL) {
3329
        nodeAttrCount = xdmNode->getAttributeCount();
3330
        
3331
    }
3332
     RETURN_LONG(nodeAttrCount);
3333

    
3334
} 
3335

    
3336
PHP_METHOD(XdmNode,  getChildNode){
3337
    long indexi;        
3338
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l",&indexi) == FAILURE) {
3339
        RETURN_NULL();
3340
    }
3341

    
3342
    XdmNode *xdmNode;
3343
    zend_object * zobj = Z_OBJ_P(getThis());
3344
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3345
    xdmNode = obj->xdmNode;
3346

    
3347
    if (xdmNode != NULL) {
3348
         int count = xdmNode->getChildCount();
3349
         if(count==0) {
3350
                RETURN_NULL();
3351
                return;
3352
          }        
3353
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3354
                RETURN_NULL();
3355
                return;
3356
            } else {
3357
                
3358
                if(indexi>=0 && indexi < count) {
3359
                        XdmNode ** childNodes = xdmNode->getChildren();
3360
                        if(childNodes == NULL) {
3361
                                RETURN_NULL();
3362
                                return;
3363
                        }
3364
                        XdmNode * childNode = childNodes[indexi];
3365
                        if(childNode != NULL) {
3366
                                childNode->incrementRefCount();
3367
                                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
3368
                                zend_object * zobj = Z_OBJ_P(return_value);
3369
                                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3370
                                assert (vobj != NULL);
3371
                                vobj->xdmNode = childNode;
3372
                                return;
3373
                        }
3374
                }
3375
            }
3376
    }
3377
    RETURN_NULL();
3378
}
3379

    
3380
PHP_METHOD(XdmNode,  getParent){
3381
    XdmNode *xdmNode;
3382
    zend_object * zobj = Z_OBJ_P(getThis());
3383
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3384
    xdmNode = obj->xdmNode;
3385

    
3386
    if (xdmNode != NULL) {
3387
        XdmNode * parent = xdmNode->getParent();
3388
        if(parent == NULL) {
3389
                        RETURN_NULL();
3390
                        return;
3391
        }
3392
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3393
                RETURN_NULL();
3394
                return;
3395
            } else {
3396
                parent->incrementRefCount();
3397
                       //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
3398
                zend_object * zobj = Z_OBJ_P(return_value);
3399
                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3400
                       assert (vobj != NULL);
3401
                       vobj->xdmNode = parent;
3402
                       return;
3403
            }
3404
    }
3405
    RETURN_NULL();
3406
}
3407

    
3408
PHP_METHOD(XdmNode,  getAttributeNode){
3409
    long indexi;        
3410
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l",&indexi) == FAILURE) {
3411
        RETURN_NULL();
3412
    }
3413

    
3414
    XdmNode *xdmNode;
3415
    zend_object * zobj = Z_OBJ_P(getThis());
3416
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3417
    xdmNode = obj->xdmNode;
3418

    
3419
    if (xdmNode != NULL) {
3420
          int count = xdmNode->getAttributeCount();
3421
          if(count > 0) {
3422
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3423
                RETURN_NULL();
3424
                return;
3425
            } else {
3426
                
3427
                if(indexi < count) {
3428
                        XdmNode * attNode = xdmNode->getAttributeNodes()[indexi];
3429
                        if(attNode != NULL) {
3430
                                attNode->incrementRefCount();
3431
                                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
3432
                                zend_object * zobj = Z_OBJ_P(return_value);
3433
                                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3434
                                assert (vobj != NULL);
3435
                                vobj->xdmNode = attNode;
3436

    
3437
                                return;
3438
                        }
3439
                }
3440
            }
3441
        }
3442
    }
3443
    RETURN_NULL();
3444

    
3445
}
3446

    
3447
PHP_METHOD(XdmNode,  getAttributeValue){
3448
   char * name;
3449
   long len1;        
3450
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
3451
        RETURN_NULL();
3452
    }
3453
    XdmNode *xdmNode;
3454
    zend_object * zobj = Z_OBJ_P(getThis());
3455
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3456
    xdmNode = obj->xdmNode;
3457
    if (xdmNode != NULL && name != NULL) {
3458
        
3459
        const char * valueStr = xdmNode->getAttributeValue(name);
3460
        if(valueStr != NULL) {
3461
            //char *str = estrdup(valueStr);
3462
            _RETURN_STRING(valueStr);
3463
            return;
3464
        }
3465
    }
3466
    RETURN_NULL();
3467

    
3468

    
3469
}
3470

    
3471
/*     ============== PHP Interface of   XdmAtomicValue =============== */
3472

    
3473
void xdmAtomicValue_free_storage(zend_object *object)
3474
{
3475
    zend_object_std_dtor(object);
3476
}
3477

    
3478
void XdmAtomicValue_destroy_storage(zend_object *object)
3479
{
3480
    zend_objects_destroy_object(object);
3481
    
3482
}
3483

    
3484
zend_object *xdmAtomicValue_create_handler(zend_class_entry *type)
3485
{
3486

    
3487
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)ecalloc(1, sizeof(xdmAtomicValue_object)+ zend_object_properties_size(type));
3488

    
3489
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
3490
    object_properties_init(&obj->std, type);
3491

    
3492
    obj->std.handlers = &xdmAtomicValue_object_handlers;
3493

    
3494
    return &obj->std;
3495
}
3496

    
3497
PHP_METHOD(XdmAtomicValue, __construct)
3498
{
3499
   /* XdmAtomicValue *xdmValue = NULL;
3500
    bool bVal;
3501
    char * sVal;
3502
    int len;
3503
    long iVal;
3504
    double dVal;
3505
    zval *zvalue;*/
3506

    
3507
   // xdmAtomicValue_object *obj = (xdmAtomicValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
3508

    
3509
}
3510

    
3511
PHP_METHOD(XdmAtomicValue, __destruct)
3512
{
3513
     zval *object = getThis();
3514
     zend_object * zobj = Z_OBJ_P(object);
3515

    
3516
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3517

    
3518
    XdmAtomicValue * xdmValue= obj->xdmAtomicValue;
3519
    if(xdmValue!= NULL && xdmValue->getRefCount()< 1){
3520
        xdmValue->decrementRefCount();
3521
            delete xdmValue;
3522
    }
3523
    
3524
}
3525

    
3526
PHP_METHOD(XdmAtomicValue, getBooleanValue)
3527
{
3528
    XdmAtomicValue *xdmAtomicValue;
3529
    zval *object = getThis();
3530
     zend_object * zobj = Z_OBJ_P(object);
3531

    
3532
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3533
    xdmAtomicValue = obj->xdmAtomicValue;
3534

    
3535

    
3536
    bool resultb = false;
3537
    if (xdmAtomicValue != NULL) {
3538
         resultb = xdmAtomicValue->getBooleanValue();
3539
        
3540
    }
3541
    RETURN_BOOL(resultb);
3542
}
3543

    
3544

    
3545
PHP_METHOD(XdmAtomicValue, getDoubleValue)
3546
{
3547
    XdmAtomicValue *xdmAtomicValue;
3548
   zval *object = getThis();
3549
     zend_object * zobj = Z_OBJ_P(object);
3550

    
3551
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3552
    xdmAtomicValue = obj->xdmAtomicValue;
3553

    
3554

    
3555
    double resultb = 0;
3556
    if (xdmAtomicValue != NULL) {
3557
         resultb = xdmAtomicValue->getDoubleValue();
3558
        
3559
    }
3560
    RETURN_DOUBLE(resultb);
3561
}
3562

    
3563
PHP_METHOD(XdmAtomicValue, getLongValue)
3564
{
3565
    XdmAtomicValue *xdmAtomicValue;
3566
    zval *object = getThis();
3567
     zend_object * zobj = Z_OBJ_P(object);
3568

    
3569
    
3570
    long result = 0;
3571
    if (xdmAtomicValue != NULL) {
3572
         result = xdmAtomicValue->getLongValue();
3573
        
3574
    }
3575
    RETURN_LONG(result);
3576
}
3577

    
3578
PHP_METHOD(XdmAtomicValue, getStringValue)
3579
{
3580
    XdmAtomicValue *xdmAtomicValue;
3581
    zval *object = getThis();
3582
     zend_object * zobj = Z_OBJ_P(object);
3583

    
3584
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3585
    xdmAtomicValue = obj->xdmAtomicValue;
3586

    
3587
    SaxonProcessor * saxonProc;
3588
     zend_object * zzobj = Z_OBJ_P(getThis());
3589

    
3590
    saxonProcessor_object * obj2 = (saxonProcessor_object *)((char *)zzobj - XtOffsetOf(xdmAtomicValue_object, std));
3591
    
3592
    saxonProc =  obj2->saxonProcessor;
3593

    
3594
    if (xdmAtomicValue != NULL) {
3595
        const char * valueStr = saxonProc->getStringValue(xdmAtomicValue);
3596
        if(valueStr != NULL) {
3597
            //char *str = estrdup(valueStr);
3598
            _RETURN_STRING(valueStr);
3599
        }
3600
    }
3601
    RETURN_NULL();
3602
}
3603

    
3604
PHP_METHOD(XdmAtomicValue, isAtomic)
3605
{
3606

    
3607
    RETURN_TRUE;
3608
}
3609

    
3610

    
3611
// =============================================================
3612

    
3613
zend_function_entry SaxonProcessor_methods[] = {
3614
    PHP_ME(SaxonProcessor,  __construct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3615
    PHP_ME(SaxonProcessor,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3616
    PHP_ME(SaxonProcessor,  createAtomicValue,      NULL, ZEND_ACC_PUBLIC)
3617
    PHP_ME(SaxonProcessor,  parseXmlFromString,      NULL, ZEND_ACC_PUBLIC)
3618
    PHP_ME(SaxonProcessor,  parseXmlFromFile,      NULL, ZEND_ACC_PUBLIC)
3619
    PHP_ME(SaxonProcessor,  setcwd,     NULL, ZEND_ACC_PUBLIC)
3620
    PHP_ME(SaxonProcessor,  newXPathProcessor,     NULL, ZEND_ACC_PUBLIC)
3621
    PHP_ME(SaxonProcessor,  newXsltProcessor,     NULL, ZEND_ACC_PUBLIC)
3622
    PHP_ME(SaxonProcessor,  newXQueryProcessor,     NULL, ZEND_ACC_PUBLIC)
3623
    PHP_ME(SaxonProcessor,  newSchemaValidator,     NULL, ZEND_ACC_PUBLIC)
3624
//    PHP_ME(SaxonProcessor,  importDocument,      NULL, ZEND_ACC_PUBLIC)
3625
    PHP_ME(SaxonProcessor,  setResourcesDirectory,      NULL, ZEND_ACC_PUBLIC)
3626
    PHP_ME(SaxonProcessor,  setCatalog,      NULL, ZEND_ACC_PUBLIC)
3627
    PHP_ME(SaxonProcessor, setConfigurationProperty,      NULL, ZEND_ACC_PUBLIC)
3628
    PHP_ME(SaxonProcessor,  registerPHPFunctions,      NULL, ZEND_ACC_PUBLIC)
3629
    PHP_ME(SaxonProcessor,  version,      NULL, ZEND_ACC_PUBLIC)
3630
    {NULL, NULL, NULL}
3631
};
3632

    
3633
zend_function_entry XsltProcessor_methods[] = {
3634
    PHP_ME(XsltProcessor,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3635
    PHP_ME(XsltProcessor,  transformFileToFile, NULL, ZEND_ACC_PUBLIC)
3636
    PHP_ME(XsltProcessor,  transformFileToString, NULL, ZEND_ACC_PUBLIC)
3637
    PHP_ME(XsltProcessor,  transformFileToValue, NULL, ZEND_ACC_PUBLIC)
3638
    PHP_ME(XsltProcessor,  transformToString, NULL, ZEND_ACC_PUBLIC)
3639
    PHP_ME(XsltProcessor,  transformToValue, NULL, ZEND_ACC_PUBLIC)
3640
    PHP_ME(XsltProcessor,  transformToFile, NULL, ZEND_ACC_PUBLIC)
3641
    PHP_ME(XsltProcessor, compileFromFile, NULL, ZEND_ACC_PUBLIC)
3642
    PHP_ME(XsltProcessor, compileFromValue, NULL, ZEND_ACC_PUBLIC)
3643
    PHP_ME(XsltProcessor, compileFromString, NULL, ZEND_ACC_PUBLIC)
3644
    PHP_ME(XsltProcessor,  setOutputFile, NULL, ZEND_ACC_PUBLIC)
3645
    PHP_ME(XsltProcessor,  setSourceFromFile, NULL, ZEND_ACC_PUBLIC)
3646
    PHP_ME(XsltProcessor,  setSourceFromXdmValue, NULL, ZEND_ACC_PUBLIC)
3647
    PHP_ME(XsltProcessor,  setParameter, NULL, ZEND_ACC_PUBLIC)
3648
    PHP_ME(XsltProcessor,  setProperty, NULL, ZEND_ACC_PUBLIC)
3649
    PHP_ME(XsltProcessor,  clearParameters, NULL, ZEND_ACC_PUBLIC)
3650
    PHP_ME(XsltProcessor,  clearProperties, NULL, ZEND_ACC_PUBLIC)
3651
    PHP_ME(XsltProcessor,  exceptionOccurred, NULL, ZEND_ACC_PUBLIC)
3652
    PHP_ME(XsltProcessor,  exceptionClear, NULL, ZEND_ACC_PUBLIC)
3653
    PHP_ME(XsltProcessor,  getErrorCode, NULL, ZEND_ACC_PUBLIC)
3654
    PHP_ME(XsltProcessor,  getErrorMessage, NULL, ZEND_ACC_PUBLIC)
3655
    PHP_ME(XsltProcessor,  getExceptionCount, NULL, ZEND_ACC_PUBLIC)
3656
{NULL, NULL, NULL}
3657
};
3658

    
3659
zend_function_entry XQueryProcessor_methods[] = {
3660
    PHP_ME(XQueryProcessor,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3661
   // PHP_ME(XQueryProcessor,  getErrorCode,      NULL, ZEND_ACC_PUBLIC)
3662
    PHP_ME(XQueryProcessor,  setQueryContent,      NULL, ZEND_ACC_PUBLIC)
3663
    PHP_ME(XQueryProcessor,  setContextItem,      NULL, ZEND_ACC_PUBLIC)
3664
    PHP_ME(XQueryProcessor,  setContextItemFromFile,      NULL, ZEND_ACC_PUBLIC)
3665
    PHP_ME(XQueryProcessor,  setParameter,      NULL, ZEND_ACC_PUBLIC)
3666
    PHP_ME(XQueryProcessor,  setProperty,      NULL, ZEND_ACC_PUBLIC)
3667
    PHP_ME(XQueryProcessor,  clearParameters,      NULL, ZEND_ACC_PUBLIC)
3668
    PHP_ME(XQueryProcessor,  clearProperties,      NULL, ZEND_ACC_PUBLIC)
3669
    PHP_ME(XQueryProcessor, runQueryToValue,      NULL, ZEND_ACC_PUBLIC)
3670
    PHP_ME(XQueryProcessor, runQueryToString,      NULL, ZEND_ACC_PUBLIC)
3671
    PHP_ME(XQueryProcessor, runQueryToFile,      NULL, ZEND_ACC_PUBLIC)
3672
    PHP_ME(XQueryProcessor, setQueryFile,      NULL, ZEND_ACC_PUBLIC)
3673
    PHP_ME(XQueryProcessor, setQueryBaseURI,      NULL, ZEND_ACC_PUBLIC)
3674
    PHP_ME(XQueryProcessor, declareNamespace,      NULL, ZEND_ACC_PUBLIC)
3675
    PHP_ME(XQueryProcessor,  exceptionOccurred, NULL, ZEND_ACC_PUBLIC)
3676
    PHP_ME(XQueryProcessor,  exceptionClear, NULL, ZEND_ACC_PUBLIC)
3677
    PHP_ME(XQueryProcessor,  getErrorCode, NULL, ZEND_ACC_PUBLIC)
3678
    PHP_ME(XQueryProcessor,  getErrorMessage, NULL, ZEND_ACC_PUBLIC)
3679
    PHP_ME(XQueryProcessor,  getExceptionCount, NULL, ZEND_ACC_PUBLIC)
3680
{NULL, NULL, NULL}
3681
};
3682

    
3683
zend_function_entry XPathProcessor_methods[] = {
3684
    PHP_ME(XPathProcessor,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3685
    PHP_ME(XPathProcessor,  setContextItem,      NULL, ZEND_ACC_PUBLIC)
3686
    PHP_ME(XPathProcessor,  setContextFile,      NULL, ZEND_ACC_PUBLIC)
3687
    PHP_ME(XPathProcessor,  effectiveBooleanValue,      NULL, ZEND_ACC_PUBLIC)
3688
    PHP_ME(XPathProcessor,  evaluate,      NULL, ZEND_ACC_PUBLIC)
3689
    PHP_ME(XPathProcessor,  evaluateSingle,      NULL, ZEND_ACC_PUBLIC)
3690
    PHP_ME(XPathProcessor,  setParameter,      NULL, ZEND_ACC_PUBLIC)
3691
    PHP_ME(XPathProcessor,  setProperty,      NULL, ZEND_ACC_PUBLIC)
3692
    PHP_ME(XPathProcessor,  clearParameters,      NULL, ZEND_ACC_PUBLIC)
3693
    PHP_ME(XPathProcessor,  clearProperties,      NULL, ZEND_ACC_PUBLIC)
3694
    PHP_ME(XPathProcessor,  exceptionOccurred, NULL, ZEND_ACC_PUBLIC)
3695
    PHP_ME(XPathProcessor,  exceptionClear, NULL, ZEND_ACC_PUBLIC)
3696
    PHP_ME(XPathProcessor,  getErrorCode, NULL, ZEND_ACC_PUBLIC)
3697
    PHP_ME(XPathProcessor,  getErrorMessage, NULL, ZEND_ACC_PUBLIC)
3698
    PHP_ME(XPathProcessor,  getExceptionCount, NULL, ZEND_ACC_PUBLIC)
3699
    PHP_ME(XPathProcessor, declareNamespace,      NULL, ZEND_ACC_PUBLIC)
3700
    PHP_ME(XPathProcessor, setBaseURI, NULL, ZEND_ACC_PUBLIC)
3701
{NULL, NULL, NULL}
3702
};
3703

    
3704
zend_function_entry SchemaValidator_methods[] = {
3705
    PHP_ME(SchemaValidator,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3706
    PHP_ME(SchemaValidator,  setSourceNode,      NULL, ZEND_ACC_PUBLIC)
3707
    PHP_ME(SchemaValidator,  setOutputFile,      NULL, ZEND_ACC_PUBLIC)
3708
    PHP_ME(SchemaValidator,  validate,      NULL, ZEND_ACC_PUBLIC)
3709
    PHP_ME(SchemaValidator,  validateToNode,      NULL, ZEND_ACC_PUBLIC)
3710
    PHP_ME(SchemaValidator,  registerSchemaFromFile,      NULL, ZEND_ACC_PUBLIC)
3711
    PHP_ME(SchemaValidator,  registerSchemaFromString,      NULL, ZEND_ACC_PUBLIC)
3712
    PHP_ME(SchemaValidator,  getValidationReport,      NULL, ZEND_ACC_PUBLIC)
3713
    PHP_ME(SchemaValidator,  setParameter,      NULL, ZEND_ACC_PUBLIC)
3714
    PHP_ME(SchemaValidator,  setProperty,      NULL, ZEND_ACC_PUBLIC)
3715
    PHP_ME(SchemaValidator,  clearParameters,      NULL, ZEND_ACC_PUBLIC)
3716
    PHP_ME(SchemaValidator,  clearProperties,      NULL, ZEND_ACC_PUBLIC)
3717
    PHP_ME(SchemaValidator,  exceptionOccurred, NULL, ZEND_ACC_PUBLIC)
3718
    PHP_ME(SchemaValidator,  exceptionClear, NULL, ZEND_ACC_PUBLIC)
3719
    PHP_ME(SchemaValidator,  getErrorCode, NULL, ZEND_ACC_PUBLIC)
3720
    PHP_ME(SchemaValidator,  getErrorMessage, NULL, ZEND_ACC_PUBLIC)
3721
    PHP_ME(SchemaValidator,  getExceptionCount, NULL, ZEND_ACC_PUBLIC)
3722
{NULL, NULL, NULL}
3723
};
3724

    
3725
zend_function_entry xdmValue_methods[] = {
3726
    PHP_ME(XdmValue,  __construct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3727
    PHP_ME(XdmValue,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3728
    PHP_ME(XdmValue,  getHead,      NULL, ZEND_ACC_PUBLIC)
3729
    PHP_ME(XdmValue,  itemAt,      NULL, ZEND_ACC_PUBLIC)
3730
    PHP_ME(XdmValue,  size,      NULL, ZEND_ACC_PUBLIC)
3731
    PHP_ME(XdmValue, addXdmItem,      NULL, ZEND_ACC_PUBLIC)
3732
    {NULL, NULL, NULL}
3733
};
3734

    
3735
zend_function_entry xdmItem_methods[] = {
3736
    PHP_ME(XdmItem,  __construct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3737
    PHP_ME(XdmItem,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3738
    PHP_ME(XdmItem,  getStringValue,      NULL, ZEND_ACC_PUBLIC)
3739
    PHP_ME(XdmItem,  isAtomic,      NULL, ZEND_ACC_PUBLIC)
3740
    PHP_ME(XdmItem,  isNode,      NULL, ZEND_ACC_PUBLIC)
3741
    PHP_ME(XdmItem,  getAtomicValue,      NULL, ZEND_ACC_PUBLIC)
3742
    PHP_ME(XdmItem,  getNodeValue,      NULL, ZEND_ACC_PUBLIC)
3743
    {NULL, NULL, NULL}
3744
};
3745

    
3746
zend_function_entry xdmNode_methods[] = {
3747
    PHP_ME(XdmNode,  __construct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3748
    PHP_ME(XdmNode,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3749
    PHP_ME(XdmNode,  getStringValue,      NULL, ZEND_ACC_PUBLIC)
3750
    PHP_ME(XdmNode,  getNodeKind,      NULL, ZEND_ACC_PUBLIC)
3751
    PHP_ME(XdmNode,  getNodeName,      NULL, ZEND_ACC_PUBLIC)
3752
    PHP_ME(XdmNode,  isAtomic,      NULL, ZEND_ACC_PUBLIC)
3753
    PHP_ME(XdmNode,  getChildCount,      NULL, ZEND_ACC_PUBLIC)
3754
    PHP_ME(XdmNode,  getAttributeCount,      NULL, ZEND_ACC_PUBLIC) 
3755
    PHP_ME(XdmNode,  getChildNode,      NULL, ZEND_ACC_PUBLIC)
3756
    PHP_ME(XdmNode,  getParent,      NULL, ZEND_ACC_PUBLIC)
3757
    PHP_ME(XdmNode,  getAttributeNode,      NULL, ZEND_ACC_PUBLIC)
3758
    PHP_ME(XdmNode,  getAttributeValue,      NULL, ZEND_ACC_PUBLIC)
3759
    {NULL, NULL, NULL}
3760
};
3761

    
3762
zend_function_entry xdmAtomicValue_methods[] = {
3763
    PHP_ME(XdmAtomicValue,  __construct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3764
    PHP_ME(XdmAtomicValue,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3765
    PHP_ME(XdmAtomicValue,  getStringValue,      NULL, ZEND_ACC_PUBLIC)
3766
    PHP_ME(XdmAtomicValue,  isAtomic,      NULL, ZEND_ACC_PUBLIC)
3767
    PHP_ME(XdmAtomicValue,  getBooleanValue,      NULL, ZEND_ACC_PUBLIC)
3768
    PHP_ME(XdmAtomicValue,  getDoubleValue,      NULL, ZEND_ACC_PUBLIC)
3769
    PHP_ME(XdmAtomicValue,  getLongValue,      NULL, ZEND_ACC_PUBLIC)
3770
    {NULL, NULL, NULL}
3771
};
3772

    
3773
PHP_MINIT_FUNCTION(saxon)
3774
{
3775
    zend_class_entry ce;
3776
    INIT_CLASS_ENTRY(ce, "Saxon\\SaxonProcessor", SaxonProcessor_methods);
3777
    saxonProcessor_ce = zend_register_internal_class(&ce);
3778
    saxonProcessor_ce->create_object = saxonProcessor_create_handler;
3779
    memcpy(&saxonProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(saxonProcessor_object_handlers));//zend_object_handlers
3780
    saxonProcessor_object_handlers.offset = XtOffsetOf(saxonProcessor_object, std);
3781
    saxonProcessor_object_handlers.free_obj = SaxonProcessor_free_storage;
3782
    saxonProcessor_object_handlers.dtor_obj = SaxonProcessor_destroy_storage;
3783
   
3784
   // saxonProcessor_object_handlers.clone_obj = NULL;
3785

    
3786
    INIT_CLASS_ENTRY(ce, "Saxon\\XSLTProcessor", XsltProcessor_methods);
3787
    xsltProcessor_ce = zend_register_internal_class(&ce);
3788
    xsltProcessor_ce->create_object = xsltProcessor_create_handler;
3789
    memcpy(&xsltProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xsltProcessor_object_handlers));
3790
    xsltProcessor_object_handlers.offset = XtOffsetOf(xsltProcessor_object, std);
3791
    xsltProcessor_object_handlers.free_obj = XsltProcessor_free_storage;
3792
    xsltProcessor_object_handlers.dtor_obj = XsltProcessor_destroy_storage;
3793
    //xsltProcessor_object_handlers.clone_obj = NULL;
3794

    
3795
    INIT_CLASS_ENTRY(ce, "Saxon\\XQueryProcessor", XQueryProcessor_methods);
3796
    xqueryProcessor_ce = zend_register_internal_class(&ce);
3797
    xqueryProcessor_ce->create_object = xqueryProcessor_create_handler;
3798
    memcpy(&xqueryProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xqueryProcessor_object_handlers));
3799
    xqueryProcessor_object_handlers.offset = XtOffsetOf(xqueryProcessor_object, std);
3800
    xqueryProcessor_object_handlers.free_obj = xqueryProcessor_free_storage;
3801
    xqueryProcessor_object_handlers.dtor_obj = xqueryProcessor_destroy_storage;    
3802

    
3803
        //xqueryProcessor_object_handlers.clone_obj = NULL;
3804

    
3805
    INIT_CLASS_ENTRY(ce, "Saxon\\XPathProcessor", XPathProcessor_methods);
3806
    xpathProcessor_ce = zend_register_internal_class(&ce);
3807
    xpathProcessor_ce->create_object = xpathProcessor_create_handler;
3808
    memcpy(&xpathProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xpathProcessor_object_handlers));
3809
    xpathProcessor_object_handlers.offset = XtOffsetOf(xpathProcessor_object, std);
3810
    xpathProcessor_object_handlers.free_obj = xpathProcessor_free_storage;
3811
    xpathProcessor_object_handlers.dtor_obj = xpathProcessor_destroy_storage; 
3812
    //xpathProcessor_object_handlers.clone_obj = NULL;
3813

    
3814
    INIT_CLASS_ENTRY(ce, "Saxon\\SchemaValidator", SchemaValidator_methods);
3815
    schemaValidator_ce = zend_register_internal_class(&ce);
3816
    schemaValidator_ce->create_object = schemaValidator_create_handler;
3817
    memcpy(&schemaValidator_object_handlers, zend_get_std_object_handlers(), sizeof(schemaValidator_object_handlers));
3818
    schemaValidator_object_handlers.offset = XtOffsetOf(xpathProcessor_object, std);
3819
    schemaValidator_object_handlers.free_obj = schemaValidator_free_storage;
3820
    schemaValidator_object_handlers.dtor_obj = schemaValidator_destroy_storage; 
3821
    //schemaValidator_object_handlers.clone_obj = NULL;
3822

    
3823
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmValue", xdmValue_methods);
3824
    xdmValue_ce = zend_register_internal_class(&ce);
3825
    xdmValue_ce->create_object = xdmValue_create_handler;
3826
    memcpy(&xdmValue_object_handlers, zend_get_std_object_handlers(), sizeof(xdmValue_object_handlers));
3827
    xdmValue_object_handlers.offset = XtOffsetOf(xdmValue_object, std);
3828
    xdmValue_object_handlers.free_obj = xdmValue_free_storage;
3829
    xdmValue_object_handlers.dtor_obj = XdmValue_destroy_storage;
3830
    //xdmValue_object_handlers.clone_obj = NULL;
3831

    
3832
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmItem", xdmItem_methods);
3833
    xdmItem_ce = zend_register_internal_class(&ce);
3834
    xdmItem_ce->create_object = xdmItem_create_handler;
3835
    memcpy(&xdmItem_object_handlers, zend_get_std_object_handlers(), sizeof(xdmItem_object_handlers));
3836
    xdmItem_object_handlers.offset = XtOffsetOf(xdmItem_object, std);
3837
    xdmItem_object_handlers.free_obj = xdmItem_free_storage;
3838
    xdmItem_object_handlers.dtor_obj = XdmItem_destroy_storage;
3839
    //xdmItem_object_handlers.clone_obj = NULL;
3840

    
3841
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmNode", xdmNode_methods);
3842
    xdmNode_ce = zend_register_internal_class(&ce);
3843
    xdmNode_ce->create_object = xdmNode_create_handler;
3844
    memcpy(&xdmNode_object_handlers, zend_get_std_object_handlers(), sizeof(xdmNode_object_handlers));
3845
    xdmNode_object_handlers.offset = XtOffsetOf(xdmNode_object, std);
3846
    xdmNode_object_handlers.free_obj = xdmNode_free_storage;
3847
    xdmNode_object_handlers.dtor_obj = XdmNode_destroy_storage;
3848
 
3849
    //xdmNode_object_handlers.clone_obj = NULL;
3850

    
3851
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmAtomicValue", xdmAtomicValue_methods);
3852
    xdmAtomicValue_ce = zend_register_internal_class(&ce);
3853
    xdmAtomicValue_ce->create_object = xdmAtomicValue_create_handler;
3854
    memcpy(&xdmAtomicValue_object_handlers, zend_get_std_object_handlers(), sizeof(xdmAtomicValue_object_handlers));
3855
    xdmAtomicValue_object_handlers.offset = XtOffsetOf(xdmAtomicValue_object, std);
3856
    xdmAtomicValue_object_handlers.free_obj = xdmAtomicValue_free_storage;
3857
    xdmAtomicValue_object_handlers.dtor_obj = XdmAtomicValue_destroy_storage;
3858
    //REGISTER_INI_ENTRIES();
3859
    return SUCCESS;
3860
}
3861

    
3862
PHP_MINFO_FUNCTION(saxon)
3863
{
3864
    php_info_print_table_start();
3865
    php_info_print_table_header(2, "Saxon/C", "enabled");
3866
    php_info_print_table_row(2, "Saxon/C EXT version", "1.1.0");
3867
    php_info_print_table_row(2, "Saxon", "9.8.0.4");
3868
    php_info_print_table_row(2, "Excelsior JET", "11.3 MP1");
3869
    php_info_print_table_end();
3870
    DISPLAY_INI_ENTRIES();
3871
}
3872

    
3873
PHP_MSHUTDOWN_FUNCTION(saxon) {
3874
    UNREGISTER_INI_ENTRIES();
3875
    SaxonProcessor::release();
3876

    
3877
    return SUCCESS;
3878
}
3879

    
3880
PHP_RSHUTDOWN_FUNCTION(saxon) {
3881
    return SUCCESS;
3882
}
3883

    
3884
PHP_RINIT_FUNCTION(saxon) {
3885
   // std::cerr<<"RINIT called -start"<<std::endl;
3886
    return SUCCESS;
3887
}
3888

    
3889
zend_module_entry saxon_module_entry = {
3890
#if ZEND_MODULE_API_NO >= 20010901
3891
    STANDARD_MODULE_HEADER,
3892
#endif
3893
    PHP_SAXON_EXTNAME,
3894
    NULL,        /* Functions */
3895
    PHP_MINIT(saxon),        /* MINIT */
3896
    PHP_MSHUTDOWN(saxon),        /* MSHUTDOWN */
3897
    NULL,        /* RINIT */
3898
    NULL,        /* RSHUTDOWN */
3899
    PHP_MINFO(saxon),        /* MINFO */
3900
#if ZEND_MODULE_API_NO >= 20010901
3901
    PHP_SAXON_EXTVER,
3902
#endif
3903
    STANDARD_MODULE_PROPERTIES
3904
};
3905

    
3906
#ifdef COMPILE_DL_SAXONC
3907
#ifdef ZTS
3908
ZEND_TSRMLS_CACHE_DEFINE()
3909
#endif
3910
ZEND_GET_MODULE(saxonc)
3911
#endif
3912

    
(4-4/4)