stylesheet.c 21.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 *    XSLTemplate/XSLProcessor support
 *
 * Copyright 2011 Nikolay Sivov for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#define COBJMACROS

#include "config.h"

#include <stdarg.h>
26 27 28 29 30
#ifdef HAVE_LIBXML2
# include <libxml/parser.h>
# include <libxml/xmlerror.h>
#endif

31 32 33 34 35 36 37 38
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "ole2.h"
#include "msxml6.h"

#include "msxml_private.h"

39 40 41
#include "initguid.h"
#include "asptlb.h"

42 43 44 45
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(msxml);

46
typedef struct
47
{
48
    DispatchEx dispex;
49 50
    IXSLTemplate IXSLTemplate_iface;
    LONG ref;
51 52

    IXMLDOMNode *node;
53 54
} xsltemplate;

55 56 57 58 59
enum output_type
{
    PROCESSOR_OUTPUT_NOT_SET,
    PROCESSOR_OUTPUT_STREAM,        /* IStream or ISequentialStream */
    PROCESSOR_OUTPUT_PERSISTSTREAM, /* IPersistStream or IPersistStreamInit */
60
    PROCESSOR_OUTPUT_RESPONSE,      /* IResponse */
61 62
};

63
typedef struct
64
{
65
    DispatchEx dispex;
66 67
    IXSLProcessor IXSLProcessor_iface;
    LONG ref;
68

69
    xsltemplate *stylesheet;
70
    IXMLDOMNode *input;
71

72 73 74 75 76
    union
    {
        IUnknown *unk;
        ISequentialStream *stream;
        IPersistStream *persiststream;
77
        IResponse *response;
78 79 80
    } output;
    enum output_type output_type;
    BSTR outstr;
81 82

    struct xslprocessor_params params;
83 84
} xslprocessor;

85
static HRESULT XSLProcessor_create(xsltemplate*, IXSLProcessor**);
86

87 88 89 90 91
static inline xsltemplate *impl_from_IXSLTemplate( IXSLTemplate *iface )
{
    return CONTAINING_RECORD(iface, xsltemplate, IXSLTemplate_iface);
}

92 93 94 95 96
static inline xslprocessor *impl_from_IXSLProcessor( IXSLProcessor *iface )
{
    return CONTAINING_RECORD(iface, xslprocessor, IXSLProcessor_iface);
}

97 98 99 100 101 102 103 104 105
static void xslprocessor_par_free(struct xslprocessor_params *params, struct xslprocessor_par *par)
{
    params->count--;
    list_remove(&par->entry);
    SysFreeString(par->name);
    SysFreeString(par->value);
    heap_free(par);
}

106 107 108 109 110 111 112
static void xsltemplate_set_node( xsltemplate *This, IXMLDOMNode *node )
{
    if (This->node) IXMLDOMNode_Release(This->node);
    This->node = node;
    if (node) IXMLDOMNode_AddRef(node);
}

113 114 115 116 117 118 119 120 121 122 123 124 125 126
static HRESULT WINAPI xsltemplate_QueryInterface(
    IXSLTemplate *iface,
    REFIID riid,
    void** ppvObject )
{
    xsltemplate *This = impl_from_IXSLTemplate( iface );
    TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);

    if ( IsEqualGUID( riid, &IID_IXSLTemplate ) ||
         IsEqualGUID( riid, &IID_IDispatch ) ||
         IsEqualGUID( riid, &IID_IUnknown ) )
    {
        *ppvObject = iface;
    }
127 128 129 130
    else if (dispex_query_interface(&This->dispex, riid, ppvObject))
    {
        return *ppvObject ? S_OK : E_NOINTERFACE;
    }
131 132 133
    else
    {
        FIXME("Unsupported interface %s\n", debugstr_guid(riid));
134
        *ppvObject = NULL;
135 136 137 138 139 140 141 142 143 144
        return E_NOINTERFACE;
    }

    IUnknown_AddRef((IUnknown*)*ppvObject);
    return S_OK;
}

static ULONG WINAPI xsltemplate_AddRef( IXSLTemplate *iface )
{
    xsltemplate *This = impl_from_IXSLTemplate( iface );
145 146 147
    ULONG ref = InterlockedIncrement( &This->ref );
    TRACE("(%p)->(%d)\n", This, ref);
    return ref;
148 149 150 151 152
}

static ULONG WINAPI xsltemplate_Release( IXSLTemplate *iface )
{
    xsltemplate *This = impl_from_IXSLTemplate( iface );
153
    ULONG ref = InterlockedDecrement( &This->ref );
154

155
    TRACE("(%p)->(%d)\n", This, ref);
156
    if ( ref == 0 )
157 158
    {
        if (This->node) IXMLDOMNode_Release( This->node );
159
        heap_free( This );
160
    }
161 162 163 164 165 166 167

    return ref;
}

static HRESULT WINAPI xsltemplate_GetTypeInfoCount( IXSLTemplate *iface, UINT* pctinfo )
{
    xsltemplate *This = impl_from_IXSLTemplate( iface );
168
    return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
169 170 171 172 173 174 175 176
}

static HRESULT WINAPI xsltemplate_GetTypeInfo(
    IXSLTemplate *iface,
    UINT iTInfo, LCID lcid,
    ITypeInfo** ppTInfo )
{
    xsltemplate *This = impl_from_IXSLTemplate( iface );
177 178
    return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
        iTInfo, lcid, ppTInfo);
179 180 181 182 183 184 185 186
}

static HRESULT WINAPI xsltemplate_GetIDsOfNames(
    IXSLTemplate *iface,
    REFIID riid, LPOLESTR* rgszNames,
    UINT cNames, LCID lcid, DISPID* rgDispId )
{
    xsltemplate *This = impl_from_IXSLTemplate( iface );
187 188
    return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
        riid, rgszNames, cNames, lcid, rgDispId);
189 190 191 192 193 194 195 196 197
}

static HRESULT WINAPI xsltemplate_Invoke(
    IXSLTemplate *iface,
    DISPID dispIdMember, REFIID riid, LCID lcid,
    WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
    EXCEPINFO* pExcepInfo, UINT* puArgErr )
{
    xsltemplate *This = impl_from_IXSLTemplate( iface );
198 199
    return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
        dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
200 201 202 203 204 205 206
}

static HRESULT WINAPI xsltemplate_putref_stylesheet( IXSLTemplate *iface,
    IXMLDOMNode *node)
{
    xsltemplate *This = impl_from_IXSLTemplate( iface );

207 208 209 210 211 212 213 214 215 216 217 218
    TRACE("(%p)->(%p)\n", This, node);

    if (!node)
    {
        xsltemplate_set_node(This, NULL);
        return S_OK;
    }

    /* FIXME: test for document type */
    xsltemplate_set_node(This, node);

    return S_OK;
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
}

static HRESULT WINAPI xsltemplate_get_stylesheet( IXSLTemplate *iface,
    IXMLDOMNode **node)
{
    xsltemplate *This = impl_from_IXSLTemplate( iface );

    FIXME("(%p)->(%p): stub\n", This, node);
    return E_NOTIMPL;
}

static HRESULT WINAPI xsltemplate_createProcessor( IXSLTemplate *iface,
    IXSLProcessor **processor)
{
    xsltemplate *This = impl_from_IXSLTemplate( iface );

235 236 237 238
    TRACE("(%p)->(%p)\n", This, processor);

    if (!processor) return E_INVALIDARG;

239
    return XSLProcessor_create(This, processor);
240 241
}

242
static const struct IXSLTemplateVtbl XSLTemplateVtbl =
243 244 245 246 247 248 249 250 251 252 253 254 255
{
    xsltemplate_QueryInterface,
    xsltemplate_AddRef,
    xsltemplate_Release,
    xsltemplate_GetTypeInfoCount,
    xsltemplate_GetTypeInfo,
    xsltemplate_GetIDsOfNames,
    xsltemplate_Invoke,
    xsltemplate_putref_stylesheet,
    xsltemplate_get_stylesheet,
    xsltemplate_createProcessor
};

256 257 258 259 260 261 262 263 264 265 266 267
static const tid_t xsltemplate_iface_tids[] = {
    IXSLTemplate_tid,
    0
};

static dispex_static_data_t xsltemplate_dispex = {
    NULL,
    IXSLTemplate_tid,
    NULL,
    xsltemplate_iface_tids
};

268
HRESULT XSLTemplate_create(void **ppObj)
269 270 271
{
    xsltemplate *This;

272
    TRACE("(%p)\n", ppObj);
273 274 275 276 277

    This = heap_alloc( sizeof (*This) );
    if(!This)
        return E_OUTOFMEMORY;

278
    This->IXSLTemplate_iface.lpVtbl = &XSLTemplateVtbl;
279
    This->ref = 1;
280
    This->node = NULL;
281
    init_dispex(&This->dispex, (IUnknown*)&This->IXSLTemplate_iface, &xsltemplate_dispex);
282 283 284 285 286 287 288 289

    *ppObj = &This->IXSLTemplate_iface;

    TRACE("returning iface %p\n", *ppObj);

    return S_OK;
}

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
/*** IXSLProcessor ***/
static HRESULT WINAPI xslprocessor_QueryInterface(
    IXSLProcessor *iface,
    REFIID riid,
    void** ppvObject )
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );
    TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);

    if ( IsEqualGUID( riid, &IID_IXSLProcessor ) ||
         IsEqualGUID( riid, &IID_IDispatch ) ||
         IsEqualGUID( riid, &IID_IUnknown ) )
    {
        *ppvObject = iface;
    }
305 306 307 308
    else if (dispex_query_interface(&This->dispex, riid, ppvObject))
    {
        return *ppvObject ? S_OK : E_NOINTERFACE;
    }
309 310 311
    else
    {
        FIXME("Unsupported interface %s\n", debugstr_guid(riid));
312
        *ppvObject = NULL;
313 314 315 316 317 318 319 320 321 322
        return E_NOINTERFACE;
    }

    IUnknown_AddRef((IUnknown*)*ppvObject);
    return S_OK;
}

static ULONG WINAPI xslprocessor_AddRef( IXSLProcessor *iface )
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );
323 324 325
    ULONG ref = InterlockedIncrement( &This->ref );
    TRACE("(%p)->(%d)\n", This, ref);
    return ref;
326 327 328 329 330
}

static ULONG WINAPI xslprocessor_Release( IXSLProcessor *iface )
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );
331
    ULONG ref = InterlockedDecrement( &This->ref );
332

333
    TRACE("(%p)->(%d)\n", This, ref);
334
    if ( ref == 0 )
335
    {
336 337
        struct xslprocessor_par *par, *par2;

338
        if (This->input) IXMLDOMNode_Release(This->input);
339 340
        if (This->output.unk)
            IUnknown_Release(This->output.unk);
341
        SysFreeString(This->outstr);
342 343 344 345

        LIST_FOR_EACH_ENTRY_SAFE(par, par2, &This->params.list, struct xslprocessor_par, entry)
            xslprocessor_par_free(&This->params, par);

346
        IXSLTemplate_Release(&This->stylesheet->IXSLTemplate_iface);
347
        heap_free( This );
348
    }
349 350 351 352 353 354 355

    return ref;
}

static HRESULT WINAPI xslprocessor_GetTypeInfoCount( IXSLProcessor *iface, UINT* pctinfo )
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );
356
    return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
357 358 359 360 361 362 363 364
}

static HRESULT WINAPI xslprocessor_GetTypeInfo(
    IXSLProcessor *iface,
    UINT iTInfo, LCID lcid,
    ITypeInfo** ppTInfo )
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );
365 366
    return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
        iTInfo, lcid, ppTInfo);
367 368 369 370 371 372 373 374
}

static HRESULT WINAPI xslprocessor_GetIDsOfNames(
    IXSLProcessor *iface,
    REFIID riid, LPOLESTR* rgszNames,
    UINT cNames, LCID lcid, DISPID* rgDispId )
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );
375 376
    return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
        riid, rgszNames, cNames, lcid, rgDispId);
377 378 379 380 381 382 383 384 385
}

static HRESULT WINAPI xslprocessor_Invoke(
    IXSLProcessor *iface,
    DISPID dispIdMember, REFIID riid, LCID lcid,
    WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
    EXCEPINFO* pExcepInfo, UINT* puArgErr )
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );
386 387
    return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
        dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
388 389 390 391 392
}

static HRESULT WINAPI xslprocessor_put_input( IXSLProcessor *iface, VARIANT input )
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );
393 394
    IXMLDOMNode *input_node;
    HRESULT hr;
395

396 397 398 399 400 401 402 403 404 405 406
    TRACE("(%p)->(%s)\n", This, debugstr_variant(&input));

    /* try IXMLDOMNode directly first */
    if (V_VT(&input) == VT_UNKNOWN)
        hr = IUnknown_QueryInterface(V_UNKNOWN(&input), &IID_IXMLDOMNode, (void**)&input_node);
    else if (V_VT(&input) == VT_DISPATCH)
        hr = IDispatch_QueryInterface(V_DISPATCH(&input), &IID_IXMLDOMNode, (void**)&input_node);
    else
    {
        IXMLDOMDocument *doc;

407
        hr = DOMDocument_create(MSXML_DEFAULT, (void**)&doc);
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
        if (hr == S_OK)
        {
            VARIANT_BOOL b;

            hr = IXMLDOMDocument_load(doc, input, &b);
            if (hr == S_OK)
                hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&input_node);
            IXMLDOMDocument_Release(doc);
        }
    }

    if (hr == S_OK)
    {
        if (This->input) IXMLDOMNode_Release(This->input);
        This->input = input_node;
    }

    return hr;
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
}

static HRESULT WINAPI xslprocessor_get_input( IXSLProcessor *iface, VARIANT *input )
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );

    FIXME("(%p)->(%p): stub\n", This, input);
    return E_NOTIMPL;
}

static HRESULT WINAPI xslprocessor_get_ownerTemplate(
    IXSLProcessor *iface,
    IXSLTemplate **template)
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );

    FIXME("(%p)->(%p): stub\n", This, template);
    return E_NOTIMPL;
}

static HRESULT WINAPI xslprocessor_setStartMode(
    IXSLProcessor *iface,
    BSTR p,
    BSTR uri)
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );

453
    FIXME("(%p)->(%s %s): stub\n", This, debugstr_w(p), debugstr_w(uri));
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
    return E_NOTIMPL;
}

static HRESULT WINAPI xslprocessor_get_startMode(
    IXSLProcessor *iface,
    BSTR *p)
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );

    FIXME("(%p)->(%p): stub\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI xslprocessor_get_startModeURI(
    IXSLProcessor *iface,
    BSTR *uri)
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );

    FIXME("(%p)->(%p): stub\n", This, uri);
    return E_NOTIMPL;
}

static HRESULT WINAPI xslprocessor_put_output(
    IXSLProcessor *iface,
479
    VARIANT var)
480 481
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );
482 483 484
    enum output_type output_type = PROCESSOR_OUTPUT_NOT_SET;
    IUnknown *output = NULL;
    HRESULT hr = S_OK;
485

486
    TRACE("(%p)->(%s)\n", This, debugstr_variant(&var));
487

488
    switch (V_VT(&var))
489
    {
490
    case VT_EMPTY:
491
        break;
492 493 494 495 496 497 498 499 500
    case VT_UNKNOWN:
    case VT_DISPATCH:
        if (!V_UNKNOWN(&var))
            break;

        output_type = PROCESSOR_OUTPUT_STREAM;
        hr = IUnknown_QueryInterface(V_UNKNOWN(&var), &IID_IStream, (void **)&output);
        if (FAILED(hr))
            hr = IUnknown_QueryInterface(V_UNKNOWN(&var), &IID_ISequentialStream, (void **)&output);
501 502 503 504 505
        if (FAILED(hr))
        {
            output_type = PROCESSOR_OUTPUT_RESPONSE;
            hr = IUnknown_QueryInterface(V_UNKNOWN(&var), &IID_IResponse, (void **)&output);
        }
506 507 508 509 510 511 512
        if (FAILED(hr))
        {
            output_type = PROCESSOR_OUTPUT_PERSISTSTREAM;
            hr = IUnknown_QueryInterface(V_UNKNOWN(&var), &IID_IPersistStream, (void **)&output);
        }
        if (FAILED(hr))
            hr = IUnknown_QueryInterface(V_UNKNOWN(&var), &IID_IPersistStreamInit, (void **)&output);
513
        if (FAILED(hr))
514 515 516 517
        {
            output_type = PROCESSOR_OUTPUT_NOT_SET;
            WARN("failed to get output interface, 0x%08x\n", hr);
        }
518
        break;
519 520
    default:
        FIXME("output type %d not handled\n", V_VT(&var));
521 522 523 524 525
        hr = E_FAIL;
    }

    if (hr == S_OK)
    {
526 527 528 529
        if (This->output.unk)
            IUnknown_Release(This->output.unk);
        This->output.unk = output;
        This->output_type = output_type;
530 531 532
    }

    return hr;
533 534 535 536 537 538 539 540
}

static HRESULT WINAPI xslprocessor_get_output(
    IXSLProcessor *iface,
    VARIANT *output)
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );

541 542 543 544
    TRACE("(%p)->(%p)\n", This, output);

    if (!output) return E_INVALIDARG;

545
    if (This->output.unk)
546 547
    {
        V_VT(output) = VT_UNKNOWN;
548 549
        V_UNKNOWN(output) = This->output.unk;
        IUnknown_AddRef(This->output.unk);
550 551 552 553 554 555 556 557 558 559
    }
    else if (This->outstr)
    {
        V_VT(output) = VT_BSTR;
        V_BSTR(output) = SysAllocString(This->outstr);
    }
    else
        V_VT(output) = VT_EMPTY;

    return S_OK;
560 561 562 563
}

static HRESULT WINAPI xslprocessor_transform(
    IXSLProcessor *iface,
564
    VARIANT_BOOL  *ret)
565
{
566
#ifdef HAVE_LIBXML2
567
    xslprocessor *This = impl_from_IXSLProcessor( iface );
568
    ISequentialStream *stream = NULL;
569
    HRESULT hr;
570

571 572
    TRACE("(%p)->(%p)\n", This, ret);

573 574
    if (!ret)
        return E_INVALIDARG;
575 576 577 578 579 580

    if (This->output_type == PROCESSOR_OUTPUT_STREAM)
    {
        stream = This->output.stream;
        ISequentialStream_AddRef(stream);
    }
581 582 583
    else if (This->output_type == PROCESSOR_OUTPUT_PERSISTSTREAM ||
            This->output_type == PROCESSOR_OUTPUT_RESPONSE)
    {
584 585
        if (FAILED(hr = CreateStreamOnHGlobal(NULL, TRUE, (IStream **)&stream)))
            return hr;
586
    }
587

588 589
    SysFreeString(This->outstr);

590 591
    hr = node_transform_node_params(get_node_obj(This->input), This->stylesheet->node,
            &This->outstr, stream, &This->params);
592
    if (SUCCEEDED(hr))
593 594 595
    {
        IStream *src = (IStream *)stream;

596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
        switch (This->output_type)
        {
        case PROCESSOR_OUTPUT_PERSISTSTREAM:
        {
            LARGE_INTEGER zero;

            /* for IPersistStream* output seekable stream is used */
            zero.QuadPart = 0;
            IStream_Seek(src, zero, STREAM_SEEK_SET, NULL);
            hr = IPersistStream_Load(This->output.persiststream, src);
            break;
        }
        case PROCESSOR_OUTPUT_RESPONSE:
        {
            SAFEARRAYBOUND bound;
            SAFEARRAY *array;
            HGLOBAL hglobal;
            VARIANT bin;
            DWORD size;
            void *dest;

617 618
            if (FAILED(hr = GetHGlobalFromStream(src, &hglobal)))
                break;
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
            size = GlobalSize(hglobal);

            bound.lLbound = 0;
            bound.cElements = size;
            if (!(array = SafeArrayCreate(VT_UI1, 1, &bound)))
                break;

            V_VT(&bin) = VT_ARRAY | VT_UI1;
            V_ARRAY(&bin) = array;

            hr = SafeArrayAccessData(array, &dest);
            if (hr == S_OK)
            {
                void *data = GlobalLock(hglobal);
                memcpy(dest, data, size);
                GlobalUnlock(hglobal);
                SafeArrayUnaccessData(array);

                IResponse_BinaryWrite(This->output.response, bin);
            }

            VariantClear(&bin);
            break;
        }
        default:
            ;
        }
646 647 648 649 650
    }

    if (stream)
        ISequentialStream_Release(stream);

651
    *ret = hr == S_OK ? VARIANT_TRUE : VARIANT_FALSE;
652
    return hr;
653 654 655 656
#else
    FIXME("libxml2 is required but wasn't present at compile time\n");
    return E_NOTIMPL;
#endif
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
}

static HRESULT WINAPI xslprocessor_reset( IXSLProcessor *iface )
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );

    FIXME("(%p): stub\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI xslprocessor_get_readyState(
    IXSLProcessor *iface,
    LONG *state)
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );

    FIXME("(%p)->(%p): stub\n", This, state);
    return E_NOTIMPL;
}

677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
static HRESULT xslprocessor_set_parvalue(const VARIANT *var, struct xslprocessor_par *par)
{
    HRESULT hr = S_OK;

    switch (V_VT(var))
    {
    case VT_BSTR:
    {
        par->value = SysAllocString(V_BSTR(var));
        if (!par->value) hr = E_OUTOFMEMORY;
        break;
    }
    default:
        FIXME("value type %d not handled\n", V_VT(var));
        hr = E_NOTIMPL;
    }

    return hr;
}

697 698 699 700 701 702 703
static HRESULT WINAPI xslprocessor_addParameter(
    IXSLProcessor *iface,
    BSTR p,
    VARIANT var,
    BSTR uri)
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );
704 705
    struct xslprocessor_par *cur, *par = NULL;
    HRESULT hr;
706

707
    TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(p), debugstr_variant(&var),
708
        debugstr_w(uri));
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755

    if (uri && *uri)
        FIXME("namespace uri is not supported\n");

    /* search for existing parameter first */
    LIST_FOR_EACH_ENTRY(cur, &This->params.list, struct xslprocessor_par, entry)
    {
        if (!strcmpW(cur->name, p))
        {
            par = cur;
            break;
        }
    }

    /* override with new value or add new parameter */
    if (par)
    {
        if (V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY)
        {
            /* remove parameter */
            xslprocessor_par_free(&This->params, par);
            return S_OK;
        }
        SysFreeString(par->value);
        par->value = NULL;
    }
    else
    {
        /* new parameter */
        par = heap_alloc(sizeof(struct xslprocessor_par));
        if (!par) return E_OUTOFMEMORY;

        par->name = SysAllocString(p);
        if (!par->name)
        {
            heap_free(par);
            return E_OUTOFMEMORY;
        }
        list_add_tail(&This->params.list, &par->entry);
        This->params.count++;
    }

    hr = xslprocessor_set_parvalue(&var, par);
    if (FAILED(hr))
        xslprocessor_par_free(&This->params, par);

    return hr;
756 757 758 759 760 761 762 763 764
}

static HRESULT WINAPI xslprocessor_addObject(
    IXSLProcessor *iface,
    IDispatch *obj,
    BSTR uri)
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );

765
    FIXME("(%p)->(%p %s): stub\n", This, obj, debugstr_w(uri));
766 767 768 769 770 771 772 773 774 775 776 777 778
    return E_NOTIMPL;
}

static HRESULT WINAPI xslprocessor_get_stylesheet(
    IXSLProcessor *iface,
    IXMLDOMNode  **node)
{
    xslprocessor *This = impl_from_IXSLProcessor( iface );

    FIXME("(%p)->(%p): stub\n", This, node);
    return E_NOTIMPL;
}

779
static const struct IXSLProcessorVtbl XSLProcessorVtbl =
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
{
    xslprocessor_QueryInterface,
    xslprocessor_AddRef,
    xslprocessor_Release,
    xslprocessor_GetTypeInfoCount,
    xslprocessor_GetTypeInfo,
    xslprocessor_GetIDsOfNames,
    xslprocessor_Invoke,
    xslprocessor_put_input,
    xslprocessor_get_input,
    xslprocessor_get_ownerTemplate,
    xslprocessor_setStartMode,
    xslprocessor_get_startMode,
    xslprocessor_get_startModeURI,
    xslprocessor_put_output,
    xslprocessor_get_output,
    xslprocessor_transform,
    xslprocessor_reset,
    xslprocessor_get_readyState,
    xslprocessor_addParameter,
    xslprocessor_addObject,
    xslprocessor_get_stylesheet
};

804 805 806 807 808 809 810 811 812 813 814 815
static const tid_t xslprocessor_iface_tids[] = {
    IXSLProcessor_tid,
    0
};

static dispex_static_data_t xslprocessor_dispex = {
    NULL,
    IXSLProcessor_tid,
    NULL,
    xslprocessor_iface_tids
};

816
HRESULT XSLProcessor_create(xsltemplate *template, IXSLProcessor **ppObj)
817 818 819 820 821 822 823 824 825
{
    xslprocessor *This;

    TRACE("(%p)\n", ppObj);

    This = heap_alloc( sizeof (*This) );
    if(!This)
        return E_OUTOFMEMORY;

826
    This->IXSLProcessor_iface.lpVtbl = &XSLProcessorVtbl;
827
    This->ref = 1;
828
    This->input = NULL;
829 830
    This->output.unk = NULL;
    This->output_type = PROCESSOR_OUTPUT_NOT_SET;
831
    This->outstr = NULL;
832 833
    list_init(&This->params.list);
    This->params.count = 0;
834 835
    This->stylesheet = template;
    IXSLTemplate_AddRef(&template->IXSLTemplate_iface);
836
    init_dispex(&This->dispex, (IUnknown*)&This->IXSLProcessor_iface, &xslprocessor_dispex);
837 838 839 840 841 842 843

    *ppObj = &This->IXSLProcessor_iface;

    TRACE("returning iface %p\n", *ppObj);

    return S_OK;
}