Project

Profile

Help

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

he / src / main / c / Saxon.C.API / php5_saxon.cpp @ 4ee4355d

1 72bf04c6 Norman Walsh
#ifdef HAVE_CONFIG_H
2
    #include "config.h"
3
#endif
4
5
#include "php5_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(void *object TSRMLS_DC)
45
{
46
 
47
    saxonProcessor_object *obj = (saxonProcessor_object *)object;
48
49
    zend_hash_destroy(obj->std.properties);
50
    FREE_HASHTABLE(obj->std.properties);
51
    efree(obj);
52
}
53
54
zend_object_value saxonProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
55
{
56
    zval *tmp;
57
    zend_object_value retval;
58
59
    saxonProcessor_object *obj = (saxonProcessor_object *)emalloc(sizeof(saxonProcessor_object));
60
    memset(obj, 0, sizeof(saxonProcessor_object));
61
    obj->std.ce = type;
62
63
    ALLOC_HASHTABLE(obj->std.properties);
64 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
65 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
66 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, SaxonProcessor_free_storage, nullptr TSRMLS_CC);
67 72bf04c6 Norman Walsh
    retval.handlers = &saxonProcessor_object_handlers;
68
69
    return retval;
70
}
71
72
PHP_METHOD(SaxonProcessor, __construct)
73
{
74
75
    if (ZEND_NUM_ARGS()>2) {
76
        WRONG_PARAM_COUNT;
77
    }
78
79 ead48a5d O'Neil Delpratt
    char * cwdi = nullptr;
80 72bf04c6 Norman Walsh
   bool license = false;
81
    int len1;
82
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &license) == FAILURE) {
83
        php_error(E_WARNING,"Wrong SaxonProcessor argument");
84 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
85 72bf04c6 Norman Walsh
    } 
86
87
88
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "bs", &license, &cwdi, &len1) == FAILURE) {
89
        php_error(E_WARNING,"Wrong SaxonProcessor arguments");
90 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
91 72bf04c6 Norman Walsh
    }
92
 
93
94
    zval *object = getThis();
95
    SaxonProcessor * saxonProc;
96
    saxonProcessor_object * obj = (saxonProcessor_object *)zend_object_store_get_object(object TSRMLS_CC);
97
    saxonProc =  obj->saxonProcessor;
98 ead48a5d O'Neil Delpratt
    if(saxonProc == nullptr) {
99 72bf04c6 Norman Walsh
100
        saxonProc = new SaxonProcessor(license); //TODO: add license flag to PHP function argument
101
102
        obj->saxonProcessor = saxonProc;
103
    }
104
105 ead48a5d O'Neil Delpratt
    if(cwdi==nullptr) {
106 72bf04c6 Norman Walsh
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
107
            TCHAR s[256];
108
109
            // --
110
            DWORD a = GetCurrentDirectory(256, s);
111
            const size_t newsize = wcslen(s)*2;
112
            char* cwd = new char[newsize];
113
            wcstombs_s(0, cwd, newsize, s, _TRUNCATE);
114
            // -- code above returns the apache installtion directory as the CWD
115
116
            char* cwd2;
117
118
            //php_error(E_WARNING,cwd2);
119
120
            saxonProc->setcwd(cwd2);
121
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
122
#else
123
124
            char cwd[256];
125
126
            VCWD_GETCWD(cwd, sizeof(cwd));
127 ead48a5d O'Neil Delpratt
            if(cwd == nullptr) {
128
             //php_error(E_WARNING,"cwd is nullptr");
129 72bf04c6 Norman Walsh
           }else {
130
             //php_error(E_WARNING,cwd);
131
132
            saxonProc->setcwd(cwd);
133
          }
134
#endif
135
136
    } else {
137
        saxonProc->setcwd(cwdi);
138
    }
139
140
}
141
142
PHP_METHOD(SaxonProcessor, __destruct)
143
{
144
    
145
    saxonProcessor_object *obj = (saxonProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
146
147
    SaxonProcessor * saxonProc= obj->saxonProcessor;
148
149
    delete saxonProc;
150
}
151
152
153
154
PHP_METHOD(SaxonProcessor, registerPHPFunctions)
155
{
156
    SaxonProcessor *saxonProcessor;
157
    char * libName;
158
    size_t len1;
159
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
160
    if (ZEND_NUM_ARGS()!= 1) {
161
        WRONG_PARAM_COUNT;
162
    }
163
164
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &libName, &len1) == FAILURE) {
165 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
166 72bf04c6 Norman Walsh
    }
167
//std::cerr<<"checkpoint in registerPHPFunction cp2"<<std::endl;
168
169
    saxonProcessor_object *obj = (saxonProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
170
171
    saxonProcessor = obj->saxonProcessor;
172 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr && libName != nullptr) {
173 72bf04c6 Norman Walsh
        saxonProcessor->setConfigurationProperty("extc", libName);
174
    }
175
    saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PHPFunction",
176
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
177
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
178
}
179
180
PHP_METHOD(SaxonProcessor, setResourcesDirectory)
181
{
182
    SaxonProcessor *saxonProcessor;
183
    char * dirStr;
184
    int len;
185
    
186
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dirStr, &len) == FAILURE) {
187 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
188 72bf04c6 Norman Walsh
    }
189
    
190
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
191
    saxonProcessor = obj->saxonProcessor;
192 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
193 72bf04c6 Norman Walsh
       
194 ead48a5d O'Neil Delpratt
        if(dirStr != nullptr) {
195 72bf04c6 Norman Walsh
            saxonProcessor->setResourcesDirectory(dirStr);
196
        }
197
    }
198
}
199
200
PHP_METHOD(SaxonProcessor, setCatalog)
201
{
202
    SaxonProcessor *saxonProcessor;
203
    char * catalogFile;
204
    size_t len;
205
    bool trace = false;
206
    
207
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC , "sb", &catalogFile, &len, &trace) == FAILURE) {
208 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
209 72bf04c6 Norman Walsh
    }
210
    
211
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
212
    saxonProcessor = obj->saxonProcessor;
213 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
214 72bf04c6 Norman Walsh
       
215 ead48a5d O'Neil Delpratt
        if(catalogFile != nullptr) {
216 72bf04c6 Norman Walsh
            saxonProcessor->setCatalog(catalogFile, trace);
217
        }
218
    }
219
}
220
221
222
PHP_METHOD(SaxonProcessor, setcwd)
223
{
224
    SaxonProcessor *saxonProcessor;
225
    char * cwdStr;
226
    int len;
227
    
228
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cwdStr, &len) == FAILURE) {
229 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
230 72bf04c6 Norman Walsh
    }
231
    
232
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
233
    saxonProcessor = obj->saxonProcessor;
234 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
235 72bf04c6 Norman Walsh
        
236 ead48a5d O'Neil Delpratt
        if(cwdStr != nullptr) {
237 72bf04c6 Norman Walsh
            saxonProcessor->setcwd(cwdStr);
238
        }
239
    }
240
}
241
242
243
PHP_METHOD(SaxonProcessor, parseXmlFromString)
244
{
245
    SaxonProcessor * saxonProcessor;
246
    char * source;
247
    int len1;
248
249
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &len1) == FAILURE) {
250 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
251 72bf04c6 Norman Walsh
    }
252
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
253 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
254 72bf04c6 Norman Walsh
    saxonProcessor = obj->saxonProcessor;
255 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
256 72bf04c6 Norman Walsh
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
257 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
258 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
259 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
260 72bf04c6 Norman Walsh
            } else {
261
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
262 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
263 72bf04c6 Norman Walsh
                vobj->xdmNode = node;
264
            }
265
        } else {
266
            if(obj->saxonProcessor->exceptionOccurred()){
267
                //TODO throw exception
268
            }
269
        }
270
    } else {
271 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
272 72bf04c6 Norman Walsh
    }
273
}
274
275
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
276
{
277
    SaxonProcessor * saxonProcessor;
278
    char * source;
279
    int len1;
280
281
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &len1) == FAILURE) {
282 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
283 72bf04c6 Norman Walsh
    }
284
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
285 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
286 72bf04c6 Norman Walsh
    saxonProcessor = obj->saxonProcessor;
287 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
288 72bf04c6 Norman Walsh
        XdmValue* node = (XdmValue*)saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
289 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
290 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
291 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
292 72bf04c6 Norman Walsh
            } else {
293
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
294 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
295 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
296
            }
297
        } else {
298
           // obj->xsltProcessor->checkException();//TODO
299
        }
300
    } else {
301 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
302 72bf04c6 Norman Walsh
    }
303
}
304
305
306
PHP_METHOD(SaxonProcessor, createAtomicValue)
307
{
308 ead48a5d O'Neil Delpratt
    XdmAtomicValue * xdmValue = nullptr;
309 72bf04c6 Norman Walsh
    SaxonProcessor * proc;
310
    char * source;
311
    int len1;
312
    zval *zvalue;
313
    bool bVal;
314
    char * sVal;
315
    int len;
316
    long iVal;
317
    double dVal;
318
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&zvalue) == FAILURE) {
319 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
320 72bf04c6 Norman Walsh
    }
321
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
322 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
323 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
324 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
325
    if (proc != nullptr) {
326 72bf04c6 Norman Walsh
        switch (Z_TYPE_P(zvalue)) {
327
            case IS_BOOL:
328
                bVal = Z_BVAL_P(zvalue);
329
                xdmValue = proc->makeBooleanValue((bool)bVal);
330
            break;
331
            case IS_LONG:
332
                iVal = Z_LVAL_P(zvalue);
333
                 xdmValue = proc->makeIntegerValue((int)iVal);
334
            break;
335
            case IS_STRING:
336
                sVal = Z_STRVAL_P(zvalue);
337
                len = Z_STRLEN_P(zvalue);
338
                xdmValue = proc->makeStringValue((const char*)sVal);
339
            break;
340 ead48a5d O'Neil Delpratt
            case IS_nullptr:
341 72bf04c6 Norman Walsh
                xdmValue = new XdmAtomicValue();
342
            break;
343
            case IS_DOUBLE:
344
                dVal = (double)Z_DVAL_P(zvalue);
345
                xdmValue = proc->makeDoubleValue((double)iVal);
346
                break;
347
            case IS_ARRAY:
348
                // TODO: Should not be expected. Do this some other way
349
                //break;
350
            case IS_OBJECT:
351
                // TODO: implement this
352
                //break;
353
            default:
354 ead48a5d O'Neil Delpratt
                obj = nullptr;
355 72bf04c6 Norman Walsh
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC); 
356 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
357 72bf04c6 Norman Walsh
        }
358 ead48a5d O'Neil Delpratt
        if(xdmValue == nullptr) {
359
            RETURN_nullptr();
360 72bf04c6 Norman Walsh
        }
361
        if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
362 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
363 72bf04c6 Norman Walsh
        } else {
364
            struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
365 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
366 72bf04c6 Norman Walsh
            vobj->xdmAtomicValue = xdmValue;
367
        }
368
    } else {
369
       
370 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
371 72bf04c6 Norman Walsh
    }
372
}
373
374
375
PHP_METHOD(SaxonProcessor, newXPathProcessor)
376
{
377
   
378
    if (ZEND_NUM_ARGS()>0) {
379
        WRONG_PARAM_COUNT;
380
    }
381
    SaxonProcessor * proc;
382 ead48a5d O'Neil Delpratt
    XPathProcessor * xpathProcessor = nullptr;
383
    if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
384 72bf04c6 Norman Walsh
      
385
    }
386
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
387
388 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
389 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
390 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
391
    if (proc != nullptr) {
392 72bf04c6 Norman Walsh
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
393 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
394 72bf04c6 Norman Walsh
        } else {
395
           struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
396 ead48a5d O'Neil Delpratt
            assert (vobji != nullptr);
397 72bf04c6 Norman Walsh
            xpathProcessor = proc->newXPathProcessor();
398
            vobji->xpathProcessor = xpathProcessor;
399
        }
400
    } else {
401
       
402 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
403 72bf04c6 Norman Walsh
    }
404
}
405
406
PHP_METHOD(SaxonProcessor, newXsltProcessor)
407
{
408
    //php_error(E_WARNING,"new xsltProc 1");
409
    if (ZEND_NUM_ARGS()>0) {
410
        WRONG_PARAM_COUNT;
411
    }
412
    SaxonProcessor * proc;
413 ead48a5d O'Neil Delpratt
    XsltProcessor * xsltProcessor = nullptr;
414
if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
415 72bf04c6 Norman Walsh
   
416
}
417
418
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
419 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
420 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
421 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
422
    if (proc != nullptr) {
423 72bf04c6 Norman Walsh
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
424 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
425 72bf04c6 Norman Walsh
        } else {
426
           struct xsltProcessor_object* vobj = (struct xsltProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
427
        
428 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
429 72bf04c6 Norman Walsh
            xsltProcessor = proc->newXsltProcessor();
430
            vobj->xsltProcessor = xsltProcessor;
431
    }
432
    } else {
433
       
434 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
435 72bf04c6 Norman Walsh
    }
436
}
437
438
PHP_METHOD(SaxonProcessor, newXslt30Processor)
439
{
440
    //php_error(E_WARNING,"new xsltProc 1");
441
    if (ZEND_NUM_ARGS()>0) {
442
        WRONG_PARAM_COUNT;
443
    }
444
    SaxonProcessor * proc;
445 ead48a5d O'Neil Delpratt
    Xslt30Processor * xslt30Processor = nullptr;
446
if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
447 72bf04c6 Norman Walsh
448
}
449
450
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
451 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
452 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
453 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
454
    if (proc != nullptr) {
455 72bf04c6 Norman Walsh
    if (object_init_ex(return_value, xslt30Processor_ce) != SUCCESS) {
456 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
457 72bf04c6 Norman Walsh
        } else {
458
           struct xslt30Processor_object* vobj = (struct xslt30Processor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
459
460 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
461 72bf04c6 Norman Walsh
            xslt30Processor = proc->newXslt30Processor();
462
            vobj->xslt30Processor = xslt30Processor;
463
    }
464
    } else {
465
466 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
467 72bf04c6 Norman Walsh
    }
468
}
469
470
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
471
{
472
   
473
    if (ZEND_NUM_ARGS()>0) {
474
        WRONG_PARAM_COUNT;
475
    }
476
    SaxonProcessor * proc;
477 ead48a5d O'Neil Delpratt
    XQueryProcessor * xqueryProcessor = nullptr;
478
   if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
479 72bf04c6 Norman Walsh
   
480
   }
481
   
482
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
483 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
484 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
485 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
486
    if (proc != nullptr) {
487 72bf04c6 Norman Walsh
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
488 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
489 72bf04c6 Norman Walsh
        } else {
490
           struct xqueryProcessor_object* vobj = (struct xqueryProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
491
492 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
493 72bf04c6 Norman Walsh
            xqueryProcessor = proc->newXQueryProcessor();
494
            vobj->xqueryProcessor = xqueryProcessor;
495
     }
496
    } else {
497
       
498 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
499 72bf04c6 Norman Walsh
    }
500
}
501
502
PHP_METHOD(SaxonProcessor, newSchemaValidator)
503
{
504
   
505
    if (ZEND_NUM_ARGS()>0) {
506
        WRONG_PARAM_COUNT;
507
    }
508
    SaxonProcessor * proc;
509 ead48a5d O'Neil Delpratt
    SchemaValidator * schemaValidator = nullptr;
510 72bf04c6 Norman Walsh
   
511
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
512 ead48a5d O'Neil Delpratt
    assert (obj != nullptr);
513 72bf04c6 Norman Walsh
    proc = obj->saxonProcessor;
514 ead48a5d O'Neil Delpratt
    assert (proc != nullptr);
515
    if (proc != nullptr) {
516 72bf04c6 Norman Walsh
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
517 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
518 72bf04c6 Norman Walsh
        } else {
519
           struct schemaValidator_object* vobj = (struct schemaValidator_object *)zend_object_store_get_object(return_value TSRMLS_CC);
520 ead48a5d O'Neil Delpratt
            assert (vobj != nullptr);
521 72bf04c6 Norman Walsh
            schemaValidator = proc->newSchemaValidator();
522 ead48a5d O'Neil Delpratt
            if(schemaValidator == nullptr){
523
                RETURN_nullptr();
524 72bf04c6 Norman Walsh
            }
525
            vobj->schemaValidator = schemaValidator;
526
        }
527
    } else {
528
       
529 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
530 72bf04c6 Norman Walsh
    }
531
}
532
533
534
PHP_METHOD(SaxonProcessor, isSchemaAware)
535
{
536
    SaxonProcessor *saxonProcessor;
537
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
538
    if (ZEND_NUM_ARGS()>0) {
539
        WRONG_PARAM_COUNT;
540
    }
541
    saxonProcessor = obj->saxonProcessor;
542 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
543 72bf04c6 Norman Walsh
        return saxonProcessor->isSchemaAwareProcessor();
544
        
545
    }
546
     return false;   
547
}
548
549
PHP_METHOD(SaxonProcessor, version)
550
{
551
    SaxonProcessor *saxonProcessor;
552
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
553
    if (ZEND_NUM_ARGS()>0) {
554
        WRONG_PARAM_COUNT;
555
    }
556
    saxonProcessor = obj->saxonProcessor;
557 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr) {
558 72bf04c6 Norman Walsh
        char *str = estrdup(saxonProcessor->version());
559
        RETURN_STRING(str, 0);
560
    }
561 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
562 72bf04c6 Norman Walsh
}
563
564
565
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
566
{
567
    SaxonProcessor *saxonProcessor;
568
    char * name;
569
    int len1;
570
    char * value;
571
    int len2;
572
    if (ZEND_NUM_ARGS()!= 2) {
573
        WRONG_PARAM_COUNT;
574
    }
575
576
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
577 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
578 72bf04c6 Norman Walsh
    }
579
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
580
581
    saxonProcessor = obj->saxonProcessor;
582 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr && name != nullptr && value != nullptr) {
583 72bf04c6 Norman Walsh
        saxonProcessor->setConfigurationProperty(name, value);
584
    }
585
    
586
}
587
588
PHP_METHOD(SaxonProcessor, registerPHPFunction)
589
{
590
    SaxonProcessor *saxonProcessor;
591
    char * libName;
592
    int len1;
593
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
594
    if (ZEND_NUM_ARGS()!= 1) {
595
        WRONG_PARAM_COUNT;
596
    }
597
598
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &libName, &len1) == FAILURE) {
599 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
600 72bf04c6 Norman Walsh
    }
601
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
602
603
    saxonProcessor = obj->saxonProcessor;
604 ead48a5d O'Neil Delpratt
    if (saxonProcessor != nullptr && libName != nullptr) {
605 72bf04c6 Norman Walsh
        saxonProcessor->setConfigurationProperty("extc", libName);
606
    }
607
saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PhpFunction",
608
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
609
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
610
}
611
612
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
613
614
void XsltProcessor_free_storage(void *object TSRMLS_DC)
615
{
616
617
    xsltProcessor_object *obj = (xsltProcessor_object *)object;
618
619
    zend_hash_destroy(obj->std.properties);
620
    FREE_HASHTABLE(obj->std.properties);
621
    efree(obj);
622
623
}
624
625
zend_object_value xsltProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
626
{
627
    zval *tmp;
628
    zend_object_value retval;
629
630
    xsltProcessor_object *obj = (xsltProcessor_object *)emalloc(sizeof(xsltProcessor_object));
631
    memset(obj, 0, sizeof(xsltProcessor_object));
632
    obj->std.ce = type;
633
634
    ALLOC_HASHTABLE(obj->std.properties);
635 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
636 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
637 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, XsltProcessor_free_storage, nullptr TSRMLS_CC);
638 72bf04c6 Norman Walsh
    retval.handlers = &xsltProcessor_object_handlers;
639
640
    return retval;
641
}
642
643
644
645
PHP_METHOD(XsltProcessor, __destruct)
646
{
647
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
648
649
650
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
651
652
    delete xsltProcessor;
653
    
654
}
655
656
PHP_METHOD(XsltProcessor, transformFileToFile)
657
{
658
    XsltProcessor *xsltProcessor;
659
    char * outfileName;
660
    char * infilename;
661
    char * styleFileName;
662
    int len1, len2, len3;
663
664
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
665 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
666 72bf04c6 Norman Walsh
    }
667
668
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
669
    xsltProcessor = obj->xsltProcessor;
670
 
671 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
672 72bf04c6 Norman Walsh
673
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
674
        if(xsltProcessor->exceptionOccurred()) {
675
               // TODO: throw exception
676
        }
677
    }
678
}
679
680
PHP_METHOD(XsltProcessor, transformFileToValue)
681
{
682
    XsltProcessor *xsltProcessor;
683
    char * infilename;
684
    char * styleFileName;
685
    int len1, len2;
686
687
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
688 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
689 72bf04c6 Norman Walsh
    }
690
691
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
692
    xsltProcessor = obj->xsltProcessor;
693
    
694 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
695 72bf04c6 Norman Walsh
696
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
697 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
698 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
699 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
700 72bf04c6 Norman Walsh
            } else {
701
                struct xdmValue_object* vobj  = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
702 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
703 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
704
            }
705
        } else {
706
            if(obj->xsltProcessor->exceptionOccurred()){
707
                  //TODO
708
            }
709
        }
710
    }else {
711 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
712 72bf04c6 Norman Walsh
    }
713
}
714
715
716
PHP_METHOD(XsltProcessor, transformFileToString)
717
{
718
    XsltProcessor *xsltProcessor;
719
    char * infilename;
720
    char * styleFileName;
721
    int len1, len2;
722
723
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
724 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
725 72bf04c6 Norman Walsh
    }
726
727
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
728
    xsltProcessor = obj->xsltProcessor;
729
730 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
731 72bf04c6 Norman Walsh
732
        const char * result = xsltProcessor->transformFileToString(infilename, styleFileName);
733 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
734 72bf04c6 Norman Walsh
            char *str = estrdup(result);
735
            RETURN_STRING(str, 0);
736
        } else if(xsltProcessor->exceptionOccurred()){
737
            //TODO: xsltProcessor->checkException();
738
            const char * errStr = xsltProcessor->getErrorMessage(0);
739 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
740 72bf04c6 Norman Walsh
                const char * errorCode = xsltProcessor->getErrorCode(0);
741 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
742 72bf04c6 Norman Walsh
                    // TODO: throw exception
743
                }
744
            }
745
        }
746
    }
747
}
748
749
/*enum saxonTypeEnum
750
{
751
        enumNode,
752
        enumString,
753
        enumInteger,
754
        enumDouble,
755
        enumFloat,
756
        enumBool,
757
        enumArrXdmValue
758
};*/
759
760
jobject JNICALL phpNativeCall
761
  (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
762
        JNIEnv *senv = SaxonProcessor::sxn_environ->env;
763
764 ead48a5d O'Neil Delpratt
        const char *nativeString = senv->GetStringUTFChars(funcName, nullptr);
765 72bf04c6 Norman Walsh
766 ead48a5d O'Neil Delpratt
        if(nativeString == nullptr) {
767
                return nullptr;
768 72bf04c6 Norman Walsh
        }
769
770
        zval *function_name;
771
        zval *retval;
772
        
773
        int argLength = 0;
774 ead48a5d O'Neil Delpratt
        zvalArr * php_argv= nullptr;
775
        if(arguments != nullptr) {
776 72bf04c6 Norman Walsh
                argLength = (int)senv->GetArrayLength(arguments);
777
                php_argv = new zvalArr[argLength];
778
        }
779
        zval **params[argLength];
780
        if(argLength>0) {
781
                (*params) = (zval**)malloc(sizeof(zval*) * argLength);
782
        } else {
783 ead48a5d O'Neil Delpratt
                (*params) = nullptr;
784 72bf04c6 Norman Walsh
        }
785
        std::map<std::string, saxonTypeEnum> typeMap;
786
        typeMap["node"] = enumNode;
787
        typeMap["string"] = enumString;
788
        typeMap["integer"] = enumInteger;
789
        typeMap["double"] = enumDouble;
790
        typeMap["float"] = enumFloat;
791
        typeMap["boolean"] = enumBool;
792
        typeMap["[xdmvalue"] = enumArrXdmValue;
793
        sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
794
        SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
795
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
796
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
797
        
798
        for(int i=0; i<argLength;i++){
799
800
                jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
801
                jobject argObj = senv->GetObjectArrayElement(arguments, i);
802
803 ead48a5d O'Neil Delpratt
                const char * str = senv->GetStringUTFChars(argType,nullptr);
804
                const char *stri = nullptr;
805 72bf04c6 Norman Walsh
                double dnumber = 0;
806
                long lnumber = 0;
807
                bool bvalue = false;
808
                float fnumber = 0;
809
                
810
811
         
812
                struct xdmNode_object* vobj;
813 ead48a5d O'Neil Delpratt
                XdmNode * node = nullptr;
814 72bf04c6 Norman Walsh
                std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
815
                if (it != typeMap.end()){
816
                        switch (it->second)
817
                        {
818
                                case enumNode:
819
                                        if(!nprocessor->proc){
820
                                                nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
821
                                        }
822
                                        node = new XdmNode(argObj);
823
                                        node->setProcessor(nprocessor);
824
825
                                        MAKE_STD_ZVAL(php_argv[i]._val);
826
                                        object_init_ex(php_argv[i]._val, xdmNode_ce);
827
                                           vobj = (struct xdmNode_object *)zend_object_store_get_object(php_argv[i]._val TSRMLS_CC);
828 ead48a5d O'Neil Delpratt
                                        assert (vobj != nullptr);
829 72bf04c6 Norman Walsh
                                        vobj->xdmNode = node;
830
                                        break;
831
                                case enumString:
832 ead48a5d O'Neil Delpratt
                                        stri = senv->GetStringUTFChars((jstring)argObj, nullptr);
833 72bf04c6 Norman Walsh
                                        MAKE_STD_ZVAL(php_argv[i]._val);
834
                                        ZVAL_STRING(php_argv[i]._val, stri, 1);
835
                                        break;
836
                                case enumInteger:
837
                                        sresult->xdmvalue = argObj; 
838
                                        lnumber = getLongValue(SaxonProcessor::sxn_environ, *sresult, 0);
839
840
                                        MAKE_STD_ZVAL(php_argv[i]._val);
841
                                        ZVAL_LONG(php_argv[i]._val, lnumber);                                        
842
                                        break;
843
                                case enumDouble:
844
                                        sresult->xdmvalue = argObj; 
845
                                        dnumber = getDoubleValue(SaxonProcessor::sxn_environ, *sresult, 0);
846
                                        MAKE_STD_ZVAL(php_argv[i]._val);
847
                                        ZVAL_DOUBLE(php_argv[i]._val, dnumber);
848
                                        break;
849
                                case enumFloat:
850
                                        sresult->xdmvalue = argObj; 
851
                                        fnumber = getFloatValue(SaxonProcessor::sxn_environ, *sresult, 0);
852
                                        MAKE_STD_ZVAL(php_argv[i]._val);
853
                                        ZVAL_DOUBLE(php_argv[i]._val, fnumber);                                        
854
                                        break;
855
                                case enumBool:
856
                                        sresult->xdmvalue = argObj; 
857
                                        bvalue = getBooleanValue(SaxonProcessor::sxn_environ, *sresult);
858
                                        MAKE_STD_ZVAL(php_argv[i]._val);
859
                                        ZVAL_BOOL(php_argv[i]._val, bvalue);                                                
860
                                        break;
861
                                case enumArrXdmValue:
862
                                        //TODO - not currently supported
863
                                        argLength--;
864
                                        break;
865
                        }
866
                        senv->ReleaseStringUTFChars(argType, str);
867
                } 
868
869
        //TODO should free sresult but it causes memory corruption        
870
                
871
// array of zvals to execute
872
    
873
874
 
875
            // convert all the values
876
            for(int i = 0; i < argLength; i++) { params[i] = &php_argv[i]._val; }
877
878
        }
879
        //note: no implicit type conversion.
880
881 ead48a5d O'Neil Delpratt
        zval *argvv = nullptr;//xparams;
882 72bf04c6 Norman Walsh
        MAKE_STD_ZVAL(function_name);
883
        ZVAL_STRING(function_name, nativeString, 1);
884 ead48a5d O'Neil Delpratt
        if(call_user_function_ex(CG(function_table), nullptr, function_name, &retval, argLength, params, 0, nullptr TSRMLS_CC) != SUCCESS)
885 72bf04c6 Norman Walsh
        {
886
            zend_error(E_ERROR, "Function call failed");
887
        }
888
889
890
891
        if(Z_TYPE(*retval) ==0){
892 ead48a5d O'Neil Delpratt
                zend_error(E_ERROR, "Function returned nullptr");
893 72bf04c6 Norman Walsh
        }
894
895 ead48a5d O'Neil Delpratt
        char * sVal = nullptr;
896 72bf04c6 Norman Walsh
        int len = 0;
897 ead48a5d O'Neil Delpratt
        jobject obj = nullptr;
898 72bf04c6 Norman Walsh
        std::cerr<<" Return type="<<Z_TYPE_P(retval)<<std::endl;
899
//TODO handle XdmValue wrapped object
900 ead48a5d O'Neil Delpratt
const char * objName = nullptr;
901
xdmNode_object* ooth = nullptr;
902 72bf04c6 Norman Walsh
        switch (Z_TYPE_P(retval)) {
903
            case IS_BOOL:
904
                obj= booleanValue(SaxonProcessor::sxn_environ, Z_BVAL_P(retval));
905
                break;
906
            
907
            case IS_LONG:
908
                obj= longValue(SaxonProcessor::sxn_environ, Z_LVAL_P(retval));
909
                break;
910
            case IS_STRING:
911
                sVal = Z_STRVAL_P(retval);
912
                len = Z_STRLEN_P(retval);
913
                obj = getJavaStringValue(SaxonProcessor::sxn_environ,estrndup(sVal, len));
914
                break;
915
            break;
916 ead48a5d O'Neil Delpratt
            case IS_nullptr:
917 72bf04c6 Norman Walsh
                
918
                    break;
919
            case IS_DOUBLE:
920
                obj = doubleValue(SaxonProcessor::sxn_environ, (double)Z_DVAL_P(retval));
921
                 break;
922
            
923
            case IS_ARRAY:
924
            //break;
925
            case IS_OBJECT:
926
                    objName =Z_OBJCE_P(retval)->name;
927
      
928
929
                      if(strcmp(objName, "Saxon\\XdmNode")==0) {
930
                        ooth = (xdmNode_object*)zend_object_store_get_object(retval TSRMLS_CC);
931 ead48a5d O'Neil Delpratt
                        if(ooth != nullptr) {
932 72bf04c6 Norman Walsh
                                    obj = ooth->xdmNode->getUnderlyingValue();
933
                    
934
                        }
935
                      }
936
                break;
937
            default:
938 ead48a5d O'Neil Delpratt
                obj = nullptr;
939 72bf04c6 Norman Walsh
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
940
        }
941
942
        //zend_printf("We have %i as type<br>", retval->type);
943
        //*return_value = *retval;
944
        //zval_copy_ctor(return_value);
945
        //zval_ptr_dtor(&retval);
946
        /*int cstrlen = Z_STRLEN_P(retval);
947
        char * str = estrndup(Z_STRVAL_P(retval), cstrlen);
948
        
949
        jstring jstrBuf = SaxonProcessor::sxn_environ->env->NewStringUTF(str);*/
950
        zval_ptr_dtor(&retval);
951
        return obj;
952
}
953
954
955
956
PHP_METHOD(XsltProcessor, transformToString)
957
{
958
    XsltProcessor *xsltProcessor;
959
 
960
    if (ZEND_NUM_ARGS()>0) {
961
        WRONG_PARAM_COUNT;
962
    }
963
////
964
/*zval *function_name;
965
zval *retval;
966

967
char * str = "userFunction";
968

969

970
MAKE_STD_ZVAL(function_name);
971
ZVAL_STRING(function_name, str, 1);
972 ead48a5d O'Neil Delpratt
if(call_user_function_ex(CG(function_table), nullptr, function_name, &retval, 0, nullptr, 0, nullptr TSRMLS_CC) != SUCCESS)
973 72bf04c6 Norman Walsh
{
974
    zend_error(E_ERROR, "Function call failed");
975
}
976

977
if(Z_TYPE(*retval) ==0){
978 ead48a5d O'Neil Delpratt
zend_error(E_ERROR, "DATAYYY is nullptr");
979 72bf04c6 Norman Walsh
}else {
980
str = Z_STRVAL_P(retval);
981
zend_printf("DATAYYY= %i <br>", str);
982
} 
983

984
zend_printf("We have %i as type<br>", retval->type);
985
*return_value = *retval;
986
zval_copy_ctor(return_value);
987
zval_ptr_dtor(&retval);*/
988
989
990
////
991
992
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
993
    xsltProcessor = obj->xsltProcessor;
994
995 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
996 72bf04c6 Norman Walsh
997
        const char * result = xsltProcessor->transformToString();
998 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
999 72bf04c6 Norman Walsh
            char *str = estrdup(result);
1000
            RETURN_STRING(str, 0);
1001
        } else if(xsltProcessor->exceptionOccurred()){
1002
            xsltProcessor->checkException();
1003
            const char * errStr = xsltProcessor->getErrorMessage(0);
1004 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
1005 72bf04c6 Norman Walsh
                const char * errorCode = xsltProcessor->getErrorCode(0);
1006 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
1007 72bf04c6 Norman Walsh
                    // TODO: throw exception
1008
                }
1009
            }
1010
        }
1011
    }
1012 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
1013 72bf04c6 Norman Walsh
}
1014
1015
PHP_METHOD(XsltProcessor, transformToValue)
1016
{
1017
    XsltProcessor *xsltProcessor;
1018
1019
    if (ZEND_NUM_ARGS()>0) {
1020
        WRONG_PARAM_COUNT;
1021
    }
1022
1023
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1024
    xsltProcessor = obj->xsltProcessor;
1025
1026 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1027 72bf04c6 Norman Walsh
1028
        XdmValue * node = xsltProcessor->transformToValue();
1029 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
1030 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1031 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
1032 72bf04c6 Norman Walsh
            } else {
1033
                struct xdmValue_object* vobj  = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
1034 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1035 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
1036
            }
1037
        } else if(xsltProcessor->exceptionOccurred()){
1038
            xsltProcessor->checkException();
1039
        }
1040
    } else {
1041 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1042 72bf04c6 Norman Walsh
    }
1043
}
1044
1045
PHP_METHOD(XsltProcessor, transformToFile)
1046
{
1047
    XsltProcessor *xsltProcessor;
1048
 
1049
    if (ZEND_NUM_ARGS()>0) {
1050
        WRONG_PARAM_COUNT;
1051
    }
1052
1053
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1054
    xsltProcessor = obj->xsltProcessor;
1055
1056 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1057 72bf04c6 Norman Walsh
1058
        xsltProcessor->transformToFile();
1059
        if(xsltProcessor->exceptionOccurred()) {
1060
           //TODO
1061
            const char * exStr = xsltProcessor->checkException();
1062
        }
1063
    } else {
1064 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1065 72bf04c6 Norman Walsh
    }
1066
}
1067
1068
PHP_METHOD(XsltProcessor, setBaseOutputURI)
1069
{
1070
    XsltProcessor *xsltProcessor;
1071
    char * name;
1072
    int len1;
1073
1074
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
1075 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1076 72bf04c6 Norman Walsh
    }
1077
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1078
    xsltProcessor = obj->xsltProcessor;
1079 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1080 72bf04c6 Norman Walsh
        xsltProcessor->setBaseOutputURI(name);
1081
    }
1082
}
1083
1084
PHP_METHOD(XsltProcessor, compileFromFile)
1085
{
1086
    XsltProcessor *xsltProcessor;
1087
    char * name;
1088
    int len1;
1089
1090
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
1091 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1092 72bf04c6 Norman Walsh
    }
1093
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1094
    xsltProcessor = obj->xsltProcessor;
1095 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1096 72bf04c6 Norman Walsh
        xsltProcessor->compileFromFile(name);
1097
    }
1098
}
1099
1100
PHP_METHOD(XsltProcessor, compileFromString)
1101
{
1102
    XsltProcessor *xsltProcessor;
1103
    char * stylesheetStr;
1104
    int len1, myint;
1105
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &stylesheetStr, &len1) == FAILURE) {
1106 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1107 72bf04c6 Norman Walsh
    }
1108
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1109
    xsltProcessor = obj->xsltProcessor;
1110 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1111 72bf04c6 Norman Walsh
        xsltProcessor->compileFromString(stylesheetStr);
1112
    }
1113
}
1114
1115
PHP_METHOD(XsltProcessor, compileFromValue)
1116
{
1117
    XsltProcessor *xsltProcessor;
1118
   zval* oth;
1119
1120
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &oth, xdmValue_ce) == FAILURE) {
1121 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1122 72bf04c6 Norman Walsh
    }
1123
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1124
    xsltProcessor = obj->xsltProcessor;
1125 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1126 72bf04c6 Norman Walsh
         xdmValue_object* ooth = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
1127 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1128 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1129 ead48a5d O'Neil Delpratt
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
1130 72bf04c6 Norman Walsh
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1131
            }
1132
        }
1133
    }
1134
}
1135
1136
1137
1138
PHP_METHOD(XsltProcessor, compileFromStringAndSave)
1139
{
1140
    XsltProcessor *xsltProcessor;
1141
    char * stylesheetStr;
1142
    char * filename;
1143
    size_t len1, len2, myint;
1144
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &stylesheetStr, filename, &len1, &len2) == FAILURE) {
1145 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1146 72bf04c6 Norman Walsh
    }
1147
1148
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1149
        xsltProcessor = obj->xsltProcessor;
1150 ead48a5d O'Neil Delpratt
        if (xsltProcessor != nullptr) {
1151 72bf04c6 Norman Walsh
            xsltProcessor->compileFromStringAndSave(stylesheetStr, filename);
1152
        }
1153
1154
   
1155
}
1156
1157
PHP_METHOD(XsltProcessor, compileFromFileAndSave)
1158
{
1159
    XsltProcessor *xsltProcessor;
1160
    char * stylesheetFilename;
1161
    char * filename;
1162
    size_t len1, len2, myint;
1163
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
1164 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1165 72bf04c6 Norman Walsh
    }
1166
     xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1167
    xsltProcessor = obj->xsltProcessor;
1168 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1169 72bf04c6 Norman Walsh
        xsltProcessor->compileFromStringAndSave(stylesheetFilename, filename);
1170
    }
1171
}
1172
1173
1174
1175
1176
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1177
{
1178
    XsltProcessor *xsltProcessor;
1179 ead48a5d O'Neil Delpratt
    zval* oth = nullptr;
1180 72bf04c6 Norman Walsh
1181
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
1182 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1183 72bf04c6 Norman Walsh
    }
1184
1185
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1186
    xsltProcessor = obj->xsltProcessor;
1187 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1188 72bf04c6 Norman Walsh
1189
    if(!oth) {
1190
        php_error(E_WARNING, "Error setting source value");
1191
        return;
1192
    } else {
1193
1194
      const char * objName =Z_OBJCE_P(oth)->name;
1195
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1196
1197
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1198
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1199 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1200 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
1201 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1202 72bf04c6 Norman Walsh
                xsltProcessor->setSourceFromXdmNode(value);
1203
1204
            }
1205
        }
1206
      } /*else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1207
        xdmValue_object* ooth = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
1208 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1209 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1210 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1211 72bf04c6 Norman Walsh
                xsltProcessor->setSourceFromXdmValue((XdmItem*)value);
1212
            }
1213
        }
1214
      }  */
1215
1216
        
1217
    }
1218
  }
1219
}
1220
1221
PHP_METHOD(XsltProcessor, setJustInTimeCompilation)
1222
{
1223
    XsltProcessor *xsltProcessor;
1224
    bool jit = false;
1225
1226
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &jit) == FAILURE) {
1227 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1228 72bf04c6 Norman Walsh
    }
1229
1230
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1231
    xsltProcessor = obj->xsltProcessor;
1232 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1233 72bf04c6 Norman Walsh
1234
         xsltProcessor->setJustInTimeCompilation(jit);
1235
1236
1237
    }
1238
}
1239
1240
PHP_METHOD(XsltProcessor, setOutputFile)
1241
{
1242
    XsltProcessor *xsltProcessor;
1243
    char * outputFilename;
1244
    int len1;
1245
1246
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &outputFilename, &len1, xdmValue_ce) == FAILURE) {
1247 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1248 72bf04c6 Norman Walsh
    }
1249
1250
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1251
    xsltProcessor = obj->xsltProcessor;
1252 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr && outputFilename != nullptr) {
1253 72bf04c6 Norman Walsh
        
1254
         xsltProcessor->setOutputFile(outputFilename);
1255
            
1256
        
1257
    }
1258
}
1259
1260
PHP_METHOD(XsltProcessor, setSourceFromFile)
1261
{
1262
    XsltProcessor *xsltProcessor;
1263
    char * inFilename;
1264
    int len1;
1265
1266
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &inFilename, &len1, xdmValue_ce) == FAILURE) {
1267 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1268 72bf04c6 Norman Walsh
    }
1269
1270
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1271
    xsltProcessor = obj->xsltProcessor;
1272 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr && inFilename != nullptr) {
1273 72bf04c6 Norman Walsh
        
1274
         xsltProcessor->setSourceFromFile(inFilename);
1275
            
1276
        
1277
    }
1278
}
1279
1280
1281
PHP_METHOD(XsltProcessor, setProperty)
1282
{
1283
    XsltProcessor *xsltProcessor;
1284
    char * name;
1285
    char * value;
1286
    int len1, len2, myint;
1287
1288
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1289 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1290 72bf04c6 Norman Walsh
    }
1291
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1292
    xsltProcessor = obj->xsltProcessor;
1293 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1294 72bf04c6 Norman Walsh
        xsltProcessor->setProperty(name, value);
1295
    }
1296
}
1297
1298
PHP_METHOD(XsltProcessor, setParameter)
1299
{
1300
1301
   XsltProcessor *xsltProcessor;
1302
   char * name;
1303
   zval* oth;
1304
   int len1, len2, myint;        
1305
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1306 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1307 72bf04c6 Norman Walsh
    }
1308
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1309
    xsltProcessor = obj->xsltProcessor;
1310 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1311 72bf04c6 Norman Walsh
1312 ead48a5d O'Neil Delpratt
      if(Z_TYPE_P(oth) ==IS_nullptr){
1313
                      php_error(E_WARNING, "Error setting source value - value is nullptr");
1314 72bf04c6 Norman Walsh
                      return;
1315
              }
1316
      const char * objName =Z_OBJCE_P(oth)->name;
1317
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1318
1319
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1320
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1321 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1322 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
1323 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1324 72bf04c6 Norman Walsh
                xsltProcessor->setParameter(name, (XdmValue *)value);
1325
1326
            }
1327
        }
1328
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1329
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1330 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1331 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
1332 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1333 72bf04c6 Norman Walsh
                
1334
                xsltProcessor->setParameter(name, value);
1335
            }
1336
        }
1337
1338
1339
1340
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1341
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1342 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
1343 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1344 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
1345 72bf04c6 Norman Walsh
                
1346
                xsltProcessor->setParameter(name, (XdmValue *)value);
1347
            }
1348
        }
1349
1350
1351
1352
      }
1353
1354
    }
1355
}
1356
1357
PHP_METHOD(XsltProcessor, clearParameters)
1358
{
1359
    XsltProcessor *xsltProcessor;
1360
    if (ZEND_NUM_ARGS()>0) {
1361
        WRONG_PARAM_COUNT;
1362
    }
1363
1364
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1365
    xsltProcessor = obj->xsltProcessor;
1366 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1367 72bf04c6 Norman Walsh
        xsltProcessor->clearParameters(true);
1368
    }
1369
}
1370
1371
PHP_METHOD(XsltProcessor, clearProperties)
1372
{
1373
    XsltProcessor *xsltProcessor;
1374
    if (ZEND_NUM_ARGS()>0) {
1375
        WRONG_PARAM_COUNT;
1376
    }
1377
1378
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1379
    xsltProcessor = obj->xsltProcessor;
1380 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1381 72bf04c6 Norman Walsh
        xsltProcessor->clearProperties();
1382
    }
1383
}
1384
1385
1386
PHP_METHOD(XsltProcessor, setupXslMessage)
1387
{
1388
    XsltProcessor *xsltProcessor;
1389
    bool show = false;
1390 ead48a5d O'Neil Delpratt
    char * filename = nullptr;
1391 72bf04c6 Norman Walsh
    size_t len1;
1392
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "bs", &show, &filename &len1) == FAILURE) {
1393 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1394 72bf04c6 Norman Walsh
    }
1395
1396
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1397
    xsltProcessor = obj->xsltProcessor;
1398
1399 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1400 72bf04c6 Norman Walsh
1401
            xsltProcessor->setupXslMessage(show, filename);
1402
        }
1403
1404
}
1405
1406
1407
PHP_METHOD(XsltProcessor, exceptionOccurred)
1408
{
1409
    XsltProcessor *xsltProcessor;
1410
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1411
    if (ZEND_NUM_ARGS()>0) {
1412
        WRONG_PARAM_COUNT;
1413
    }
1414
1415
    xsltProcessor = obj->xsltProcessor;
1416 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1417 72bf04c6 Norman Walsh
        bool result = xsltProcessor->exceptionOccurred();
1418
        RETURN_BOOL(result);
1419
    }
1420
    RETURN_BOOL(false);
1421
}
1422
1423
PHP_METHOD(XsltProcessor, getExceptionCount)
1424
{
1425
    XsltProcessor *xsltProcessor;
1426
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1427
    if (ZEND_NUM_ARGS()>0) {
1428
        WRONG_PARAM_COUNT;
1429
    }
1430
1431
    xsltProcessor = obj->xsltProcessor;
1432 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1433 72bf04c6 Norman Walsh
        int count = xsltProcessor->exceptionCount();
1434
        RETURN_LONG(count);
1435
    }
1436
    RETURN_LONG(0);
1437
}
1438
1439
PHP_METHOD(XsltProcessor, getErrorCode)
1440
{
1441
    XsltProcessor *xsltProcessor;
1442
    long index;
1443
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1444 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1445 72bf04c6 Norman Walsh
    }
1446
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1447
    xsltProcessor = obj->xsltProcessor;
1448 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1449 72bf04c6 Norman Walsh
        const char * errCode = xsltProcessor->getErrorCode((int)index);
1450 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
1451 72bf04c6 Norman Walsh
            char *str = estrdup(errCode);
1452
            RETURN_STRING(str, 0);
1453
        }
1454
    }
1455 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
1456 72bf04c6 Norman Walsh
}
1457
1458
PHP_METHOD(XsltProcessor, getErrorMessage)
1459
{
1460
    XsltProcessor *xsltProcessor;
1461
    long index;
1462
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1463 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1464 72bf04c6 Norman Walsh
    }
1465
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1466
    xsltProcessor = obj->xsltProcessor;
1467 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1468 72bf04c6 Norman Walsh
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1469 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
1470 72bf04c6 Norman Walsh
            char *str = estrdup(errStr);
1471
            RETURN_STRING(str, 0);
1472
        }
1473
    }
1474 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
1475 72bf04c6 Norman Walsh
}
1476
PHP_METHOD(XsltProcessor, exceptionClear)
1477
{
1478
    XsltProcessor *xsltProcessor;
1479
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1480
    xsltProcessor = obj->xsltProcessor;
1481 ead48a5d O'Neil Delpratt
    if (xsltProcessor != nullptr) {
1482 72bf04c6 Norman Walsh
        xsltProcessor->exceptionClear();
1483
    }
1484
}
1485
1486
1487
/*     ============== XSLT30: PHP Interface of  Xslt30Processor class =============== */
1488
1489
void Xslt30Processor_free_storage(void *object TSRMLS_DC)
1490
{
1491
1492
    xslt30Processor_object *obj = (xslt30Processor_object *)object;
1493
1494
    zend_hash_destroy(obj->std.properties);
1495
    FREE_HASHTABLE(obj->std.properties);
1496
    efree(obj);
1497
}
1498
1499
zend_object_value xslt30Processor_create_handler(zend_class_entry *type TSRMLS_DC)
1500
{
1501
    zval *tmp;
1502
    zend_object_value retval;
1503
1504
    xslt30Processor_object *obj = (xslt30Processor_object *)emalloc(sizeof(xslt30Processor_object));
1505
    memset(obj, 0, sizeof(xslt30Processor_object));
1506
    obj->std.ce = type;
1507
1508
    ALLOC_HASHTABLE(obj->std.properties);
1509 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
1510 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
1511 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, Xslt30Processor_free_storage, nullptr TSRMLS_CC);
1512 72bf04c6 Norman Walsh
    retval.handlers = &xslt30Processor_object_handlers;
1513
1514
    return retval;
1515
}
1516
1517
1518
1519
PHP_METHOD(Xslt30Processor, __destruct)
1520
{
1521
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1522
1523
1524
    Xslt30Processor * xslt30Processor= obj->xslt30Processor;
1525
1526
    delete xslt30Processor;
1527
    
1528
}
1529
1530
PHP_METHOD(Xslt30Processor, setBaseOutputURI)
1531
{
1532
    Xslt30Processor *xslt30Processor;
1533
    char * name;
1534
    int len1;
1535
1536
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
1537 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1538 72bf04c6 Norman Walsh
    }
1539
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1540
    xslt30Processor = obj->xslt30Processor;
1541 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1542 72bf04c6 Norman Walsh
        xslt30Processor->setBaseOutputURI(name);
1543
    }
1544
}
1545
1546
1547
1548
1549
PHP_METHOD(Xslt30Processor, callFunctionReturningValue)
1550
{
1551
//arguments: const char * stylesheetFilename, const char* functionName, XdmValue * arguments, int argument_length
1552
1553
    Xslt30Processor *xslt30Processor;
1554
    HashTable *arr_hash;
1555
    char* functionName;
1556
    zval * arguments_zval;
1557
    zval * ar;
1558
1559
    XdmValue ** arguments;
1560
    int argument_length=0;
1561
1562
    zval **val;
1563
       HashPosition pointer;
1564
       int array_count;
1565
       char * string_key;
1566
       int str_key_len;
1567
       long num_key=0;
1568
1569
    char * infilename;
1570
    char * styleFileName;
1571
    size_t len1, len2;
1572
1573
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1574 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1575 72bf04c6 Norman Walsh
    }
1576
1577
1578
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1579
1580
    xslt30Processor = obj->xslt30Processor;
1581
    arr_hash = Z_ARRVAL_P(arguments_zval);
1582
    argument_length = zend_hash_num_elements(arr_hash);
1583
   
1584
    arguments = new XdmValue*[argument_length];
1585
1586 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1587 72bf04c6 Norman Walsh
      for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &val, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) {
1588 ead48a5d O'Neil Delpratt
        //if(Z_TYPE_P(val) != nullptr) {
1589 72bf04c6 Norman Walsh
1590 ead48a5d O'Neil Delpratt
        if(Z_TYPE_PP(val) != IS_nullptr) {
1591 72bf04c6 Norman Walsh
                     // zend_object* ooth = Z_OBJCE_PP(val);
1592
                    const char * objName = Z_OBJCE_PP(val)->name;
1593 ead48a5d O'Neil Delpratt
                    char *key = nullptr;
1594 72bf04c6 Norman Walsh
                    uint  klen;
1595
                    ulong index;
1596
1597
         if (zend_hash_get_current_key_ex(arr_hash, &key, &klen, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
1598
             /* the key is a string, do nothing */
1599
         } else {
1600
             /* we assume the key to be long, index will be set */
1601
1602
1603
1604
         //const char * objName = ooth->name;
1605
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1606
        php_printf("num_key %d =>", num_key);
1607
        php_printf("key %d =>", key);
1608
        */
1609
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1610
        xdmNode_object* nobj = (xdmNode_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1611 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1612 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1613
                            arguments[index] = value;
1614
                }
1615
        }
1616
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1617
        xdmAtomicValue_object* nobj = (xdmAtomicValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1618
                //xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1619 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1620 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1621
                            arguments[index] = value;
1622
                }
1623
        }
1624
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1625
                xdmValue_object* nobj = ( xdmValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1626
                //xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1627 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1628 72bf04c6 Norman Walsh
                            XdmValue * value = nobj->xdmValue;
1629
                            arguments[index] = value;
1630
                }
1631
        }
1632
        else {//TODO error warning}
1633
         }}
1634
        }
1635
1636
       }
1637
1638
        //php_printf(" argument_length= %d",argument_length);
1639
        XdmValue * result = xslt30Processor->callFunctionReturningValue(styleFileName, functionName, arguments, argument_length);
1640 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1641 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1642 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
1643 72bf04c6 Norman Walsh
            } else {
1644
                struct xdmValue_object* vobj  = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
1645
                        //xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1646 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1647 72bf04c6 Norman Walsh
                vobj->xdmValue = result;
1648
            }
1649
        } else {
1650
            if(obj->xslt30Processor->exceptionOccurred()){
1651
                  //TODO
1652
            }
1653
        } }
1654
1655
}
1656
1657
PHP_METHOD(Xslt30Processor, callFunctionReturningString){
1658
    Xslt30Processor *xslt30Processor;
1659
    HashTable *arr_hash;
1660
    char* functionName;
1661
    zval * arguments_zval;
1662
    zval ** val;
1663
1664
    XdmValue ** arguments;
1665
    int argument_length=0;
1666
1667
    HashPosition pointer;
1668
    int array_count;
1669
    char * string_key;
1670
    int str_key_len;
1671
    long num_key=0;
1672
1673
    char * infilename;
1674
    char * styleFileName;
1675
    size_t len1, len2;
1676
1677
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1678 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1679 72bf04c6 Norman Walsh
    }
1680
1681
  
1682
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1683
    xslt30Processor = obj->xslt30Processor;
1684
    arr_hash = Z_ARRVAL_P(arguments_zval);
1685
    argument_length = zend_hash_num_elements(arr_hash);
1686
   
1687
    arguments = new XdmValue*[argument_length];
1688
1689 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1690 72bf04c6 Norman Walsh
      for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &val, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) {
1691 ead48a5d O'Neil Delpratt
              if(Z_TYPE_PP(val) != IS_nullptr) {
1692 72bf04c6 Norman Walsh
              const char* objName = Z_OBJCE_PP(val)->name;
1693
                    //const char * objName = ooth->name;
1694
1695 ead48a5d O'Neil Delpratt
              char *key = nullptr;
1696 72bf04c6 Norman Walsh
         uint  klen;
1697
         ulong index;
1698
1699
          if (zend_hash_get_current_key_ex(arr_hash, &key, &klen, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
1700
                      /* the key is a string, do nothing */
1701
           } else {
1702
                      /* we assume the key to be long, index will be set */
1703
1704
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1705
        php_printf("num_key %d =>", num_key);
1706
        php_printf("key %d =>", key);
1707
        */
1708
1709
1710
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1711
        xdmNode_object* nobj = (xdmNode_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1712
                //xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1713 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1714 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1715
                            arguments[index] = value;
1716
                }
1717
        }
1718
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1719
                //xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1720
                xdmAtomicValue_object* nobj = (xdmAtomicValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1721 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1722 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1723
                            arguments[index] = value;
1724
                }
1725
        }
1726
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1727
                //xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1728
                xdmValue_object* nobj = (xdmValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1729 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1730 72bf04c6 Norman Walsh
                            XdmValue * value = nobj->xdmValue;
1731
                            arguments[index] = value;
1732
                }
1733
        }
1734
        else {//TODO error warning}
1735
         }}
1736
      }
1737
1738
      }
1739
1740
        const char * result = xslt30Processor->callFunctionReturningString(styleFileName, functionName, arguments, argument_length);
1741 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1742 72bf04c6 Norman Walsh
            //char *str = estrdup(result);
1743
            RETURN_STRING(result, 0);
1744
        } else if(xslt30Processor->exceptionOccurred()){
1745
            //TODO: xslt30Processor->checkException();
1746
            const char * errStr = xslt30Processor->getErrorMessage(0);
1747 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
1748 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
1749 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
1750 72bf04c6 Norman Walsh
                    // TODO: throw exception
1751
                }
1752
            }
1753
        }
1754
    }
1755
1756
1757
1758
}
1759
1760
1761
    PHP_METHOD(Xslt30Processor, callFunctionReturningFile){
1762
    HashTable *arr_hash;
1763
    Xslt30Processor *xslt30Processor;
1764
    char* functionName;
1765
    zval * arguments_zval;
1766
    zval ** val;
1767
1768
    XdmValue ** arguments;
1769
    int argument_length=0;
1770
1771
    HashPosition pointer;
1772
    int array_count;
1773
    char * string_key;
1774
    int str_key_len;
1775
    long num_key=0;
1776
1777
    char * outfilename;
1778
    char * styleFileName;
1779
    size_t len1, len2, len3;
1780
1781
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sszs", &styleFileName, &len1, &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
1782 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1783 72bf04c6 Norman Walsh
    }
1784
1785
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1786
    xslt30Processor = obj->xslt30Processor;
1787
    arr_hash = Z_ARRVAL_P(arguments_zval);
1788
    argument_length = zend_hash_num_elements(arr_hash);
1789
   
1790
    arguments = new XdmValue*[argument_length];
1791
1792 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1793 72bf04c6 Norman Walsh
    for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &val, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) {
1794 ead48a5d O'Neil Delpratt
            if(Z_TYPE_PP(val) != IS_nullptr) {
1795 72bf04c6 Norman Walsh
            const char * objName = Z_OBJCE_PP(val)->name;
1796
                  //const char * objName = ooth->name;
1797 ead48a5d O'Neil Delpratt
            char *key = nullptr;
1798 72bf04c6 Norman Walsh
            uint  klen;
1799
            ulong index;
1800
1801
 if (zend_hash_get_current_key_ex(arr_hash, &key, &klen, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
1802
             /* the key is a string, do nothing */
1803
         } else {
1804
             /* we assume the key to be long, index will be set */
1805
1806
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1807
        php_printf("num_key %d =>", num_key);
1808
        php_printf("key %d =>", key);
1809
        */
1810
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1811
                xdmNode_object* nobj = (xdmNode_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1812 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1813 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1814
                            arguments[index] = value;
1815
                }
1816
        }
1817
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1818
                //zend_object* ooth = Z_OBJCE_P(val);
1819
                //xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1820
                xdmAtomicValue_object* nobj = (xdmAtomicValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1821 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1822 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1823
                            arguments[index] = value;
1824
                }
1825
        }
1826
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1827
                //zend_object* ooth = Z_OBJCE_P(val);
1828
                xdmValue_object* nobj = (xdmValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1829 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
1830 72bf04c6 Norman Walsh
                            XdmValue * value = nobj->xdmValue;
1831
                            arguments[index] = value;
1832
                }
1833
        }
1834
        else {//TODO error warning}
1835
         }}
1836
        }
1837
      }
1838
1839
1840
1841
        xslt30Processor->callFunctionReturningFile(styleFileName, functionName, arguments, argument_length, outfilename);
1842
        if(xslt30Processor->exceptionOccurred()){
1843
            //TODO: xslt30Processor->checkException();
1844
            const char * errStr = xslt30Processor->getErrorMessage(0);
1845 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
1846 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
1847
            }
1848
        }
1849
    }
1850
1851
}
1852
1853
    PHP_METHOD(Xslt30Processor, callTemplateReturningValue){
1854
1855
  Xslt30Processor *xslt30Processor;
1856
    char* templateName;
1857
   
1858
    char * styleFileName;
1859
    size_t len1, len2;
1860
1861
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1862 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1863 72bf04c6 Norman Walsh
    }
1864
1865
    
1866
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1867
    xslt30Processor = obj->xslt30Processor;
1868
      
1869 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1870 72bf04c6 Norman Walsh
   
1871
1872
        //php_printf(" argument_length= %d",argument_length);
1873
        XdmValue * result = xslt30Processor->callTemplateReturningValue(styleFileName, templateName);
1874 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1875 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1876 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
1877 72bf04c6 Norman Walsh
            } else {
1878
                struct xdmValue_object* vobj  = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
1879
                        //xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1880 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1881 72bf04c6 Norman Walsh
                vobj->xdmValue = result;
1882
            }
1883
        } else {
1884
            if(obj->xslt30Processor->exceptionOccurred()){
1885
                  //TODO
1886
            }
1887
        }
1888
    }
1889
1890
   }
1891
1892
1893
    PHP_METHOD(Xslt30Processor, callTemplateReturningString){
1894
    Xslt30Processor *xslt30Processor;
1895
    char* templateName;
1896
   
1897
    char * styleFileName;
1898
    size_t len1, len2;
1899
1900
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1901 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1902 72bf04c6 Norman Walsh
    }
1903
1904
    
1905
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1906
    xslt30Processor = obj->xslt30Processor;
1907
      
1908 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1909 72bf04c6 Norman Walsh
   
1910
1911
        //php_printf(" argument_length= %d",argument_length);
1912
        const char * result = xslt30Processor->callTemplateReturningString(styleFileName, templateName);
1913 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1914 72bf04c6 Norman Walsh
            RETURN_STRING(result, 0);
1915
        } else {
1916
            if(xslt30Processor->exceptionOccurred()){
1917
            xslt30Processor->checkException();
1918
            const char * errStr = xslt30Processor->getErrorMessage(0);
1919 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
1920 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
1921 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
1922 72bf04c6 Norman Walsh
                    // TODO: throw exception
1923
                }
1924
            }
1925
           }
1926
        }
1927
    }
1928
1929 ead48a5d O'Neil Delpratt
     RETURN_nullptr();
1930 72bf04c6 Norman Walsh
    }
1931
1932
    PHP_METHOD(Xslt30Processor, callTemplateReturningFile){
1933
   Xslt30Processor *xslt30Processor;
1934
    char* templateName;
1935
    char * filename;
1936
    char * styleFileName;
1937
    size_t len1, len2, len3;
1938
1939
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &styleFileName, &len1, &templateName, &len2, &filename, &len3) == FAILURE) {
1940 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1941 72bf04c6 Norman Walsh
    }
1942
1943
    
1944
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1945
    xslt30Processor = obj->xslt30Processor;
1946
      
1947 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1948 72bf04c6 Norman Walsh
           xslt30Processor->callTemplateReturningFile(styleFileName, templateName, filename);
1949
    }
1950
1951
  }
1952
1953
1954
PHP_METHOD(Xslt30Processor, applyTemplatesReturningValue){
1955
   Xslt30Processor *xslt30Processor;
1956
    char * styleFileName;
1957
    size_t len1;
1958
1959
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &styleFileName, &len1) == FAILURE) {
1960 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
1961 72bf04c6 Norman Walsh
    }
1962
1963
    
1964
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1965
    xslt30Processor = obj->xslt30Processor;
1966
      
1967 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
1968 72bf04c6 Norman Walsh
           XdmValue * result = xslt30Processor->applyTemplatesReturningValue(styleFileName);
1969
    
1970 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
1971 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1972 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
1973 72bf04c6 Norman Walsh
            } else {
1974
                    struct xdmValue_object* vobj  = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
1975 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
1976 72bf04c6 Norman Walsh
                vobj->xdmValue = result;
1977
            }
1978
        } else {
1979
            if(obj->xslt30Processor->exceptionOccurred()){
1980
                  //TODO
1981
            }
1982
        }
1983
1984
1985
1986
    }
1987 ead48a5d O'Neil Delpratt
     RETURN_nullptr();
1988 72bf04c6 Norman Walsh
1989
}
1990
1991
1992
PHP_METHOD(Xslt30Processor, applyTemplatesReturningString){
1993
 Xslt30Processor *xslt30Processor;
1994
1995
    char * styleFileName;
1996
    size_t len1;
1997
1998
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &styleFileName, &len1) == FAILURE) {
1999 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2000 72bf04c6 Norman Walsh
    }
2001
2002
    
2003
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2004
    xslt30Processor = obj->xslt30Processor;
2005
      
2006 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2007 72bf04c6 Norman Walsh
   
2008
        //php_printf(" argument_length= %d",argument_length);
2009
        const char * result = xslt30Processor->applyTemplatesReturningString(styleFileName);
2010 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
2011 72bf04c6 Norman Walsh
            RETURN_STRING(result, 0);
2012
        } else {
2013
            if(xslt30Processor->exceptionOccurred()){
2014
            xslt30Processor->checkException();
2015
            const char * errStr = xslt30Processor->getErrorMessage(0);
2016 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
2017 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
2018 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
2019 72bf04c6 Norman Walsh
                    // TODO: throw exception
2020
                }
2021
            }
2022
           }
2023
        }
2024
    }
2025
2026 ead48a5d O'Neil Delpratt
     RETURN_nullptr();
2027 72bf04c6 Norman Walsh
   
2028
2029
2030
}
2031
2032
2033
2034
PHP_METHOD(Xslt30Processor, applyTemplatesReturningFile){
2035
 Xslt30Processor *xslt30Processor;
2036
    char * filename;
2037
    char * styleFileName;
2038
    size_t len1, len2;
2039
2040
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &styleFileName, &len1, &filename, &len2) == FAILURE) {
2041 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2042 72bf04c6 Norman Walsh
    }
2043
2044
    
2045
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2046
    xslt30Processor = obj->xslt30Processor;
2047
      
2048 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2049 72bf04c6 Norman Walsh
           xslt30Processor->applyTemplatesReturningFile(styleFileName, filename);
2050
    }
2051
2052
2053
2054
}
2055
2056
2057
PHP_METHOD(Xslt30Processor, addPackages){
2058
    HashTable *arr_hash;
2059
    Xslt30Processor *xslt30Processor;
2060
    char* functionName;
2061
    zval * arguments_zval;
2062
    zval ** val;
2063
2064
    const char ** arguments;
2065
    int argument_length=0;
2066
2067
       HashPosition pointer;
2068
       int array_count;
2069
       char * string_key;
2070
       int str_key_len;
2071
       long num_key;
2072
2073
    char * infilename;
2074
    char * styleFileName;
2075
    size_t len1, len2;
2076
2077
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arguments_zval) == FAILURE) {
2078 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2079 72bf04c6 Norman Walsh
    }
2080
2081
    
2082
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2083
    xslt30Processor = obj->xslt30Processor;
2084
    arr_hash = Z_ARRVAL_P(arguments_zval);
2085
    argument_length = zend_hash_num_elements(arr_hash);
2086
   
2087
    arguments = new const char*[argument_length];
2088
2089 ead48a5d O'Neil Delpratt
  if (xslt30Processor != nullptr) {
2090 72bf04c6 Norman Walsh
2091
        for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &val, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) {
2092 ead48a5d O'Neil Delpratt
                if(Z_TYPE_PP(val) != IS_nullptr) {
2093 72bf04c6 Norman Walsh
                //zend_object* ooth = Z_OBJCE_PP(val);
2094
                      const char * objName = Z_OBJCE_PP(val)->name;
2095 ead48a5d O'Neil Delpratt
                char *key = nullptr;
2096 72bf04c6 Norman Walsh
                uint  klen;
2097
                ulong index;
2098
2099
     if (zend_hash_get_current_key_ex(arr_hash, &key, &klen, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
2100
                 /* the key is a string, do nothing */
2101
             } else {
2102
                 /* we assume the key to be long, index will be set */
2103
                        arguments[index] = (const char*)Z_STRVAL_PP(val);
2104
             }
2105
        } 
2106
    }
2107
2108
        xslt30Processor->addPackages(arguments, argument_length);
2109
        if(xslt30Processor->exceptionOccurred()){
2110
            //TODO: xslt30Processor->checkException();
2111
            const char * errStr = xslt30Processor->getErrorMessage(0);
2112 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
2113 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
2114
            }
2115
        }
2116
    }
2117
}
2118
2119
2120
    PHP_METHOD(Xslt30Processor,setInitialTemplateParameters){
2121
2122
  Xslt30Processor *xslt30Processor;
2123
    HashTable *arr_hash;
2124
    zval * arguments_zval;
2125
    zval ** val;
2126
2127
    XdmValue ** arguments;
2128
    int argument_length=0;
2129
2130
       HashPosition pointer;
2131
       int array_count;
2132
       char * string_key;
2133
       int str_key_len;
2134
       long num_key;
2135
2136
    bool tunnel = false;
2137
2138
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arguments_zval) == FAILURE) {
2139 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2140 72bf04c6 Norman Walsh
    }
2141
2142
    
2143
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2144
    xslt30Processor = obj->xslt30Processor;
2145
    arr_hash = Z_ARRVAL_P(arguments_zval);
2146
    argument_length = zend_hash_num_elements(arr_hash);
2147
   
2148
    arguments = new XdmValue*[argument_length];
2149
    std::map<std::string,XdmValue*> parameters;
2150 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2151 72bf04c6 Norman Walsh
      for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &val, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) {
2152 ead48a5d O'Neil Delpratt
                      if(Z_TYPE_PP(val) != IS_nullptr) {
2153 72bf04c6 Norman Walsh
                      //zend_object* ooth = Z_OBJCE_PP(val);
2154
                            const char * objName = Z_OBJCE_PP(val)->name;
2155 ead48a5d O'Neil Delpratt
                      char *key = nullptr;
2156 72bf04c6 Norman Walsh
                      uint  klen;
2157
                      ulong index;
2158
2159
           if (zend_hash_get_current_key_ex(arr_hash, &key, &klen, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
2160
                       /* the key is a string, do nothing */
2161
              }else {
2162
                       /* we assume the key to be long, index will be set */
2163
              
2164
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
2165
        php_printf("num_key %d =>", num_key);
2166
        php_printf("key %d =>", key);
2167
        */
2168
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2169
                //zend_object* ooth = Z_OBJCE_PP(val);
2170
                xdmNode_object* nobj = (xdmNode_object*)zend_object_store_get_object((*val) TSRMLS_CC);
2171
                //xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
2172 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
2173 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
2174
                            parameters[key] = value;
2175
                }
2176
        }
2177
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2178
                //zend_object* ooth = Z_OBJCE_P(val);
2179
                xdmAtomicValue_object* nobj = (xdmAtomicValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
2180
                //xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
2181 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
2182 72bf04c6 Norman Walsh
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
2183
                            parameters[key] = value;
2184
                }
2185
        }
2186
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
2187
                //zend_object* ooth = Z_OBJCE_P(val);
2188
                xdmValue_object* nobj = (xdmValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
2189
                //xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2190 ead48a5d O'Neil Delpratt
                if(nobj != nullptr) {
2191 72bf04c6 Norman Walsh
                            XdmValue * value = nobj->xdmValue;
2192
                            parameters[key] = value;
2193
                }
2194
        }
2195
        else {//TODO error warning}
2196
         }
2197
    }}else {
2198
                //TODO error warning
2199
        }
2200
      }
2201
      }
2202
2203
2204
        //php_printf(" argument_length= %d",argument_length);
2205
        xslt30Processor->setInitialTemplateParameters(parameters, tunnel);
2206
        
2207
    }
2208
2209
2210
2211
2212
PHP_METHOD(Xslt30Processor, setInitialMatchSelection){
2213
   Xslt30Processor *xslt30Processor;
2214 ead48a5d O'Neil Delpratt
    zval* oth = nullptr;
2215 72bf04c6 Norman Walsh
2216
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2217 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2218 72bf04c6 Norman Walsh
    }
2219
2220
    
2221
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2222
2223
    xslt30Processor = obj->xslt30Processor;
2224 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2225 72bf04c6 Norman Walsh
2226
    if(!oth) {
2227
        php_error(E_WARNING, "Error setting source value");
2228
        return;
2229
    } else {
2230 ead48a5d O'Neil Delpratt
        if(Z_TYPE_P(oth) ==IS_nullptr){
2231 72bf04c6 Norman Walsh
                php_error(E_WARNING, "Error setting source value");
2232
                return;
2233
        }
2234
2235
      const char * objName =Z_OBJCE_P(oth)->name;
2236
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2237
2238
      
2239
      if(strcmp(objName, "Saxon\\XdmValue")==0) {
2240
     xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2241
        //(xdmNode_object*)Z_OBJ_P(oth);
2242 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2243 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
2244 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2245 72bf04c6 Norman Walsh
                        xslt30Processor->setInitialMatchSelection(value);
2246
2247
            }
2248
        }
2249
      } else if(strcmp(objName, "Saxon\\XdmNode")==0) {
2250
        xdmNode_object* ooth = (xdmNode_object*) zend_object_store_get_object(oth TSRMLS_CC);
2251
        //xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2252 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2253 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2254 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2255 72bf04c6 Norman Walsh
                XdmValue  *valueX = (XdmValue*)value;
2256
                xslt30Processor->setInitialMatchSelection(valueX);
2257
2258
            }
2259
        }
2260
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2261
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2262 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2263 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2264 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2265 72bf04c6 Norman Walsh
                xslt30Processor->setInitialMatchSelection((XdmValue*)value);
2266
            }
2267
        }
2268
      } else {
2269
        //TODO raise warning
2270
        }
2271
2272
2273
    }
2274
  }
2275
2276
2277
2278
2279
}
2280
    
2281
2282
PHP_METHOD(Xslt30Processor, setGlobalContextItem)
2283
{
2284
    Xslt30Processor *xslt30Processor;
2285 ead48a5d O'Neil Delpratt
    zval* oth = nullptr;
2286 72bf04c6 Norman Walsh
2287
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2288 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2289 72bf04c6 Norman Walsh
    }
2290
2291
    
2292
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2293
    xslt30Processor = obj->xslt30Processor;
2294 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2295 72bf04c6 Norman Walsh
2296
    if(!oth) {
2297
        php_error(E_WARNING, "Error setting source value");
2298
        return;
2299
    } else {
2300 ead48a5d O'Neil Delpratt
        if(Z_TYPE_P(oth) ==IS_nullptr){
2301 72bf04c6 Norman Walsh
                php_error(E_WARNING, "Error setting source value");
2302
                return;
2303
        }
2304
2305
      const char * objName =Z_OBJCE_P(oth)->name;
2306
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2307
2308
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2309
2310
    xdmNode_object* ooth = (xdmNode_object*) zend_object_store_get_object(oth TSRMLS_CC);
2311
        //xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2312 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2313 72bf04c6 Norman Walsh
            XdmNode * value = ooth->xdmNode;
2314 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2315 72bf04c6 Norman Walsh
                XdmItem  *valueX = (XdmItem*)value;
2316
                xslt30Processor->setGlobalContextItem(valueX);
2317
2318
            }
2319
        }
2320
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2321
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2322
        //xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2323 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2324 72bf04c6 Norman Walsh
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2325 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2326 72bf04c6 Norman Walsh
                xslt30Processor->setGlobalContextItem((XdmItem*)value);
2327
            }
2328
        }
2329
      } else {
2330
        //TODO raise warning
2331
        }
2332
2333
2334
    }
2335
  }
2336
}
2337
2338
2339
PHP_METHOD(Xslt30Processor, setGlobalContextFromFile)
2340
{
2341
    Xslt30Processor *xslt30Processor;
2342
    char * inFilename;
2343
    size_t len1;
2344
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2345 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2346 72bf04c6 Norman Walsh
    }
2347
2348
    
2349
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2350
    xslt30Processor = obj->xslt30Processor;
2351 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr && inFilename != nullptr) {
2352 72bf04c6 Norman Walsh
         xslt30Processor->setGlobalContextFromFile(inFilename);
2353
2354
2355
    }
2356
}
2357
2358
2359
PHP_METHOD(Xslt30Processor, setInitialMatchSelectionAsFile)
2360
{
2361
    Xslt30Processor *xslt30Processor;
2362
    char * inFilename;
2363
    size_t len1;
2364
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2365 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2366 72bf04c6 Norman Walsh
    }
2367
2368
    
2369
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2370
    xslt30Processor = obj->xslt30Processor;
2371 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr && inFilename != nullptr) {
2372 72bf04c6 Norman Walsh
         xslt30Processor->setInitialMatchSelectionAsFile(inFilename);
2373
2374
2375
    }
2376
}
2377
2378
2379
PHP_METHOD(Xslt30Processor, transformFileToFile)
2380
{
2381
    Xslt30Processor *xslt30Processor;
2382
    char * outfileName;
2383
    char * infilename;
2384
    char * styleFileName;
2385
    size_t len1, len2, len3;
2386
2387
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
2388 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2389 72bf04c6 Norman Walsh
    }
2390
2391
    
2392
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2393
    xslt30Processor = obj->xslt30Processor;
2394
2395 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2396 72bf04c6 Norman Walsh
2397
        xslt30Processor->transformFileToFile(infilename, styleFileName, outfileName);
2398
        if(xslt30Processor->exceptionOccurred()) {
2399
               // TODO: throw exception
2400
        }
2401
    }
2402
}
2403
2404
PHP_METHOD(Xslt30Processor, transformFileToValue)
2405
{
2406
    Xslt30Processor *xslt30Processor;
2407
    char * infilename;
2408
    char * styleFileName;
2409
   size_t len1, len2;
2410
2411
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2412 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2413 72bf04c6 Norman Walsh
    }
2414
2415
    
2416
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2417
    xslt30Processor = obj->xslt30Processor;
2418
2419 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2420 72bf04c6 Norman Walsh
2421
        XdmValue * node = xslt30Processor->transformFileToValue(infilename, styleFileName);
2422 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2423 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2424 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2425 72bf04c6 Norman Walsh
            } else {
2426
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
2427
                //zend_object *ooth =  Z_OBJCE_P(return_value);
2428
                //xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2429
                    struct xdmValue_object* vobj = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
2430 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2431 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
2432
            }
2433
        } else {
2434
            if(obj->xslt30Processor->exceptionOccurred()){
2435
                  //TODO
2436
            }
2437
        }
2438
    }else {
2439 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2440 72bf04c6 Norman Walsh
    }
2441
}
2442
2443
2444
PHP_METHOD(Xslt30Processor, transformFileToString)
2445
{
2446
    Xslt30Processor *xslt30Processor;
2447
    char * infilename;
2448
    char * styleFileName;
2449
    size_t len1, len2;
2450
2451
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2452 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2453 72bf04c6 Norman Walsh
    }
2454
2455
    
2456
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2457
    xslt30Processor = obj->xslt30Processor;
2458
2459 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2460 72bf04c6 Norman Walsh
2461
        const char * result = xslt30Processor->transformFileToString(infilename, styleFileName);
2462 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
2463 72bf04c6 Norman Walsh
            //char *str = estrdup(result);
2464
            RETURN_STRING(result, 0);
2465
        } else if(xslt30Processor->exceptionOccurred()){
2466
            //TODO: xslt30Processor->checkException();
2467
            const char * errStr = xslt30Processor->getErrorMessage(0);
2468 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
2469 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
2470 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
2471 72bf04c6 Norman Walsh
                    // TODO: throw exception
2472
                }
2473
            }
2474
        }
2475
    }
2476
}
2477
2478
2479
2480
PHP_METHOD(Xslt30Processor, transformToString)
2481
{
2482
    Xslt30Processor *xslt30Processor;
2483
2484
    if (ZEND_NUM_ARGS()>0) {
2485
        WRONG_PARAM_COUNT;
2486
    }
2487
2488
2489
    
2490
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2491
    xslt30Processor = obj->xslt30Processor;
2492 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2493 72bf04c6 Norman Walsh
2494
        const char * result = xslt30Processor->transformToString();
2495 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
2496 72bf04c6 Norman Walsh
            RETURN_STRING(result, 0);
2497
        } else if(xslt30Processor->exceptionOccurred()){
2498
            xslt30Processor->checkException();
2499
            const char * errStr = xslt30Processor->getErrorMessage(0);
2500 ead48a5d O'Neil Delpratt
            if(errStr != nullptr) {
2501 72bf04c6 Norman Walsh
                const char * errorCode = xslt30Processor->getErrorCode(0);
2502 ead48a5d O'Neil Delpratt
                if(errorCode!=nullptr) {
2503 72bf04c6 Norman Walsh
                    // TODO: throw exception
2504
                }
2505
            }
2506
        }
2507
    }
2508 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2509 72bf04c6 Norman Walsh
}
2510
2511
PHP_METHOD(Xslt30Processor, transformToValue)
2512
{
2513
    Xslt30Processor *xslt30Processor;
2514
2515
    if (ZEND_NUM_ARGS()>0) {
2516
        WRONG_PARAM_COUNT;
2517
    }
2518
2519
    
2520
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2521
    xslt30Processor = obj->xslt30Processor;
2522
2523 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2524 72bf04c6 Norman Walsh
2525
        XdmValue * node = xslt30Processor->transformToValue();
2526 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2527 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2528 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2529 72bf04c6 Norman Walsh
            } else {
2530
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value);
2531
2532
                //xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2533
            struct xdmValue_object* vobj = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
2534
2535 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2536 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
2537
            }
2538
        } else if(xslt30Processor->exceptionOccurred()){
2539
            xslt30Processor->checkException();
2540 ead48a5d O'Neil Delpratt
            RETURN_nullptr();
2541 72bf04c6 Norman Walsh
        }
2542
    } else {
2543 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2544 72bf04c6 Norman Walsh
    }
2545
}
2546
2547
PHP_METHOD(Xslt30Processor, transformToFile)
2548
{
2549
    Xslt30Processor *xslt30Processor;
2550
2551
    if (ZEND_NUM_ARGS()>0) {
2552
        WRONG_PARAM_COUNT;
2553
    }
2554
2555
    
2556
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2557
    xslt30Processor = obj->xslt30Processor;
2558
2559 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2560 72bf04c6 Norman Walsh
2561
        xslt30Processor->transformToFile();
2562
        if(xslt30Processor->exceptionOccurred()) {
2563
           //TODO
2564
            const char * exStr = xslt30Processor->checkException();
2565
        }
2566
    } else {
2567 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2568 72bf04c6 Norman Walsh
    }
2569
}
2570
2571
PHP_METHOD(Xslt30Processor, compileFromFile)
2572
{
2573
    Xslt30Processor *xslt30Processor;
2574
    char * name;
2575
    size_t len1;
2576
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2577 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2578 72bf04c6 Norman Walsh
    }
2579
    
2580
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2581
    xslt30Processor = obj->xslt30Processor;
2582 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2583 72bf04c6 Norman Walsh
        xslt30Processor->compileFromFile(name);
2584
    }
2585
}
2586
2587
PHP_METHOD(Xslt30Processor, compileFromString)
2588
{
2589
    Xslt30Processor *xslt30Processor;
2590
    char * stylesheetStr;
2591
    size_t len1, myint;
2592
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &stylesheetStr, &len1) == FAILURE) {
2593 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2594 72bf04c6 Norman Walsh
    }
2595
    
2596
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2597
    xslt30Processor = obj->xslt30Processor;
2598 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2599 72bf04c6 Norman Walsh
        xslt30Processor->compileFromString(stylesheetStr);
2600
    }
2601
}
2602
2603
PHP_METHOD(Xslt30Processor, compileFromStringAndSave)
2604
{
2605
    Xslt30Processor *xslt30Processor;
2606
    char * stylesheetStr;
2607
    char * filename;
2608
    size_t len1, len2, myint;
2609
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &stylesheetStr, filename, &len1, &len2) == FAILURE) {
2610 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2611 72bf04c6 Norman Walsh
    }
2612
    
2613
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2614
    xslt30Processor = obj->xslt30Processor;
2615
    xslt30Processor = obj->xslt30Processor;
2616 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2617 72bf04c6 Norman Walsh
        xslt30Processor->compileFromStringAndSave(stylesheetStr, filename);
2618
    }
2619
}
2620
2621
PHP_METHOD(Xslt30Processor, compileFromFileAndSave)
2622
{
2623
    Xslt30Processor *xslt30Processor;
2624
    char * stylesheetFilename;
2625
    char * filename;
2626
    size_t len1, len2, myint;
2627
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
2628 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2629 72bf04c6 Norman Walsh
    }
2630
    
2631
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2632
    xslt30Processor = obj->xslt30Processor;
2633 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2634 72bf04c6 Norman Walsh
        xslt30Processor->compileFromStringAndSave(stylesheetFilename, filename);
2635
    }
2636
}
2637
2638
2639
2640
PHP_METHOD(Xslt30Processor, compileFromValue)
2641
{
2642
    Xslt30Processor *xslt30Processor;
2643
   zval* oth;
2644
2645
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &oth, xdmValue_ce) == FAILURE) {
2646 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2647 72bf04c6 Norman Walsh
    }
2648
    
2649
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2650
    xslt30Processor = obj->xslt30Processor;
2651 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2652 72bf04c6 Norman Walsh
        //zend_object* vvobj = Z_OBJCE_P(oth);
2653
        //xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2654
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2655 ead48a5d O'Neil Delpratt
        if(ooth != nullptr) {
2656 72bf04c6 Norman Walsh
            XdmValue * value = ooth->xdmValue;
2657 ead48a5d O'Neil Delpratt
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
2658 72bf04c6 Norman Walsh
                xslt30Processor->compileFromXdmNode((XdmNode*)(value->getHead()));
2659
            }
2660
        }
2661
    }
2662
}
2663
2664
2665
2666
2667
2668
2669
2670
PHP_METHOD(Xslt30Processor, setJustInTimeCompilation)
2671
{
2672
    Xslt30Processor *xslt30Processor;
2673
    bool jit = false;
2674
    size_t len1;
2675
2676
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &jit) == FAILURE) {
2677 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2678 72bf04c6 Norman Walsh
    }
2679
2680
    
2681
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2682
    xslt30Processor = obj->xslt30Processor;
2683 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2684 72bf04c6 Norman Walsh
         xslt30Processor->setJustInTimeCompilation(jit);
2685
    }
2686
}
2687
2688
PHP_METHOD(Xslt30Processor, setOutputFile)
2689
{
2690
    Xslt30Processor *xslt30Processor;
2691
    char * outputFilename;
2692
    size_t len1;
2693
2694
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &outputFilename, &len1) == FAILURE) {
2695 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2696 72bf04c6 Norman Walsh
    }
2697
2698
    
2699
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2700
    xslt30Processor = obj->xslt30Processor;
2701 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr && outputFilename != nullptr) {
2702 72bf04c6 Norman Walsh
2703
         xslt30Processor->setOutputFile(outputFilename);
2704
2705
2706
    }
2707
}
2708
2709
2710
2711
2712
PHP_METHOD(Xslt30Processor, setProperty)
2713
{
2714
    Xslt30Processor *xslt30Processor;
2715
    char * name;
2716
    char * value;
2717
    size_t len1, len2, myint;
2718
2719
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
2720 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2721 72bf04c6 Norman Walsh
    }
2722
    
2723
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2724
    xslt30Processor = obj->xslt30Processor;
2725 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2726 72bf04c6 Norman Walsh
        xslt30Processor->setProperty(name, value);
2727
    }
2728
}
2729
2730
PHP_METHOD(Xslt30Processor, setParameter)
2731
{
2732
2733
   Xslt30Processor *xslt30Processor;
2734
   char * name;
2735
   zval* oth;
2736
   size_t len1, len2, myint;
2737
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
2738 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2739 72bf04c6 Norman Walsh
    }
2740
    
2741
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2742
    xslt30Processor = obj->xslt30Processor;
2743 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2744
        if(Z_TYPE_P(oth) ==IS_nullptr){
2745
                php_error(E_WARNING, "Error setting source value - value is nullptr");
2746 72bf04c6 Norman Walsh
                return;
2747
        }
2748
2749
      const char * objName =Z_OBJCE_P(oth)->name;
2750
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2751
2752
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2753
        //zend_object* ooth = Z_OBJCE_P(oth);
2754
            xdmNode_object* nobj = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2755 ead48a5d O'Neil Delpratt
        if(nobj != nullptr) {
2756 72bf04c6 Norman Walsh
            XdmNode * value = nobj->xdmNode;
2757 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2758 72bf04c6 Norman Walsh
                xslt30Processor->setParameter(name, (XdmValue *)value);
2759
2760
            }
2761
        }
2762
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2763
        //zend_object* ooth = Z_OBJCE_P(oth);
2764
        xdmValue_object* vobj = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
2765 ead48a5d O'Neil Delpratt
        if(vobj != nullptr) {
2766 72bf04c6 Norman Walsh
            XdmValue * value = vobj->xdmValue;
2767 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2768 72bf04c6 Norman Walsh
2769
                xslt30Processor->setParameter(name, value);
2770
            }
2771
        }
2772
2773
2774
2775
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2776
        //zend_object* ooth = Z_OBJCE_P(oth);
2777
        xdmAtomicValue_object* aobj = (xdmAtomicValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
2778 ead48a5d O'Neil Delpratt
        if(aobj != nullptr) {
2779 72bf04c6 Norman Walsh
            XdmAtomicValue * value = aobj->xdmAtomicValue;
2780 ead48a5d O'Neil Delpratt
            if(value != nullptr) {
2781 72bf04c6 Norman Walsh
                xslt30Processor->setParameter(name, (XdmValue *)value);
2782
            }
2783
        }
2784
2785
2786
2787
      }
2788
2789
    }
2790
}
2791
2792
PHP_METHOD(Xslt30Processor, clearParameters)
2793
{
2794
    Xslt30Processor *xslt30Processor;
2795
    if (ZEND_NUM_ARGS()>0) {
2796
        WRONG_PARAM_COUNT;
2797
    }
2798
2799
    
2800
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2801
    xslt30Processor = obj->xslt30Processor;
2802 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2803 72bf04c6 Norman Walsh
        xslt30Processor->clearParameters(true);
2804
    }
2805
}
2806
2807
PHP_METHOD(Xslt30Processor, clearProperties)
2808
{
2809
    Xslt30Processor *xslt30Processor;
2810
    if (ZEND_NUM_ARGS()>0) {
2811
        WRONG_PARAM_COUNT;
2812
    }
2813
2814
    
2815
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2816
    xslt30Processor = obj->xslt30Processor;
2817 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2818 72bf04c6 Norman Walsh
        xslt30Processor->clearProperties();
2819
    }
2820
}
2821
2822
PHP_METHOD(Xslt30Processor, setupXslMessage)
2823
{
2824
    Xslt30Processor *xslt30Processor;
2825
    bool show = false;
2826 ead48a5d O'Neil Delpratt
    char * filename = nullptr;
2827 72bf04c6 Norman Walsh
    size_t len1;
2828
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "bs", &show, &filename &len1) == FAILURE) {
2829 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2830 72bf04c6 Norman Walsh
    }
2831
2832
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2833
    xslt30Processor = obj->xslt30Processor;
2834
2835 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2836 72bf04c6 Norman Walsh
2837
            xslt30Processor->setupXslMessage(show, filename);
2838
        }
2839
2840
}
2841
2842
2843
2844
2845
PHP_METHOD(Xslt30Processor, exceptionOccurred)
2846
{
2847
    Xslt30Processor *xslt30Processor;
2848
    
2849
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2850
    if (ZEND_NUM_ARGS()>0) {
2851
        WRONG_PARAM_COUNT;
2852
    }
2853
2854
    xslt30Processor = obj->xslt30Processor;
2855 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2856 72bf04c6 Norman Walsh
        bool result = xslt30Processor->exceptionOccurred();
2857
        RETURN_BOOL(result);
2858
    }
2859
    RETURN_BOOL(false);
2860
}
2861
2862
PHP_METHOD(Xslt30Processor, getExceptionCount)
2863
{
2864
    Xslt30Processor *xslt30Processor;
2865
    
2866
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2867
    if (ZEND_NUM_ARGS()>0) {
2868
        WRONG_PARAM_COUNT;
2869
    }
2870
2871
    xslt30Processor = obj->xslt30Processor;
2872 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2873 72bf04c6 Norman Walsh
        int count = xslt30Processor->exceptionCount();
2874
        RETURN_LONG(count);
2875
    }
2876
    RETURN_LONG(0);
2877
}
2878
2879
PHP_METHOD(Xslt30Processor, getErrorCode)
2880
{
2881
    Xslt30Processor *xslt30Processor;
2882
    long index;
2883
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
2884 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2885 72bf04c6 Norman Walsh
    }
2886
    
2887
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2888
    xslt30Processor = obj->xslt30Processor;
2889 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2890 72bf04c6 Norman Walsh
        const char * errCode = xslt30Processor->getErrorCode((int)index);
2891 ead48a5d O'Neil Delpratt
        if(errCode != nullptr) {
2892 72bf04c6 Norman Walsh
            //char *str = estrdup(errCode);
2893
            RETURN_STRING(errCode, 0);
2894
        }
2895
    }
2896 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2897 72bf04c6 Norman Walsh
}
2898
2899
PHP_METHOD(Xslt30Processor, getErrorMessage)
2900
{
2901
    Xslt30Processor *xslt30Processor;
2902
    long index;
2903
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2904 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
2905 72bf04c6 Norman Walsh
    }
2906
    
2907
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2908
    xslt30Processor = obj->xslt30Processor;
2909 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2910 72bf04c6 Norman Walsh
        const char * errStr = xslt30Processor->getErrorMessage((int)index);
2911 ead48a5d O'Neil Delpratt
        if(errStr != nullptr) {
2912 72bf04c6 Norman Walsh
            //char *str = estrdup(errStr);
2913
            RETURN_STRING(errStr, 0);
2914
        }
2915
    }
2916 ead48a5d O'Neil Delpratt
    RETURN_nullptr();
2917 72bf04c6 Norman Walsh
}
2918
PHP_METHOD(Xslt30Processor, exceptionClear)
2919
{
2920
    Xslt30Processor *xslt30Processor;
2921
    
2922
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2923
    xslt30Processor = obj->xslt30Processor;
2924 ead48a5d O'Neil Delpratt
    if (xslt30Processor != nullptr) {
2925 72bf04c6 Norman Walsh
        xslt30Processor->exceptionClear();
2926
    }
2927
}
2928
2929
2930
2931
2932
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
2933
2934
void xqueryProcessor_free_storage(void *object TSRMLS_DC)
2935
{
2936
    xqueryProcessor_object *obj = (xqueryProcessor_object *)object;
2937
    //obj->xqueryProcessor->clearParameters(true);
2938
    //obj->xqueryProcessor->clearProperties();
2939
    zend_hash_destroy(obj->std.properties);
2940
    FREE_HASHTABLE(obj->std.properties);
2941
    efree(obj);
2942
}
2943
2944
zend_object_value xqueryProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
2945
{
2946
    zval *tmp;
2947
    zend_object_value retval;
2948
    xqueryProcessor_object *obj = (xqueryProcessor_object *)emalloc(sizeof(xqueryProcessor_object));
2949
    memset(obj, 0, sizeof(xqueryProcessor_object));
2950
    obj->std.ce = type;
2951
2952
    ALLOC_HASHTABLE(obj->std.properties);
2953 ead48a5d O'Neil Delpratt
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
2954 72bf04c6 Norman Walsh
    object_properties_init(&obj->std, type);
2955 ead48a5d O'Neil Delpratt
    retval.handle = zend_objects_store_put(obj, nullptr, xqueryProcessor_free_storage, nullptr TSRMLS_CC);
2956 72bf04c6 Norman Walsh
    retval.handlers = &xqueryProcessor_object_handlers;
2957
2958
    return retval;
2959
}
2960
2961
PHP_METHOD(XQueryProcessor, __destruct)
2962
{
2963
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2964
2965
2966
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
2967
2968
    delete xqueryProcessor;
2969
    
2970
}
2971
2972
2973
PHP_METHOD(XQueryProcessor, runQueryToValue)
2974
{
2975
    XQueryProcessor *xqueryProcessor;
2976
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2977
2978
    if (ZEND_NUM_ARGS()>0) {
2979
        WRONG_PARAM_COUNT;
2980
    }
2981
2982
    xqueryProcessor = obj->xqueryProcessor;
2983
2984 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
2985 72bf04c6 Norman Walsh
        XdmValue * node = xqueryProcessor->runQueryToValue();
2986 ead48a5d O'Neil Delpratt
        if(node != nullptr) {
2987 72bf04c6 Norman Walsh
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2988 ead48a5d O'Neil Delpratt
                RETURN_nullptr();
2989 72bf04c6 Norman Walsh
                return;
2990
            } else {
2991
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2992 ead48a5d O'Neil Delpratt
                assert (vobj != nullptr);
2993 72bf04c6 Norman Walsh
                vobj->xdmValue = node;
2994
                return;
2995
            }
2996
        }
2997
        xqueryProcessor->checkException();//TODO
2998
    } else {
2999 ead48a5d O'Neil Delpratt
        RETURN_nullptr();
3000 72bf04c6 Norman Walsh
    }
3001
}
3002
3003
PHP_METHOD(XQueryProcessor, runQueryToString)
3004
{
3005
    XQueryProcessor *xqueryProcessor;
3006
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3007
3008
    if (ZEND_NUM_ARGS()>0) {
3009
        WRONG_PARAM_COUNT;
3010
    }
3011
3012
    xqueryProcessor = obj->xqueryProcessor;
3013
3014 ead48a5d O'Neil Delpratt
    if (xqueryProcessor != nullptr) {
3015 72bf04c6 Norman Walsh
        const char * result = xqueryProcessor->runQueryToString();
3016 ead48a5d O'Neil Delpratt
        if(result != nullptr) {
3017 72bf04c6 Norman Walsh
            char *str = estrdup(result);
3018
            RETURN_STRING(str, 0);
3019