Project

Profile

Help

Download (185 KB) Statistics
| Branch: | Revision:

he / src / main / c / Saxon.C.API / php7_saxon.cpp @ 03fcd3f9

1 72bf04c6 Norman Walsh
#ifdef HAVE_CONFIG_H
2
    #include "config.h"
3
#endif
4
5
#include "php_saxon.h"
6
7
#ifdef COMPILE_DL_SAXON
8
    extern "C" {
9
        ZEND_GET_MODULE(saxon)
10
    }
11
#endif
12
13
JNINativeMethod phpMethods[] =
14
{
15
    {
16
         "_phpCall",
17
         "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;",
18
         (void *)&phpNativeCall
19
    }
20
};
21
22
zend_object_handlers saxonProcessor_object_handlers;
23
zend_object_handlers xsltProcessor_object_handlers;
24
zend_object_handlers xslt30Processor_object_handlers;
25
zend_object_handlers xqueryProcessor_object_handlers;
26
zend_object_handlers xpathProcessor_object_handlers;
27
zend_object_handlers schemaValidator_object_handlers;
28
zend_object_handlers xdmValue_object_handlers;
29
zend_object_handlers xdmItem_object_handlers;
30
zend_object_handlers xdmNode_object_handlers;
31
zend_object_handlers xdmAtomicValue_object_handlers;
32
33
zend_class_entry *saxonProcessor_ce;
34
zend_class_entry *xsltProcessor_ce;
35
zend_class_entry *xslt30Processor_ce;
36
zend_class_entry *xqueryProcessor_ce;
37
zend_class_entry *xpathProcessor_ce;
38
zend_class_entry *schemaValidator_ce;
39
zend_class_entry *xdmValue_ce;
40
zend_class_entry *xdmItem_ce;
41
zend_class_entry *xdmNode_ce;
42
zend_class_entry *xdmAtomicValue_ce;
43
44
void SaxonProcessor_free_storage(zend_object *object)
45
{
46
47
//std::cerr<<"_free_Storage called php-saxonProc"<<std::endl;
48
         
49
    saxonProcessor_object *obj;
50
        
51
        obj =  (saxonProcessor_object *)((char *)object - XtOffsetOf(saxonProcessor_object, std));
52
53
 SaxonProcessor * saxonProc= obj->saxonProcessor;
54 ead48a5d O'Neil Delpratt
    if(saxonProc != nullptr) {
55 72bf04c6 Norman Walsh
        //SaxonProcessor::release();    
56
        delete saxonProc;
57
    }
58
 zend_object_std_dtor(object);
59
60
    efree(obj);
61
}
62
63
void SaxonProcessor_destroy_storage(zend_object *pobj)
64
{
65
66
        //php_error(E_WARNING,"_destroy_Storage called php-saxonProc");
67
          //  saxonProcessor_object *obj;
68
        //zend_object* pobj = Z_OBJ_P(getThis()); 
69
 /*  saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
70

71
    SaxonProcessor * saxonProc= obj->saxonProcessor;
72 ead48a5d O'Neil Delpratt
    if(saxonProc != nullptr) {
73 72bf04c6 Norman Walsh
        SaxonProcessor::release();    
74
        delete saxonProc;
75
    }*/
76
        
77
    zend_objects_destroy_object(pobj);
78
79
    
80
}
81
82
zend_object *saxonProcessor_create_handler(zend_class_entry *type)
83
{
84
    zval *tmp;
85
    zend_object retval;
86
    saxonProcessor_object *obj = (saxonProcessor_object *)ecalloc(1, sizeof(saxonProcessor_object) + zend_object_properties_size(type));
87
 
88
89
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
90
    object_properties_init(&obj->std, type);
91
92
    obj->std.handlers = &saxonProcessor_object_handlers;
93
94
    return &obj->std;
95
}
96
97
PHP_METHOD(SaxonProcessor, __construct)
98
{
99
    if (ZEND_NUM_ARGS()>2) {
100
        WRONG_PARAM_COUNT;
101
    }
102
103 ead48a5d O'Neil Delpratt
    char * cwdi = nullptr;
104 72bf04c6 Norman Walsh
   bool license = false;
105
    size_t len1;
106
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS(), "b", &license) == FAILURE) {
107
        RETURN_NULL();
108
    } 
109
110
111
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS(), "bs", &license, &cwdi, &len1) == FAILURE) {
112
        RETURN_NULL();
113
    }
114
115
116
    zval *object = getThis();
117 ead48a5d O'Neil Delpratt
    SaxonProcessor * saxonProc = nullptr;
118 72bf04c6 Norman Walsh
    zend_object * zobj = Z_OBJ_P(object);
119
120
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)zobj - XtOffsetOf(saxonProcessor_object, std));
121
122
        saxonProc = new SaxonProcessor(license); //TODO: add license flag to PHP function argument
123
                
124
    
125
        obj->saxonProcessor = saxonProc;
126
//std::cerr<<"SaxonProcessorConstructor cp1"<<std::endl;
127 ead48a5d O'Neil Delpratt
    if(cwdi==nullptr) {
128 72bf04c6 Norman Walsh
//std::cerr<<"SaxonProcessorConstructor cp1-1"<<std::endl;
129
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
130
            TCHAR s[256];
131
132
            // --
133
            DWORD a = GetCurrentDirectory(256, s);
134
            const size_t newsize = wcslen(s)*2;
135
            char* cwd = new char[newsize];
136
            wcstombs_s(0, cwd, newsize, s, _TRUNCATE);
137
            // -- code above returns the apache installation directory as the CWD
138
139
            char* cwd2;
140
141
            //php_error(E_WARNING,cwd2);
142
143
            saxonProc->setcwd(cwd);
144
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
145
#else
146
            char cwd[256];
147
148
            VCWD_GETCWD(cwd, sizeof(cwd));
149 ead48a5d O'Neil Delpratt
            if(cwd == nullptr) {
150
             //php_error(E_WARNING,"cwd is nullptrXXXXXXXXXXXXXXXXXXXXXXX");
151 72bf04c6 Norman Walsh
           }else {
152
           //  php_error(E_WARNING,cwd);
153
 
154
            saxonProc->setcwd(cwd);
155
156
          }
157
#endif
158
159
    } else {
160
        saxonProc->setcwd(cwdi);
161
    }
162
163
}
164
165
PHP_METHOD(SaxonProcessor, __destruct)
166
{
167
    //php_error(E_WARNING,"__destruct called php-saxonProc");
168
    //std::cerr<<"__destruct call saxonProc"<<std::endl;
169
        zend_object* pobj = Z_OBJ_P(getThis()); 
170
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
171
172
    SaxonProcessor * saxonProc= obj->saxonProcessor;
173 ead48a5d O'Neil Delpratt
    if(saxonProc != nullptr) {
174 72bf04c6 Norman Walsh
        //SaxonProcessor::release();    
175
        //delete saxonProc;
176
    }
177
}
178
179
180
PHP_METHOD(SaxonProcessor, release)
181
{
182
//php_error(E_WARNING,"__destruct called php-saxonProc");
183
  //  std::cerr<<"__destruct call saxonProc"<<std::endl;
184
        zend_object* pobj = Z_OBJ_P(getThis()); 
185
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
186
187
    SaxonProcessor * saxonProc= obj->saxonProcessor;
188 ead48a5d O'Neil Delpratt
    if(saxonProc != nullptr) {
189 72bf04c6 Norman Walsh
        SaxonProcessor::release();    
190
    }
191
}
192
193
PHP_METHOD(SaxonProcessor, setResourcesDirectory)
194
{
195
    SaxonProcessor *saxonProcessor;
196
    char * dirStr;
197
    size_t len;
198
    
199
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &dirStr, &len) == FAILURE) {
200
        RETURN_NULL();
201
    }
202
    
203
    zend_object* pobj = Z_OBJ_P(getThis()); 
204
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
205
    saxonProcessor = obj->saxonProcessor;
206 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
207 72bf04c6 Norman Walsh
       
208 ead48a5d O'Neil Delpratt
        if(dirStr != nullptr) {
209 72bf04c6 Norman Walsh
            saxonProcessor->setResourcesDirectory(dirStr);
210
        }
211
    }
212
}
213
214
215
PHP_METHOD(SaxonProcessor, isSchemaAware)
216
{
217
    SaxonProcessor *saxonProcessor;
218
    
219
    if (ZEND_NUM_ARGS()>0) {
220
        WRONG_PARAM_COUNT;
221
    }
222
    zend_object* pobj = Z_OBJ_P(getThis()); 
223
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
224
    saxonProcessor = obj->saxonProcessor;
225 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
226 72bf04c6 Norman Walsh
       
227
         if(saxonProcessor->isSchemaAwareProcessor()){
228
229
                RETURN_TRUE;
230
         }
231
    }
232
    RETURN_FALSE;
233
}
234
235
PHP_METHOD(SaxonProcessor, setCatalog)
236
{
237
    SaxonProcessor *saxonProcessor;
238
    char * catalogFile;
239
    size_t len;
240
    bool trace = false;
241
    
242
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sb", &catalogFile, &len, &trace) == FAILURE) {
243
        RETURN_NULL();
244
    }
245
    
246
    zend_object* pobj = Z_OBJ_P(getThis()); 
247
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
248
    saxonProcessor = obj->saxonProcessor;
249 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
250 72bf04c6 Norman Walsh
       
251 ead48a5d O'Neil Delpratt
        if(catalogFile != nullptr) {
252 72bf04c6 Norman Walsh
            saxonProcessor->setCatalog(catalogFile, trace);
253
        }
254
    }
255
}
256
257
258
259
PHP_METHOD(SaxonProcessor, setcwd)
260
{
261
    SaxonProcessor *saxonProcessor;
262
    char * cwdStr;
263
    size_t len;
264
    
265
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &cwdStr, &len) == FAILURE) {
266
        RETURN_NULL();
267
    }
268
    
269
    zend_object* pobj = Z_OBJ_P(getThis()); 
270
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
271
    saxonProcessor = obj->saxonProcessor;
272 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
273 72bf04c6 Norman Walsh
        
274 ead48a5d O'Neil Delpratt
        if(cwdStr != nullptr) {
275 72bf04c6 Norman Walsh
            saxonProcessor->setcwd(cwdStr);
276
        }
277
    }
278
}
279
280
281
PHP_METHOD(SaxonProcessor, parseXmlFromString)
282
{
283
    SaxonProcessor * saxonProcessor;
284
    char * source;
285
    size_t len1;
286
287
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
288
        RETURN_NULL();
289
    }
290
    zend_object* pobj = Z_OBJ_P(getThis()); 
291
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
292 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
293 72bf04c6 Norman Walsh
    saxonProcessor = obj->saxonProcessor;
294 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
295 72bf04c6 Norman Walsh
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
296 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
297 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
298
                RETURN_NULL();
299
            } else {
300
                zend_object* vobj = Z_OBJ_P(return_value);
301
                 xdmNode_object * xdmNObj = (xdmNode_object *)((char *)vobj - XtOffsetOf(xdmNode_object, std));
302 ead48a5d O'Neil Delpratt
                assert (xdmNObj != nullptr);
303 72bf04c6 Norman Walsh
                xdmNObj->xdmNode = node;
304
            }
305
        } else {
306
            if(obj->saxonProcessor->exceptionOccurred()){
307
                //TODO throw exception
308
            }
309
        }
310
    } else {
311
        RETURN_NULL();
312
    }
313
}
314
315
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
316
{
317
    SaxonProcessor * saxonProcessor;
318
    char * source;
319
    size_t len1;
320
321
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
322
        RETURN_NULL();
323
    }
324
    zend_object* pobj = Z_OBJ_P(getThis()); 
325
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
326 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
327 72bf04c6 Norman Walsh
    saxonProcessor = obj->saxonProcessor;
328 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
329 72bf04c6 Norman Walsh
        XdmNode* node = saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
330 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
331 72bf04c6 Norman Walsh
      
332
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
333
                RETURN_NULL();
334
            } else {
335
          
336
            zend_object* vvobj = Z_OBJ_P(return_value);
337
            xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
338
                
339 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
340 72bf04c6 Norman Walsh
                vobj->xdmNode = node;
341
            }
342
        } else {
343
           // obj->xsltProcessor->checkException();//TODO
344
        }
345
    } else {
346
  //  std::cerr<<"parseXmlFromFile cp2"<<std::endl;
347
        RETURN_NULL();
348
    }
349
   // std::cerr<<"parseXmlFromFile cp3"<<std::endl;
350
}
351
352
353
PHP_METHOD(SaxonProcessor, createAtomicValue)
354
{
355 ead48a5d O'Neil Delpratt
    XdmAtomicValue * xdmValue = nullptr;
356 72bf04c6 Norman Walsh
    SaxonProcessor * proc;
357
    char * source;
358
    int len1;
359
    zval *zvalue;
360
    bool bVal;
361
    char * sVal;
362
    int len;
363
    long iVal;
364
    double dVal;
365
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == FAILURE) {
366
        RETURN_NULL();
367
    }
368
    zend_object* pobj = Z_OBJ_P(getThis()); 
369
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
370 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
371 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
372 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
373
    if (proc != nullptr) {
374 72bf04c6 Norman Walsh
        switch (Z_TYPE_P(zvalue)) {
375
            case IS_FALSE:
376
            xdmValue = proc->makeBooleanValue(false);
377
            case IS_TRUE:
378
                xdmValue = proc->makeBooleanValue(true);
379
            break;
380
            case IS_LONG:
381
                iVal = Z_LVAL_P(zvalue);
382
                 xdmValue = proc->makeIntegerValue((int)iVal);
383
            break;
384
            case IS_STRING:
385
                sVal = Z_STRVAL_P(zvalue);
386
                len = Z_STRLEN_P(zvalue);
387
                
388
                xdmValue = proc->makeStringValue((const char*)sVal);
389
                //efree(sVal);
390
            break;
391
            case IS_NULL:
392
                xdmValue = new XdmAtomicValue();
393
            break;
394
            case IS_DOUBLE:
395
                dVal = (double)Z_DVAL_P(zvalue);
396
                xdmValue = proc->makeDoubleValue((double)iVal);
397
                break;
398
            case IS_ARRAY:
399
                // TODO: Should not be expected. Do this some other way
400
                //break;
401
            case IS_OBJECT:
402
                // TODO: implement this
403
                //break;
404
            default:
405 ead48a5d O'Neil Delpratt
                obj = nullptr;
406 72bf04c6 Norman Walsh
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC); 
407
                RETURN_NULL();
408
        }
409
//std::cerr<<"createAtomicValue cp0"<<std::endl;
410 ead48a5d O'Neil Delpratt
        if(xdmValue == nullptr) {
411 72bf04c6 Norman Walsh
            RETURN_NULL();
412
        }
413
        if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
414
            RETURN_NULL();
415
        } else {
416
            //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value);
417
             zend_object* vvobj = Z_OBJ_P(return_value);
418
           xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
419 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
420 72bf04c6 Norman Walsh
            vobj->xdmAtomicValue = xdmValue;
421
        }
422
    } else {
423
       
424
        RETURN_NULL();
425
    }
426
}
427
428
429
PHP_METHOD(SaxonProcessor, newXPathProcessor)
430
{
431
   
432
    if (ZEND_NUM_ARGS()>0) {
433
        WRONG_PARAM_COUNT;
434
    }
435
    SaxonProcessor * proc;
436 ead48a5d O'Neil Delpratt
    XPathProcessor * xpathProcessor = nullptr;
437 72bf04c6 Norman Walsh
438
    zend_object* pobj = Z_OBJ_P(getThis()); 
439
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
440
441 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
442 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
443 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
444
    if (proc != nullptr) {
445 72bf04c6 Norman Walsh
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
446
            RETURN_NULL();
447
        } else {
448
          // struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)Z_OBJ_P(return_value TSRMLS_CC);
449
           zend_object* vvobj = Z_OBJ_P(return_value);
450
           xpathProcessor_object * vobj = (xpathProcessor_object *)((char *)vvobj - XtOffsetOf(xpathProcessor_object, std));
451 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
452 72bf04c6 Norman Walsh
            xpathProcessor = proc->newXPathProcessor();
453
            vobj->xpathProcessor = xpathProcessor;
454
        }
455
    } else {
456
       
457
        RETURN_NULL();
458
    }
459
}
460
461
PHP_METHOD(SaxonProcessor, newXsltProcessor)
462
{
463
//std::cerr<<"SaxonProcessor newXsltproc point 1"<<std::endl;
464
    //php_error(E_WARNING,"new xsltProc 1");
465
    if (ZEND_NUM_ARGS()>0) {
466
        WRONG_PARAM_COUNT;
467
    }
468
    SaxonProcessor * proc;
469 ead48a5d O'Neil Delpratt
    XsltProcessor * xsltProcessor = nullptr;
470 72bf04c6 Norman Walsh
471
      zend_object* pobj = Z_OBJ_P(getThis()); 
472
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
473
474
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
475 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
476 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
477
478 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
479
    if (proc != nullptr) {
480 72bf04c6 Norman Walsh
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
481
            RETURN_NULL();
482
        } else {
483
        xsltProcessor = proc->newXsltProcessor();
484
           zend_object* vobj = Z_OBJ_P(return_value);
485
           xsltProcessor_object * xproc_object = (xsltProcessor_object *)((char *)vobj - XtOffsetOf(xsltProcessor_object, std));
486 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
487 72bf04c6 Norman Walsh
            
488
            xproc_object->xsltProcessor = xsltProcessor;
489
490
    }
491
    } else {
492
       
493
        RETURN_NULL();
494
    }
495
}
496
497
498
PHP_METHOD(SaxonProcessor, newXslt30Processor)
499
{
500
//std::cerr<<"SaxonProcessor newXslt30proc point 1"<<std::endl;
501
   // php_error(E_WARNING,"new xslt30Proc 1");
502
    if (ZEND_NUM_ARGS()>0) {
503
        WRONG_PARAM_COUNT;
504
    }
505
    SaxonProcessor * proc;
506 ead48a5d O'Neil Delpratt
    Xslt30Processor * xslt30Processor = nullptr;
507 72bf04c6 Norman Walsh
508
      zend_object* pobj = Z_OBJ_P(getThis());
509
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
510
511
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
512 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
513 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
514
515 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
516
    if (proc != nullptr) {
517 72bf04c6 Norman Walsh
    if (object_init_ex(return_value, xslt30Processor_ce) != SUCCESS) {
518
            RETURN_NULL();
519
        } else {
520
        xslt30Processor = proc->newXslt30Processor();        
521
           zend_object* vobj = Z_OBJ_P(return_value);
522
           xslt30Processor_object * xproc_object = (xslt30Processor_object *)((char *)vobj - XtOffsetOf(xslt30Processor_object, std));
523 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
524 72bf04c6 Norman Walsh
525
            xproc_object->xslt30Processor = xslt30Processor;
526
527
    }
528
    } else {
529
530
        RETURN_NULL();
531
    }
532
}
533
534
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
535
{
536
   
537
    if (ZEND_NUM_ARGS()>0) {
538
        WRONG_PARAM_COUNT;
539
    }
540
    SaxonProcessor * proc;
541 ead48a5d O'Neil Delpratt
    XQueryProcessor * xqueryProcessor = nullptr;
542 72bf04c6 Norman Walsh
     zend_object* pobj = Z_OBJ_P(getThis()); 
543
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
544 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
545 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
546 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
547
    if (proc != nullptr) {
548 72bf04c6 Norman Walsh
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
549
            RETURN_NULL();
550
        } else {
551
          xqueryProcessor = proc->newXQueryProcessor();
552
          zend_object* vvobj = Z_OBJ_P(return_value);
553
           xqueryProcessor_object * vobj = (xqueryProcessor_object *)((char *)vvobj - XtOffsetOf(xqueryProcessor_object, std));
554 ead48a5d O'Neil Delpratt
            assert (vvobj != nullptr);
555 72bf04c6 Norman Walsh
            
556
            vobj->xqueryProcessor = xqueryProcessor;
557
     }
558
    } else {
559
       
560
        RETURN_NULL();
561
    }
562
}
563
564
PHP_METHOD(SaxonProcessor, newSchemaValidator)
565
{
566
   
567
    if (ZEND_NUM_ARGS()>0) {
568
        WRONG_PARAM_COUNT;
569
    }
570
    SaxonProcessor * proc;
571 ead48a5d O'Neil Delpratt
    SchemaValidator * schemaValidator = nullptr;
572 72bf04c6 Norman Walsh
   
573
    zend_object* pobj = Z_OBJ_P(getThis()); 
574
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
575 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
576 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
577 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
578
    if (proc != nullptr) {
579 72bf04c6 Norman Walsh
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
580
            RETURN_NULL();
581
        } else {
582
           //struct schemaValidator_object* vobj = (struct schemaValidator_object *)Z_OBJ_P(return_value TSRMLS_CC);
583
           zend_object* vvobj = Z_OBJ_P(return_value);
584
           schemaValidator_object * vobj = (schemaValidator_object *)((char *)vvobj - XtOffsetOf(schemaValidator_object, std));
585 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
586 72bf04c6 Norman Walsh
            schemaValidator = proc->newSchemaValidator();
587 ead48a5d O'Neil Delpratt
            if(schemaValidator == nullptr){
588 72bf04c6 Norman Walsh
                RETURN_NULL();
589
            }
590
            vobj->schemaValidator = schemaValidator;
591
        }
592
    } else {
593
       
594
        RETURN_NULL();
595
    }
596
}
597
598
599
PHP_METHOD(SaxonProcessor, version)
600
{
601
    SaxonProcessor *saxonProcessor;
602
603
   
604
    if (ZEND_NUM_ARGS()>0) {
605
        WRONG_PARAM_COUNT;
606
    }
607
    zend_object* pobj = Z_OBJ_P(getThis()); 
608
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
609
    saxonProcessor = obj->saxonProcessor;
610 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
611 72bf04c6 Norman Walsh
        const char * verStr = saxonProcessor->version();
612
        //char *str = estrdup(saxonProcessor->version());
613
        _RETURN_STRING(verStr);
614
//efree(verStr);
615
    }
616
    RETURN_NULL();
617
}
618
619
620
621
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
622
{
623
    SaxonProcessor *saxonProcessor;
624
    char * name;
625
    char * value;
626
    size_t len1, len2;
627
    if (ZEND_NUM_ARGS()!= 2) {
628
        WRONG_PARAM_COUNT;
629
    }
630
631
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
632
        RETURN_NULL();
633
    }
634
    zend_object* pobj = Z_OBJ_P(getThis()); 
635
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
636
637
    saxonProcessor = obj->saxonProcessor;
638 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr && name != nullptr && value != nullptr) {
639 72bf04c6 Norman Walsh
        saxonProcessor->setConfigurationProperty(name, value);
640
    }
641
    
642
}
643
644
PHP_METHOD(SaxonProcessor, registerPHPFunctions)
645
{
646
    SaxonProcessor *saxonProcessor;
647
    char * libName;
648
    size_t len1;
649
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
650
    if (ZEND_NUM_ARGS()!= 1) {
651
        WRONG_PARAM_COUNT;
652
    }
653
654
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &libName, &len1) == FAILURE) {
655
        RETURN_NULL();
656
    }
657
//std::cerr<<"checkpoint in registerPHPFunction cp2"<<std::endl;
658
    zend_object* pobj = Z_OBJ_P(getThis()); 
659
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
660
661
    saxonProcessor = obj->saxonProcessor;
662 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr && libName != nullptr) {
663 72bf04c6 Norman Walsh
        saxonProcessor->setConfigurationProperty("extc", libName);
664
    }
665
saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PHPFunction",
666
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
667
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
668
}
669
670
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
671
672
void XsltProcessor_free_storage(zend_object *object)
673
{
674
675
    zend_object_std_dtor(object);
676
}
677
678
void XsltProcessor_destroy_storage(zend_object *object)
679
{
680
    xsltProcessor_object *obj;
681
682
    zend_objects_destroy_object(object);
683
}
684
685
zend_object * xsltProcessor_create_handler(zend_class_entry *type)
686
{
687
   
688
689
    xsltProcessor_object *obj = (xsltProcessor_object *)ecalloc(1, sizeof(xsltProcessor_object)+ zend_object_properties_size(type));
690
   
691
    
692
   zend_object_std_init(&obj->std,type);
693
    object_properties_init(&obj->std, type);
694
    
695
    obj->std.handlers = &xsltProcessor_object_handlers;
696
697
    return &obj->std;
698
}
699
700
701
702
PHP_METHOD(XsltProcessor, __destruct)
703
{
704
705
    zend_object* pobj = Z_OBJ_P(getThis()); 
706
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
707
708
709
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
710 ead48a5d O'Neil Delpratt
    if(xsltProcessor != nullptr){
711 72bf04c6 Norman Walsh
            delete xsltProcessor;
712
     }
713
 
714
    
715
}
716
717
PHP_METHOD(XsltProcessor, transformFileToFile)
718
{
719
    XsltProcessor *xsltProcessor;
720
    char * outfileName;
721
    char * infilename;
722
    char * styleFileName;
723
    size_t len1, len2, len3;
724
725
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
726
        RETURN_NULL();
727
    }
728
729
    zend_object* pobj = Z_OBJ_P(getThis()); 
730
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
731
    xsltProcessor = obj->xsltProcessor;
732
 
733 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
734 72bf04c6 Norman Walsh
735
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
736
        if(xsltProcessor->exceptionOccurred()) {
737
               // TODO: throw exception
738
        }
739
    }
740
}
741
742
PHP_METHOD(XsltProcessor, transformFileToValue)
743
{
744
    XsltProcessor *xsltProcessor;
745
    char * infilename;
746
    char * styleFileName;
747
   size_t len1, len2;
748
749
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
750
        RETURN_NULL();
751
    }
752
753
    zend_object* pobj = Z_OBJ_P(getThis()); 
754
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
755
    xsltProcessor = obj->xsltProcessor;
756
    
757 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
758 72bf04c6 Norman Walsh
759
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
760 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
761 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
762
                RETURN_NULL();
763
            } else {
764
                zend_object *ooth =  Z_OBJ_P(return_value);
765
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
766
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
767 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
768 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
769
            }
770
        } else {
771
            if(obj->xsltProcessor->exceptionOccurred()){
772
                  //TODO
773
            }
774
        }
775
    }else {
776
        RETURN_NULL();
777
    }
778
}
779
780
781
PHP_METHOD(XsltProcessor, transformFileToString)
782
{
783
    XsltProcessor *xsltProcessor;
784
    char * infilename;
785
    char * styleFileName;
786
    size_t len1, len2;
787
788
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
789
        RETURN_NULL();
790
    }
791
792
    zend_object* pobj = Z_OBJ_P(getThis()); 
793
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
794
    xsltProcessor = obj->xsltProcessor;
795
796 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
797 72bf04c6 Norman Walsh
798
        const char * result = xsltProcessor->transformFileToString(infilename, styleFileName);
799 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
800 72bf04c6 Norman Walsh
            //char *str = estrdup(result);
801
            _RETURN_STRING(result);
802
        } else if(xsltProcessor->exceptionOccurred()){
803
            //TODO: xsltProcessor->checkException();
804
            const char * errStr = xsltProcessor->getErrorMessage(0);
805 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
806 72bf04c6 Norman Walsh
                const char * errorCode = xsltProcessor->getErrorCode(0);
807 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
808 72bf04c6 Norman Walsh
                    // TODO: throw exception
809
                }
810
            }
811
        }
812
    }
813
}
814
815
/*enum saxonTypeEnum
816
{
817
        enumNode,
818
        enumString,
819
        enumInteger,
820
        enumDouble,
821
        enumFloat,
822
        enumBool,
823
        enumArrXdmValue
824
};*/
825
826 e05bbe34 O'Neil Delpratt
827 72bf04c6 Norman Walsh
jobject JNICALL phpNativeCall
828 e05bbe34 O'Neil Delpratt
        (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
829
    JNIEnv *senv = SaxonProcessor::sxn_environ->env;
830
    char *nativeString = (char *)senv->GetStringUTFChars(funcName, NULL);
831
    //std::string nativeString2 = std::string(nativeString);
832
    if(nativeString == NULL) {
833
        return NULL;
834
    }
835
    int nativeStrLen = strlen(nativeString);
836
    //std::cerr<<"phpNative called. nativeString="<<nativeString<<", length="<<nativeStrLen<<std::endl;
837
    zval function_name;
838
    zval retval;
839
840
    int argLength = 0;
841
    zval  *  params;
842
    if(arguments != NULL) {
843
        argLength = (int)senv->GetArrayLength(arguments);
844
        //(*params) = (zval**)malloc(sizeof(zval*) * argLength);
845
        params =  new zval[argLength];
846
    } else {
847
        params = NULL;
848
    }
849
    std::map<std::string, saxonTypeEnum> typeMap;
850
    typeMap["node"] = enumNode;
851
    typeMap["string"] = enumString;
852
    typeMap["integer"] = enumInteger;
853
    typeMap["double"] = enumDouble;
854
    typeMap["float"] = enumFloat;
855
    typeMap["boolean"] = enumBool;
856
    typeMap["[xdmvalue"] = enumArrXdmValue;
857
    sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
858
859
    SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
860 72bf04c6 Norman Walsh
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
861
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
862
863 e05bbe34 O'Neil Delpratt
    for(int i=0; i<argLength;i++){
864
        jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
865
        jobject argObj = senv->GetObjectArrayElement(arguments, i);
866
867
        const char * str = senv->GetStringUTFChars(argType,NULL);
868
        const char *stri = NULL;
869
        double dnumber = 0;
870
        long lnumber = 0;
871
        bool bvalue = false;
872
        float fnumber = 0;
873
874
875
876
        struct xdmNode_object* vobj;
877
        zend_object* zend_vobj;
878
        XdmNode * node = NULL;
879
        std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
880
        if (it != typeMap.end()){
881
            switch (it->second)
882
            {
883
                case enumNode:
884
                    std::cerr<<"enumNode path - cp0 - phpNtiveCall"<<std::endl;
885
                    if(!nprocessor->proc){
886
                        nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
887
                    }
888
                    if (object_init_ex(&params[i], xdmNode_ce) != SUCCESS) {
889
                        //error
890
891
                        //php_error(E_WARNING,"error phpNative xdmNode creation failed");
892
                        break;
893
                    }
894
                    node = new XdmNode(argObj);
895
                    node->setProcessor(nprocessor);
896
897
                    //MAKE_STD_ZVAL(php_argv[i]._val);
898
                    zend_vobj = Z_OBJ_P(&params[i]);
899
                    vobj = (xdmNode_object *)((char *)zend_vobj - XtOffsetOf(xdmNode_object, std));
900
                    assert (vobj != NULL);
901
902
                    vobj->xdmNode = node;
903
                    break;
904
                case enumString:
905
                    //sresult->xdmvalue = argObj;
906
                    stri = stringValue(SaxonProcessor::sxn_environ, argObj);
907
                    //stri = getStringValue(SaxonProcessor::sxn_environ, *sresult);
908
                    //stri = senv->GetStringUTFChars((jstring)argObj, 0);
909
                    //ZVAL_STRING(php_argv[i]._val);
910
                    ZVAL_STRING(&params[i], stri);
911
                    break;
912
                case enumInteger:
913
                    sresult->xdmvalue = argObj;
914
                    lnumber = getLongValue(SaxonProcessor::sxn_environ, *sresult, 0);
915
916
                    //MAKE_STD_ZVAL(php_argv[i]._val);
917
                    ZVAL_LONG(&params[i], lnumber);
918
                    break;
919
                case enumDouble:
920
                    sresult->xdmvalue = argObj;
921
                    dnumber = getDoubleValue(SaxonProcessor::sxn_environ, *sresult, 0);                                        //MAKE_STD_ZVAL(php_argv[i]._val);
922
                    ZVAL_DOUBLE(&params[i], dnumber);
923
                    break;
924
                case enumFloat:
925
                    sresult->xdmvalue = argObj;
926
                    fnumber = getFloatValue(SaxonProcessor::sxn_environ, *sresult, 0);
927
                    //MAKE_STD_ZVAL(php_argv[i]._val);
928
                    ZVAL_DOUBLE(&params[i], fnumber);
929
                    break;
930
                case enumBool:
931
                    sresult->xdmvalue = argObj;
932
                    bvalue = getBooleanValue(SaxonProcessor::sxn_environ, *sresult);
933
                    //MAKE_STD_ZVAL(php_argv[i]._val);
934
                    ZVAL_BOOL(&params[i], bvalue);
935
                    break;
936
                case enumArrXdmValue:
937
                    //TODO - not currently supported
938
                    argLength--;
939
                    break;
940
            }
941
            senv->ReleaseStringUTFChars(argType, str);
942
        }
943 72bf04c6 Norman Walsh
944 e05bbe34 O'Neil Delpratt
    }
945 72bf04c6 Norman Walsh
946
947 e05bbe34 O'Neil Delpratt
    free(sresult);
948 72bf04c6 Norman Walsh
949
950 e05bbe34 O'Neil Delpratt
    zval *argvv = NULL;
951
    zval* callOnObj = NULL;
952
    //MAKE_STD_ZVAL(function_name);
953
    //nativeString[nativeStrLen] = '\0';
954 72bf04c6 Norman Walsh
955 e05bbe34 O'Neil Delpratt
    ZVAL_STRING(&function_name, nativeString);
956
    if(call_user_function_ex(CG(function_table), (zval*)callOnObj, &function_name, &retval, argLength, params, 0, NULL) != SUCCESS)
957
    {
958
        zend_error(E_ERROR, "Function call failed");
959
    }
960 72bf04c6 Norman Walsh
961 e05bbe34 O'Neil Delpratt
    if(Z_TYPE(retval) ==0){
962
        zend_error(E_ERROR, "Function returned null");
963
    }
964 72bf04c6 Norman Walsh
965 e05bbe34 O'Neil Delpratt
    char * sVal = NULL;
966
    int len = 0;
967
    jobject obj = NULL;
968 72bf04c6 Norman Walsh
//TODO handle XdmValue wrapped object
969 e05bbe34 O'Neil Delpratt
    const char * objName = NULL;
970
    xdmNode_object* ooth = NULL;
971
    zend_object* zend_vobj2;
972
    bool bVal;
973
    switch (Z_TYPE_P(&retval)) {
974
        case IS_FALSE:
975 72bf04c6 Norman Walsh
                obj= booleanValue(SaxonProcessor::sxn_environ, false);
976
                break;
977 e05bbe34 O'Neil Delpratt
        case IS_TRUE:
978
            obj= booleanValue(SaxonProcessor::sxn_environ, true);
979 72bf04c6 Norman Walsh
            break;
980 e05bbe34 O'Neil Delpratt
981
        case IS_LONG:
982
            obj= longValue(SaxonProcessor::sxn_environ, Z_LVAL_P(&retval));
983
            break;
984
        case IS_STRING:
985
            sVal = Z_STRVAL_P(&retval);
986
            len = Z_STRLEN_P(&retval);
987
            obj = getJavaStringValue(SaxonProcessor::sxn_environ,estrndup(sVal, len));
988
            break;
989
            break;
990
        case IS_NULL:
991
992
            break;
993
        case IS_DOUBLE:
994
            obj = doubleValue(SaxonProcessor::sxn_environ, (double)Z_DVAL_P(&retval));
995
            break;
996
997
        case IS_ARRAY:
998 72bf04c6 Norman Walsh
            //break;
999 e05bbe34 O'Neil Delpratt
        case IS_OBJECT:
1000 72bf04c6 Norman Walsh
1001 e05bbe34 O'Neil Delpratt
            objName =ZSTR_VAL(Z_OBJCE_P(&retval)->name);
1002 72bf04c6 Norman Walsh
1003 e05bbe34 O'Neil Delpratt
1004
            if(strcmp(objName, "Saxon\\XdmNode")==0) {
1005
1006
                zend_vobj2 =  Z_OBJ_P(&retval);
1007
                ooth = (xdmNode_object *)((char *)zend_vobj2 - XtOffsetOf(xdmNode_object, std));
1008
1009
                if(ooth != NULL) {
1010
                    obj = ooth->xdmNode->getUnderlyingValue();
1011
                }
1012
            }
1013
            break;
1014
        default:
1015
            obj = NULL;
1016
            zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
1017
    }
1018
1019
    delete nprocessor;
1020
    zval_ptr_dtor(&retval);
1021
    return obj;
1022 72bf04c6 Norman Walsh
}
1023
1024
1025
1026
PHP_METHOD(XsltProcessor, transformToString)
1027
{
1028
    XsltProcessor *xsltProcessor;
1029
 
1030
    if (ZEND_NUM_ARGS()>0) {
1031
        WRONG_PARAM_COUNT;
1032
    }
1033
1034
1035
    zend_object* pobj = Z_OBJ_P(getThis()); 
1036
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1037
    xsltProcessor = obj->xsltProcessor;
1038 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1039 72bf04c6 Norman Walsh
1040
        const char * result = xsltProcessor->transformToString();
1041 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1042 72bf04c6 Norman Walsh
            _RETURN_STRING(result);
1043
        } else if(xsltProcessor->exceptionOccurred()){
1044
            xsltProcessor->checkException();
1045
            const char * errStr = xsltProcessor->getErrorMessage(0);
1046 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
1047 72bf04c6 Norman Walsh
                const char * errorCode = xsltProcessor->getErrorCode(0);
1048 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
1049 72bf04c6 Norman Walsh
                    // TODO: throw exception
1050
                }
1051
            }
1052
        }
1053
    }
1054
    RETURN_NULL();
1055
}
1056
1057
PHP_METHOD(XsltProcessor, transformToValue)
1058
{
1059
    XsltProcessor *xsltProcessor;
1060
1061
    if (ZEND_NUM_ARGS()>0) {
1062
        WRONG_PARAM_COUNT;
1063
    }
1064
1065
    zend_object* pobj = Z_OBJ_P(getThis()); 
1066
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1067
    xsltProcessor = obj->xsltProcessor;
1068
1069 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1070 72bf04c6 Norman Walsh
1071
        XdmValue * node = xsltProcessor->transformToValue();
1072 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
1073 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1074
                RETURN_NULL();
1075
            } else {
1076
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value);
1077
                zend_object *vvobj =  Z_OBJ_P(return_value);
1078
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1079 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1080 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
1081
            }
1082
        } else if(xsltProcessor->exceptionOccurred()){
1083
            xsltProcessor->checkException();
1084
            RETURN_NULL();
1085
        }
1086
    } else {
1087
        RETURN_NULL();
1088
    }
1089
}
1090
1091
PHP_METHOD(XsltProcessor, transformToFile)
1092
{
1093
    XsltProcessor *xsltProcessor;
1094
 
1095
    if (ZEND_NUM_ARGS()>0) {
1096
        WRONG_PARAM_COUNT;
1097
    }
1098
1099
    zend_object* pobj = Z_OBJ_P(getThis()); 
1100
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1101
    xsltProcessor = obj->xsltProcessor;
1102
1103 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1104 72bf04c6 Norman Walsh
1105
        xsltProcessor->transformToFile();
1106
        if(xsltProcessor->exceptionOccurred()) {
1107
           //TODO
1108
            const char * exStr = xsltProcessor->checkException();
1109
        }
1110
    } else {
1111
        RETURN_NULL();
1112
    }
1113
}
1114
1115
PHP_METHOD(XsltProcessor, compileFromFile)
1116
{
1117
    XsltProcessor *xsltProcessor;
1118
    char * name;
1119
    size_t len1;
1120
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
1121
        RETURN_NULL();
1122
    }
1123
    zend_object* pobj = Z_OBJ_P(getThis()); 
1124
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1125
    xsltProcessor = obj->xsltProcessor;
1126 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1127 72bf04c6 Norman Walsh
        xsltProcessor->compileFromFile(name);
1128
    }
1129
}
1130
1131
PHP_METHOD(XsltProcessor, compileFromString)
1132
{
1133
    XsltProcessor *xsltProcessor;
1134
    char * stylesheetStr;
1135
    size_t len1, myint;
1136
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
1137
        RETURN_NULL();
1138
    }
1139
    zend_object* pobj = Z_OBJ_P(getThis()); 
1140
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1141
    xsltProcessor = obj->xsltProcessor;
1142 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1143 72bf04c6 Norman Walsh
        xsltProcessor->compileFromString(stylesheetStr);
1144
    }
1145
}
1146
1147
PHP_METHOD(XsltProcessor, compileFromStringAndSave)
1148
{
1149
    XsltProcessor *xsltProcessor;
1150
    char * stylesheetStr;
1151
    char * filename;
1152
    size_t len1, len2, myint;
1153
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetStr, &filename, &len1, &len2) == FAILURE) {
1154
        RETURN_NULL();
1155
    }
1156
    zend_object* pobj = Z_OBJ_P(getThis()); 
1157
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1158
    xsltProcessor = obj->xsltProcessor;
1159 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1160 72bf04c6 Norman Walsh
        xsltProcessor->compileFromStringAndSave(stylesheetStr, filename);
1161
    }
1162
}
1163
1164
PHP_METHOD(XsltProcessor, compileFromFileAndSave)
1165
{
1166
    XsltProcessor *xsltProcessor;
1167
    char * stylesheetFilename;
1168
    char * filename;
1169
    size_t len1, len2, myint;
1170
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, &filename, &len1, &len2) == FAILURE) {
1171
        RETURN_NULL();
1172
    }
1173
    zend_object* pobj = Z_OBJ_P(getThis()); 
1174
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1175
    xsltProcessor = obj->xsltProcessor;
1176 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1177 72bf04c6 Norman Walsh
        xsltProcessor->compileFromStringAndSave(stylesheetFilename, filename);
1178
    }
1179
}
1180
1181
1182
1183
PHP_METHOD(XsltProcessor, compileFromValue)
1184
{
1185
    XsltProcessor *xsltProcessor;
1186
   zval* oth;
1187
1188
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
1189
        RETURN_NULL();
1190
    }
1191
    zend_object* pobj = Z_OBJ_P(getThis()); 
1192
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1193
    xsltProcessor = obj->xsltProcessor;
1194 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1195 72bf04c6 Norman Walsh
        zend_object* vvobj = Z_OBJ_P(oth);
1196
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1197 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1198 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1199 ead48a5d O'Neil Delpratt
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
1200 72bf04c6 Norman Walsh
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1201
            }
1202
        }
1203
    }
1204
}
1205
1206
1207
1208
1209
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1210
{
1211
    XsltProcessor *xsltProcessor;
1212 ead48a5d O'Neil Delpratt
    zval* oth = nullptr;
1213 72bf04c6 Norman Walsh
1214
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1215
        RETURN_NULL();
1216
    }
1217
1218
    zend_object* pobj = Z_OBJ_P(getThis()); 
1219
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1220
    xsltProcessor = obj->xsltProcessor;
1221 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1222 72bf04c6 Norman Walsh
1223
    if(!oth) {
1224
        php_error(E_WARNING, "Error setting source value");
1225
        return;
1226
    } else {
1227
        if(Z_TYPE_P(oth) ==IS_NULL){
1228
                php_error(E_WARNING, "Error setting source value");
1229
                return;
1230
        }
1231
        
1232
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1233
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1234
1235
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1236
        zend_object * nobj = Z_OBJ_P(oth);
1237
1238
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1239 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1240 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
1241 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1242 72bf04c6 Norman Walsh
                
1243
                xsltProcessor->setSourceFromXdmNode(value);
1244
1245
            }
1246
        }
1247
      } /*else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1248
        zend_object* vvobj = Z_OBJ_P(oth);
1249
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1250 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1251 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1252 ead48a5d O'Neil Delpratt
            if(value != nullptr && value) {
1253 72bf04c6 Norman Walsh
                xsltProcessor->setSourceFromXdmNode((XdmNode*)value);
1254
            }
1255
        }
1256
      }  */
1257
1258
        
1259
    }
1260
  }
1261
}
1262
1263
1264
PHP_METHOD(XsltProcessor, setJustInTimeCompilation)
1265
{
1266
    XsltProcessor *xsltProcessor;
1267
    bool jit = false;
1268
    size_t len1;
1269
1270
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
1271
        RETURN_NULL();
1272
    }
1273
1274
    zend_object* pobj = Z_OBJ_P(getThis());
1275
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1276
    xsltProcessor = obj->xsltProcessor;
1277 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1278 72bf04c6 Norman Walsh
         xsltProcessor->setJustInTimeCompilation(jit);
1279
    }
1280
}
1281
1282
PHP_METHOD(XsltProcessor, setOutputFile)
1283
{
1284
    XsltProcessor *xsltProcessor;
1285
    char * outputFilename;
1286
    size_t len1;
1287
1288
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
1289
        RETURN_NULL();
1290
    }
1291
1292
    zend_object* pobj = Z_OBJ_P(getThis()); 
1293
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1294
    xsltProcessor = obj->xsltProcessor;
1295 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr && outputFilename != nullptr) {
1296 72bf04c6 Norman Walsh
        
1297
         xsltProcessor->setOutputFile(outputFilename);
1298
            
1299
        
1300
    }
1301
}
1302
1303
1304
PHP_METHOD(XsltProcessor, setBaseOutputURI)
1305
{
1306
    XsltProcessor *xsltProcessor;
1307 ead48a5d O'Neil Delpratt
    char * baseOutputURI = nullptr;
1308 72bf04c6 Norman Walsh
    size_t len1;
1309
1310
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &len1) == FAILURE) {
1311
        RETURN_NULL();
1312
    }
1313
1314
    zend_object* pobj = Z_OBJ_P(getThis());
1315
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1316
    xsltProcessor = obj->xsltProcessor;
1317 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr && baseOutputURI != nullptr) {
1318 72bf04c6 Norman Walsh
1319
         xsltProcessor->setBaseOutputURI(baseOutputURI);
1320
1321
1322
    }
1323
}
1324
1325
1326
int size_t2int(size_t val) {
1327
    return (val <= INT_MAX) ? (int)((ssize_t)val) : -1;
1328
}
1329
1330
PHP_METHOD(XsltProcessor, setSourceFromFile)
1331
{
1332
    XsltProcessor *xsltProcessor;
1333
    char * inFilename;
1334
    size_t len1;
1335
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
1336
        RETURN_NULL();
1337
    }
1338
1339
    zend_object* pobj = Z_OBJ_P(getThis()); 
1340
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1341
    xsltProcessor = obj->xsltProcessor;
1342 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr && inFilename != nullptr) {
1343 72bf04c6 Norman Walsh
         xsltProcessor->setSourceFromFile(inFilename);
1344
            
1345
        
1346
    }
1347
}
1348
1349
1350
PHP_METHOD(XsltProcessor, setProperty)
1351
{
1352
    XsltProcessor *xsltProcessor;
1353
    char * name;
1354
    char * value;
1355
    size_t len1, len2, myint;
1356
1357
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
1358
        RETURN_NULL();
1359
    }
1360
    zend_object* pobj = Z_OBJ_P(getThis()); 
1361
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1362
    xsltProcessor = obj->xsltProcessor;
1363 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1364 72bf04c6 Norman Walsh
        xsltProcessor->setProperty(name, value);
1365
    }
1366
}
1367
1368
PHP_METHOD(XsltProcessor, setParameter)
1369
{
1370
1371
   XsltProcessor *xsltProcessor;
1372
   char * name;
1373
   zval* oth;
1374
   size_t len1, len2, myint;        
1375
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1376
        RETURN_NULL();
1377
    }
1378
    zend_object* pobj = Z_OBJ_P(getThis()); 
1379
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1380
    xsltProcessor = obj->xsltProcessor;
1381 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1382 72bf04c6 Norman Walsh
        if(Z_TYPE_P(oth) ==IS_NULL){
1383 ead48a5d O'Neil Delpratt
                php_error(E_WARNING, "Error setting source value - value is nullptr");
1384 72bf04c6 Norman Walsh
                return;
1385
        }
1386
1387
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1388
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1389
1390
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1391
        zend_object* ooth = Z_OBJ_P(oth);
1392
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1393 ead48a5d O'Neil Delpratt
        if(nobj != nullptr) {
1394 72bf04c6 Norman Walsh
            XdmNode * value = nobj->xdmNode;
1395 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1396 72bf04c6 Norman Walsh
                xsltProcessor->setParameter(name, (XdmValue *)value);
1397
1398
            }
1399
        }
1400
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1401
        zend_object* ooth = Z_OBJ_P(oth);
1402
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1403 ead48a5d O'Neil Delpratt
        if(vobj != nullptr) {
1404 72bf04c6 Norman Walsh
            XdmValue * value = vobj->xdmValue;
1405 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1406 72bf04c6 Norman Walsh
                
1407
                xsltProcessor->setParameter(name, value);
1408
            }
1409
        }
1410
1411
1412
1413
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1414
        zend_object* ooth = Z_OBJ_P(oth);
1415
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1416 ead48a5d O'Neil Delpratt
        if(aobj != nullptr) {
1417 72bf04c6 Norman Walsh
            XdmAtomicValue * value = aobj->xdmAtomicValue;
1418 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1419 72bf04c6 Norman Walsh
                xsltProcessor->setParameter(name, (XdmValue *)value);
1420
            }
1421
        }
1422
1423
1424
1425
      }
1426
1427
    }
1428
}
1429
1430
PHP_METHOD(XsltProcessor, clearParameters)
1431
{
1432
    XsltProcessor *xsltProcessor;
1433
    if (ZEND_NUM_ARGS()>0) {
1434
        WRONG_PARAM_COUNT;
1435
    }
1436
1437
    zend_object* pobj = Z_OBJ_P(getThis()); 
1438
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1439
    xsltProcessor = obj->xsltProcessor;
1440 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1441 72bf04c6 Norman Walsh
        xsltProcessor->clearParameters(true);
1442
    }
1443
}
1444
1445
PHP_METHOD(XsltProcessor, clearProperties)
1446
{
1447
    XsltProcessor *xsltProcessor;
1448
    if (ZEND_NUM_ARGS()>0) {
1449
        WRONG_PARAM_COUNT;
1450
    }
1451
1452
    zend_object* pobj = Z_OBJ_P(getThis()); 
1453
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1454
    xsltProcessor = obj->xsltProcessor;
1455 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1456 72bf04c6 Norman Walsh
        xsltProcessor->clearProperties();
1457
    }
1458
}
1459
1460
1461
1462
PHP_METHOD(XsltProcessor, setupXslMessage)
1463
{
1464
    XsltProcessor *xsltProcessor;
1465
    bool show = false;
1466 ead48a5d O'Neil Delpratt
    char * filename = nullptr;
1467 72bf04c6 Norman Walsh
    size_t len1;
1468
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename &len1) == FAILURE) {
1469
        RETURN_NULL();
1470
    }
1471
1472
    zend_object* pobj = Z_OBJ_P(getThis());
1473
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1474
    xsltProcessor = obj->xsltProcessor;
1475
1476 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1477 72bf04c6 Norman Walsh
1478
            xsltProcessor->setupXslMessage(show, filename);
1479
        }
1480
1481
}
1482
1483
1484
1485
PHP_METHOD(XsltProcessor, exceptionOccurred)
1486
{
1487
    XsltProcessor *xsltProcessor;
1488
    zend_object* pobj = Z_OBJ_P(getThis()); 
1489
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1490
    if (ZEND_NUM_ARGS()>0) {
1491
        WRONG_PARAM_COUNT;
1492
    }
1493
1494
    xsltProcessor = obj->xsltProcessor;
1495 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1496 72bf04c6 Norman Walsh
        bool result = xsltProcessor->exceptionOccurred();
1497
        RETURN_BOOL(result);
1498
    }
1499
    RETURN_BOOL(false);
1500
}
1501
1502
PHP_METHOD(XsltProcessor, getExceptionCount)
1503
{
1504
    XsltProcessor *xsltProcessor;
1505
    zend_object* pobj = Z_OBJ_P(getThis()); 
1506
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1507
    if (ZEND_NUM_ARGS()>0) {
1508
        WRONG_PARAM_COUNT;
1509
    }
1510
1511
    xsltProcessor = obj->xsltProcessor;
1512 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1513 72bf04c6 Norman Walsh
        int count = xsltProcessor->exceptionCount();
1514
        RETURN_LONG(count);
1515
    }
1516
    RETURN_LONG(0);
1517
}
1518
1519
PHP_METHOD(XsltProcessor, getErrorCode)
1520
{
1521
    XsltProcessor *xsltProcessor;
1522
    long index;
1523
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1524
        RETURN_NULL();
1525
    }
1526
    zend_object* pobj = Z_OBJ_P(getThis()); 
1527
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1528
    xsltProcessor = obj->xsltProcessor;
1529 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1530 72bf04c6 Norman Walsh
        const char * errCode = xsltProcessor->getErrorCode((int)index);
1531 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
1532 72bf04c6 Norman Walsh
            //char *str = estrdup(errCode);
1533
            _RETURN_STRING(errCode);
1534
        }
1535
    }
1536
    RETURN_NULL();
1537
}
1538
1539
PHP_METHOD(XsltProcessor, getErrorMessage)
1540
{
1541
    XsltProcessor *xsltProcessor;
1542
    long index;
1543
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1544
        RETURN_NULL();
1545
    }
1546
    zend_object* pobj = Z_OBJ_P(getThis()); 
1547
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1548
    xsltProcessor = obj->xsltProcessor;
1549 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1550 72bf04c6 Norman Walsh
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1551 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
1552 72bf04c6 Norman Walsh
            //char *str = estrdup(errStr);
1553
            _RETURN_STRING(errStr);
1554
        }
1555
    }
1556
    RETURN_NULL();
1557
}
1558
PHP_METHOD(XsltProcessor, exceptionClear)
1559
{
1560
    XsltProcessor *xsltProcessor;
1561
    zend_object* pobj = Z_OBJ_P(getThis()); 
1562
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1563
    xsltProcessor = obj->xsltProcessor;
1564 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1565 72bf04c6 Norman Walsh
        xsltProcessor->exceptionClear();
1566
    }
1567
}
1568
1569
1570
1571
/*     ============== XSLT30: PHP Interface of  Xslt30Processor class =============== */
1572
1573
void Xslt30Processor_free_storage(zend_object *object)
1574
{
1575
1576
    zend_object_std_dtor(object);
1577
1578
}
1579
1580
void Xslt30Processor_destroy_storage(zend_object *object)
1581
{
1582
    xslt30Processor_object *obj;
1583
1584
    zend_objects_destroy_object(object);
1585
}
1586
1587
zend_object * xslt30Processor_create_handler(zend_class_entry *type)
1588
{
1589
1590
1591
    xslt30Processor_object *obj = (xslt30Processor_object *)ecalloc(1, sizeof(xslt30Processor_object)+ zend_object_properties_size(type));
1592
1593
1594
   zend_object_std_init(&obj->std,type);
1595
    object_properties_init(&obj->std, type);
1596
1597
    obj->std.handlers = &xslt30Processor_object_handlers;
1598
1599
    return &obj->std;
1600
}
1601
1602
1603
1604
PHP_METHOD(Xslt30Processor, __destruct)
1605
{
1606
1607
    zend_object* pobj = Z_OBJ_P(getThis());
1608
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1609
1610
1611
    Xslt30Processor * xslt30Processor= obj->xslt30Processor;
1612 ead48a5d O'Neil Delpratt
    if(xslt30Processor != nullptr){
1613 72bf04c6 Norman Walsh
            delete xslt30Processor;
1614
     }
1615
1616
1617
}
1618
1619
1620
PHP_METHOD(Xslt30Processor, setBaseOutputURI)
1621
{
1622
    Xslt30Processor *xslt30Processor;
1623 ead48a5d O'Neil Delpratt
    char * baseOutputURI = nullptr;
1624 72bf04c6 Norman Walsh
    size_t len1;
1625
1626
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &len1) == FAILURE) {
1627
        RETURN_NULL();
1628
    }
1629
1630
    zend_object* pobj = Z_OBJ_P(getThis());
1631
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1632
    xslt30Processor = obj->xslt30Processor;
1633 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr && baseOutputURI != nullptr) {
1634 72bf04c6 Norman Walsh
1635
         xslt30Processor->setBaseOutputURI(baseOutputURI);
1636
1637
1638
    }
1639
}
1640
1641
1642
1643
PHP_METHOD(Xslt30Processor, callFunctionReturningValue)
1644
{
1645
//arguments: const char * stylesheetFilename, const char* functionName, XdmValue * arguments, int argument_length
1646
1647
    Xslt30Processor *xslt30Processor;
1648
    HashTable *arr_hash;
1649
    char* functionName;
1650
    zval * arguments_zval;
1651
    zval * val;
1652
    long num_key;
1653 ead48a5d O'Neil Delpratt
    XdmValue ** arguments = nullptr;
1654 72bf04c6 Norman Walsh
    int argument_length=0;
1655
    zend_string *key;
1656
1657
    char * infilename;
1658 ead48a5d O'Neil Delpratt
    char * styleFileName = nullptr;
1659 72bf04c6 Norman Walsh
    size_t len1, len2;
1660
1661
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len2, &arguments_zval) == FAILURE) {
1662
        RETURN_NULL();
1663
    } else if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssa", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1664
        RETURN_NULL();
1665
    }
1666
1667
    zend_object* pobj = Z_OBJ_P(getThis());
1668
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1669
    xslt30Processor = obj->xslt30Processor;
1670
    arr_hash = Z_ARRVAL_P(arguments_zval);
1671
    argument_length = zend_hash_num_elements(arr_hash);
1672
   
1673
    arguments = new XdmValue*[argument_length];
1674
      
1675 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1676 72bf04c6 Norman Walsh
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1677 ead48a5d O'Neil Delpratt
        if(Z_TYPE_P(val) != nullptr) {
1678 72bf04c6 Norman Walsh
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1679
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1680
        php_printf("num_key %d =>", num_key);
1681
        php_printf("key %d =>", key);
1682
        */
1683
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1684
                zend_object* ooth = Z_OBJ_P(val);
1685
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1686 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1687 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1688
                            arguments[num_key] = value;
1689
                }
1690
        }
1691
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1692
                zend_object* ooth = Z_OBJ_P(val);
1693
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1694 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1695 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1696
                            arguments[num_key] = value;
1697
                }
1698
        }
1699
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1700
                zend_object* ooth = Z_OBJ_P(val);
1701
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1702 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1703 72bf04c6 Norman Walsh
                            XdmValue * value = nobj->xdmValue;
1704
                            arguments[num_key] = value;
1705
                }
1706
        }
1707
        else {//TODO error warning}
1708
         }}else {
1709
                //TODO error warning
1710
        }
1711
      } ZEND_HASH_FOREACH_END();
1712
1713
1714
        //php_printf(" argument_length= %d",argument_length);
1715
        XdmValue * result = xslt30Processor->callFunctionReturningValue(styleFileName, functionName, arguments, argument_length);
1716 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1717 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1718
                RETURN_NULL();
1719
            } else {
1720
                zend_object *ooth =  Z_OBJ_P(return_value);
1721
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
1722
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1723 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1724 72bf04c6 Norman Walsh
                vobj->xdmValue = result;
1725
            }
1726
        } else {
1727
            if(obj->xslt30Processor->exceptionOccurred()){
1728
                  //TODO
1729
            }
1730
            RETURN_NULL();
1731
        }
1732
    }
1733
1734
1735
}
1736
1737
PHP_METHOD(Xslt30Processor, callFunctionReturningString){
1738
    Xslt30Processor *xslt30Processor;
1739
    HashTable *arr_hash;
1740
    char* functionName;
1741
    zval * arguments_zval;
1742
    zval * val;
1743
    long num_key;
1744 ead48a5d O'Neil Delpratt
    XdmValue ** arguments = nullptr;
1745 72bf04c6 Norman Walsh
    int argument_length=0;
1746
    zend_string *key;
1747
1748
    char * infilename;
1749 ead48a5d O'Neil Delpratt
    char * styleFileName = nullptr;
1750 72bf04c6 Norman Walsh
    size_t len1, len2;
1751
1752
     if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len2, &arguments_zval) == FAILURE) {
1753
        RETURN_NULL();
1754
      }else if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssa", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1755
        RETURN_NULL();
1756
    }
1757
1758
    zend_object* pobj = Z_OBJ_P(getThis());
1759
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1760
    xslt30Processor = obj->xslt30Processor;
1761
    arr_hash = Z_ARRVAL_P(arguments_zval);
1762
    argument_length = zend_hash_num_elements(arr_hash);
1763
   
1764
    arguments = new XdmValue*[argument_length];
1765
      
1766 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1767 72bf04c6 Norman Walsh
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1768 ead48a5d O'Neil Delpratt
        if(Z_TYPE_P(val) != nullptr) {
1769 72bf04c6 Norman Walsh
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1770
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1771
        php_printf("num_key %d =>", num_key);
1772
        php_printf("key %d =>", key);
1773
        */
1774
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1775
                zend_object* ooth = Z_OBJ_P(val);
1776
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1777 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1778 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1779
                            arguments[num_key] = value;
1780
                }
1781
        }
1782
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1783
                zend_object* ooth = Z_OBJ_P(val);
1784
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1785 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1786 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1787
                            arguments[num_key] = value;
1788
                }
1789
        }
1790
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1791
                zend_object* ooth = Z_OBJ_P(val);
1792
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1793 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1794 72bf04c6 Norman Walsh
                            XdmValue * value = nobj->xdmValue;
1795
                            arguments[num_key] = value;
1796
                }
1797
        }
1798
        else {//TODO error warning}
1799
         }}else {
1800
                //TODO error warning
1801
        }
1802
      } ZEND_HASH_FOREACH_END();
1803
1804
        const char * result = xslt30Processor->callFunctionReturningString(styleFileName, functionName, arguments, argument_length);
1805 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1806 72bf04c6 Norman Walsh
            //char *str = estrdup(result);
1807
            _RETURN_STRING(result);
1808
        } else if(xslt30Processor->exceptionOccurred()){
1809
            //TODO: xslt30Processor->checkException();
1810
            const char * errStr = xslt30Processor->getErrorMessage(0);
1811 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
1812 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
1813 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
1814 72bf04c6 Norman Walsh
                    // TODO: throw exception
1815
                }
1816
            }
1817
        }
1818
    }
1819
1820
1821
1822
}
1823
1824
1825
    PHP_METHOD(Xslt30Processor, callFunctionReturningFile){
1826
    HashTable *arr_hash;
1827
    Xslt30Processor *xslt30Processor;
1828
    char* functionName;
1829
    zval * arguments_zval;
1830
    zval * val;
1831
    long num_key;
1832 ead48a5d O'Neil Delpratt
    XdmValue ** arguments = nullptr;
1833 72bf04c6 Norman Walsh
    int argument_length=0;
1834
    zend_string *key;
1835
1836
    char * outfilename;
1837 ead48a5d O'Neil Delpratt
    char * styleFileName = nullptr;
1838 72bf04c6 Norman Walsh
    size_t len1, len2, len3;
1839
1840
1841
    if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "sas", &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
1842
        RETURN_NULL();
1843
    } else if (ZEND_NUM_ARGS()==4 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssas", &styleFileName, &len1, &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
1844
        RETURN_NULL();
1845
    }
1846
1847
    zend_object* pobj = Z_OBJ_P(getThis());
1848
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1849
    xslt30Processor = obj->xslt30Processor;
1850
    arr_hash = Z_ARRVAL_P(arguments_zval);
1851
    argument_length = zend_hash_num_elements(arr_hash);
1852
   
1853
    arguments = new XdmValue*[argument_length];
1854
      
1855 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1856 72bf04c6 Norman Walsh
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
1857 ead48a5d O'Neil Delpratt
        if(Z_TYPE_P(val) != nullptr) {
1858 72bf04c6 Norman Walsh
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
1859
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1860
        php_printf("num_key %d =>", num_key);
1861
        php_printf("key %d =>", key);
1862
        */
1863
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1864
                zend_object* ooth = Z_OBJ_P(val);
1865
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1866 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1867 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1868
                            arguments[num_key] = value;
1869
                }
1870
        }
1871
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1872
                zend_object* ooth = Z_OBJ_P(val);
1873
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1874 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1875 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1876
                            arguments[num_key] = value;
1877
                }
1878
        }
1879
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1880
                zend_object* ooth = Z_OBJ_P(val);
1881
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1882 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1883 72bf04c6 Norman Walsh
                            XdmValue * value = nobj->xdmValue;
1884
                            arguments[num_key] = value;
1885
                }
1886
        }
1887
        else {//TODO error warning}
1888
         }}else {
1889
                //TODO error warning
1890
        }
1891
      } ZEND_HASH_FOREACH_END();
1892
1893
1894
        xslt30Processor->callFunctionReturningFile(styleFileName, functionName, arguments, argument_length, outfilename);
1895
        if(xslt30Processor->exceptionOccurred()){
1896
            //TODO: xslt30Processor->checkException();
1897
            const char * errStr = xslt30Processor->getErrorMessage(0);
1898 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
1899 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
1900
            }
1901
        }
1902
    }
1903
1904
}
1905
1906
    PHP_METHOD(Xslt30Processor, callTemplateReturningValue){
1907
1908
  Xslt30Processor *xslt30Processor;
1909 ead48a5d O'Neil Delpratt
    char* templateName = nullptr;
1910 72bf04c6 Norman Walsh
   
1911 ead48a5d O'Neil Delpratt
    char * styleFileName = nullptr;
1912 72bf04c6 Norman Walsh
    size_t len1, len2;
1913
1914
1915
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
1916
        RETURN_NULL();
1917
    } else if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1918
        RETURN_NULL();
1919
    }
1920
1921
1922
    zend_object* pobj = Z_OBJ_P(getThis());
1923
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1924
    xslt30Processor = obj->xslt30Processor;
1925
      
1926 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1927 72bf04c6 Norman Walsh
   
1928
1929
        //php_printf(" argument_length= %d",argument_length);
1930
        XdmValue * result = xslt30Processor->callTemplateReturningValue(styleFileName, templateName);
1931 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1932 72bf04c6 Norman Walsh
 
1933
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) { 
1934
               RETURN_NULL();
1935
            } else {
1936
                zend_object *ooth =  Z_OBJ_P(return_value);
1937
              
1938
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1939 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1940 72bf04c6 Norman Walsh
                vobj->xdmValue = result;
1941
                
1942
            }
1943
        } else {
1944
            if(obj->xslt30Processor->exceptionOccurred()){
1945
                  //TODO
1946
            }
1947
            RETURN_NULL();
1948
        }
1949
    }
1950
   }
1951
1952
1953
    PHP_METHOD(Xslt30Processor, callTemplateReturningString){
1954
    Xslt30Processor *xslt30Processor;
1955 ead48a5d O'Neil Delpratt
    char* templateName = nullptr;
1956 72bf04c6 Norman Walsh
   
1957 ead48a5d O'Neil Delpratt
    char * styleFileName = nullptr;
1958 72bf04c6 Norman Walsh
    size_t len1, len2;
1959
1960
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
1961
        RETURN_NULL();
1962
    }
1963
1964
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1965
        RETURN_NULL();
1966
    }
1967
1968
    zend_object* pobj = Z_OBJ_P(getThis());
1969
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
1970
    xslt30Processor = obj->xslt30Processor;
1971
      
1972 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1973 72bf04c6 Norman Walsh
   
1974
1975
        //php_printf(" argument_length= %d",argument_length);
1976
        const char * result = xslt30Processor->callTemplateReturningString(styleFileName, templateName);
1977 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1978 72bf04c6 Norman Walsh
            _RETURN_STRING(result); 
1979
        } else {
1980
            if(xslt30Processor->exceptionOccurred()){
1981
            xslt30Processor->checkException();
1982
            const char * errStr = xslt30Processor->getErrorMessage(0);
1983 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
1984 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
1985 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
1986 72bf04c6 Norman Walsh
                    // TODO: throw exception
1987
                }
1988
            }
1989
           }
1990
        }
1991
    }
1992
1993
     RETURN_NULL();
1994
    }
1995
1996
    PHP_METHOD(Xslt30Processor, callTemplateReturningFile){
1997
   Xslt30Processor *xslt30Processor;
1998 ead48a5d O'Neil Delpratt
    char* templateName = nullptr;
1999
    char * filename = nullptr;
2000
    char * styleFileName = nullptr;
2001 72bf04c6 Norman Walsh
    size_t len1, len2, len3;
2002
2003
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
2004
        RETURN_NULL();
2005
    }
2006
2007
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
2008
        RETURN_NULL();
2009
    }
2010
2011
    zend_object* pobj = Z_OBJ_P(getThis());
2012
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2013
    xslt30Processor = obj->xslt30Processor;
2014
      
2015 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2016 72bf04c6 Norman Walsh
           xslt30Processor->callTemplateReturningFile(styleFileName, templateName, filename);
2017
    }
2018
2019
  }
2020
2021
2022
PHP_METHOD(Xslt30Processor, applyTemplatesReturningValue){
2023
   Xslt30Processor *xslt30Processor;
2024 ead48a5d O'Neil Delpratt
    char * styleFileName = nullptr;
2025 72bf04c6 Norman Walsh
    size_t len1;
2026
2027
    if (ZEND_NUM_ARGS()>0) {
2028
2029
      if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &styleFileName, &len1) == FAILURE) {
2030
          RETURN_NULL();
2031
      }
2032
    }
2033
2034
    zend_object* pobj = Z_OBJ_P(getThis());
2035
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2036
    xslt30Processor = obj->xslt30Processor;
2037
      
2038 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2039 72bf04c6 Norman Walsh
           XdmValue * result = xslt30Processor->applyTemplatesReturningValue(styleFileName);
2040
    
2041 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
2042 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2043
                RETURN_NULL();
2044
            } else {
2045
                zend_object *ooth =  Z_OBJ_P(return_value);
2046
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2047 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2048 72bf04c6 Norman Walsh
                vobj->xdmValue = result;
2049
            }
2050
        } else {
2051
            if(obj->xslt30Processor->exceptionOccurred()){
2052
                  //TODO
2053
            }
2054
            RETURN_NULL();
2055
        }
2056
2057
2058
2059
    } else {
2060
     RETURN_NULL();
2061
    }
2062
}
2063
2064
2065
PHP_METHOD(Xslt30Processor, applyTemplatesReturningString){
2066
 Xslt30Processor *xslt30Processor;
2067
2068 ead48a5d O'Neil Delpratt
    char * styleFileName = nullptr;
2069 72bf04c6 Norman Walsh
    size_t len1;
2070
2071
2072
    if (ZEND_NUM_ARGS()>0) {
2073
    
2074
            if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &styleFileName, &len1) == FAILURE) {
2075
                RETURN_NULL();
2076
            }
2077
    }
2078
2079
    zend_object* pobj = Z_OBJ_P(getThis());
2080
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2081
    xslt30Processor = obj->xslt30Processor;
2082
      
2083 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2084 72bf04c6 Norman Walsh
        const char * result = xslt30Processor->applyTemplatesReturningString(styleFileName);
2085
   
2086 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
2087 72bf04c6 Norman Walsh
            _RETURN_STRING(result); 
2088
        } else {
2089
            if(xslt30Processor->exceptionOccurred()){
2090
            xslt30Processor->checkException();
2091
            const char * errStr = xslt30Processor->getErrorMessage(0);
2092 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
2093 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
2094 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
2095 72bf04c6 Norman Walsh
                    // TODO: throw exception
2096
                }
2097
            }
2098
           }
2099
        }
2100
    }
2101
2102
     RETURN_NULL();
2103
   
2104
2105
2106
}
2107
2108
2109
2110
PHP_METHOD(Xslt30Processor, applyTemplatesReturningFile){
2111
 Xslt30Processor *xslt30Processor;
2112 ead48a5d O'Neil Delpratt
    char * filename = nullptr;
2113
    char * styleFileName = nullptr;
2114 72bf04c6 Norman Walsh
    size_t len1, len2;
2115
2116
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &filename, &len2) == FAILURE) {
2117
          RETURN_NULL();
2118
    }
2119
2120
   if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &filename, &len2) == FAILURE) {
2121
          RETURN_NULL();
2122
    }
2123
    
2124
2125
    zend_object* pobj = Z_OBJ_P(getThis());
2126
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2127
    xslt30Processor = obj->xslt30Processor;
2128
      
2129 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2130 72bf04c6 Norman Walsh
           xslt30Processor->applyTemplatesReturningFile(styleFileName, filename);
2131
    }
2132
2133
2134
2135
}
2136
2137
2138
/*PHP_METHOD(Xslt30Processor, addPackages){
2139
    HashTable *arr_hash;
2140
    Xslt30Processor *xslt30Processor;
2141 ead48a5d O'Neil Delpratt
    char* functionName = nullptr;
2142 72bf04c6 Norman Walsh
    zval * arguments_zval;
2143
    zval * val;
2144
    long num_key;
2145 ead48a5d O'Neil Delpratt
    const char ** arguments = nullptr;
2146 72bf04c6 Norman Walsh
    int argument_length=0;
2147
    zend_string *key;
2148

2149 ead48a5d O'Neil Delpratt
    char * infilename = nullptr;
2150
    char * styleFileName = nullptr;
2151 72bf04c6 Norman Walsh
    size_t len1, len2;
2152

2153
        if (zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
2154
        RETURN_NULL();
2155
    }
2156

2157
    zend_object* pobj = Z_OBJ_P(getThis());
2158
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2159
    xslt30Processor = obj->xslt30Processor;
2160
    arr_hash = Z_ARRVAL_P(arguments_zval);
2161
    argument_length = zend_hash_num_elements(arr_hash);
2162
   
2163
    arguments = new const char*[argument_length];
2164

2165 ead48a5d O'Neil Delpratt
  if (xslt30Processor != nullptr) {
2166 72bf04c6 Norman Walsh
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
2167 ead48a5d O'Neil Delpratt
        if(Z_TYPE_P(val) != nullptr && Z_TYPE_P(val)== IS_STRING) {
2168 72bf04c6 Norman Walsh

2169
                arguments[num_key] = (const char*)Z_STRVAL_P(val);
2170
                     
2171
        } 
2172
    }  ZEND_HASH_FOREACH_END();
2173

2174
        xslt30Processor->addPackages(arguments, argument_length);
2175
        if(xslt30Processor->exceptionOccurred()){
2176
            //TODO: xslt30Processor->checkException();
2177
            const char * errStr = xslt30Processor->getErrorMessage(0);
2178 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
2179 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
2180
            }
2181
        }
2182
    }
2183
}    */
2184
2185
2186
    PHP_METHOD(Xslt30Processor,setInitialTemplateParameters){
2187
2188
  Xslt30Processor *xslt30Processor;
2189
    HashTable *arr_hash;
2190
    zval * arguments_zval;
2191
    zval * val;
2192
    long num_key;
2193
    XdmValue ** arguments;
2194
    int argument_length=0;
2195
    zend_string *key;
2196
2197
    bool tunnel = false;
2198
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
2199
        RETURN_NULL();
2200
    }
2201
2202
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ab", &arguments_zval, &tunnel) == FAILURE) {
2203
        RETURN_NULL();
2204
    }
2205
2206
2207
    zend_object* pobj = Z_OBJ_P(getThis());
2208
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2209
    xslt30Processor = obj->xslt30Processor;
2210
    arr_hash = Z_ARRVAL_P(arguments_zval);
2211
    argument_length = zend_hash_num_elements(arr_hash);
2212
   
2213
    arguments = new XdmValue*[argument_length];
2214
    std::map<std::string,XdmValue*> parameters;
2215 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2216 72bf04c6 Norman Walsh
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
2217 ead48a5d O'Neil Delpratt
        if(Z_TYPE_P(val) != nullptr) {
2218 72bf04c6 Norman Walsh
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
2219
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
2220
        php_printf("num_key %d =>", num_key);
2221
        php_printf("key %d =>", key);
2222
        */
2223
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2224
                zend_object* ooth = Z_OBJ_P(val);
2225
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
2226 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
2227 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
2228
                            parameters[ZSTR_VAL(key)] = value;
2229
                }
2230
        }
2231
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2232
                zend_object* ooth = Z_OBJ_P(val);
2233
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
2234 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
2235 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
2236
                            parameters[ZSTR_VAL(key)] = value;
2237
                }
2238
        }
2239
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
2240
                zend_object* ooth = Z_OBJ_P(val);
2241
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2242 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
2243 72bf04c6 Norman Walsh
                            XdmValue * value = nobj->xdmValue;
2244
                            parameters[ZSTR_VAL(key)] = value;
2245
                }
2246
        }
2247
        else {//TODO error warning}
2248
         }}else {
2249
                //TODO error warning
2250
        }
2251
      } ZEND_HASH_FOREACH_END();
2252
2253
2254
        //php_printf(" argument_length= %d",argument_length);
2255
        xslt30Processor->setInitialTemplateParameters(parameters, tunnel);
2256
        
2257
    }
2258
2259
    }
2260
2261
2262
PHP_METHOD(Xslt30Processor, setInitialMatchSelection){
2263
   Xslt30Processor *xslt30Processor;
2264 ead48a5d O'Neil Delpratt
    zval* oth = nullptr;
2265 72bf04c6 Norman Walsh
2266
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2267
        RETURN_NULL();
2268
    }
2269
2270
    zend_object* pobj = Z_OBJ_P(getThis());
2271
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2272
    xslt30Processor = obj->xslt30Processor;
2273 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2274 72bf04c6 Norman Walsh
2275
    if(!oth) {
2276
        php_error(E_WARNING, "Error setting source value");
2277
        return;
2278
    } else {
2279
        if(Z_TYPE_P(oth) ==IS_NULL){
2280 ead48a5d O'Neil Delpratt
                php_error(E_WARNING, "Error setting source value - nullptr found");
2281 72bf04c6 Norman Walsh
                return;
2282
        }
2283
2284
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2285
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2286
2287
      
2288
      if(strcmp(objName, "Saxon\\XdmValue")==0) {
2289
        zend_object * nobj = Z_OBJ_P(oth);
2290
2291
        xdmValue_object* ooth = (xdmValue_object *)((char *)nobj - XtOffsetOf(xdmValue_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2292 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2293 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
2294 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2295 72bf04c6 Norman Walsh
                xslt30Processor->setInitialMatchSelection(value);
2296
2297
            }
2298
        }
2299
      } else if(strcmp(objName, "Saxon\\XdmNode")==0) {
2300
        zend_object * nobj = Z_OBJ_P(oth);
2301
2302
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2303 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2304 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2305 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2306 72bf04c6 Norman Walsh
                XdmValue  *valueX = (XdmValue*)value;
2307
                xslt30Processor->setInitialMatchSelection(valueX);
2308
2309
            } else {
2310
2311
php_error(E_WARNING, "XdmNode - seInitialMatchSelection - cp1");
2312
}
2313
        }
2314
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2315
        zend_object* vvobj = Z_OBJ_P(oth);
2316
2317
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2318 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2319 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2320 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2321 72bf04c6 Norman Walsh
                xslt30Processor->setInitialMatchSelection((XdmValue*)value);
2322
            }
2323
        }
2324
      } else {
2325
        //TODO raise warning
2326
        }
2327
2328
2329
    }
2330
  }
2331
2332
2333
2334
2335
}
2336
    
2337
2338
PHP_METHOD(Xslt30Processor, setGlobalContextItem)
2339
{
2340
    Xslt30Processor *xslt30Processor;
2341 ead48a5d O'Neil Delpratt
    zval* oth = nullptr;
2342 72bf04c6 Norman Walsh
2343
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2344
        RETURN_NULL();
2345
    }
2346
2347
    zend_object* pobj = Z_OBJ_P(getThis());
2348
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2349
    xslt30Processor = obj->xslt30Processor;
2350 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2351 72bf04c6 Norman Walsh
2352
    if(!oth) {
2353
        php_error(E_WARNING, "Error setting source value");
2354
        return;
2355
    } else {
2356
        if(Z_TYPE_P(oth) ==IS_NULL){
2357
                php_error(E_WARNING, "Error setting source value");
2358
                return;
2359
        }
2360
2361
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2362
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2363
2364
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2365
        zend_object * nobj = Z_OBJ_P(oth);
2366
2367
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2368 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2369 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2370 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2371 72bf04c6 Norman Walsh
                XdmItem  *valueX = (XdmItem*)value;
2372
                xslt30Processor->setGlobalContextItem(valueX);
2373
2374
            }
2375
        }
2376
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2377
        zend_object* vvobj = Z_OBJ_P(oth);
2378
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2379 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2380 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2381 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2382 72bf04c6 Norman Walsh
                xslt30Processor->setGlobalContextItem((XdmItem*)value);
2383
            }
2384
        }
2385
      } else {
2386
        //TODO raise warning
2387
        }
2388
2389
2390
    }
2391
  }
2392
}
2393
2394
2395
PHP_METHOD(Xslt30Processor, setGlobalContextFromFile)
2396
{
2397
    Xslt30Processor *xslt30Processor;
2398 ead48a5d O'Neil Delpratt
    char * inFilename = nullptr;
2399 72bf04c6 Norman Walsh
    size_t len1;
2400
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2401
        RETURN_NULL();
2402
    }
2403
2404
    zend_object* pobj = Z_OBJ_P(getThis());
2405
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2406
    xslt30Processor = obj->xslt30Processor;
2407 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr && inFilename != nullptr) {
2408 72bf04c6 Norman Walsh
         xslt30Processor->setGlobalContextFromFile(inFilename);
2409
2410
2411
    }
2412
}
2413
2414
2415
PHP_METHOD(Xslt30Processor, setInitialMatchSelectionAsFile)
2416
{
2417
    Xslt30Processor *xslt30Processor;
2418 ead48a5d O'Neil Delpratt
    char * inFilename = nullptr;
2419 72bf04c6 Norman Walsh
    size_t len1;
2420
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2421
        RETURN_NULL();
2422
    }
2423
2424
    zend_object* pobj = Z_OBJ_P(getThis());
2425
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2426
    xslt30Processor = obj->xslt30Processor;
2427 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr && inFilename != nullptr) {
2428 72bf04c6 Norman Walsh
         xslt30Processor->setInitialMatchSelectionAsFile(inFilename);
2429
2430
2431
    }
2432
}
2433
2434
2435
PHP_METHOD(Xslt30Processor, transformFileToFile)
2436
{
2437
    Xslt30Processor *xslt30Processor;
2438 ead48a5d O'Neil Delpratt
    char * outfileName = nullptr;
2439
    char * infilename = nullptr;
2440
    char * styleFileName = nullptr;
2441 72bf04c6 Norman Walsh
    size_t len1, len2, len3;
2442
2443
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
2444
        RETURN_NULL();
2445
    }
2446
2447
    zend_object* pobj = Z_OBJ_P(getThis());
2448
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2449
    xslt30Processor = obj->xslt30Processor;
2450
2451 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2452 72bf04c6 Norman Walsh
2453
        xslt30Processor->transformFileToFile(infilename, styleFileName, outfileName);
2454
        if(xslt30Processor->exceptionOccurred()) {
2455
               // TODO: throw exception
2456
        }
2457
    }
2458
}
2459
2460
PHP_METHOD(Xslt30Processor, transformFileToValue)
2461
{
2462
    Xslt30Processor *xslt30Processor;
2463 ead48a5d O'Neil Delpratt
    char * infilename = nullptr;
2464
    char * styleFileName = nullptr;
2465 72bf04c6 Norman Walsh
   size_t len1, len2;
2466
2467
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2468
        RETURN_NULL();
2469
    }
2470
2471
    zend_object* pobj = Z_OBJ_P(getThis());
2472
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2473
    xslt30Processor = obj->xslt30Processor;
2474
2475 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2476 72bf04c6 Norman Walsh
2477
        XdmValue * node = xslt30Processor->transformFileToValue(infilename, styleFileName);
2478 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2479 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2480
                RETURN_NULL();
2481
            } else {
2482
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
2483
                zend_object *ooth =  Z_OBJ_P(return_value);
2484
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2485 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2486 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
2487
            }
2488
        } else {
2489
            if(obj->xslt30Processor->exceptionOccurred()){
2490
                  //TODO
2491
            }
2492
        }
2493
    }else {
2494
        RETURN_NULL();
2495
    }
2496
}
2497
2498
2499
PHP_METHOD(Xslt30Processor, transformFileToString)
2500
{
2501
    Xslt30Processor *xslt30Processor;
2502 ead48a5d O'Neil Delpratt
    char * infilename = nullptr;
2503
    char * styleFileName = nullptr;
2504 72bf04c6 Norman Walsh
    size_t len1, len2;
2505
2506
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2507
        RETURN_NULL();
2508
    }
2509
2510
    zend_object* pobj = Z_OBJ_P(getThis());
2511
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2512
    xslt30Processor = obj->xslt30Processor;
2513
2514 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2515 72bf04c6 Norman Walsh
2516
        const char * result = xslt30Processor->transformFileToString(infilename, styleFileName);
2517 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
2518 72bf04c6 Norman Walsh
            //char *str = estrdup(result);
2519
            _RETURN_STRING(result);
2520
        } else if(xslt30Processor->exceptionOccurred()){
2521
            //TODO: xslt30Processor->checkException();
2522
            const char * errStr = xslt30Processor->getErrorMessage(0);
2523 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
2524 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
2525 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
2526 72bf04c6 Norman Walsh
                    // TODO: throw exception
2527
                }
2528
            }
2529
        }
2530
    }
2531
}
2532
2533
2534
2535
PHP_METHOD(Xslt30Processor, transformToString)
2536
{
2537
    Xslt30Processor *xslt30Processor;
2538
2539
    if (ZEND_NUM_ARGS()>1) {
2540
        WRONG_PARAM_COUNT;
2541
    }
2542
2543
2544
    zval* oth;
2545
   
2546
2547 ead48a5d O'Neil Delpratt
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2548 72bf04c6 Norman Walsh
        RETURN_NULL();
2549
    }
2550
2551
2552
    zend_object* pobj = Z_OBJ_P(getThis());
2553
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2554
    xslt30Processor = obj->xslt30Processor;
2555 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2556
2557
2558
     if(ZEND_NUM_ARGS() == 0) {
2559
        const char * result = xslt30Processor->transformToString();
2560
        if(result != nullptr) {
2561
            _RETURN_STRING(result);
2562
            return;
2563
2564
        }
2565
2566
2567
     } else {
2568
        if(!oth) {
2569
            php_error(E_WARNING, "Error setting source value");
2570
            return;
2571
        }
2572
2573
            if(Z_TYPE_P(oth) ==IS_NULL){
2574
                    php_error(E_WARNING, "Error setting source value");
2575
                    return;
2576
            }
2577 72bf04c6 Norman Walsh
2578
        const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2579
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2580 ead48a5d O'Neil Delpratt
                zend_object * nobj = Z_OBJ_P(oth);
2581
2582
                xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2583
            if(ooth != nullptr) {
2584
                XdmNode * value = ooth->xdmNode;
2585
                if(value != nullptr) {
2586
                        const char * result = xslt30Processor->transformToString(value);
2587
                    if(result != nullptr) {
2588
                        _RETURN_STRING(result);
2589
                    }
2590 72bf04c6 Norman Walsh
                }
2591
2592 ead48a5d O'Neil Delpratt
            }
2593 72bf04c6 Norman Walsh
        }
2594 ead48a5d O'Neil Delpratt
     }
2595
    }
2596
2597 72bf04c6 Norman Walsh
    RETURN_NULL();
2598
}
2599
2600
PHP_METHOD(Xslt30Processor, transformToValue)
2601
{
2602
    Xslt30Processor *xslt30Processor;
2603
2604
    if (ZEND_NUM_ARGS()>1) {
2605
        WRONG_PARAM_COUNT;
2606
    }
2607
2608
2609
    zval* oth;
2610
   
2611
2612 ead48a5d O'Neil Delpratt
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2613 72bf04c6 Norman Walsh
        RETURN_NULL();
2614
    }
2615
2616
    zend_object* pobj = Z_OBJ_P(getThis());
2617
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2618
    xslt30Processor = obj->xslt30Processor;
2619
2620 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2621 72bf04c6 Norman Walsh
      if(!oth) {
2622
        php_error(E_WARNING, "Error setting source value");
2623
        return;
2624
      } else {
2625 ead48a5d O'Neil Delpratt
        XdmValue * node = nullptr;
2626
        if(ZEND_NUM_ARGS() == 0) {
2627
            XdmValue * node = xslt30Processor->transformToValue();
2628 72bf04c6 Norman Walsh
2629 ead48a5d O'Neil Delpratt
        } else {
2630
2631
            if(Z_TYPE_P(oth) == IS_NULL){
2632
                php_error(E_WARNING, "Error setting source value");
2633
                return;
2634 72bf04c6 Norman Walsh
            }
2635
2636 ead48a5d O'Neil Delpratt
            const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2637
2638
            if(strcmp(objName,"Saxon\\XdmNode")==0) {
2639
                zend_object *nobj = Z_OBJ_P(oth);
2640
2641
                xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
2642
                                           XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2643
                if(ooth != nullptr) {
2644
                    XdmNode *value = ooth->xdmNode;
2645
                    if(value != nullptr) {
2646
                        node = xslt30Processor->transformToValue(value);
2647
                    }
2648
                }
2649
            }
2650
        }
2651
        if(node != nullptr) {
2652
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2653
                RETURN_NULL();
2654
            } else {
2655
                zend_object *vvobj =  Z_OBJ_P(return_value);
2656
                        xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2657
                        assert (vobj != nullptr);
2658
                        vobj->xdmValue = node;
2659
                        return;
2660
            }
2661
        }
2662
      }
2663
2664
2665
2666
    } else {
2667 72bf04c6 Norman Walsh
        RETURN_NULL();
2668
    }
2669
}
2670
2671
PHP_METHOD(Xslt30Processor, transformToFile)
2672
{
2673
    Xslt30Processor *xslt30Processor;
2674
2675
    if (ZEND_NUM_ARGS()>1) {
2676
        WRONG_PARAM_COUNT;
2677
    }
2678
2679
2680
    zval* oth;
2681
   
2682
2683 ead48a5d O'Neil Delpratt
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2684 72bf04c6 Norman Walsh
        RETURN_NULL();
2685
    }
2686
2687
    zend_object* pobj = Z_OBJ_P(getThis());
2688
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2689
    xslt30Processor = obj->xslt30Processor;
2690
2691 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2692 72bf04c6 Norman Walsh
      if(!oth) {
2693
        php_error(E_WARNING, "Error setting source value");
2694
        return;
2695
      } else {
2696 ead48a5d O'Neil Delpratt
        if(ZEND_NUM_ARGS() == 0) {
2697
            xslt30Processor->transformToFile();
2698
        } else {
2699
            if(Z_TYPE_P(oth) == mIS_NULL){
2700
                php_error(E_WARNING,"Error setting source value");
2701
                return;
2702
            }
2703 72bf04c6 Norman Walsh
2704 ead48a5d O'Neil Delpratt
            const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2705 72bf04c6 Norman Walsh
2706 ead48a5d O'Neil Delpratt
            if(strcmp(objName,"Saxon\\XdmNode")==0) {
2707
                zend_object *nobj = Z_OBJ_P(oth);
2708
2709
                xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
2710
                                           XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2711
                if(ooth != nullptr) {
2712
                    XdmNode *value = ooth->xdmNode;
2713
                    if(value != nullptr) {
2714
                        xslt30Processor->transformToFile(value);
2715
                    }
2716 72bf04c6 Norman Walsh
                }
2717
            }
2718 ead48a5d O'Neil Delpratt
2719 72bf04c6 Norman Walsh
        }
2720
      }
2721
    }
2722
}
2723
2724
PHP_METHOD(Xslt30Processor, compileFromFile)
2725
{
2726
    Xslt30Processor *xslt30Processor;
2727 ead48a5d O'Neil Delpratt
    char * name = nullptr;
2728 72bf04c6 Norman Walsh
    size_t len1;
2729
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2730
        RETURN_NULL();
2731
    }
2732
    zend_object* pobj = Z_OBJ_P(getThis());
2733
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2734
    xslt30Processor = obj->xslt30Processor;
2735 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2736 72bf04c6 Norman Walsh
        xslt30Processor->compileFromFile(name);
2737
    }
2738
}
2739
2740
2741
PHP_METHOD(Xslt30Processor, compileFromAssociatedFile)
2742
{
2743
    Xslt30Processor *xslt30Processor;
2744 ead48a5d O'Neil Delpratt
    char * name = nullptr;
2745 72bf04c6 Norman Walsh
    size_t len1;
2746
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2747
        RETURN_NULL();
2748
    }
2749
    zend_object* pobj = Z_OBJ_P(getThis());
2750
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2751
    xslt30Processor = obj->xslt30Processor;
2752 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2753 72bf04c6 Norman Walsh
        xslt30Processor->compileFromAssociatedFile(name);
2754
    }
2755
}
2756
2757
2758
PHP_METHOD(Xslt30Processor, compileFromString)
2759
{
2760
    Xslt30Processor *xslt30Processor;
2761
    char * stylesheetStr;
2762
    size_t len1, myint;
2763
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
2764
        RETURN_NULL();
2765
    }
2766
    zend_object* pobj = Z_OBJ_P(getThis());
2767
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2768
    xslt30Processor = obj->xslt30Processor;
2769 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2770 72bf04c6 Norman Walsh
        xslt30Processor->compileFromString(stylesheetStr);
2771
    }
2772
}
2773
2774
PHP_METHOD(Xslt30Processor, compileFromStringAndSave)
2775
{
2776
    Xslt30Processor *xslt30Processor;
2777
    char * stylesheetStr;
2778 ead48a5d O'Neil Delpratt
    char * filename = nullptr;
2779 72bf04c6 Norman Walsh
    size_t len1, len2, myint;
2780
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetStr, filename, &len1, &len2) == FAILURE) {
2781
        RETURN_NULL();
2782
    }
2783
    zend_object* pobj = Z_OBJ_P(getThis());
2784
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2785
    xslt30Processor = obj->xslt30Processor;
2786 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2787 72bf04c6 Norman Walsh
        xslt30Processor->compileFromStringAndSave(stylesheetStr, filename);
2788
    }
2789
}
2790
2791
PHP_METHOD(Xslt30Processor, compileFromFileAndSave)
2792
{
2793
    Xslt30Processor *xslt30Processor;
2794 ead48a5d O'Neil Delpratt
    char * stylesheetFilename = nullptr;
2795
    char * filename = nullptr;
2796 72bf04c6 Norman Walsh
    size_t len1, len2, myint;
2797
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
2798
        RETURN_NULL();
2799
    }
2800
    zend_object* pobj = Z_OBJ_P(getThis());
2801
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2802
    xslt30Processor = obj->xslt30Processor;
2803 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2804 72bf04c6 Norman Walsh
        xslt30Processor->compileFromStringAndSave(stylesheetFilename, filename);
2805
    }
2806
}
2807
2808
2809
2810
PHP_METHOD(Xslt30Processor, compileFromValue)
2811
{
2812
    Xslt30Processor *xslt30Processor;
2813
   zval* oth;
2814
2815
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
2816
        RETURN_NULL();
2817
    }
2818
    zend_object* pobj = Z_OBJ_P(getThis());
2819
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2820
    xslt30Processor = obj->xslt30Processor;
2821 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2822 72bf04c6 Norman Walsh
        zend_object* vvobj = Z_OBJ_P(oth);
2823
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2824 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2825 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
2826 ead48a5d O'Neil Delpratt
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
2827 72bf04c6 Norman Walsh
                xslt30Processor->compileFromXdmNode((XdmNode*)(value->getHead()));
2828
            }
2829
        }
2830
    }
2831
}
2832
2833
2834
2835
PHP_METHOD(Xslt30Processor, setResultAsRawValue)
2836
{
2837
    Xslt30Processor *xslt30Processor;
2838
    bool raw = false;
2839
2840
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &raw) == FAILURE) {
2841
        RETURN_NULL();
2842
    }
2843
2844
    zend_object* pobj = Z_OBJ_P(getThis());
2845
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2846
    xslt30Processor = obj->xslt30Processor;
2847 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2848 72bf04c6 Norman Walsh
         xslt30Processor->setResultAsRawValue(raw);
2849
    }
2850
2851
}
2852
2853
2854
2855
PHP_METHOD(Xslt30Processor, setJustInTimeCompilation)
2856
{
2857
    Xslt30Processor *xslt30Processor;
2858
    bool jit = false;
2859
    size_t len1;
2860
2861
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
2862
        RETURN_NULL();
2863
    }
2864
2865
    zend_object* pobj = Z_OBJ_P(getThis());
2866
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2867
    xslt30Processor = obj->xslt30Processor;
2868 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2869 72bf04c6 Norman Walsh
         xslt30Processor->setJustInTimeCompilation(jit);
2870
    }
2871
}
2872
2873
PHP_METHOD(Xslt30Processor, setOutputFile)
2874
{
2875
    Xslt30Processor *xslt30Processor;
2876 ead48a5d O'Neil Delpratt
    char * outputFilename = nullptr;
2877 72bf04c6 Norman Walsh
    size_t len1;
2878
2879
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
2880
        RETURN_NULL();
2881
    }
2882
2883
    zend_object* pobj = Z_OBJ_P(getThis());
2884
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2885
    xslt30Processor = obj->xslt30Processor;
2886 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr && outputFilename != nullptr) {
2887 72bf04c6 Norman Walsh
2888
         xslt30Processor->setOutputFile(outputFilename);
2889
2890
2891
    }
2892
}
2893
2894
2895
2896
2897
PHP_METHOD(Xslt30Processor, setProperty)
2898
{
2899
    Xslt30Processor *xslt30Processor;
2900 ead48a5d O'Neil Delpratt
    char * name = nullptr;
2901 72bf04c6 Norman Walsh
    char * value;
2902
    size_t len1, len2, myint;
2903
2904
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
2905
        RETURN_NULL();
2906
    }
2907
    zend_object* pobj = Z_OBJ_P(getThis());
2908
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2909
    xslt30Processor = obj->xslt30Processor;
2910 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2911 72bf04c6 Norman Walsh
        xslt30Processor->setProperty(name, value);
2912
    }
2913
}
2914
2915
PHP_METHOD(Xslt30Processor, setParameter)
2916
{
2917
2918
   Xslt30Processor *xslt30Processor;
2919
   char * name;
2920
   zval* oth;
2921
   size_t len1, len2, myint;
2922
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
2923
        RETURN_NULL();
2924
    }
2925
    zend_object* pobj = Z_OBJ_P(getThis());
2926
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2927
    xslt30Processor = obj->xslt30Processor;
2928 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2929 72bf04c6 Norman Walsh
        if(Z_TYPE_P(oth) ==IS_NULL){
2930 ead48a5d O'Neil Delpratt
                php_error(E_WARNING, "Error setting source value - value is nullptr");
2931 72bf04c6 Norman Walsh
                return;
2932
        }
2933
2934
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2935
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2936
2937
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2938
        zend_object* ooth = Z_OBJ_P(oth);
2939
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
2940 ead48a5d O'Neil Delpratt
        if(nobj != nullptr) {
2941 72bf04c6 Norman Walsh
            XdmNode * value = nobj->xdmNode;
2942 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2943 72bf04c6 Norman Walsh
                xslt30Processor->setParameter(name, (XdmValue *)value);
2944
2945
            }
2946
        }
2947
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2948
        zend_object* ooth = Z_OBJ_P(oth);
2949
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2950 ead48a5d O'Neil Delpratt
        if(vobj != nullptr) {
2951 72bf04c6 Norman Walsh
            XdmValue * value = vobj->xdmValue;
2952 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2953 72bf04c6 Norman Walsh
2954
                xslt30Processor->setParameter(name, value);
2955
            }
2956
        }
2957
2958
2959
2960
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2961
        zend_object* ooth = Z_OBJ_P(oth);
2962
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
2963 ead48a5d O'Neil Delpratt
        if(aobj != nullptr) {
2964 72bf04c6 Norman Walsh
            XdmAtomicValue * value = aobj->xdmAtomicValue;
2965 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2966 72bf04c6 Norman Walsh
                xslt30Processor->setParameter(name, (XdmValue *)value);
2967
            }
2968
        }
2969
2970
2971
2972
      }
2973
2974
    }
2975
}
2976
2977
PHP_METHOD(Xslt30Processor, clearParameters)
2978
{
2979
    Xslt30Processor *xslt30Processor;
2980
    if (ZEND_NUM_ARGS()>0) {
2981
        WRONG_PARAM_COUNT;
2982
    }
2983
2984
    zend_object* pobj = Z_OBJ_P(getThis());
2985
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
2986
    xslt30Processor = obj->xslt30Processor;
2987 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2988 72bf04c6 Norman Walsh
        xslt30Processor->clearParameters(true);
2989
    }
2990
}
2991
2992
PHP_METHOD(Xslt30Processor, clearProperties)
2993
{
2994
    Xslt30Processor *xslt30Processor;
2995
    if (ZEND_NUM_ARGS()>0) {
2996
        WRONG_PARAM_COUNT;
2997
    }
2998
2999
    zend_object* pobj = Z_OBJ_P(getThis());
3000
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3001
    xslt30Processor = obj->xslt30Processor;
3002 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
3003 72bf04c6 Norman Walsh
        xslt30Processor->clearProperties();
3004
    }
3005
}
3006
3007
3008
PHP_METHOD(Xslt30Processor, setupXslMessage)
3009
{
3010
    Xslt30Processor *xslt30Processor;
3011
    bool show = false;
3012 ead48a5d O'Neil Delpratt
    char * filename = nullptr;
3013 72bf04c6 Norman Walsh
    size_t len1;
3014
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename &len1) == FAILURE) {
3015
        RETURN_NULL();
3016
    }
3017
3018
    zend_object* pobj = Z_OBJ_P(getThis());
3019
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3020
    xslt30Processor = obj->xslt30Processor;
3021
3022 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
3023 72bf04c6 Norman Walsh
3024
            xslt30Processor->setupXslMessage(show, filename);
3025
        }
3026
3027
}
3028
3029
3030
3031
PHP_METHOD(Xslt30Processor, exceptionOccurred)
3032
{
3033
    Xslt30Processor *xslt30Processor;
3034
    zend_object* pobj = Z_OBJ_P(getThis());
3035
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3036
    if (ZEND_NUM_ARGS()>0) {
3037
        WRONG_PARAM_COUNT;
3038
    }
3039
3040
    xslt30Processor = obj->xslt30Processor;
3041 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
3042 72bf04c6 Norman Walsh
        bool result = xslt30Processor->exceptionOccurred();
3043
        RETURN_BOOL(result);
3044
    }
3045
    RETURN_BOOL(false);
3046
}
3047
3048
PHP_METHOD(Xslt30Processor, getExceptionCount)
3049
{
3050
    Xslt30Processor *xslt30Processor;
3051
    zend_object* pobj = Z_OBJ_P(getThis());
3052
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3053
    if (ZEND_NUM_ARGS()>0) {
3054
        WRONG_PARAM_COUNT;
3055
    }
3056
3057
    xslt30Processor = obj->xslt30Processor;
3058 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
3059 72bf04c6 Norman Walsh
        int count = xslt30Processor->exceptionCount();
3060
        RETURN_LONG(count);
3061
    }
3062
    RETURN_LONG(0);
3063
}
3064
3065
PHP_METHOD(Xslt30Processor, getErrorCode)
3066
{
3067
    Xslt30Processor *xslt30Processor;
3068
    long index;
3069
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3070
        RETURN_NULL();
3071
    }
3072
    zend_object* pobj = Z_OBJ_P(getThis());
3073
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3074
    xslt30Processor = obj->xslt30Processor;
3075 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
3076 72bf04c6 Norman Walsh
        const char * errCode = xslt30Processor->getErrorCode((int)index);
3077 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
3078 72bf04c6 Norman Walsh
            //char *str = estrdup(errCode);
3079
            _RETURN_STRING(errCode);
3080
        }
3081
    }
3082
    RETURN_NULL();
3083
}
3084
3085
PHP_METHOD(Xslt30Processor, getErrorMessage)
3086
{
3087
    Xslt30Processor *xslt30Processor;
3088
    long index;
3089
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
3090
        RETURN_NULL();
3091
    }
3092
    zend_object* pobj = Z_OBJ_P(getThis());
3093
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3094
    xslt30Processor = obj->xslt30Processor;
3095 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
3096 72bf04c6 Norman Walsh
        const char * errStr = xslt30Processor->getErrorMessage((int)index);
3097 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
3098 72bf04c6 Norman Walsh
            //char *str = estrdup(errStr);
3099
            _RETURN_STRING(errStr);
3100
        }
3101
    }
3102
    RETURN_NULL();
3103
}
3104
PHP_METHOD(Xslt30Processor, exceptionClear)
3105
{
3106
    Xslt30Processor *xslt30Processor;
3107
    zend_object* pobj = Z_OBJ_P(getThis());
3108
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
3109