Project

Profile

Help

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

he / tags / 9.8.0.14 / hec / Saxon.C.API / php_saxon.cpp @ 02f8308b

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(void *object TSRMLS_DC)
43
{
44
 
45
    saxonProcessor_object *obj = (saxonProcessor_object *)object;
46

    
47
    zend_hash_destroy(obj->std.properties);
48
    FREE_HASHTABLE(obj->std.properties);
49
    efree(obj);
50
}
51

    
52
zend_object_value saxonProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
53
{
54
    zval *tmp;
55
    zend_object_value retval;
56

    
57
    saxonProcessor_object *obj = (saxonProcessor_object *)emalloc(sizeof(saxonProcessor_object));
58
    memset(obj, 0, sizeof(saxonProcessor_object));
59
    obj->std.ce = type;
60

    
61
    ALLOC_HASHTABLE(obj->std.properties);
62
    zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
63
    object_properties_init(&obj->std, type);
64
    retval.handle = zend_objects_store_put(obj, NULL, SaxonProcessor_free_storage, NULL TSRMLS_CC);
65
    retval.handlers = &saxonProcessor_object_handlers;
66

    
67
    return retval;
68
}
69

    
70
PHP_METHOD(SaxonProcessor, __construct)
71
{
72

    
73
    if (ZEND_NUM_ARGS()>2) {
74
        WRONG_PARAM_COUNT;
75
    }
76

    
77
    char * cwdi = NULL;
78
   bool license = false;
79
    int len1;
80
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &license) == FAILURE) {
81
        php_error(E_WARNING,"Wrong SaxonProcessor argument");
82
        RETURN_NULL();
83
    } 
84

    
85

    
86
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "bs", &license, &cwdi, &len1) == FAILURE) {
87
        php_error(E_WARNING,"Wrong SaxonProcessor arguments");
88
        RETURN_NULL();
89
    }
90
 
91

    
92
    zval *object = getThis();
93
    SaxonProcessor * saxonProc;
94
    saxonProcessor_object * obj = (saxonProcessor_object *)zend_object_store_get_object(object TSRMLS_CC);
95
    saxonProc =  obj->saxonProcessor;
96
    if(saxonProc == NULL) {
97

    
98
        saxonProc = new SaxonProcessor(license); //TODO: add license flag to PHP function argument
99

    
100
        obj->saxonProcessor = saxonProc;
101
    }
102

    
103
    if(cwdi==NULL) {
104
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
105
            TCHAR s[256];
106

    
107
            // --
108
            DWORD a = GetCurrentDirectory(256, s);
109
            const size_t newsize = wcslen(s)*2;
110
            char* cwd = new char[newsize];
111
            wcstombs_s(0, cwd, newsize, s, _TRUNCATE);
112
            // -- code above returns the apache installtion directory as the CWD
113

    
114
            char* cwd2;
115

    
116
            //php_error(E_WARNING,cwd2);
117

    
118
            saxonProc->setcwd(cwd2);
119
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
120
#else
121

    
122
            char cwd[256];
123

    
124
            VCWD_GETCWD(cwd, sizeof(cwd));
125
            if(cwd == NULL) {
126
             //php_error(E_WARNING,"cwd is null");
127
           }else {
128
             //php_error(E_WARNING,cwd);
129

    
130
            saxonProc->setcwd(cwd);
131
          }
132
#endif
133

    
134
    } else {
135
        saxonProc->setcwd(cwdi);
136
    }
137

    
138
}
139

    
140
PHP_METHOD(SaxonProcessor, __destruct)
141
{
142
    
143
    saxonProcessor_object *obj = (saxonProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
144

    
145
    SaxonProcessor * saxonProc= obj->saxonProcessor;
146

    
147
    delete saxonProc;
148
}
149

    
150
PHP_METHOD(SaxonProcessor, setResourcesDirectory)
151
{
152
    SaxonProcessor *saxonProcessor;
153
    char * dirStr;
154
    int len;
155
    
156
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dirStr, &len) == FAILURE) {
157
        RETURN_NULL();
158
    }
159
    
160
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
161
    saxonProcessor = obj->saxonProcessor;
162
    if (saxonProcessor != NULL) {
163
       
164
        if(dirStr != NULL) {
165
            saxonProcessor->setResourcesDirectory(dirStr);
166
        }
167
    }
168
}
169

    
170

    
171

    
172

    
173
PHP_METHOD(SaxonProcessor, setcwd)
174
{
175
    SaxonProcessor *saxonProcessor;
176
    char * cwdStr;
177
    int len;
178
    
179
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cwdStr, &len) == FAILURE) {
180
        RETURN_NULL();
181
    }
182
    
183
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
184
    saxonProcessor = obj->saxonProcessor;
185
    if (saxonProcessor != NULL) {
186
        
187
        if(cwdStr != NULL) {
188
            saxonProcessor->setcwd(cwdStr);
189
        }
190
    }
191
}
192

    
193

    
194
PHP_METHOD(SaxonProcessor, parseXmlFromString)
195
{
196
    SaxonProcessor * saxonProcessor;
197
    char * source;
198
    int len1;
199

    
200
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &len1) == FAILURE) {
201
        RETURN_NULL();
202
    }
203
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
204
    assert (obj != NULL);
205
    saxonProcessor = obj->saxonProcessor;
206
    if (saxonProcessor != NULL) {
207
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
208
        if(node != NULL) {
209
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
210
                RETURN_NULL();
211
            } else {
212
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
213
                assert (vobj != NULL);
214
                vobj->xdmNode = node;
215
            }
216
        } else {
217
            if(obj->saxonProcessor->exceptionOccurred()){
218
                //TODO throw exception
219
            }
220
        }
221
    } else {
222
        RETURN_NULL();
223
    }
224
}
225

    
226
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
227
{
228
    SaxonProcessor * saxonProcessor;
229
    char * source;
230
    int len1;
231

    
232
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &len1) == FAILURE) {
233
        RETURN_NULL();
234
    }
235
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
236
    assert (obj != NULL);
237
    saxonProcessor = obj->saxonProcessor;
238
    if (saxonProcessor != NULL) {
239
        XdmValue* node = (XdmValue*)saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
240
        if(node != NULL) {
241
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
242
                RETURN_NULL();
243
            } else {
244
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
245
                assert (vobj != NULL);
246
                vobj->xdmValue = node;
247
            }
248
        } else {
249
           // obj->xsltProcessor->checkException();//TODO
250
        }
251
    } else {
252
        RETURN_NULL();
253
    }
254
}
255

    
256

    
257
PHP_METHOD(SaxonProcessor, createAtomicValue)
258
{
259
    XdmAtomicValue * xdmValue = NULL;
260
    SaxonProcessor * proc;
261
    char * source;
262
    int len1;
263
    zval *zvalue;
264
    bool bVal;
265
    char * sVal;
266
    int len;
267
    long iVal;
268
    double dVal;
269
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&zvalue) == FAILURE) {
270
        RETURN_NULL();
271
    }
272
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
273
    assert (obj != NULL);
274
    proc = obj->saxonProcessor;
275
    assert (proc != NULL);
276
    if (proc != NULL) {
277
        switch (Z_TYPE_P(zvalue)) {
278
            case IS_BOOL:
279
                bVal = Z_BVAL_P(zvalue);
280
                xdmValue = proc->makeBooleanValue((bool)bVal);
281
            break;
282
            case IS_LONG:
283
                iVal = Z_LVAL_P(zvalue);
284
                 xdmValue = proc->makeIntegerValue((int)iVal);
285
            break;
286
            case IS_STRING:
287
                sVal = Z_STRVAL_P(zvalue);
288
                len = Z_STRLEN_P(zvalue);
289
                xdmValue = proc->makeStringValue((const char*)sVal);
290
            break;
291
            case IS_NULL:
292
                xdmValue = new XdmAtomicValue();
293
            break;
294
            case IS_DOUBLE:
295
                dVal = (double)Z_DVAL_P(zvalue);
296
                xdmValue = proc->makeDoubleValue((double)iVal);
297
                break;
298
            case IS_ARRAY:
299
                // TODO: Should not be expected. Do this some other way
300
                //break;
301
            case IS_OBJECT:
302
                // TODO: implement this
303
                //break;
304
            default:
305
                obj = NULL;
306
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC); 
307
                RETURN_NULL();
308
        }
309
        if(xdmValue == NULL) {
310
            RETURN_NULL();
311
        }
312
        if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
313
            RETURN_NULL();
314
        } else {
315
            struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
316
            assert (vobj != NULL);
317
            vobj->xdmAtomicValue = xdmValue;
318
        }
319
    } else {
320
       
321
        RETURN_NULL();
322
    }
323
}
324

    
325

    
326
PHP_METHOD(SaxonProcessor, newXPathProcessor)
327
{
328
   
329
    if (ZEND_NUM_ARGS()>0) {
330
        WRONG_PARAM_COUNT;
331
    }
332
    SaxonProcessor * proc;
333
    XPathProcessor * xpathProcessor = NULL;
334
    if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == NULL) {
335
      
336
    }
337
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
338

    
339
    assert (obj != NULL);
340
    proc = obj->saxonProcessor;
341
    assert (proc != NULL);
342
    if (proc != NULL) {
343
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
344
            RETURN_NULL();
345
        } else {
346
           struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
347
            assert (vobji != NULL);
348
            xpathProcessor = proc->newXPathProcessor();
349
            vobji->xpathProcessor = xpathProcessor;
350
        }
351
    } else {
352
       
353
        RETURN_NULL();
354
    }
355
}
356

    
357
PHP_METHOD(SaxonProcessor, newXsltProcessor)
358
{
359
    //php_error(E_WARNING,"new xsltProc 1");
360
    if (ZEND_NUM_ARGS()>0) {
361
        WRONG_PARAM_COUNT;
362
    }
363
    SaxonProcessor * proc;
364
    XsltProcessor * xsltProcessor = NULL;
365
if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == NULL) {
366
   
367
}
368

    
369
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
370
    assert (obj != NULL);
371
    proc = obj->saxonProcessor;
372
    assert (proc != NULL);
373
    if (proc != NULL) {
374
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
375
            RETURN_NULL();
376
        } else {
377
           struct xsltProcessor_object* vobj = (struct xsltProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
378
        
379
            assert (vobj != NULL);
380
            xsltProcessor = proc->newXsltProcessor();
381
            vobj->xsltProcessor = xsltProcessor;
382
    }
383
    } else {
384
       
385
        RETURN_NULL();
386
    }
387
}
388

    
389
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
390
{
391
   
392
    if (ZEND_NUM_ARGS()>0) {
393
        WRONG_PARAM_COUNT;
394
    }
395
    SaxonProcessor * proc;
396
    XQueryProcessor * xqueryProcessor = NULL;
397
   if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == NULL) {
398
   
399
   }
400
   
401
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
402
    assert (obj != NULL);
403
    proc = obj->saxonProcessor;
404
    assert (proc != NULL);
405
    if (proc != NULL) {
406
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
407
            RETURN_NULL();
408
        } else {
409
           struct xqueryProcessor_object* vobj = (struct xqueryProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
410

    
411
            assert (vobj != NULL);
412
            xqueryProcessor = proc->newXQueryProcessor();
413
            vobj->xqueryProcessor = xqueryProcessor;
414
     }
415
    } else {
416
       
417
        RETURN_NULL();
418
    }
419
}
420

    
421
PHP_METHOD(SaxonProcessor, newSchemaValidator)
422
{
423
   
424
    if (ZEND_NUM_ARGS()>0) {
425
        WRONG_PARAM_COUNT;
426
    }
427
    SaxonProcessor * proc;
428
    SchemaValidator * schemaValidator = NULL;
429
   
430
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
431
    assert (obj != NULL);
432
    proc = obj->saxonProcessor;
433
    assert (proc != NULL);
434
    if (proc != NULL) {
435
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
436
            RETURN_NULL();
437
        } else {
438
           struct schemaValidator_object* vobj = (struct schemaValidator_object *)zend_object_store_get_object(return_value TSRMLS_CC);
439
            assert (vobj != NULL);
440
            schemaValidator = proc->newSchemaValidator();
441
            if(schemaValidator == NULL){
442
                RETURN_NULL();
443
            }
444
            vobj->schemaValidator = schemaValidator;
445
        }
446
    } else {
447
       
448
        RETURN_NULL();
449
    }
450
}
451

    
452

    
453
PHP_METHOD(SaxonProcessor, version)
454
{
455
    SaxonProcessor *saxonProcessor;
456
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
457
    if (ZEND_NUM_ARGS()>0) {
458
        WRONG_PARAM_COUNT;
459
    }
460
    saxonProcessor = obj->saxonProcessor;
461
    if (saxonProcessor != NULL) {
462
        char *str = estrdup(saxonProcessor->version());
463
        RETURN_STRING(str, 0);
464
    }
465
    RETURN_NULL();
466
}
467

    
468

    
469
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
470
{
471
    SaxonProcessor *saxonProcessor;
472
    char * name;
473
    int len1;
474
    char * value;
475
    int len2;
476
    if (ZEND_NUM_ARGS()!= 2) {
477
        WRONG_PARAM_COUNT;
478
    }
479

    
480
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
481
        RETURN_NULL();
482
    }
483
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
484

    
485
    saxonProcessor = obj->saxonProcessor;
486
    if (saxonProcessor != NULL && name != NULL && value != NULL) {
487
        saxonProcessor->setConfigurationProperty(name, value);
488
    }
489
    
490
}
491

    
492
PHP_METHOD(SaxonProcessor, registerPHPFunction)
493
{
494
    SaxonProcessor *saxonProcessor;
495
    char * libName;
496
    int len1;
497
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
498
    if (ZEND_NUM_ARGS()!= 1) {
499
        WRONG_PARAM_COUNT;
500
    }
501

    
502
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &libName, &len1) == FAILURE) {
503
        RETURN_NULL();
504
    }
505
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
506

    
507
    saxonProcessor = obj->saxonProcessor;
508
    if (saxonProcessor != NULL && libName != NULL) {
509
        saxonProcessor->setConfigurationProperty("extc", libName);
510
    }
511
saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PhpFunction",
512
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
513
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
514
}
515

    
516
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
517

    
518
void XsltProcessor_free_storage(void *object TSRMLS_DC)
519
{
520

    
521
    xsltProcessor_object *obj = (xsltProcessor_object *)object;
522

    
523
    zend_hash_destroy(obj->std.properties);
524
    FREE_HASHTABLE(obj->std.properties);
525
    efree(obj);
526

    
527
}
528

    
529
zend_object_value xsltProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
530
{
531
    zval *tmp;
532
    zend_object_value retval;
533

    
534
    xsltProcessor_object *obj = (xsltProcessor_object *)emalloc(sizeof(xsltProcessor_object));
535
    memset(obj, 0, sizeof(xsltProcessor_object));
536
    obj->std.ce = type;
537

    
538
    ALLOC_HASHTABLE(obj->std.properties);
539
    zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
540
    object_properties_init(&obj->std, type);
541
    retval.handle = zend_objects_store_put(obj, NULL, XsltProcessor_free_storage, NULL TSRMLS_CC);
542
    retval.handlers = &xsltProcessor_object_handlers;
543

    
544
    return retval;
545
}
546

    
547

    
548

    
549
PHP_METHOD(XsltProcessor, __destruct)
550
{
551
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
552

    
553

    
554
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
555

    
556
    delete xsltProcessor;
557
    
558
}
559

    
560
PHP_METHOD(XsltProcessor, transformFileToFile)
561
{
562
    XsltProcessor *xsltProcessor;
563
    char * outfileName;
564
    char * infilename;
565
    char * styleFileName;
566
    int len1, len2, len3;
567

    
568
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
569
        RETURN_NULL();
570
    }
571

    
572
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
573
    xsltProcessor = obj->xsltProcessor;
574
 
575
    if (xsltProcessor != NULL) {
576

    
577
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
578
        if(xsltProcessor->exceptionOccurred()) {
579
               // TODO: throw exception
580
        }
581
    }
582
}
583

    
584
PHP_METHOD(XsltProcessor, transformFileToValue)
585
{
586
    XsltProcessor *xsltProcessor;
587
    char * infilename;
588
    char * styleFileName;
589
    int len1, len2;
590

    
591
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
592
        RETURN_NULL();
593
    }
594

    
595
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
596
    xsltProcessor = obj->xsltProcessor;
597
    
598
    if (xsltProcessor != NULL) {
599

    
600
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
601
        if(node != NULL) {
602
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
603
                RETURN_NULL();
604
            } else {
605
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
606
                assert (vobj != NULL);
607
                vobj->xdmValue = node;
608
            }
609
        } else {
610
            if(obj->xsltProcessor->exceptionOccurred()){
611
                  //TODO
612
            }
613
        }
614
    }else {
615
        RETURN_NULL();
616
    }
617
}
618

    
619

    
620
PHP_METHOD(XsltProcessor, transformFileToString)
621
{
622
    XsltProcessor *xsltProcessor;
623
    char * infilename;
624
    char * styleFileName;
625
    int len1, len2;
626

    
627
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
628
        RETURN_NULL();
629
    }
630

    
631
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
632
    xsltProcessor = obj->xsltProcessor;
633

    
634
    if (xsltProcessor != NULL) {
635

    
636
        const char * result = xsltProcessor->transformFileToString(infilename, styleFileName);
637
        if(result != NULL) {
638
            char *str = estrdup(result);
639
            RETURN_STRING(str, 0);
640
        } else if(xsltProcessor->exceptionOccurred()){
641
            //TODO: xsltProcessor->checkException();
642
            const char * errStr = xsltProcessor->getErrorMessage(0);
643
            if(errStr != NULL) {
644
                const char * errorCode = xsltProcessor->getErrorCode(0);
645
                if(errorCode!=NULL) {
646
                    // TODO: throw exception
647
                }
648
            }
649
        }
650
    }
651
}
652

    
653
/*enum saxonTypeEnum
654
{
655
        enumNode,
656
        enumString,
657
        enumInteger,
658
        enumDouble,
659
        enumFloat,
660
        enumBool,
661
        enumArrXdmValue
662
};*/
663

    
664
jobject JNICALL phpNativeCall
665
  (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
666
        JNIEnv *senv = SaxonProcessor::sxn_environ->env;
667

    
668
        const char *nativeString = senv->GetStringUTFChars(funcName, NULL);
669

    
670
        if(nativeString == NULL) {
671
                return NULL;        
672
        }
673

    
674
        zval *function_name;
675
        zval *retval;
676
        
677
        int argLength = 0;
678
        zvalArr * php_argv= NULL;
679
        if(arguments != NULL) {
680
                argLength = (int)senv->GetArrayLength(arguments);
681
                php_argv = new zvalArr[argLength];
682
        }
683
        zval **params[argLength];
684
        if(argLength>0) {
685
                (*params) = (zval**)malloc(sizeof(zval*) * argLength);
686
        } else {
687
                (*params) = NULL;
688
        }
689
        std::map<std::string, saxonTypeEnum> typeMap;
690
        typeMap["node"] = enumNode;
691
        typeMap["string"] = enumString;
692
        typeMap["integer"] = enumInteger;
693
        typeMap["double"] = enumDouble;
694
        typeMap["float"] = enumFloat;
695
        typeMap["boolean"] = enumBool;
696
        typeMap["[xdmvalue"] = enumArrXdmValue;
697
        sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
698
        SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
699
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
700
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
701
        
702
        for(int i=0; i<argLength;i++){
703

    
704
                jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
705
                jobject argObj = senv->GetObjectArrayElement(arguments, i);
706

    
707
                const char * str = senv->GetStringUTFChars(argType,NULL);
708
                const char *stri = NULL;
709
                double dnumber = 0;
710
                long lnumber = 0;
711
                bool bvalue = false;
712
                float fnumber = 0;
713
                
714

    
715
         
716
                struct xdmNode_object* vobj;
717
                XdmNode * node = NULL;
718
                std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
719
                if (it != typeMap.end()){
720
                        switch (it->second)
721
                        {
722
                                case enumNode:
723
                                        if(!nprocessor->proc){
724
                                                nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
725
                                        }
726
                                        node = new XdmNode(argObj);
727
                                        node->setProcessor(nprocessor);
728

    
729
                                        MAKE_STD_ZVAL(php_argv[i]._val);
730
                                        object_init_ex(php_argv[i]._val, xdmNode_ce);
731
                                           vobj = (struct xdmNode_object *)zend_object_store_get_object(php_argv[i]._val TSRMLS_CC);
732
                                        assert (vobj != NULL);
733
                                        vobj->xdmNode = node;
734
                                        break;
735
                                case enumString:
736
                                        stri = senv->GetStringUTFChars((jstring)argObj, NULL);
737
                                        MAKE_STD_ZVAL(php_argv[i]._val);
738
                                        ZVAL_STRING(php_argv[i]._val, stri, 1);
739
                                        break;
740
                                case enumInteger:
741
                                        sresult->xdmvalue = argObj; 
742
                                        lnumber = getLongValue(*SaxonProcessor::sxn_environ, *sresult, 0);
743

    
744
                                        MAKE_STD_ZVAL(php_argv[i]._val);
745
                                        ZVAL_LONG(php_argv[i]._val, lnumber);                                        
746
                                        break;
747
                                case enumDouble:
748
                                        sresult->xdmvalue = argObj; 
749
                                        dnumber = getDoubleValue(*SaxonProcessor::sxn_environ, *sresult, 0);
750
                                        MAKE_STD_ZVAL(php_argv[i]._val);
751
                                        ZVAL_DOUBLE(php_argv[i]._val, dnumber);
752
                                        break;
753
                                case enumFloat:
754
                                        sresult->xdmvalue = argObj; 
755
                                        fnumber = getFloatValue(*SaxonProcessor::sxn_environ, *sresult, 0);
756
                                        MAKE_STD_ZVAL(php_argv[i]._val);
757
                                        ZVAL_DOUBLE(php_argv[i]._val, fnumber);                                        
758
                                        break;
759
                                case enumBool:
760
                                        sresult->xdmvalue = argObj; 
761
                                        bvalue = getBooleanValue(*SaxonProcessor::sxn_environ, *sresult);
762
                                        MAKE_STD_ZVAL(php_argv[i]._val);
763
                                        ZVAL_BOOL(php_argv[i]._val, bvalue);                                                
764
                                        break;
765
                                case enumArrXdmValue:
766
                                        //TODO - not currently supported
767
                                        argLength--;
768
                                        break;
769
                        }
770
                        senv->ReleaseStringUTFChars(argType, str);
771
                } 
772

    
773
        //TODO should free sresult but it causes memory corruption        
774
                
775
// array of zvals to execute
776
    
777

    
778
 
779
            // convert all the values
780
            for(int i = 0; i < argLength; i++) { params[i] = &php_argv[i]._val; }
781

    
782
        }
783
        //note: no implicit type conversion.
784

    
785
        zval *argvv = NULL;//xparams;
786
        MAKE_STD_ZVAL(function_name);
787
        ZVAL_STRING(function_name, nativeString, 1);
788
        if(call_user_function_ex(CG(function_table), NULL, function_name, &retval, argLength, params, 0, NULL TSRMLS_CC) != SUCCESS)
789
        {
790
            zend_error(E_ERROR, "Function call failed");
791
        }
792

    
793

    
794

    
795
        if(Z_TYPE(*retval) ==0){
796
                zend_error(E_ERROR, "Function returned null");
797
        }
798

    
799
        char * sVal = NULL;
800
        int len = 0;
801
        jobject obj = NULL;
802
        std::cerr<<" Return type="<<Z_TYPE_P(retval)<<std::endl;
803
//TODO handle XdmValue wrapped object
804
const char * objName = NULL;
805
xdmNode_object* ooth = NULL;
806
        switch (Z_TYPE_P(retval)) {
807
            case IS_BOOL:
808
                obj= booleanValue(*SaxonProcessor::sxn_environ, Z_BVAL_P(retval));
809
                break;
810
            
811
            case IS_LONG:
812
                obj= longValue(*SaxonProcessor::sxn_environ, Z_LVAL_P(retval));
813
                break;
814
            case IS_STRING:
815
                sVal = Z_STRVAL_P(retval);
816
                len = Z_STRLEN_P(retval);
817
                obj = getJavaStringValue(*SaxonProcessor::sxn_environ,estrndup(sVal, len)); 
818
                break;
819
            break;
820
            case IS_NULL:
821
                
822
                    break;
823
            case IS_DOUBLE:
824
                obj = doubleValue(*SaxonProcessor::sxn_environ, (double)Z_DVAL_P(retval));                
825
                 break;
826
            
827
            case IS_ARRAY:
828
            //break;
829
            case IS_OBJECT:
830
                    objName =Z_OBJCE_P(retval)->name;
831
      
832

    
833
                      if(strcmp(objName, "Saxon\\XdmNode")==0) {
834
                        ooth = (xdmNode_object*)zend_object_store_get_object(retval TSRMLS_CC);
835
                        if(ooth != NULL) {
836
                                    obj = ooth->xdmNode->getUnderlyingValue(NULL);
837
                    
838
                        }
839
                      }
840
                break;
841
            default:
842
                obj = NULL;
843
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
844
        }
845

    
846
        //zend_printf("We have %i as type<br>", retval->type);
847
        //*return_value = *retval;
848
        //zval_copy_ctor(return_value);
849
        //zval_ptr_dtor(&retval);
850
        /*int cstrlen = Z_STRLEN_P(retval);
851
        char * str = estrndup(Z_STRVAL_P(retval), cstrlen);
852
        
853
        jstring jstrBuf = SaxonProcessor::sxn_environ->env->NewStringUTF(str);*/
854
        zval_ptr_dtor(&retval);
855
        return obj;
856
}
857

    
858

    
859

    
860
PHP_METHOD(XsltProcessor, transformToString)
861
{
862
    XsltProcessor *xsltProcessor;
863
 
864
    if (ZEND_NUM_ARGS()>0) {
865
        WRONG_PARAM_COUNT;
866
    }
867
////
868
/*zval *function_name;
869
zval *retval;
870

871
char * str = "userFunction";
872

873

874
MAKE_STD_ZVAL(function_name);
875
ZVAL_STRING(function_name, str, 1);
876
if(call_user_function_ex(CG(function_table), NULL, function_name, &retval, 0, NULL, 0, NULL TSRMLS_CC) != SUCCESS)
877
{
878
    zend_error(E_ERROR, "Function call failed");
879
}
880

881
if(Z_TYPE(*retval) ==0){
882
zend_error(E_ERROR, "DATAYYY is NULL");
883
}else {
884
str = Z_STRVAL_P(retval);
885
zend_printf("DATAYYY= %i <br>", str);
886
} 
887

888
zend_printf("We have %i as type<br>", retval->type);
889
*return_value = *retval;
890
zval_copy_ctor(return_value);
891
zval_ptr_dtor(&retval);*/
892

    
893

    
894
////
895

    
896
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
897
    xsltProcessor = obj->xsltProcessor;
898

    
899
    if (xsltProcessor != NULL) {
900

    
901
        const char * result = xsltProcessor->transformToString();
902
        if(result != NULL) {
903
            char *str = estrdup(result);
904
            RETURN_STRING(str, 0);
905
        } else if(xsltProcessor->exceptionOccurred()){
906
            xsltProcessor->checkException();
907
            const char * errStr = xsltProcessor->getErrorMessage(0);
908
            if(errStr != NULL) {
909
                const char * errorCode = xsltProcessor->getErrorCode(0);
910
                if(errorCode!=NULL) {
911
                    // TODO: throw exception
912
                }
913
            }
914
        }
915
    }
916
    RETURN_NULL();
917
}
918

    
919
PHP_METHOD(XsltProcessor, transformToValue)
920
{
921
    XsltProcessor *xsltProcessor;
922

    
923
    if (ZEND_NUM_ARGS()>0) {
924
        WRONG_PARAM_COUNT;
925
    }
926

    
927
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
928
    xsltProcessor = obj->xsltProcessor;
929

    
930
    if (xsltProcessor != NULL) {
931

    
932
        XdmValue * node = xsltProcessor->transformToValue();
933
        if(node != NULL) {
934
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
935
                RETURN_NULL();
936
            } else {
937
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
938
                assert (vobj != NULL);
939
                vobj->xdmValue = node;
940
            }
941
        } else if(xsltProcessor->exceptionOccurred()){
942
            xsltProcessor->checkException();
943
        }
944
    } else {
945
        RETURN_NULL();
946
    }
947
}
948

    
949
PHP_METHOD(XsltProcessor, transformToFile)
950
{
951
    XsltProcessor *xsltProcessor;
952
 
953
    if (ZEND_NUM_ARGS()>0) {
954
        WRONG_PARAM_COUNT;
955
    }
956

    
957
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
958
    xsltProcessor = obj->xsltProcessor;
959

    
960
    if (xsltProcessor != NULL) {
961

    
962
        xsltProcessor->transformToFile();
963
        if(xsltProcessor->exceptionOccurred()) {
964
           //TODO
965
            const char * exStr = xsltProcessor->checkException();
966
        }
967
    } else {
968
        RETURN_NULL();
969
    }
970
}
971

    
972
PHP_METHOD(XsltProcessor, compileFromFile)
973
{
974
    XsltProcessor *xsltProcessor;
975
    char * name;
976
    int len1;
977

    
978
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
979
        RETURN_NULL();
980
    }
981
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
982
    xsltProcessor = obj->xsltProcessor;
983
    if (xsltProcessor != NULL) {
984
        xsltProcessor->compileFromFile(name);
985
    }
986
}
987

    
988
PHP_METHOD(XsltProcessor, compileFromString)
989
{
990
    XsltProcessor *xsltProcessor;
991
    char * stylesheetStr;
992
    int len1, myint;
993
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &stylesheetStr, &len1) == FAILURE) {
994
        RETURN_NULL();
995
    }
996
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
997
    xsltProcessor = obj->xsltProcessor;
998
    if (xsltProcessor != NULL) {
999
        xsltProcessor->compileFromString(stylesheetStr);
1000
    }
1001
}
1002

    
1003
PHP_METHOD(XsltProcessor, compileFromValue)
1004
{
1005
    XsltProcessor *xsltProcessor;
1006
   zval* oth;
1007

    
1008
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &oth, xdmValue_ce) == FAILURE) {
1009
        RETURN_NULL();
1010
    }
1011
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1012
    xsltProcessor = obj->xsltProcessor;
1013
    if (xsltProcessor != NULL) {
1014
         xdmValue_object* ooth = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
1015
        if(ooth != NULL) {
1016
            XdmValue * value = ooth->xdmValue;
1017
            if(value != NULL && value->size() == 1 && (value->getHead())->getType() == 3) {
1018
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1019
            }
1020
        }
1021
    }
1022
}
1023

    
1024

    
1025

    
1026

    
1027
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1028
{
1029
    XsltProcessor *xsltProcessor;
1030
    zval* oth = NULL;
1031

    
1032
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
1033
        RETURN_NULL();
1034
    }
1035

    
1036
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1037
    xsltProcessor = obj->xsltProcessor;
1038
    if (xsltProcessor != NULL) {
1039

    
1040
    if(!oth) {
1041
        php_error(E_WARNING, "Error setting source value");
1042
        return;
1043
    } else {
1044

    
1045
      const char * objName =Z_OBJCE_P(oth)->name;
1046
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1047

    
1048
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1049
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1050
        if(ooth != NULL) {
1051
            XdmNode * value = ooth->xdmNode;
1052
            if(value != NULL) {        
1053
                XdmItem  *valueX = (XdmItem*)value;
1054
                xsltProcessor->setSourceFromXdmValue(valueX);
1055

    
1056
            }
1057
        }
1058
      } else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1059
        xdmValue_object* ooth = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
1060
        if(ooth != NULL) {
1061
            XdmValue * value = ooth->xdmValue;
1062
            if(value != NULL) {
1063
                xsltProcessor->setSourceFromXdmValue((XdmItem*)value);
1064
            }
1065
        }
1066
      }  
1067

    
1068
        
1069
    }
1070
  }
1071
}
1072

    
1073
PHP_METHOD(XsltProcessor, setOutputFile)
1074
{
1075
    XsltProcessor *xsltProcessor;
1076
    char * outputFilename;
1077
    int len1;
1078

    
1079
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &outputFilename, &len1, xdmValue_ce) == FAILURE) {
1080
        RETURN_NULL();
1081
    }
1082

    
1083
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1084
    xsltProcessor = obj->xsltProcessor;
1085
    if (xsltProcessor != NULL && outputFilename != NULL) {
1086
        
1087
         xsltProcessor->setOutputFile(outputFilename);
1088
            
1089
        
1090
    }
1091
}
1092

    
1093
PHP_METHOD(XsltProcessor, setSourceFromFile)
1094
{
1095
    XsltProcessor *xsltProcessor;
1096
    char * inFilename;
1097
    int len1;
1098

    
1099
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &inFilename, &len1, xdmValue_ce) == FAILURE) {
1100
        RETURN_NULL();
1101
    }
1102

    
1103
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1104
    xsltProcessor = obj->xsltProcessor;
1105
    if (xsltProcessor != NULL && inFilename != NULL) {
1106
        
1107
         xsltProcessor->setSourceFromFile(inFilename);
1108
            
1109
        
1110
    }
1111
}
1112

    
1113

    
1114
PHP_METHOD(XsltProcessor, setProperty)
1115
{
1116
    XsltProcessor *xsltProcessor;
1117
    char * name;
1118
    char * value;
1119
    int len1, len2, myint;
1120

    
1121
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1122
        RETURN_NULL();
1123
    }
1124
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1125
    xsltProcessor = obj->xsltProcessor;
1126
    if (xsltProcessor != NULL) {
1127
        xsltProcessor->setProperty(name, value);
1128
    }
1129
}
1130

    
1131
PHP_METHOD(XsltProcessor, setParameter)
1132
{
1133

    
1134
   XsltProcessor *xsltProcessor;
1135
   char * name;
1136
   zval* oth;
1137
   int len1, len2, myint;        
1138
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1139
        RETURN_NULL();
1140
    }
1141
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1142
    xsltProcessor = obj->xsltProcessor;
1143
    if (xsltProcessor != NULL) {
1144

    
1145

    
1146
      const char * objName =Z_OBJCE_P(oth)->name;
1147
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1148

    
1149
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1150
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1151
        if(ooth != NULL) {
1152
            XdmNode * value = ooth->xdmNode;
1153
            if(value != NULL) {        
1154
                xsltProcessor->setParameter(name, (XdmValue *)value);
1155

    
1156
            }
1157
        }
1158
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1159
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1160
        if(ooth != NULL) {
1161
            XdmValue * value = ooth->xdmValue;
1162
            if(value != NULL) {
1163
                
1164
                xsltProcessor->setParameter(name, value);
1165
            }
1166
        }
1167

    
1168

    
1169

    
1170
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1171
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1172
        if(ooth != NULL) {
1173
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1174
            if(value != NULL) {
1175
                
1176
                xsltProcessor->setParameter(name, (XdmValue *)value);
1177
            }
1178
        }
1179

    
1180

    
1181

    
1182
      }
1183

    
1184
    }
1185
}
1186

    
1187
PHP_METHOD(XsltProcessor, clearParameters)
1188
{
1189
    XsltProcessor *xsltProcessor;
1190
    if (ZEND_NUM_ARGS()>0) {
1191
        WRONG_PARAM_COUNT;
1192
    }
1193

    
1194
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1195
    xsltProcessor = obj->xsltProcessor;
1196
    if (xsltProcessor != NULL) {
1197
        xsltProcessor->clearParameters(true);
1198
    }
1199
}
1200

    
1201
PHP_METHOD(XsltProcessor, clearProperties)
1202
{
1203
    XsltProcessor *xsltProcessor;
1204
    if (ZEND_NUM_ARGS()>0) {
1205
        WRONG_PARAM_COUNT;
1206
    }
1207

    
1208
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1209
    xsltProcessor = obj->xsltProcessor;
1210
    if (xsltProcessor != NULL) {
1211
        xsltProcessor->clearProperties();
1212
    }
1213
}
1214

    
1215
PHP_METHOD(XsltProcessor, exceptionOccurred)
1216
{
1217
    XsltProcessor *xsltProcessor;
1218
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1219
    if (ZEND_NUM_ARGS()>0) {
1220
        WRONG_PARAM_COUNT;
1221
    }
1222

    
1223
    xsltProcessor = obj->xsltProcessor;
1224
    if (xsltProcessor != NULL) {
1225
        bool result = xsltProcessor->exceptionOccurred();
1226
        RETURN_BOOL(result);
1227
    }
1228
    RETURN_BOOL(false);
1229
}
1230

    
1231
PHP_METHOD(XsltProcessor, getExceptionCount)
1232
{
1233
    XsltProcessor *xsltProcessor;
1234
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1235
    if (ZEND_NUM_ARGS()>0) {
1236
        WRONG_PARAM_COUNT;
1237
    }
1238

    
1239
    xsltProcessor = obj->xsltProcessor;
1240
    if (xsltProcessor != NULL) {
1241
        int count = xsltProcessor->exceptionCount();
1242
        RETURN_LONG(count);
1243
    }
1244
    RETURN_LONG(0);
1245
}
1246

    
1247
PHP_METHOD(XsltProcessor, getErrorCode)
1248
{
1249
    XsltProcessor *xsltProcessor;
1250
    long index;
1251
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1252
        RETURN_NULL();
1253
    }
1254
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1255
    xsltProcessor = obj->xsltProcessor;
1256
    if (xsltProcessor != NULL) {
1257
        const char * errCode = xsltProcessor->getErrorCode((int)index);
1258
        if(errCode != NULL) {
1259
            char *str = estrdup(errCode);
1260
            RETURN_STRING(str, 0);
1261
        }
1262
    }
1263
    RETURN_NULL();
1264
}
1265

    
1266
PHP_METHOD(XsltProcessor, getErrorMessage)
1267
{
1268
    XsltProcessor *xsltProcessor;
1269
    long index;
1270
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1271
        RETURN_NULL();
1272
    }
1273
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1274
    xsltProcessor = obj->xsltProcessor;
1275
    if (xsltProcessor != NULL) {
1276
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1277
        if(errStr != NULL) {
1278
            char *str = estrdup(errStr);
1279
            RETURN_STRING(str, 0);
1280
        }
1281
    }
1282
    RETURN_NULL();
1283
}
1284
PHP_METHOD(XsltProcessor, exceptionClear)
1285
{
1286
    XsltProcessor *xsltProcessor;
1287
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1288
    xsltProcessor = obj->xsltProcessor;
1289
    if (xsltProcessor != NULL) {
1290
        xsltProcessor->exceptionClear();
1291
    }
1292
}
1293

    
1294

    
1295

    
1296

    
1297
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
1298

    
1299
void xqueryProcessor_free_storage(void *object TSRMLS_DC)
1300
{
1301
    xqueryProcessor_object *obj = (xqueryProcessor_object *)object;
1302
    //obj->xqueryProcessor->clearParameters(true);
1303
    //obj->xqueryProcessor->clearProperties();
1304
    zend_hash_destroy(obj->std.properties);
1305
    FREE_HASHTABLE(obj->std.properties);
1306
    efree(obj);
1307
}
1308

    
1309
zend_object_value xqueryProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
1310
{
1311
    zval *tmp;
1312
    zend_object_value retval;
1313
    xqueryProcessor_object *obj = (xqueryProcessor_object *)emalloc(sizeof(xqueryProcessor_object));
1314
    memset(obj, 0, sizeof(xqueryProcessor_object));
1315
    obj->std.ce = type;
1316

    
1317
    ALLOC_HASHTABLE(obj->std.properties);
1318
    zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
1319
    object_properties_init(&obj->std, type);
1320
    retval.handle = zend_objects_store_put(obj, NULL, xqueryProcessor_free_storage, NULL TSRMLS_CC);
1321
    retval.handlers = &xqueryProcessor_object_handlers;
1322

    
1323
    return retval;
1324
}
1325

    
1326
PHP_METHOD(XQueryProcessor, __destruct)
1327
{
1328
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1329

    
1330

    
1331
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
1332

    
1333
    delete xqueryProcessor;
1334
    
1335
}
1336

    
1337

    
1338
PHP_METHOD(XQueryProcessor, runQueryToValue)
1339
{
1340
    XQueryProcessor *xqueryProcessor;
1341
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1342

    
1343
    if (ZEND_NUM_ARGS()>0) {
1344
        WRONG_PARAM_COUNT;
1345
    }
1346

    
1347
    xqueryProcessor = obj->xqueryProcessor;
1348

    
1349
    if (xqueryProcessor != NULL) {
1350
        XdmValue * node = xqueryProcessor->runQueryToValue();
1351
        if(node != NULL) {
1352
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1353
                RETURN_NULL();
1354
                return;
1355
            } else {
1356
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
1357
                assert (vobj != NULL);
1358
                vobj->xdmValue = node;
1359
                return;
1360
            }
1361
        }
1362
        xqueryProcessor->checkException();//TODO
1363
    } else {
1364
        RETURN_NULL();
1365
    }
1366
}
1367

    
1368
PHP_METHOD(XQueryProcessor, runQueryToString)
1369
{
1370
    XQueryProcessor *xqueryProcessor;
1371
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1372

    
1373
    if (ZEND_NUM_ARGS()>0) {
1374
        WRONG_PARAM_COUNT;
1375
    }
1376

    
1377
    xqueryProcessor = obj->xqueryProcessor;
1378

    
1379
    if (xqueryProcessor != NULL) {
1380
        const char * result = xqueryProcessor->runQueryToString();
1381
        if(result != NULL) {
1382
            char *str = estrdup(result);
1383
            RETURN_STRING(str, 0);
1384
            return;
1385
        } else {
1386
          xqueryProcessor->checkException(); //TODO
1387
        }
1388
    }
1389
   RETURN_NULL();
1390
}
1391

    
1392
PHP_METHOD(XQueryProcessor, runQueryToFile)
1393
{
1394

    
1395
     char * ofilename;
1396
     int len1 =0;
1397
    if (ZEND_NUM_ARGS()!= 1) {
1398
        WRONG_PARAM_COUNT;
1399
    }
1400
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ofilename, &len1) == FAILURE) {
1401
        RETURN_NULL();
1402
    }
1403
    XQueryProcessor *xqueryProcessor;
1404
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1405

    
1406

    
1407

    
1408
    xqueryProcessor = obj->xqueryProcessor;
1409

    
1410
    if (xqueryProcessor != NULL) {
1411
        if(ofilename != NULL) {
1412
                xqueryProcessor->setOutputFile(ofilename);        
1413
        }
1414
        xqueryProcessor->runQueryToFile(); 
1415
    }
1416

    
1417
}
1418

    
1419
PHP_METHOD(XQueryProcessor, setQueryContent)
1420
{
1421
    char * queryStr;
1422
    int len1;
1423

    
1424
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &queryStr, &len1) == FAILURE) {
1425
        RETURN_NULL();
1426
    }
1427
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC); 
1428
    if(queryStr != NULL) { 
1429
      obj->xqueryProcessor->setProperty("qs", queryStr);
1430
   }
1431
}
1432

    
1433
PHP_METHOD(XQueryProcessor, setQueryFile)
1434
{
1435
   char * fileName;
1436
   int len1;
1437
    XQueryProcessor *xqueryProcessor;
1438

    
1439
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fileName, &len1) == FAILURE) {
1440
        RETURN_NULL();
1441
    }
1442
    if(fileName != NULL) {
1443
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1444
            xqueryProcessor = obj->xqueryProcessor;
1445
            xqueryProcessor->setQueryFile(fileName);
1446
    }
1447
            
1448
}
1449

    
1450
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
1451
{
1452
   char * base;
1453
   int len1;
1454
    XQueryProcessor *xqueryProcessor;
1455

    
1456
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &base, &len1) == FAILURE) {
1457
        RETURN_NULL();
1458
    }
1459
    if(base != NULL) {
1460
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1461
            xqueryProcessor = obj->xqueryProcessor;
1462
            xqueryProcessor->setQueryBaseURI(base);
1463
    }
1464
            
1465
}
1466

    
1467
PHP_METHOD(XQueryProcessor, declareNamespace)
1468
{
1469
   char * prefix;
1470
   char * ns;
1471
   int len1, len2;
1472
    XQueryProcessor *xqueryProcessor;
1473

    
1474
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
1475
        RETURN_NULL();
1476
    }
1477
    if(prefix != NULL && ns != NULL) {
1478
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1479
            xqueryProcessor = obj->xqueryProcessor;
1480
            xqueryProcessor->declareNamespace(prefix, ns);
1481
    }
1482
            
1483
}
1484

    
1485

    
1486

    
1487
PHP_METHOD(XQueryProcessor, setContextItem)
1488
{
1489
   char * context;
1490
   int len1;
1491
   zval* oth;
1492
    XQueryProcessor *xqueryProcessor;
1493

    
1494
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
1495
        RETURN_NULL();
1496
    }
1497
    if(oth != NULL) {
1498
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1499
            xqueryProcessor = obj->xqueryProcessor;
1500
    const char * objName =Z_OBJCE_P(oth)->name;
1501
      //std::cerr<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1502

    
1503
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1504
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1505
        if(ooth != NULL) {
1506
            XdmNode * value = ooth->xdmNode;
1507
            if(value != NULL) {        
1508
                xqueryProcessor->setContextItem((XdmItem *)value);
1509
                return;
1510
            }
1511
        }
1512
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
1513
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
1514
        if(ooth != NULL) {
1515
            XdmItem * value = ooth->xdmItem;
1516
            if(value != NULL) {        
1517
                xqueryProcessor->setContextItem(value);
1518
                return;
1519
            }
1520
         }
1521
        
1522

    
1523

    
1524

    
1525
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1526
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1527
        if(ooth != NULL) {
1528
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1529
            if(value != NULL) {
1530
                
1531
                xqueryProcessor->setContextItem((XdmItem *)value);
1532
                return;
1533
            }
1534
        }
1535

    
1536

    
1537

    
1538
      } 
1539

    
1540

    
1541

    
1542

    
1543
        /*xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
1544
        if(ooth != NULL) {
1545
            XdmItem * value = ooth->xdmItem;
1546
            if(value != NULL) {
1547
                    xqueryProcessor->setContextItem(value);
1548
            }
1549
        }*/
1550
    }
1551
        //throw exception
1552
        php_error(E_WARNING,"contextItem not set");
1553
        
1554
            
1555
}
1556

    
1557
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
1558
{
1559
   char * cfilename;
1560
   int len1;
1561
    XQueryProcessor *xqueryProcessor;
1562

    
1563
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cfilename, &len1) == FAILURE) {
1564
        RETURN_NULL();
1565
    }
1566
    if(cfilename != NULL) {
1567
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1568
            xqueryProcessor = obj->xqueryProcessor;
1569
            xqueryProcessor->setContextItemFromFile(cfilename);
1570
    }
1571
            
1572
}
1573

    
1574

    
1575
PHP_METHOD(XQueryProcessor, setProperty)
1576
{
1577
    XQueryProcessor *xqueryProcessor;
1578
    char * name;
1579
    char * value;
1580
    int len1, len2, myint;
1581

    
1582
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1583
        RETURN_NULL();
1584
    }
1585
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1586
    xqueryProcessor = obj->xqueryProcessor;
1587
    if (xqueryProcessor != NULL) {
1588
        xqueryProcessor->setProperty(name, value);
1589
    }
1590
}
1591

    
1592
PHP_METHOD(XQueryProcessor, setParameter)
1593
{
1594

    
1595
   XQueryProcessor *xqueryProcessor;
1596
   char * name;
1597
   zval* oth;
1598
   int len1, len2, myint;        
1599
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1600
        RETURN_NULL();
1601
    }
1602
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1603
    xqueryProcessor = obj->xqueryProcessor;
1604
    if (xqueryProcessor != NULL) {
1605
             const char * objName =Z_OBJCE_P(oth)->name;
1606
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1607

    
1608
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1609
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1610
        if(ooth != NULL) {
1611
            XdmNode * value = ooth->xdmNode;
1612
            if(value != NULL) {        
1613
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1614

    
1615
            }
1616
        }
1617
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1618
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1619
        if(ooth != NULL) {
1620
            XdmValue * value = ooth->xdmValue;
1621
            if(value != NULL) {
1622
                
1623
                xqueryProcessor->setParameter(name, value);
1624
            }
1625
        }
1626

    
1627

    
1628

    
1629
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1630
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1631
        if(ooth != NULL) {
1632
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1633
            if(value != NULL) {
1634
                
1635
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1636
            } 
1637
        }
1638

    
1639

    
1640

    
1641
      }
1642

    
1643
    }
1644
}
1645

    
1646

    
1647

    
1648

    
1649
PHP_METHOD(XQueryProcessor, clearParameters)
1650
{
1651
    XQueryProcessor *xqueryProcessor;
1652
    if (ZEND_NUM_ARGS()>0) {
1653
        WRONG_PARAM_COUNT;
1654
    }
1655

    
1656
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1657
    xqueryProcessor = obj->xqueryProcessor;
1658
    if (xqueryProcessor != NULL) {
1659
        xqueryProcessor->clearParameters(true);
1660
    }
1661
}
1662

    
1663
PHP_METHOD(XQueryProcessor, clearProperties)
1664
{
1665
    XQueryProcessor *xqueryProcessor;
1666

    
1667
    if (ZEND_NUM_ARGS()>0) {
1668
        WRONG_PARAM_COUNT;
1669
    }
1670

    
1671
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1672
    xqueryProcessor = obj->xqueryProcessor;
1673
    if (xqueryProcessor != NULL) {
1674
        xqueryProcessor->clearProperties();
1675
    }
1676
}
1677

    
1678
PHP_METHOD(XQueryProcessor, exceptionOccurred)
1679
{
1680
    XQueryProcessor *xqueryProcessor;
1681
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1682
    if (ZEND_NUM_ARGS()>0) {
1683
        WRONG_PARAM_COUNT;
1684
    }
1685

    
1686
    xqueryProcessor = obj->xqueryProcessor;
1687
    if (xqueryProcessor != NULL) {
1688
        bool result = xqueryProcessor->exceptionOccurred();
1689
        RETURN_BOOL(result);
1690
    }
1691
    RETURN_BOOL(false);
1692
}
1693

    
1694
PHP_METHOD(XQueryProcessor, getExceptionCount)
1695
{
1696
    XQueryProcessor *xqueryProcessor;
1697
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1698
    if (ZEND_NUM_ARGS()>0) {
1699
        WRONG_PARAM_COUNT;
1700
    }
1701

    
1702
    xqueryProcessor = obj->xqueryProcessor;
1703
    if (xqueryProcessor != NULL) {
1704
        int count = xqueryProcessor->exceptionCount();
1705
        RETURN_LONG(count);
1706
    }
1707
    RETURN_LONG(0);
1708
}
1709

    
1710
PHP_METHOD(XQueryProcessor, getErrorCode)
1711
{
1712
    XQueryProcessor *xqueryProcessor;
1713
    long index;
1714
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1715
        RETURN_NULL();
1716
    }
1717
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1718
    xqueryProcessor = obj->xqueryProcessor;
1719
    if (xqueryProcessor != NULL) {
1720
        const char * errCode = xqueryProcessor->getErrorCode((int)index);
1721
        if(errCode != NULL) {
1722
            char *str = estrdup(errCode);
1723
            RETURN_STRING(str, 0);
1724
        }
1725
    }
1726
    RETURN_NULL();
1727
}
1728

    
1729
PHP_METHOD(XQueryProcessor, getErrorMessage)
1730
{
1731
    XQueryProcessor *xqueryProcessor;
1732
    long index;
1733
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1734
        RETURN_NULL();
1735
    }
1736
    xqueryProcessor_object *obj = (xqueryProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1737
    xqueryProcessor = obj->xqueryProcessor;
1738
    if (xqueryProcessor != NULL) {
1739
        const char * errStr = xqueryProcessor->getErrorMessage((int)index);
1740
        if(errStr != NULL) {
1741
            char *str = estrdup(errStr);
1742
            RETURN_STRING(str, 0);
1743
        }
1744
    }
1745
    RETURN_NULL();
1746
}
1747
PHP_METHOD(XQueryProcessor, exceptionClear)
1748
{
1749
    XQueryProcessor *xqueryProcessor;
1750
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1751
    xqueryProcessor = obj->xqueryProcessor;
1752
    if (xqueryProcessor != NULL) {
1753
        xqueryProcessor->exceptionClear();
1754
    }
1755
}
1756

    
1757
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
1758

    
1759
void xpathProcessor_free_storage(void *object TSRMLS_DC)
1760
{
1761
    xpathProcessor_object *obj = (xpathProcessor_object *)object;
1762

    
1763
    zend_hash_destroy(obj->std.properties);
1764
    FREE_HASHTABLE(obj->std.properties);
1765
    efree(obj);
1766
}
1767

    
1768
PHP_METHOD(XPathProcessor, __destruct)
1769
{
1770
   xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1771
   XPathProcessor * xpathProc= obj->xpathProcessor;
1772

    
1773

    
1774
    delete xpathProc;
1775
    
1776
}
1777

    
1778
zend_object_value xpathProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
1779
{
1780
    zval *tmp;
1781
    zend_object_value retval;
1782
    xpathProcessor_object *obj = (xpathProcessor_object *)emalloc(sizeof(xpathProcessor_object));
1783
    memset(obj, 0, sizeof(xpathProcessor_object));
1784
    obj->std.ce = type;
1785

    
1786
    ALLOC_HASHTABLE(obj->std.properties);
1787
    zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
1788
    object_properties_init(&obj->std, type);
1789

    
1790
    retval.handle = zend_objects_store_put(obj, NULL, xpathProcessor_free_storage, NULL TSRMLS_CC);
1791
    retval.handlers = &xpathProcessor_object_handlers;
1792

    
1793
    return retval;
1794
}
1795

    
1796

    
1797

    
1798
PHP_METHOD(XPathProcessor, setProperty)
1799
{
1800
    XPathProcessor *xpathProcessor;
1801
    char * name;
1802
    char * value;
1803
    int len1, len2;
1804

    
1805
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1806
        RETURN_NULL();
1807
    }
1808
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1809
    xpathProcessor = obj->xpathProcessor;
1810
    if (xpathProcessor != NULL) {
1811
        xpathProcessor->setProperty(name, value);
1812
    }
1813
}
1814

    
1815
PHP_METHOD(XPathProcessor, setParameter)
1816
{
1817

    
1818
   XPathProcessor *xpathProcessor;
1819
   char * name;
1820
   zval* oth;
1821
   int len1, len2;        
1822
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1823
        RETURN_NULL();
1824
    }
1825
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1826
    xpathProcessor = obj->xpathProcessor;
1827
    if (xpathProcessor != NULL) {
1828
            const char * objName =Z_OBJCE_P(oth)->name;
1829
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1830

    
1831
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1832
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1833
        if(ooth != NULL) {
1834
            XdmNode * value = ooth->xdmNode;
1835
            if(value != NULL) {        
1836
                xpathProcessor->setParameter(name, (XdmValue *)value);
1837

    
1838
            }
1839
        }
1840
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1841
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1842
        if(ooth != NULL) {
1843
            XdmValue * value = ooth->xdmValue;
1844
            if(value != NULL) {
1845
                
1846
                xpathProcessor->setParameter(name, value);
1847
            }
1848
        }
1849

    
1850

    
1851

    
1852
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1853
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1854
        if(ooth != NULL) {
1855
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1856
            if(value != NULL) {
1857
                
1858
                xpathProcessor->setParameter(name, (XdmValue *)value);
1859
            }
1860
        }
1861

    
1862

    
1863

    
1864
      }
1865

    
1866
    }
1867
}
1868

    
1869
PHP_METHOD(XPathProcessor, declareNamespace)
1870
{
1871
   char * prefix;
1872
   char * ns;
1873
   int len1, len2;
1874
   XPathProcessor *xpathProcessor;
1875

    
1876
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
1877
        RETURN_NULL();
1878
    }
1879
    if(prefix != NULL && ns != NULL) {
1880
            xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1881
            xpathProcessor = obj->xpathProcessor;
1882
            xpathProcessor->declareNamespace(prefix, ns);
1883
    }
1884
            
1885
}
1886

    
1887
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
1888
{
1889

    
1890
   XPathProcessor *xpathProcessor;
1891
   char * xpathStr;
1892
   zval* oth;
1893
   int len1, myint;        
1894
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
1895
        RETURN_NULL();
1896
    }
1897
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1898
    xpathProcessor = obj->xpathProcessor;
1899
    if (xpathProcessor != NULL && xpathStr != NULL) {
1900
        
1901
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
1902
                RETURN_BOOL(result);
1903
    }
1904
}
1905

    
1906
PHP_METHOD(XPathProcessor, evaluate)
1907
{
1908

    
1909
   XPathProcessor *xpathProcessor;
1910
   char * xpathStr;
1911
   zval* oth;
1912
   int len1, myint;        
1913
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
1914
        RETURN_NULL();
1915
    }
1916
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1917
    xpathProcessor = obj->xpathProcessor;
1918
    if (xpathProcessor != NULL && xpathStr != NULL) {
1919
        
1920
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
1921
        if(node != NULL) {
1922
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1923
                RETURN_NULL();
1924
                return;
1925
            } else {
1926
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
1927
                assert (vobj != NULL);
1928
                vobj->xdmValue = node;
1929
                return;
1930
            }
1931
        }
1932
        xpathProcessor->checkException();//TODO
1933
    } 
1934
    RETURN_NULL();
1935
    
1936
}
1937

    
1938
PHP_METHOD(XPathProcessor, evaluateSingle)
1939
{
1940

    
1941
   XPathProcessor *xpathProcessor;
1942
   char * xpathStr;
1943
   zval* oth;
1944
   int len1, myint;        
1945
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
1946
        RETURN_NULL();
1947
    }
1948
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1949
    xpathProcessor = obj->xpathProcessor;
1950

    
1951
    if(xpathStr == NULL) { 
1952
        RETURN_NULL();        
1953
        return;
1954
        }
1955

    
1956

    
1957
    if (xpathProcessor != NULL) {
1958
        
1959
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
1960
        if(node != NULL) {
1961
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
1962
                RETURN_NULL();
1963
                return;
1964
            } else {
1965
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
1966
                assert (vobj != NULL);
1967
                vobj->xdmItem = node;
1968
                return;
1969
            }
1970
        } 
1971
        xpathProcessor->checkException();//TODO
1972
    } 
1973
    RETURN_NULL();
1974
}
1975

    
1976
PHP_METHOD(XPathProcessor, setContextItem)
1977
{
1978

    
1979
   XPathProcessor *xpathProcessor;
1980

    
1981
   zval* oth;
1982
        //TODO this should be relaxed to accept item/atomic/node as well as Value
1983

    
1984
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
1985
        RETURN_NULL();
1986
    }
1987
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1988
    xpathProcessor = obj->xpathProcessor;
1989
    if (xpathProcessor != NULL) {
1990
        if(!oth) {
1991
                php_error(E_WARNING, "Error setting source value");
1992
                return;
1993
         } 
1994
        const char * objName =Z_OBJCE_P(oth)->name;
1995
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
1996
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
1997
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1998
        if(ooth != NULL) {
1999
            XdmNode * value = ooth->xdmNode;
2000
            if(value != NULL) {        
2001
                xpathProcessor->setContextItem((XdmItem *)value);
2002
                value->incrementRefCount();
2003

    
2004
            }
2005
        }
2006
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2007
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2008
        if(ooth != NULL) {
2009
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2010
            if(value != NULL) {
2011
                
2012
                xpathProcessor->setContextItem((XdmItem *)value);
2013
                value->incrementRefCount();
2014
            }
2015
        }
2016
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
2017
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
2018
        if(ooth != NULL) {
2019
            XdmItem * value = ooth->xdmItem;
2020
            if(value != NULL) {
2021
                
2022
                xpathProcessor->setContextItem(value);
2023
                value->incrementRefCount();
2024
            }
2025
        }
2026

    
2027
      }
2028
    }
2029
}
2030

    
2031
PHP_METHOD(XPathProcessor, setBaseURI)
2032
{
2033

    
2034
   XPathProcessor *xpathProcessor;
2035

    
2036
   char * uriStr;
2037
   int len1;
2038
        
2039
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &uriStr, &len1, xdmValue_ce) == FAILURE) {
2040
        RETURN_NULL();
2041
    }
2042
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2043
    xpathProcessor = obj->xpathProcessor;
2044
    if (xpathProcessor != NULL) {
2045
        
2046
        if(uriStr != NULL) {
2047
           
2048
                xpathProcessor->setBaseURI(uriStr);
2049
            
2050
        }
2051
    }
2052
}
2053

    
2054
PHP_METHOD(XPathProcessor, setContextFile)
2055
{
2056

    
2057
   XPathProcessor *xpathProcessor;
2058

    
2059
   char * name;
2060
   int len1;
2061
        
2062
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1, xdmValue_ce) == FAILURE) {
2063
        RETURN_NULL();
2064
    }
2065
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2066
    xpathProcessor = obj->xpathProcessor;
2067
    if (xpathProcessor != NULL) {
2068
        
2069
        if(name != NULL) {
2070
           
2071
                xpathProcessor->setContextFile(name);
2072
            
2073
        }
2074
    }
2075
}
2076

    
2077
PHP_METHOD(XPathProcessor, clearParameters)
2078
{
2079
    XPathProcessor *xpathProcessor;
2080
    if (ZEND_NUM_ARGS()>0) {
2081
        WRONG_PARAM_COUNT;
2082
    }
2083

    
2084
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2085
    xpathProcessor = obj->xpathProcessor;
2086
    if (xpathProcessor != NULL) {
2087
        xpathProcessor->clearParameters(true);
2088
    }
2089
}
2090

    
2091
PHP_METHOD(XPathProcessor, clearProperties)
2092
{
2093
     XPathProcessor *xpathProcessor;
2094
    if (ZEND_NUM_ARGS()>0) {
2095
        WRONG_PARAM_COUNT;
2096
    }
2097

    
2098
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2099
    xpathProcessor = obj->xpathProcessor;
2100
    if (xpathProcessor != NULL) {
2101
        xpathProcessor->clearProperties();
2102
    }
2103
}
2104

    
2105

    
2106
PHP_METHOD(XPathProcessor, exceptionOccurred)
2107
{
2108
   XPathProcessor *xpathProcessor;
2109
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2110
    if (ZEND_NUM_ARGS()>0) {
2111
        WRONG_PARAM_COUNT;
2112
    }
2113

    
2114
    xpathProcessor = obj->xpathProcessor;
2115
    if (xpathProcessor != NULL) {
2116
        bool result = xpathProcessor->exceptionOccurred();
2117
        RETURN_BOOL(result);
2118
    }
2119
    RETURN_BOOL(false);
2120
}
2121

    
2122
PHP_METHOD(XPathProcessor, getExceptionCount)
2123
{
2124
    XPathProcessor *xpathProcessor;
2125
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2126
    if (ZEND_NUM_ARGS()>0) {
2127
        WRONG_PARAM_COUNT;
2128
    }
2129

    
2130
    xpathProcessor = obj->xpathProcessor;
2131
    if (xpathProcessor != NULL) {
2132
        int count = xpathProcessor->exceptionCount();
2133
        RETURN_LONG(count);
2134
    }
2135
    RETURN_LONG(0);
2136
}
2137

    
2138
PHP_METHOD(XPathProcessor, getErrorCode)
2139
{
2140
    XPathProcessor *xpathProcessor;
2141
    long index;
2142
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2143
        RETURN_NULL();
2144
    }
2145
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2146
    xpathProcessor = obj->xpathProcessor;
2147
    if (xpathProcessor != NULL) {
2148
        const char * errCode = xpathProcessor->getErrorCode((int)index);
2149
        if(errCode != NULL) {
2150
            char *str = estrdup(errCode);
2151
            RETURN_STRING(str, 0);
2152
        }
2153
    }
2154
    RETURN_NULL();
2155
}
2156

    
2157
PHP_METHOD(XPathProcessor, getErrorMessage)
2158
{
2159
    XPathProcessor *xpathProcessor;
2160
    long index;
2161
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2162
        RETURN_NULL();
2163
    }
2164
    xpathProcessor_object *obj = (xpathProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2165
    xpathProcessor = obj->xpathProcessor;
2166
    if (xpathProcessor != NULL) {
2167
        const char * errStr = xpathProcessor->getErrorMessage((int)index);
2168
        if(errStr != NULL) {
2169
            char *str = estrdup(errStr);
2170
            RETURN_STRING(str, 0);
2171
        }
2172
    }
2173
    RETURN_NULL();
2174
}
2175
PHP_METHOD(XPathProcessor, exceptionClear)
2176
{
2177
    XPathProcessor *xpathProcessor;
2178
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2179
    xpathProcessor = obj->xpathProcessor;
2180
    if (xpathProcessor != NULL) {
2181
        xpathProcessor->exceptionClear();
2182
    }
2183
}
2184

    
2185
/*     ============== PHP Interface of   SchemaValidator =============== */
2186

    
2187
void schemaValidator_free_storage(void *object TSRMLS_DC)
2188
{
2189
    schemaValidator_object *obj = (schemaValidator_object *)object;
2190

    
2191
    zend_hash_destroy(obj->std.properties);
2192
    FREE_HASHTABLE(obj->std.properties);
2193
    efree(obj);
2194
}
2195

    
2196
zend_object_value schemaValidator_create_handler(zend_class_entry *type TSRMLS_DC)
2197
{
2198
    zval *tmp;
2199
    zend_object_value retval;
2200
    schemaValidator_object *obj = (schemaValidator_object *)emalloc(sizeof(schemaValidator_object));
2201
    memset(obj, 0, sizeof(schemaValidator_object));
2202
    obj->std.ce = type;
2203

    
2204
    ALLOC_HASHTABLE(obj->std.properties);
2205
    zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
2206
    object_properties_init(&obj->std, type);
2207

    
2208
    retval.handle = zend_objects_store_put(obj, NULL, schemaValidator_free_storage, NULL TSRMLS_CC);
2209
    retval.handlers = &schemaValidator_object_handlers;
2210

    
2211
    return retval;
2212
}
2213

    
2214

    
2215

    
2216
PHP_METHOD(SchemaValidator, __destruct)
2217
{
2218
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2219

    
2220

    
2221
    SchemaValidator * schemaValidator= obj->schemaValidator;
2222

    
2223
    delete schemaValidator;
2224
    
2225
}
2226

    
2227

    
2228

    
2229
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
2230
{
2231
    SchemaValidator *schemaValidator;
2232
    char * name;
2233
    int len1;
2234

    
2235
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2236
        RETURN_NULL();
2237
    }
2238
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2239
    schemaValidator = obj->schemaValidator;
2240
    if (name != NULL && schemaValidator != NULL) {
2241
        schemaValidator->registerSchemaFromFile(name);
2242
    }
2243
}
2244

    
2245
PHP_METHOD(SchemaValidator, registerSchemaFromString)
2246
{
2247
    char * schemaStr;
2248
    int len1;
2249
    SchemaValidator *schemaValidator;
2250
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &schemaStr, &len1) == FAILURE) {
2251
        RETURN_NULL();
2252
    }
2253
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2254
    schemaValidator = obj->schemaValidator;
2255
    if (schemaStr!= NULL && schemaValidator != NULL) {
2256
        schemaValidator->registerSchemaFromString(schemaStr);
2257
    }
2258
}
2259

    
2260
PHP_METHOD(SchemaValidator, validate)
2261
{
2262
    char * name = NULL;
2263
    int len1;
2264
    SchemaValidator *schemaValidator;
2265
    if (ZEND_NUM_ARGS()>1) {
2266
        WRONG_PARAM_COUNT;
2267
    }
2268
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2269
        RETURN_NULL();
2270
    }
2271
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2272
    schemaValidator = obj->schemaValidator;
2273
    if (schemaValidator != NULL) {
2274
        schemaValidator->validate(name);
2275
    }
2276
}
2277

    
2278
PHP_METHOD(SchemaValidator, validateToNode)
2279
{
2280
    char * name = NULL;
2281
    int len1;
2282
    SchemaValidator *schemaValidator;
2283
    if (ZEND_NUM_ARGS()>1) {
2284
        WRONG_PARAM_COUNT;
2285
    }
2286
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2287
        RETURN_NULL();
2288
    }
2289
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2290
    schemaValidator = obj->schemaValidator;
2291
    if (schemaValidator != NULL) {
2292
        XdmNode * node = schemaValidator->validateToNode(name);
2293
        if(node != NULL) {
2294
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2295
                RETURN_NULL();
2296
                return;
2297
            } else {
2298
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2299
                assert (vobj != NULL);
2300
                vobj->xdmNode = node;
2301
                return;
2302
            }
2303
        } 
2304
            schemaValidator->checkException();//TODO
2305
    } 
2306
    RETURN_NULL();
2307
}
2308

    
2309

    
2310
PHP_METHOD(SchemaValidator, getValidationReport)
2311
{
2312

    
2313
    SchemaValidator *schemaValidator;
2314
    if (ZEND_NUM_ARGS()>0) {
2315
        WRONG_PARAM_COUNT;
2316
    }
2317

    
2318
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2319
    schemaValidator = obj->schemaValidator;
2320
    if (schemaValidator != NULL) {
2321
        XdmNode * node = schemaValidator->getValidationReport();
2322
        if(node != NULL) {
2323
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2324
                RETURN_NULL();
2325
                return;
2326
            } else {
2327
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2328
                assert (vobj != NULL);
2329
                vobj->xdmNode = node;
2330
                return;
2331
            }
2332
        } 
2333
            schemaValidator->checkException();//TODO
2334
    } 
2335
    RETURN_NULL();
2336
}
2337

    
2338

    
2339
PHP_METHOD(SchemaValidator, setSourceNode)
2340
{
2341
    SchemaValidator *schemaValidator;
2342

    
2343
    zval* oth;
2344
   
2345

    
2346
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2347
        RETURN_NULL();
2348
    }
2349
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2350
    schemaValidator = obj->schemaValidator;
2351
    if (schemaValidator != NULL) {
2352
        const char * objName =Z_OBJCE_P(oth)->name;
2353
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2354
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2355
        if(ooth != NULL) {
2356
            XdmNode * value = ooth->xdmNode;
2357
            if(value != NULL) {        
2358
                schemaValidator->setSourceNode(value);
2359

    
2360
            }
2361
        }
2362
      
2363
        
2364
      }
2365
    }
2366
}
2367

    
2368
PHP_METHOD(SchemaValidator, setOutputFile)
2369
{
2370
    SchemaValidator *schemaValidator;
2371
    char * name;
2372
    int len1;
2373

    
2374
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2375
        RETURN_NULL();
2376
    }
2377
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2378
    schemaValidator = obj->schemaValidator;
2379
    if (schemaValidator != NULL) {
2380
        schemaValidator->setOutputFile(name);
2381
    }
2382
}
2383

    
2384

    
2385
PHP_METHOD(SchemaValidator, setProperty)
2386
{
2387
    SchemaValidator *schemaValidator;
2388
    char * name;
2389
    char * value;
2390
    int len1, len2, myint;
2391

    
2392
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
2393
        RETURN_NULL();
2394
    }
2395
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2396
    schemaValidator = obj->schemaValidator;
2397
    if (schemaValidator != NULL) {
2398
        schemaValidator->setProperty(name, value);
2399
    }
2400
}
2401

    
2402
PHP_METHOD(SchemaValidator, setParameter)
2403
{
2404

    
2405
   SchemaValidator *schemaValidator;
2406
   char * name;
2407
   zval* oth;
2408
   int len1, len2, myint;        
2409
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
2410
        RETURN_NULL();
2411
    }
2412
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2413
    schemaValidator = obj->schemaValidator;
2414
    if (schemaValidator != NULL) {
2415
      const char * objName =Z_OBJCE_P(oth)->name;
2416
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2417

    
2418
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2419
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2420
        if(ooth != NULL) {
2421
            XdmNode * value = ooth->xdmNode;
2422
            if(value != NULL) {        
2423
                schemaValidator->setParameter(name, (XdmValue *)value);
2424

    
2425
            }
2426
        }
2427
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2428
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2429
        if(ooth != NULL) {
2430
            XdmValue * value = ooth->xdmValue;
2431
            if(value != NULL) {
2432
                
2433
                schemaValidator->setParameter(name, value);
2434
            }
2435
        }
2436

    
2437

    
2438

    
2439
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2440
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2441
        if(ooth != NULL) {
2442
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2443
            if(value != NULL) {
2444
                
2445
                schemaValidator->setParameter(name, (XdmValue *)value);
2446
            }
2447
        }
2448

    
2449

    
2450

    
2451
      }
2452

    
2453
    }
2454
}
2455

    
2456
PHP_METHOD(SchemaValidator, clearProperties)
2457
{
2458
    SchemaValidator *schemaValidator;
2459
    if (ZEND_NUM_ARGS()>0) {
2460
        WRONG_PARAM_COUNT;
2461
    }
2462

    
2463
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2464
    schemaValidator = obj->schemaValidator;
2465
    if (schemaValidator != NULL) {
2466
        schemaValidator->clearProperties();
2467
        schemaValidator->exceptionClear();
2468
    }
2469
}
2470

    
2471
PHP_METHOD(SchemaValidator, clearParameters)
2472
{
2473

    
2474
   SchemaValidator *schemaValidator;
2475
    if (ZEND_NUM_ARGS()>0) {
2476
        WRONG_PARAM_COUNT;
2477
    }
2478

    
2479
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2480
    schemaValidator = obj->schemaValidator;
2481
    if (schemaValidator != NULL) {
2482
       
2483
                schemaValidator->clearParameters(true);
2484
                schemaValidator->exceptionClear();
2485
        }
2486
    }
2487

    
2488
PHP_METHOD(SchemaValidator, exceptionOccurred)
2489
{
2490
    SchemaValidator *schemaValidator;
2491
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2492
    if (ZEND_NUM_ARGS()>0) {
2493
        WRONG_PARAM_COUNT;
2494
    }
2495

    
2496
    schemaValidator = obj->schemaValidator;
2497
    if (schemaValidator != NULL) {
2498
        bool result = schemaValidator->exceptionOccurred();
2499
        RETURN_BOOL(result);
2500
    }
2501
    RETURN_BOOL(false);
2502
}
2503

    
2504
PHP_METHOD(SchemaValidator, getExceptionCount)
2505
{
2506
    SchemaValidator *schemaValidator;
2507
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2508
    if (ZEND_NUM_ARGS()>0) {
2509
        WRONG_PARAM_COUNT;
2510
    }
2511

    
2512
    schemaValidator = obj->schemaValidator;
2513
    if (schemaValidator != NULL) {
2514
        int count = schemaValidator->exceptionCount();
2515
        RETURN_LONG(count);
2516
    }
2517
    RETURN_LONG(0);
2518
}
2519

    
2520
PHP_METHOD(SchemaValidator, getErrorCode)
2521
{
2522
    SchemaValidator *schemaValidator;
2523
    long index;
2524
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2525
        RETURN_NULL();
2526
    }
2527
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2528
    schemaValidator = obj->schemaValidator;
2529
    if (schemaValidator != NULL) {
2530
        const char * errCode = schemaValidator->getErrorCode((int)index);
2531
        if(errCode != NULL) {
2532
            char *str = estrdup(errCode);
2533
            RETURN_STRING(str, 0);
2534
        }
2535
    }
2536
    RETURN_NULL();
2537
}
2538

    
2539
PHP_METHOD(SchemaValidator, getErrorMessage)
2540
{
2541
    SchemaValidator *schemaValidator;
2542
    long index;
2543
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2544
        RETURN_NULL();
2545
    }
2546
    schemaValidator_object *obj = (schemaValidator_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2547
    schemaValidator = obj->schemaValidator;
2548
    if (schemaValidator != NULL) {
2549
        const char * errStr = schemaValidator->getErrorMessage((int)index);
2550
        if(errStr != NULL) {
2551
            char *str = estrdup(errStr);
2552
            RETURN_STRING(str, 0);
2553
        }
2554
    }
2555
    RETURN_NULL();
2556
}
2557
PHP_METHOD(SchemaValidator, exceptionClear)
2558
{
2559
    SchemaValidator * schemaValidator;
2560
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2561
    schemaValidator = obj->schemaValidator;
2562
    if (schemaValidator != NULL) {
2563
        schemaValidator->exceptionClear();
2564
    }
2565
}
2566

    
2567
/*     ============== PHP Interface of   XdmValue =============== */
2568
void xdmValue_free_storage(void *object TSRMLS_DC)
2569
{
2570
    xdmValue_object *obj = (xdmValue_object *)object;
2571
    //obj->xdmValue->releaseXdmValue(NULL);
2572
    zend_hash_destroy(obj->std.properties);
2573
    FREE_HASHTABLE(obj->std.properties);
2574
    efree(obj);
2575
}
2576

    
2577
zend_object_value xdmValue_create_handler(zend_class_entry *type TSRMLS_DC)
2578
{
2579
    zval *tmp;
2580
    zend_object_value retval;
2581
    xdmValue_object *obj = (xdmValue_object *)emalloc(sizeof(xdmValue_object));
2582
    memset(obj, 0, sizeof(xdmValue_object));
2583
    obj->std.ce = type;
2584

    
2585
    ALLOC_HASHTABLE(obj->std.properties);
2586
    zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
2587
    object_properties_init(&obj->std, type);
2588

    
2589
    retval.handle = zend_objects_store_put(obj, NULL, xdmValue_free_storage, NULL TSRMLS_CC);
2590
    retval.handlers = &xdmValue_object_handlers;
2591

    
2592
    return retval;
2593
}
2594

    
2595
PHP_METHOD(XdmValue, __construct)
2596
{
2597
    XdmValue *xdmValue = NULL;
2598
    bool bVal;
2599
    char * sVal;
2600
    int len;
2601
    long iVal;
2602
    double dVal;
2603
    zval *zvalue;
2604

    
2605
    SaxonProcessor *proc= NULL;
2606
    xdmValue_object *obj = (xdmValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2607
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&zvalue) == SUCCESS) {
2608
        switch (Z_TYPE_P(zvalue)) {
2609
            case IS_BOOL:
2610
                bVal = Z_BVAL_P(zvalue);
2611
                xdmValue = new XdmValue(bVal);
2612
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2613
                obj->xdmValue = xdmValue;
2614
            break;
2615
            case IS_LONG:
2616
                iVal = Z_LVAL_P(zvalue);
2617
                xdmValue = new XdmValue((int)iVal);
2618
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2619
                obj->xdmValue = xdmValue;
2620
            break;
2621
            case IS_STRING:
2622
                sVal = Z_STRVAL_P(zvalue);
2623
                len = Z_STRLEN_P(zvalue);
2624
                xdmValue = new XdmValue("string", sVal);
2625
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2626
                obj->xdmValue = xdmValue;
2627
            break;
2628
            case IS_NULL:
2629
                xdmValue = new XdmValue();
2630
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2631
                obj->xdmValue = xdmValue;
2632
            break;
2633
            case IS_DOUBLE:
2634
                // TODO: implement this
2635
                //index = (long)Z_DVAL_P(zvalue);
2636
            //break;
2637
            case IS_ARRAY:
2638
            //break;
2639
            case IS_OBJECT:
2640
            //break;
2641
            default:
2642
                obj = NULL;
2643
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
2644
        }
2645
    }*/
2646
}
2647

    
2648
PHP_METHOD(XdmValue, __destruct)
2649
{
2650
    xdmValue_object *obj = (xdmValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2651
    XdmValue * xdmValue= obj->xdmValue;
2652
    xdmValue->decrementRefCount();
2653
    if(xdmValue->getRefCount()< 1){
2654
            delete xdmValue;
2655
    } 
2656
    
2657
    
2658
}
2659

    
2660
PHP_METHOD(XdmValue,  getHead){
2661
    XdmValue *xdmValue;
2662
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2663
    xdmValue = obj->xdmValue;
2664
    if (xdmValue != NULL) {
2665
        XdmItem * item = xdmValue->getHead();
2666
        if(item != NULL) {
2667
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2668
                RETURN_NULL();
2669
                return;
2670
            } else {
2671
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2672
                assert (vobj != NULL);
2673
                vobj->xdmItem = item;
2674
                return;
2675
            }
2676
        }
2677
        
2678
    } else {
2679
        RETURN_NULL();
2680
    }
2681
}
2682

    
2683

    
2684
PHP_METHOD(XdmValue,  itemAt){
2685
    XdmValue *xdmValue;
2686

    
2687
    long index;
2688
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2689
        RETURN_NULL();
2690
    }
2691

    
2692
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2693
    xdmValue = obj->xdmValue;
2694
    if (xdmValue != NULL) {
2695
        XdmItem * item = xdmValue->itemAt((int)index);
2696
        if(item != NULL) {
2697
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2698
                RETURN_NULL();
2699
                return;
2700
            } else {
2701
                item->incrementRefCount();
2702
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2703
                assert (vobj != NULL);
2704
                vobj->xdmItem = item;
2705
                return;
2706
            }
2707
        }
2708
        
2709
    } else {
2710
        RETURN_NULL();
2711
    }
2712
}
2713

    
2714

    
2715
PHP_METHOD(XdmValue,  size){
2716
    XdmValue *xdmValue;
2717
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2718
    xdmValue = obj->xdmValue;
2719
    int sizei = 0;
2720
    if (xdmValue != NULL) {
2721
        sizei = xdmValue->size();
2722
    }
2723
     RETURN_LONG(sizei);
2724
}
2725

    
2726

    
2727
PHP_METHOD(XdmValue, addXdmItem){
2728
    XdmValue *xdmValue;
2729
    zval* oth;
2730
           
2731
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2732
        RETURN_NULL();
2733
    }
2734

    
2735
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2736
    xdmValue = obj->xdmValue;
2737
    if (xdmValue != NULL) {
2738
     const char * objName =Z_OBJCE_P(oth)->name;
2739
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2740

    
2741
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2742
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2743
        if(ooth != NULL) {
2744
            XdmNode * value = ooth->xdmNode;
2745
            if(value != NULL) {        
2746
                xdmValue->addXdmItem((XdmItem *)value);
2747
                return;
2748
            }
2749
        }
2750
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
2751
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
2752
        if(ooth != NULL) {
2753
            XdmItem * value = ooth->xdmItem;
2754
            if(value != NULL) {
2755
                xdmValue->addXdmItem(value);
2756
                return;
2757
            }
2758
        }
2759

    
2760

    
2761

    
2762
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2763
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2764
        if(ooth != NULL) {
2765
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2766
            if(value != NULL) {
2767
                xdmValue->addXdmItem((XdmItem *)value);
2768
                return;
2769
            }
2770
        }
2771

    
2772
      } else {
2773
                //TODO exception
2774
        }
2775
    }
2776
}
2777

    
2778

    
2779

    
2780
/*     ============== PHP Interface of   XdmItem =============== */
2781

    
2782
void xdmItem_free_storage(void *object TSRMLS_DC)
2783
{
2784
    xdmItem_object *obj = (xdmItem_object *)object;
2785
    //obj->xdmItem->releaseXdmValue(NULL);
2786
    zend_hash_destroy(obj->std.properties);
2787
    FREE_HASHTABLE(obj->std.properties);
2788
    efree(obj);
2789
}
2790

    
2791
zend_object_value xdmItem_create_handler(zend_class_entry *type TSRMLS_DC)
2792
{
2793
    zval *tmp;
2794
    zend_object_value retval;
2795
    xdmItem_object *obj = (xdmItem_object *)emalloc(sizeof(xdmItem_object));
2796
    memset(obj, 0, sizeof(xdmItem_object));
2797
    obj->std.ce = type;
2798

    
2799
    ALLOC_HASHTABLE(obj->std.properties);
2800
    zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
2801
    object_properties_init(&obj->std, type);
2802

    
2803
    retval.handle = zend_objects_store_put(obj, NULL, xdmItem_free_storage, NULL TSRMLS_CC);
2804
    retval.handlers = &xdmItem_object_handlers;
2805

    
2806
    return retval;
2807
}
2808

    
2809
PHP_METHOD(XdmItem, __construct)
2810
{
2811
    XdmItem *xdmItem = NULL;
2812
    bool bVal;
2813
    char * sVal;
2814
    int len;
2815
    long iVal;
2816
    double dVal;
2817
    zval *zvalue;
2818

    
2819
    SaxonProcessor *proc= NULL;
2820
    xdmItem_object *obj = (xdmItem_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2821

    
2822
}
2823

    
2824
PHP_METHOD(XdmItem, __destruct)
2825
{
2826
    xdmItem_object *obj = (xdmItem_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2827

    
2828
    XdmItem * xdmItem= obj->xdmItem;
2829
    xdmItem->decrementRefCount();
2830
    if(xdmItem->getRefCount()< 1){
2831
            delete xdmItem;
2832
    }
2833
    
2834
}
2835

    
2836
PHP_METHOD(XdmItem, getStringValue)
2837
{
2838
    XdmItem *xdmItem;
2839
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2840
    xdmItem = obj->xdmItem;
2841

    
2842
    SaxonProcessor * saxonProc;
2843
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2844
    saxonProc =  obj2->saxonProcessor;
2845

    
2846
    if (xdmItem != NULL) {
2847
        const char * valueStr = saxonProc->getStringValue(xdmItem);
2848
        if(valueStr != NULL) {
2849
            char *str = estrdup(valueStr);
2850
            RETURN_STRING(str, 0);
2851
        }
2852
    }
2853
    RETURN_NULL();
2854
}
2855

    
2856
PHP_METHOD(XdmItem, isAtomic)
2857
{
2858
    XdmItem *xdmItem;
2859
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2860
    xdmItem = obj->xdmItem;
2861

    
2862
    if (xdmItem != NULL) {
2863
        bool isAtomic = xdmItem->isAtomic();
2864
        RETURN_BOOL(isAtomic);
2865
    }
2866
    RETURN_BOOL(false);
2867
}
2868

    
2869
PHP_METHOD(XdmItem, isNode)
2870
{
2871
    XdmItem *xdmItem;
2872
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2873
    xdmItem = obj->xdmItem;
2874

    
2875
    if (xdmItem != NULL && xdmItem->getType() == XDM_NODE) {
2876
        RETURN_TRUE;
2877
    }
2878
    RETURN_FALSE;
2879
}
2880

    
2881
PHP_METHOD(XdmItem, getAtomicValue)
2882
{
2883
    XdmItem *xdmItem;
2884
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2885
    xdmItem = obj->xdmItem;
2886

    
2887
    if (xdmItem != NULL) {
2888
          if(!xdmItem->isAtomic()) {
2889
                RETURN_NULL();
2890
                return;
2891
          }
2892
          if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
2893
                RETURN_NULL();
2894
                return;
2895
            } else {
2896
                xdmItem->incrementRefCount();
2897
                struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2898
                assert (vobj != NULL);
2899
                vobj->xdmAtomicValue = (XdmAtomicValue *)xdmItem;
2900
                return;
2901
            }
2902
    }
2903
    RETURN_NULL();
2904
}
2905

    
2906
PHP_METHOD(XdmItem, getNodeValue)
2907
{
2908
    XdmItem *xdmItem;
2909
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2910
    xdmItem = obj->xdmItem;
2911

    
2912
    if (xdmItem != NULL) {
2913
          if(xdmItem->isAtomic()) {
2914
                RETURN_NULL();
2915
                return;
2916
          }
2917
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2918
                RETURN_NULL();
2919
                return;
2920
            } else {
2921
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2922
                assert (vobj != NULL);
2923
                vobj->xdmNode = (XdmNode *)xdmItem;
2924
                vobj->xdmNode->incrementRefCount();
2925

    
2926
                return;
2927
            }
2928
    }
2929
    RETURN_NULL();
2930
}
2931

    
2932

    
2933

    
2934
/*     ============== PHP Interface of   XdmNode =============== */
2935

    
2936
void xdmNode_free_storage(void *object TSRMLS_DC)
2937
{
2938
    xdmNode_object *obj = (xdmNode_object *)object;
2939
    //obj->xdmItem->releaseXdmValue(NULL);
2940
    zend_hash_destroy(obj->std.properties);
2941
    FREE_HASHTABLE(obj->std.properties);
2942
    efree(obj);
2943
}
2944

    
2945
zend_object_value xdmNode_create_handler(zend_class_entry *type TSRMLS_DC)
2946
{
2947
    zval *tmp;
2948
    zend_object_value retval;
2949
    xdmNode_object *obj = (xdmNode_object *)emalloc(sizeof(xdmNode_object));
2950
    memset(obj, 0, sizeof(xdmNode_object));
2951
   // type->name ="XdmNode";
2952
         
2953
    obj->std.ce = type;        
2954

    
2955
    ALLOC_HASHTABLE(obj->std.properties);
2956
    zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
2957
    object_properties_init(&obj->std, type);
2958

    
2959
    retval.handle = zend_objects_store_put(obj, NULL, xdmNode_free_storage, NULL TSRMLS_CC);
2960
    retval.handlers = &xdmNode_object_handlers;
2961

    
2962
    return retval;
2963
}
2964

    
2965
PHP_METHOD(XdmNode, __construct)
2966
{
2967
    XdmNode *xdmNode = NULL;
2968
    bool bVal;
2969
    char * sVal;
2970
    int len;
2971
    long iVal;
2972
    double dVal;
2973
    zval *zvalue;
2974

    
2975
    SaxonProcessor *proc= NULL;
2976
    xdmNode_object *obj = (xdmNode_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2977
}
2978

    
2979
PHP_METHOD(XdmNode, __destruct)
2980
{
2981
    xdmNode_object *obj = (xdmNode_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2982

    
2983
    XdmNode * xdmNode= obj->xdmNode;
2984
   // if(xdmNode != NULL) {
2985
            xdmNode->decrementRefCount();
2986
            if(xdmNode->getRefCount()< 1){
2987
                    delete xdmNode;
2988
            }
2989
    //}
2990
    
2991
}
2992

    
2993
PHP_METHOD(XdmNode, getStringValue)
2994
{
2995
    XdmNode *xdmNode;
2996
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2997
    xdmNode = obj->xdmNode;
2998

    
2999
    SaxonProcessor * saxonProc;
3000
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3001
    saxonProc =  obj2->saxonProcessor;
3002

    
3003
    if (xdmNode != NULL) {
3004
        const char * valueStr = xdmNode->getStringValue(saxonProc);
3005
        if(valueStr != NULL) {
3006
            char *str = estrdup(valueStr);
3007
            RETURN_STRING(str, 0);
3008
            return;
3009
        }
3010
    } 
3011
    RETURN_NULL(); 
3012
    
3013
}
3014

    
3015
PHP_METHOD(XdmNode, getNodeName)
3016
{
3017
    XdmNode *xdmNode;
3018
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3019
    xdmNode = obj->xdmNode;
3020

    
3021
    if (xdmNode != NULL) {
3022
        const char * valueStr = xdmNode->getNodeName();
3023
        if(valueStr != NULL) {
3024
            char *str = estrdup(valueStr);
3025
            RETURN_STRING(str, 0);
3026
        }
3027
    } 
3028
    RETURN_NULL(); 
3029
}
3030

    
3031
PHP_METHOD(XdmNode, getNodeKind)
3032
{
3033
    XdmNode *xdmNode;
3034
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3035
    xdmNode = obj->xdmNode;
3036

    
3037
    SaxonProcessor * saxonProc;
3038
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3039
    saxonProc =  obj2->saxonProcessor;
3040
    int nodeKind = 0;
3041
    if (xdmNode != NULL) {
3042
        nodeKind = xdmNode->getNodeKind();
3043
        
3044
    }
3045
     RETURN_LONG(nodeKind);
3046
}
3047

    
3048
PHP_METHOD(XdmNode, isAtomic)
3049
{
3050

    
3051
    RETURN_FALSE;
3052
}
3053

    
3054

    
3055
PHP_METHOD(XdmNode,  getChildCount){
3056
    XdmNode *xdmNode;
3057
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3058
    xdmNode = obj->xdmNode;
3059

    
3060
    SaxonProcessor * saxonProc;
3061
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3062
    saxonProc =  obj2->saxonProcessor;
3063
    int nodeChildCount = 0;
3064
    if (xdmNode != NULL) {
3065
        nodeChildCount = xdmNode->getChildCount();
3066
        
3067
    }
3068
     RETURN_LONG(nodeChildCount);
3069
}   
3070

    
3071
PHP_METHOD(XdmNode,  getAttributeCount){
3072
    XdmNode *xdmNode;
3073
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3074
    xdmNode = obj->xdmNode;
3075

    
3076
    SaxonProcessor * saxonProc;
3077
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3078
    saxonProc =  obj2->saxonProcessor;
3079
    int nodeAttrCount = 0;
3080
    if (xdmNode != NULL) {
3081
        nodeAttrCount = xdmNode->getAttributeCount();
3082
        
3083
    }
3084
     RETURN_LONG(nodeAttrCount);
3085

    
3086
} 
3087

    
3088
PHP_METHOD(XdmNode,  getChildNode){
3089
    int indexi;        
3090
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&indexi) == FAILURE) {
3091
        RETURN_NULL();
3092
    }
3093

    
3094
    XdmNode *xdmNode;
3095
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3096
    xdmNode = obj->xdmNode;
3097

    
3098
    if (xdmNode != NULL) {
3099
         int count = xdmNode->getChildCount();
3100
         if(count==0) {
3101
                RETURN_NULL();
3102
                return;
3103
          }        
3104
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3105
                RETURN_NULL();
3106
                return;
3107
            } else {
3108
                
3109
                if(indexi>=0 && indexi < count) {
3110
                        XdmNode ** childNodes = xdmNode->getChildren();
3111
                        if(childNodes == NULL) {
3112
                                RETURN_NULL();
3113
                                return;
3114
                        }
3115
                        XdmNode * childNode = childNodes[indexi];
3116
                        if(childNode != NULL) {
3117
                                childNode->incrementRefCount();
3118
                                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
3119
                                assert (vobj != NULL);
3120
                                vobj->xdmNode = childNode;
3121
                                return;
3122
                        }
3123
                }
3124
            }
3125
    }
3126
    RETURN_NULL();
3127
}
3128

    
3129
PHP_METHOD(XdmNode,  getParent){
3130
    XdmNode *xdmNode;
3131
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3132
    xdmNode = obj->xdmNode;
3133

    
3134
    if (xdmNode != NULL) {
3135
        XdmNode * parent = xdmNode->getParent();
3136
        if(parent == NULL) {
3137
                        RETURN_NULL();
3138
                        return;
3139
        }
3140
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3141
                RETURN_NULL();
3142
                return;
3143
            } else {
3144
                parent->incrementRefCount();
3145
                       struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
3146
                       assert (vobj != NULL);
3147
                       vobj->xdmNode = parent;
3148
                       return;
3149
            }
3150
    }
3151
    RETURN_NULL();
3152
}
3153

    
3154
PHP_METHOD(XdmNode,  getAttributeNode){
3155
    int indexi;        
3156
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&indexi) == FAILURE) {
3157
        RETURN_NULL();
3158
    }
3159

    
3160
    XdmNode *xdmNode;
3161
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3162
    xdmNode = obj->xdmNode;
3163

    
3164
    if (xdmNode != NULL) {
3165
          int count = xdmNode->getAttributeCount();
3166
          if(count > 0) {
3167
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3168
                RETURN_NULL();
3169
                return;
3170
            } else {
3171
                
3172
                if(indexi < count) {
3173
                        XdmNode * attNode = xdmNode->getAttributeNodes()[indexi];
3174
                        if(attNode != NULL) {
3175
                                attNode->incrementRefCount();
3176
                                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
3177
                                assert (vobj != NULL);
3178
                                vobj->xdmNode = attNode;
3179

    
3180
                                return;
3181
                        }
3182
                }
3183
            }
3184
        }
3185
    }
3186
    RETURN_NULL();
3187

    
3188
}
3189

    
3190
PHP_METHOD(XdmNode,  getAttributeValue){
3191
   char * name;
3192
   int len1;        
3193
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
3194
        RETURN_NULL();
3195
    }
3196
    XdmNode *xdmNode;
3197
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3198
    xdmNode = obj->xdmNode;
3199
    if (xdmNode != NULL && name != NULL) {
3200
        
3201
        const char * valueStr = xdmNode->getAttributeValue(name);
3202
        if(valueStr != NULL) {
3203
            char *str = estrdup(valueStr);
3204
            RETURN_STRING(str, 0);
3205
            return;
3206
        }
3207
    }
3208
    RETURN_NULL();
3209

    
3210

    
3211
}
3212

    
3213
/*     ============== PHP Interface of   XdmAtomicValue =============== */
3214

    
3215
void xdmAtomicValue_free_storage(void *object TSRMLS_DC)
3216
{
3217
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)object;
3218
    //obj->xdmItem->releaseXdmValue(NULL);
3219
    zend_hash_destroy(obj->std.properties);
3220
    FREE_HASHTABLE(obj->std.properties);
3221
    efree(obj);
3222
}
3223

    
3224
zend_object_value xdmAtomicValue_create_handler(zend_class_entry *type TSRMLS_DC)
3225
{
3226
    zval *tmp;
3227
    zend_object_value retval;
3228
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)emalloc(sizeof(xdmAtomicValue_object));
3229
    memset(obj, 0, sizeof(xdmAtomicValue_object));
3230
   // type->name ="XdmNode";
3231
         
3232
    obj->std.ce = type;        
3233

    
3234
    ALLOC_HASHTABLE(obj->std.properties);
3235
    zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
3236
    object_properties_init(&obj->std, type);
3237

    
3238
    retval.handle = zend_objects_store_put(obj, NULL, xdmNode_free_storage, NULL TSRMLS_CC);
3239
    retval.handlers = &xdmAtomicValue_object_handlers;
3240

    
3241
    return retval;
3242
}
3243

    
3244
PHP_METHOD(XdmAtomicValue, __construct)
3245
{
3246
    XdmAtomicValue *xdmValue = NULL;
3247
    bool bVal;
3248
    char * sVal;
3249
    int len;
3250
    long iVal;
3251
    double dVal;
3252
    zval *zvalue;
3253

    
3254
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3255

    
3256
}
3257

    
3258
PHP_METHOD(XdmAtomicValue, __destruct)
3259
{
3260
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3261

    
3262

    
3263
    XdmAtomicValue * xdmValue= obj->xdmAtomicValue;
3264
    xdmValue->decrementRefCount();
3265
    if(xdmValue->getRefCount()< 1){
3266
            delete xdmValue;
3267
    }
3268
    
3269
}
3270

    
3271
PHP_METHOD(XdmAtomicValue, getBooleanValue)
3272
{
3273
    XdmAtomicValue *xdmAtomicValue;
3274
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3275
    xdmAtomicValue = obj->xdmAtomicValue;
3276

    
3277
    SaxonProcessor * saxonProc;
3278
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3279
    saxonProc =  obj2->saxonProcessor;
3280
    bool resultb = false;
3281
    if (xdmAtomicValue != NULL) {
3282
         resultb = xdmAtomicValue->getBooleanValue();
3283
        
3284
    }
3285
    RETURN_BOOL(resultb);
3286
}
3287

    
3288

    
3289
PHP_METHOD(XdmAtomicValue, getDoubleValue)
3290
{
3291
    XdmAtomicValue *xdmAtomicValue;
3292
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3293
    xdmAtomicValue = obj->xdmAtomicValue;
3294

    
3295
    SaxonProcessor * saxonProc;
3296
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3297
    saxonProc =  obj2->saxonProcessor;
3298
    double resultb = 0;
3299
    if (xdmAtomicValue != NULL) {
3300
         resultb = xdmAtomicValue->getDoubleValue();
3301
        
3302
    }
3303
    RETURN_DOUBLE(resultb);
3304
}
3305

    
3306
PHP_METHOD(XdmAtomicValue, getLongValue)
3307
{
3308
    XdmAtomicValue *xdmAtomicValue;
3309
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3310
    xdmAtomicValue = obj->xdmAtomicValue;
3311

    
3312
    SaxonProcessor * saxonProc;
3313
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3314
    saxonProc =  obj2->saxonProcessor;
3315
    long result = 0;
3316
    if (xdmAtomicValue != NULL) {
3317
         result = xdmAtomicValue->getLongValue();
3318
        
3319
    }
3320
    RETURN_LONG(result);
3321
}
3322

    
3323
PHP_METHOD(XdmAtomicValue, getStringValue)
3324
{
3325
    XdmAtomicValue *xdmAtomicValue;
3326
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3327
    xdmAtomicValue = obj->xdmAtomicValue;
3328

    
3329
    SaxonProcessor * saxonProc;
3330
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3331
    saxonProc =  obj2->saxonProcessor;
3332

    
3333
    if (xdmAtomicValue != NULL) {
3334
        const char * valueStr = saxonProc->getStringValue(xdmAtomicValue);
3335
        if(valueStr != NULL) {
3336
            char *str = estrdup(valueStr);
3337
            RETURN_STRING(str, 0);
3338
        }
3339
    }
3340
    RETURN_NULL();
3341
}
3342

    
3343
PHP_METHOD(XdmAtomicValue, isAtomic)
3344
{
3345

    
3346
    RETURN_TRUE;
3347
}
3348

    
3349

    
3350
// =============================================================
3351

    
3352
zend_function_entry SaxonProcessor_methods[] = {
3353
    PHP_ME(SaxonProcessor,  __construct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3354
    PHP_ME(SaxonProcessor,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3355
    PHP_ME(SaxonProcessor,  createAtomicValue,      NULL, ZEND_ACC_PUBLIC)
3356
    PHP_ME(SaxonProcessor,  parseXmlFromString,      NULL, ZEND_ACC_PUBLIC)
3357
    PHP_ME(SaxonProcessor,  parseXmlFromFile,      NULL, ZEND_ACC_PUBLIC)
3358
    PHP_ME(SaxonProcessor,  setcwd,     NULL, ZEND_ACC_PUBLIC)
3359
    PHP_ME(SaxonProcessor,  newXPathProcessor,     NULL, ZEND_ACC_PUBLIC)
3360
    PHP_ME(SaxonProcessor,  newXsltProcessor,     NULL, ZEND_ACC_PUBLIC)
3361
    PHP_ME(SaxonProcessor,  newXQueryProcessor,     NULL, ZEND_ACC_PUBLIC)
3362
    PHP_ME(SaxonProcessor,  newSchemaValidator,     NULL, ZEND_ACC_PUBLIC)
3363
//    PHP_ME(SaxonProcessor,  importDocument,      NULL, ZEND_ACC_PUBLIC)
3364
    PHP_ME(SaxonProcessor,  setResourcesDirectory,      NULL, ZEND_ACC_PUBLIC)
3365
    PHP_ME(SaxonProcessor, setConfigurationProperty,      NULL, ZEND_ACC_PUBLIC)
3366
    PHP_ME(SaxonProcessor,  registerPHPFunction,      NULL, ZEND_ACC_PUBLIC)
3367
    PHP_ME(SaxonProcessor,  version,      NULL, ZEND_ACC_PUBLIC)
3368
    {NULL, NULL, NULL}
3369
};
3370

    
3371
zend_function_entry XsltProcessor_methods[] = {
3372
    PHP_ME(XsltProcessor,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3373
    PHP_ME(XsltProcessor,  transformFileToFile, NULL, ZEND_ACC_PUBLIC)
3374
    PHP_ME(XsltProcessor,  transformFileToString, NULL, ZEND_ACC_PUBLIC)
3375
    PHP_ME(XsltProcessor,  transformFileToValue, NULL, ZEND_ACC_PUBLIC)
3376
    PHP_ME(XsltProcessor,  transformToString, NULL, ZEND_ACC_PUBLIC)
3377
    PHP_ME(XsltProcessor,  transformToValue, NULL, ZEND_ACC_PUBLIC)
3378
    PHP_ME(XsltProcessor,  transformToFile, NULL, ZEND_ACC_PUBLIC)
3379
    PHP_ME(XsltProcessor, compileFromFile, NULL, ZEND_ACC_PUBLIC)
3380
    PHP_ME(XsltProcessor, compileFromValue, NULL, ZEND_ACC_PUBLIC)
3381
    PHP_ME(XsltProcessor, compileFromString, NULL, ZEND_ACC_PUBLIC)
3382
    PHP_ME(XsltProcessor,  setOutputFile, NULL, ZEND_ACC_PUBLIC)
3383
    PHP_ME(XsltProcessor,  setSourceFromFile, NULL, ZEND_ACC_PUBLIC)
3384
    PHP_ME(XsltProcessor,  setSourceFromXdmValue, NULL, ZEND_ACC_PUBLIC)
3385
    PHP_ME(XsltProcessor,  setParameter, NULL, ZEND_ACC_PUBLIC)
3386
    PHP_ME(XsltProcessor,  setProperty, NULL, ZEND_ACC_PUBLIC)
3387
    PHP_ME(XsltProcessor,  clearParameters, NULL, ZEND_ACC_PUBLIC)
3388
    PHP_ME(XsltProcessor,  clearProperties, NULL, ZEND_ACC_PUBLIC)
3389
    PHP_ME(XsltProcessor,  exceptionOccurred, NULL, ZEND_ACC_PUBLIC)
3390
    PHP_ME(XsltProcessor,  exceptionClear, NULL, ZEND_ACC_PUBLIC)
3391
    PHP_ME(XsltProcessor,  getErrorCode, NULL, ZEND_ACC_PUBLIC)
3392
    PHP_ME(XsltProcessor,  getErrorMessage, NULL, ZEND_ACC_PUBLIC)
3393
    PHP_ME(XsltProcessor,  getExceptionCount, NULL, ZEND_ACC_PUBLIC)
3394
{NULL, NULL, NULL}
3395
};
3396

    
3397
zend_function_entry XQueryProcessor_methods[] = {
3398
    PHP_ME(XQueryProcessor,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3399
   // PHP_ME(XQueryProcessor,  getErrorCode,      NULL, ZEND_ACC_PUBLIC)
3400
    PHP_ME(XQueryProcessor,  setQueryContent,      NULL, ZEND_ACC_PUBLIC)
3401
    PHP_ME(XQueryProcessor,  setContextItem,      NULL, ZEND_ACC_PUBLIC)
3402
    PHP_ME(XQueryProcessor,  setContextItemFromFile,      NULL, ZEND_ACC_PUBLIC)
3403
    PHP_ME(XQueryProcessor,  setParameter,      NULL, ZEND_ACC_PUBLIC)
3404
    PHP_ME(XQueryProcessor,  setProperty,      NULL, ZEND_ACC_PUBLIC)
3405
    PHP_ME(XQueryProcessor,  clearParameters,      NULL, ZEND_ACC_PUBLIC)
3406
    PHP_ME(XQueryProcessor,  clearProperties,      NULL, ZEND_ACC_PUBLIC)
3407
    PHP_ME(XQueryProcessor, runQueryToValue,      NULL, ZEND_ACC_PUBLIC)
3408
    PHP_ME(XQueryProcessor, runQueryToString,      NULL, ZEND_ACC_PUBLIC)
3409
    PHP_ME(XQueryProcessor, runQueryToFile,      NULL, ZEND_ACC_PUBLIC)
3410
    PHP_ME(XQueryProcessor, setQueryFile,      NULL, ZEND_ACC_PUBLIC)
3411
    PHP_ME(XQueryProcessor, setQueryBaseURI,      NULL, ZEND_ACC_PUBLIC)
3412
    PHP_ME(XQueryProcessor, declareNamespace,      NULL, ZEND_ACC_PUBLIC)
3413
    PHP_ME(XQueryProcessor,  exceptionOccurred, NULL, ZEND_ACC_PUBLIC)
3414
    PHP_ME(XQueryProcessor,  exceptionClear, NULL, ZEND_ACC_PUBLIC)
3415
    PHP_ME(XQueryProcessor,  getErrorCode, NULL, ZEND_ACC_PUBLIC)
3416
    PHP_ME(XQueryProcessor,  getErrorMessage, NULL, ZEND_ACC_PUBLIC)
3417
    PHP_ME(XQueryProcessor,  getExceptionCount, NULL, ZEND_ACC_PUBLIC)
3418
{NULL, NULL, NULL}
3419
};
3420

    
3421
zend_function_entry XPathProcessor_methods[] = {
3422
    PHP_ME(XPathProcessor,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3423
    PHP_ME(XPathProcessor,  setContextItem,      NULL, ZEND_ACC_PUBLIC)
3424
    PHP_ME(XPathProcessor,  setContextFile,      NULL, ZEND_ACC_PUBLIC)
3425
    PHP_ME(XPathProcessor,  effectiveBooleanValue,      NULL, ZEND_ACC_PUBLIC)
3426
    PHP_ME(XPathProcessor,  evaluate,      NULL, ZEND_ACC_PUBLIC)
3427
    PHP_ME(XPathProcessor,  evaluateSingle,      NULL, ZEND_ACC_PUBLIC)
3428
    PHP_ME(XPathProcessor,  setParameter,      NULL, ZEND_ACC_PUBLIC)
3429
    PHP_ME(XPathProcessor,  setProperty,      NULL, ZEND_ACC_PUBLIC)
3430
    PHP_ME(XPathProcessor,  clearParameters,      NULL, ZEND_ACC_PUBLIC)
3431
    PHP_ME(XPathProcessor,  clearProperties,      NULL, ZEND_ACC_PUBLIC)
3432
    PHP_ME(XPathProcessor,  exceptionOccurred, NULL, ZEND_ACC_PUBLIC)
3433
    PHP_ME(XPathProcessor,  exceptionClear, NULL, ZEND_ACC_PUBLIC)
3434
    PHP_ME(XPathProcessor,  getErrorCode, NULL, ZEND_ACC_PUBLIC)
3435
    PHP_ME(XPathProcessor,  getErrorMessage, NULL, ZEND_ACC_PUBLIC)
3436
    PHP_ME(XPathProcessor,  getExceptionCount, NULL, ZEND_ACC_PUBLIC)
3437
    PHP_ME(XPathProcessor, declareNamespace,      NULL, ZEND_ACC_PUBLIC)
3438
    PHP_ME(XPathProcessor, setBaseURI, NULL, ZEND_ACC_PUBLIC)
3439
{NULL, NULL, NULL}
3440
};
3441

    
3442
zend_function_entry SchemaValidator_methods[] = {
3443
    PHP_ME(SchemaValidator,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3444
    PHP_ME(SchemaValidator,  setSourceNode,      NULL, ZEND_ACC_PUBLIC)
3445
    PHP_ME(SchemaValidator,  setOutputFile,      NULL, ZEND_ACC_PUBLIC)
3446
    PHP_ME(SchemaValidator,  validate,      NULL, ZEND_ACC_PUBLIC)
3447
    PHP_ME(SchemaValidator,  validateToNode,      NULL, ZEND_ACC_PUBLIC)
3448
    PHP_ME(SchemaValidator,  registerSchemaFromFile,      NULL, ZEND_ACC_PUBLIC)
3449
    PHP_ME(SchemaValidator,  registerSchemaFromString,      NULL, ZEND_ACC_PUBLIC)
3450
    PHP_ME(SchemaValidator,  getValidationReport,      NULL, ZEND_ACC_PUBLIC)
3451
    PHP_ME(SchemaValidator,  setParameter,      NULL, ZEND_ACC_PUBLIC)
3452
    PHP_ME(SchemaValidator,  setProperty,      NULL, ZEND_ACC_PUBLIC)
3453
    PHP_ME(SchemaValidator,  clearParameters,      NULL, ZEND_ACC_PUBLIC)
3454
    PHP_ME(SchemaValidator,  clearProperties,      NULL, ZEND_ACC_PUBLIC)
3455
    PHP_ME(SchemaValidator,  exceptionOccurred, NULL, ZEND_ACC_PUBLIC)
3456
    PHP_ME(SchemaValidator,  exceptionClear, NULL, ZEND_ACC_PUBLIC)
3457
    PHP_ME(SchemaValidator,  getErrorCode, NULL, ZEND_ACC_PUBLIC)
3458
    PHP_ME(SchemaValidator,  getErrorMessage, NULL, ZEND_ACC_PUBLIC)
3459
    PHP_ME(SchemaValidator,  getExceptionCount, NULL, ZEND_ACC_PUBLIC)
3460
{NULL, NULL, NULL}
3461
};
3462

    
3463
zend_function_entry xdmValue_methods[] = {
3464
    PHP_ME(XdmValue,  __construct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3465
    PHP_ME(XdmValue,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3466
    PHP_ME(XdmValue,  getHead,      NULL, ZEND_ACC_PUBLIC)
3467
    PHP_ME(XdmValue,  itemAt,      NULL, ZEND_ACC_PUBLIC)
3468
    PHP_ME(XdmValue,  size,      NULL, ZEND_ACC_PUBLIC)
3469
    PHP_ME(XdmValue, addXdmItem,      NULL, ZEND_ACC_PUBLIC)
3470
    {NULL, NULL, NULL}
3471
};
3472

    
3473
zend_function_entry xdmItem_methods[] = {
3474
    PHP_ME(XdmItem,  __construct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3475
    PHP_ME(XdmItem,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3476
    PHP_ME(XdmItem,  getStringValue,      NULL, ZEND_ACC_PUBLIC)
3477
    PHP_ME(XdmItem,  isAtomic,      NULL, ZEND_ACC_PUBLIC)
3478
    PHP_ME(XdmItem,  isNode,      NULL, ZEND_ACC_PUBLIC)
3479
    PHP_ME(XdmItem,  getAtomicValue,      NULL, ZEND_ACC_PUBLIC)
3480
    PHP_ME(XdmItem,  getNodeValue,      NULL, ZEND_ACC_PUBLIC)
3481
    {NULL, NULL, NULL}
3482
};
3483

    
3484
zend_function_entry xdmNode_methods[] = {
3485
    PHP_ME(XdmNode,  __construct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3486
    PHP_ME(XdmNode,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3487
    PHP_ME(XdmNode,  getStringValue,      NULL, ZEND_ACC_PUBLIC)
3488
    PHP_ME(XdmNode,  getNodeKind,      NULL, ZEND_ACC_PUBLIC)
3489
    PHP_ME(XdmNode,  getNodeName,      NULL, ZEND_ACC_PUBLIC)
3490
    PHP_ME(XdmNode,  isAtomic,      NULL, ZEND_ACC_PUBLIC)
3491
    PHP_ME(XdmNode,  getChildCount,      NULL, ZEND_ACC_PUBLIC)
3492
    PHP_ME(XdmNode,  getAttributeCount,      NULL, ZEND_ACC_PUBLIC) 
3493
    PHP_ME(XdmNode,  getChildNode,      NULL, ZEND_ACC_PUBLIC)
3494
    PHP_ME(XdmNode,  getParent,      NULL, ZEND_ACC_PUBLIC)
3495
    PHP_ME(XdmNode,  getAttributeNode,      NULL, ZEND_ACC_PUBLIC)
3496
    PHP_ME(XdmNode,  getAttributeValue,      NULL, ZEND_ACC_PUBLIC)
3497
    {NULL, NULL, NULL}
3498
};
3499

    
3500
zend_function_entry xdmAtomicValue_methods[] = {
3501
    PHP_ME(XdmAtomicValue,  __construct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3502
    PHP_ME(XdmAtomicValue,  __destruct,     NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3503
    PHP_ME(XdmAtomicValue,  getStringValue,      NULL, ZEND_ACC_PUBLIC)
3504
    PHP_ME(XdmAtomicValue,  isAtomic,      NULL, ZEND_ACC_PUBLIC)
3505
    PHP_ME(XdmAtomicValue,  getBooleanValue,      NULL, ZEND_ACC_PUBLIC)
3506
    PHP_ME(XdmAtomicValue,  getDoubleValue,      NULL, ZEND_ACC_PUBLIC)
3507
    PHP_ME(XdmAtomicValue,  getLongValue,      NULL, ZEND_ACC_PUBLIC)
3508
    {NULL, NULL, NULL}
3509
};
3510

    
3511
PHP_MINIT_FUNCTION(saxon)
3512
{
3513
    zend_class_entry ce;
3514
    INIT_CLASS_ENTRY(ce, "Saxon\\SaxonProcessor", SaxonProcessor_methods);
3515
    saxonProcessor_ce = zend_register_internal_class(&ce TSRMLS_CC);
3516
    saxonProcessor_ce->create_object = saxonProcessor_create_handler;
3517
    memcpy(&saxonProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3518
    saxonProcessor_object_handlers.clone_obj = NULL;
3519

    
3520
    INIT_CLASS_ENTRY(ce, "Saxon\\XSLTProcessor", XsltProcessor_methods);
3521
    xsltProcessor_ce = zend_register_internal_class(&ce TSRMLS_CC);
3522
    xsltProcessor_ce->create_object = xsltProcessor_create_handler;
3523
    memcpy(&xsltProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3524
    xsltProcessor_object_handlers.clone_obj = NULL;
3525

    
3526
    INIT_CLASS_ENTRY(ce, "Saxon\\XQueryProcessor", XQueryProcessor_methods);
3527
    xqueryProcessor_ce = zend_register_internal_class(&ce TSRMLS_CC);
3528
    xqueryProcessor_ce->create_object = xqueryProcessor_create_handler;
3529
    memcpy(&xqueryProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3530
    xqueryProcessor_object_handlers.clone_obj = NULL;
3531

    
3532
    INIT_CLASS_ENTRY(ce, "Saxon\\XPathProcessor", XPathProcessor_methods);
3533
    xpathProcessor_ce = zend_register_internal_class(&ce TSRMLS_CC);
3534
    xpathProcessor_ce->create_object = xpathProcessor_create_handler;
3535
    memcpy(&xpathProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3536
    xpathProcessor_object_handlers.clone_obj = NULL;
3537

    
3538
    INIT_CLASS_ENTRY(ce, "Saxon\\SchemaValidator", SchemaValidator_methods);
3539
    schemaValidator_ce = zend_register_internal_class(&ce TSRMLS_CC);
3540
    schemaValidator_ce->create_object = schemaValidator_create_handler;
3541
    memcpy(&schemaValidator_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3542
    schemaValidator_object_handlers.clone_obj = NULL;
3543

    
3544
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmValue", xdmValue_methods);
3545
    xdmValue_ce = zend_register_internal_class(&ce TSRMLS_CC);
3546
    xdmValue_ce->create_object = xdmValue_create_handler;
3547
    memcpy(&xdmValue_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3548
    xdmValue_object_handlers.clone_obj = NULL;
3549

    
3550
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmItem", xdmItem_methods);
3551
    xdmItem_ce = zend_register_internal_class(&ce TSRMLS_CC);
3552
    xdmItem_ce->create_object = xdmItem_create_handler;
3553
    memcpy(&xdmItem_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3554
    xdmItem_object_handlers.clone_obj = NULL;
3555

    
3556
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmNode", xdmNode_methods);
3557
    xdmNode_ce = zend_register_internal_class(&ce TSRMLS_CC);
3558
    xdmNode_ce->create_object = xdmNode_create_handler;
3559
    memcpy(&xdmNode_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3560
    xdmNode_object_handlers.clone_obj = NULL;
3561

    
3562
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmAtomicValue", xdmAtomicValue_methods);
3563
    xdmAtomicValue_ce = zend_register_internal_class(&ce TSRMLS_CC);
3564
    xdmAtomicValue_ce->create_object = xdmAtomicValue_create_handler;
3565
    memcpy(&xdmAtomicValue_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3566
    xdmAtomicValue_object_handlers.clone_obj = NULL;
3567

    
3568
    return SUCCESS;
3569
}
3570

    
3571
PHP_MINFO_FUNCTION(saxon)
3572
{
3573
    php_info_print_table_start();
3574
    php_info_print_table_header(2, "Saxon/C", "enabled");
3575
    php_info_print_table_row(2, "Saxon/C EXT version", "1.1.0");
3576
    php_info_print_table_row(2, "Saxon", "9.8.0.4");
3577
    php_info_print_table_row(2, "Excelsior JET", "11.3 MP1");
3578
    php_info_print_table_end();
3579
    DISPLAY_INI_ENTRIES();
3580
}
3581

    
3582
PHP_MSHUTDOWN_FUNCTION(saxon) {
3583
    UNREGISTER_INI_ENTRIES();
3584
    //SaxonProcessor::release();
3585

    
3586
    return SUCCESS;
3587
}
3588

    
3589
PHP_RSHUTDOWN_FUNCTION(saxon) {
3590
    //std::cerr<<"RSHUTDOWN called -start"<<std::endl;
3591
    return SUCCESS;
3592
}
3593

    
3594
PHP_RINIT_FUNCTION(saxon) {
3595
    //std::cerr<<"RINIT called -start"<<std::endl;
3596
    return SUCCESS;
3597
}
3598

    
3599
zend_module_entry saxon_module_entry = {
3600
#if ZEND_MODULE_API_NO >= 20010901
3601
    STANDARD_MODULE_HEADER,
3602
#endif
3603
    PHP_SAXON_EXTNAME,
3604
    NULL,        /* Functions */
3605
    PHP_MINIT(saxon),        /* MINIT */
3606
    PHP_MSHUTDOWN(saxon),        /* MSHUTDOWN */
3607
    NULL,        /* RINIT */
3608
    NULL,        /* RSHUTDOWN */
3609
    PHP_MINFO(saxon),        /* MINFO */
3610
#if ZEND_MODULE_API_NO >= 20010901
3611
    PHP_SAXON_EXTVER,
3612
#endif
3613
    STANDARD_MODULE_PROPERTIES
3614
};
3615

    
(40-40/45)