msvcp90: Use macro to define RTTI data.
[wine] / dlls / msxml3 / httprequest.c
1 /*
2  *    IXMLHTTPRequest implementation
3  *
4  * Copyright 2008 Alistair Leslie-Hughes
5  * Copyright 2010 Nikolay Sivov for CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #define COBJMACROS
23 #define NONAMELESSUNION
24
25 #include "config.h"
26
27 #include <stdarg.h>
28 #ifdef HAVE_LIBXML2
29 # include <libxml/parser.h>
30 # include <libxml/xmlerror.h>
31 # include <libxml/encoding.h>
32 #endif
33
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winuser.h"
37 #include "ole2.h"
38 #include "msxml6.h"
39 #include "objsafe.h"
40
41 #include "msxml_private.h"
42
43 #include "wine/debug.h"
44 #include "wine/list.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
47
48 #ifdef HAVE_LIBXML2
49
50 static const WCHAR MethodGetW[] = {'G','E','T',0};
51 static const WCHAR MethodPutW[] = {'P','U','T',0};
52 static const WCHAR MethodPostW[] = {'P','O','S','T',0};
53
54 static const WCHAR colspaceW[] = {':',' ',0};
55 static const WCHAR crlfW[] = {'\r','\n',0};
56
57 typedef struct BindStatusCallback BindStatusCallback;
58
59 struct httpheader
60 {
61     struct list entry;
62     BSTR header;
63     BSTR value;
64 };
65
66 typedef struct
67 {
68     IXMLHTTPRequest IXMLHTTPRequest_iface;
69     IObjectWithSite IObjectWithSite_iface;
70     IObjectSafety   IObjectSafety_iface;
71     LONG ref;
72
73     READYSTATE state;
74     IDispatch *sink;
75
76     /* request */
77     BINDVERB verb;
78     BSTR url;
79     BOOL async;
80     struct list reqheaders;
81     /* cached resulting custom request headers string length in WCHARs */
82     LONG reqheader_size;
83     /* use UTF-8 content type */
84     BOOL use_utf8_content;
85
86     /* response headers */
87     struct list respheaders;
88     BSTR raw_respheaders;
89
90     /* credentials */
91     BSTR user;
92     BSTR password;
93
94     /* bind callback */
95     BindStatusCallback *bsc;
96     LONG status;
97
98     /* IObjectWithSite*/
99     IUnknown *site;
100
101     /* IObjectSafety */
102     DWORD safeopt;
103 } httprequest;
104
105 static inline httprequest *impl_from_IXMLHTTPRequest( IXMLHTTPRequest *iface )
106 {
107     return CONTAINING_RECORD(iface, httprequest, IXMLHTTPRequest_iface);
108 }
109
110 static inline httprequest *impl_from_IObjectWithSite(IObjectWithSite *iface)
111 {
112     return CONTAINING_RECORD(iface, httprequest, IObjectWithSite_iface);
113 }
114
115 static inline httprequest *impl_from_IObjectSafety(IObjectSafety *iface)
116 {
117     return CONTAINING_RECORD(iface, httprequest, IObjectSafety_iface);
118 }
119
120 static void httprequest_setreadystate(httprequest *This, READYSTATE state)
121 {
122     READYSTATE last = This->state;
123
124     This->state = state;
125
126     if (This->sink && last != state)
127     {
128         DISPPARAMS params;
129
130         memset(&params, 0, sizeof(params));
131         IDispatch_Invoke(This->sink, 0, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &params, 0, 0, 0);
132     }
133 }
134
135 static void free_response_headers(httprequest *This)
136 {
137     struct httpheader *header, *header2;
138
139     LIST_FOR_EACH_ENTRY_SAFE(header, header2, &This->respheaders, struct httpheader, entry)
140     {
141         list_remove(&header->entry);
142         SysFreeString(header->header);
143         SysFreeString(header->value);
144         heap_free(header);
145     }
146
147     SysFreeString(This->raw_respheaders);
148     This->raw_respheaders = NULL;
149 }
150
151 struct BindStatusCallback
152 {
153     IBindStatusCallback IBindStatusCallback_iface;
154     IHttpNegotiate      IHttpNegotiate_iface;
155     LONG ref;
156
157     IBinding *binding;
158     httprequest *request;
159
160     /* response data */
161     IStream *stream;
162
163     /* request body data */
164     HGLOBAL body;
165 };
166
167 static inline BindStatusCallback *impl_from_IBindStatusCallback( IBindStatusCallback *iface )
168 {
169     return CONTAINING_RECORD(iface, BindStatusCallback, IBindStatusCallback_iface);
170 }
171
172 static inline BindStatusCallback *impl_from_IHttpNegotiate( IHttpNegotiate *iface )
173 {
174     return CONTAINING_RECORD(iface, BindStatusCallback, IHttpNegotiate_iface);
175 }
176
177 static void BindStatusCallback_Detach(BindStatusCallback *bsc)
178 {
179     if (bsc)
180     {
181         if (bsc->binding) IBinding_Abort(bsc->binding);
182         bsc->request = NULL;
183         IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
184     }
185 }
186
187 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
188         REFIID riid, void **ppv)
189 {
190     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
191
192     *ppv = NULL;
193
194     TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
195
196     if (IsEqualGUID(&IID_IUnknown, riid) ||
197         IsEqualGUID(&IID_IBindStatusCallback, riid))
198     {
199         *ppv = &This->IBindStatusCallback_iface;
200     }
201     else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
202     {
203         *ppv = &This->IHttpNegotiate_iface;
204     }
205     else if (IsEqualGUID(&IID_IServiceProvider, riid) ||
206              IsEqualGUID(&IID_IBindStatusCallbackEx, riid) ||
207              IsEqualGUID(&IID_IInternetProtocol, riid) ||
208              IsEqualGUID(&IID_IHttpNegotiate2, riid))
209     {
210         return E_NOINTERFACE;
211     }
212
213     if (*ppv)
214     {
215         IBindStatusCallback_AddRef(iface);
216         return S_OK;
217     }
218
219     FIXME("Unsupported riid = %s\n", debugstr_guid(riid));
220
221     return E_NOINTERFACE;
222 }
223
224 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
225 {
226     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
227     LONG ref = InterlockedIncrement(&This->ref);
228
229     TRACE("(%p) ref = %d\n", This, ref);
230
231     return ref;
232 }
233
234 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
235 {
236     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
237     LONG ref = InterlockedDecrement(&This->ref);
238
239     TRACE("(%p) ref = %d\n", This, ref);
240
241     if (!ref)
242     {
243         if (This->binding) IBinding_Release(This->binding);
244         if (This->stream) IStream_Release(This->stream);
245         if (This->body) GlobalFree(This->body);
246         heap_free(This);
247     }
248
249     return ref;
250 }
251
252 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
253         DWORD reserved, IBinding *pbind)
254 {
255     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
256
257     TRACE("(%p)->(%d %p)\n", This, reserved, pbind);
258
259     if (!pbind) return E_INVALIDARG;
260
261     This->binding = pbind;
262     IBinding_AddRef(pbind);
263
264     httprequest_setreadystate(This->request, READYSTATE_LOADED);
265
266     return CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
267 }
268
269 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pPriority)
270 {
271     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
272
273     TRACE("(%p)->(%p)\n", This, pPriority);
274
275     return E_NOTIMPL;
276 }
277
278 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
279 {
280     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
281
282     TRACE("(%p)->(%d)\n", This, reserved);
283
284     return E_NOTIMPL;
285 }
286
287 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
288         ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
289 {
290     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
291
292     TRACE("(%p)->(%u %u %u %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
293             debugstr_w(szStatusText));
294
295     return S_OK;
296 }
297
298 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
299         HRESULT hr, LPCWSTR error)
300 {
301     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
302
303     TRACE("(%p)->(0x%08x %s)\n", This, hr, debugstr_w(error));
304
305     if (This->binding)
306     {
307         IBinding_Release(This->binding);
308         This->binding = NULL;
309     }
310
311     if (hr == S_OK)
312         httprequest_setreadystate(This->request, READYSTATE_COMPLETE);
313
314     return S_OK;
315 }
316
317 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
318         DWORD *bind_flags, BINDINFO *pbindinfo)
319 {
320     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
321
322     TRACE("(%p)->(%p %p)\n", This, bind_flags, pbindinfo);
323
324     *bind_flags = 0;
325     if (This->request->async) *bind_flags |= BINDF_ASYNCHRONOUS;
326
327     if (This->request->verb != BINDVERB_GET && This->body)
328     {
329         pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
330         pbindinfo->stgmedData.u.hGlobal = This->body;
331         pbindinfo->cbstgmedData = GlobalSize(This->body);
332         /* callback owns passed body pointer */
333         IBindStatusCallback_QueryInterface(iface, &IID_IUnknown, (void**)&pbindinfo->stgmedData.pUnkForRelease);
334     }
335
336     pbindinfo->dwBindVerb = This->request->verb;
337
338     return S_OK;
339 }
340
341 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
342         DWORD flags, DWORD size, FORMATETC *format, STGMEDIUM *stgmed)
343 {
344     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
345     DWORD read, written;
346     BYTE buf[4096];
347     HRESULT hr;
348
349     TRACE("(%p)->(%08x %d %p %p)\n", This, flags, size, format, stgmed);
350
351     do
352     {
353         hr = IStream_Read(stgmed->u.pstm, buf, sizeof(buf), &read);
354         if (hr != S_OK) break;
355
356         hr = IStream_Write(This->stream, buf, read, &written);
357     } while((hr == S_OK) && written != 0 && read != 0);
358
359     httprequest_setreadystate(This->request, READYSTATE_INTERACTIVE);
360
361     return S_OK;
362 }
363
364 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
365         REFIID riid, IUnknown *punk)
366 {
367     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
368
369     FIXME("(%p)->(%s %p): stub\n", This, debugstr_guid(riid), punk);
370
371     return E_NOTIMPL;
372 }
373
374 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
375     BindStatusCallback_QueryInterface,
376     BindStatusCallback_AddRef,
377     BindStatusCallback_Release,
378     BindStatusCallback_OnStartBinding,
379     BindStatusCallback_GetPriority,
380     BindStatusCallback_OnLowResource,
381     BindStatusCallback_OnProgress,
382     BindStatusCallback_OnStopBinding,
383     BindStatusCallback_GetBindInfo,
384     BindStatusCallback_OnDataAvailable,
385     BindStatusCallback_OnObjectAvailable
386 };
387
388 static HRESULT WINAPI BSCHttpNegotiate_QueryInterface(IHttpNegotiate *iface,
389         REFIID riid, void **ppv)
390 {
391     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
392     return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
393 }
394
395 static ULONG WINAPI BSCHttpNegotiate_AddRef(IHttpNegotiate *iface)
396 {
397     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
398     return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
399 }
400
401 static ULONG WINAPI BSCHttpNegotiate_Release(IHttpNegotiate *iface)
402 {
403     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
404     return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
405 }
406
407 static HRESULT WINAPI BSCHttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
408         LPCWSTR url, LPCWSTR headers, DWORD reserved, LPWSTR *add_headers)
409 {
410     static const WCHAR content_type_utf8W[] = {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ',
411         't','e','x','t','/','p','l','a','i','n',';','c','h','a','r','s','e','t','=','u','t','f','-','8','\r','\n',0};
412
413     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
414     const struct httpheader *entry;
415     WCHAR *buff, *ptr;
416     int size = 0;
417
418     TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(url), debugstr_w(headers), reserved, add_headers);
419
420     *add_headers = NULL;
421
422     if (This->request->use_utf8_content)
423         size = sizeof(content_type_utf8W);
424
425     if (!list_empty(&This->request->reqheaders))
426         size += This->request->reqheader_size*sizeof(WCHAR);
427
428     if (!size) return S_OK;
429
430     buff = CoTaskMemAlloc(size);
431     if (!buff) return E_OUTOFMEMORY;
432
433     ptr = buff;
434     if (This->request->use_utf8_content)
435     {
436         lstrcpyW(ptr, content_type_utf8W);
437         ptr += sizeof(content_type_utf8W)/sizeof(WCHAR)-1;
438     }
439
440     /* user headers */
441     LIST_FOR_EACH_ENTRY(entry, &This->request->reqheaders, struct httpheader, entry)
442     {
443         lstrcpyW(ptr, entry->header);
444         ptr += SysStringLen(entry->header);
445
446         lstrcpyW(ptr, colspaceW);
447         ptr += sizeof(colspaceW)/sizeof(WCHAR)-1;
448
449         lstrcpyW(ptr, entry->value);
450         ptr += SysStringLen(entry->value);
451
452         lstrcpyW(ptr, crlfW);
453         ptr += sizeof(crlfW)/sizeof(WCHAR)-1;
454     }
455
456     *add_headers = buff;
457
458     return S_OK;
459 }
460
461 static void add_response_header(httprequest *This, const WCHAR *data, int len)
462 {
463     struct httpheader *entry;
464     const WCHAR *ptr = data;
465     BSTR header, value;
466
467     while (*ptr)
468     {
469         if (*ptr == ':')
470         {
471             header = SysAllocStringLen(data, ptr-data);
472             /* skip leading spaces for a value */
473             while (*++ptr == ' ')
474                 ;
475             value = SysAllocStringLen(ptr, len-(ptr-data));
476             break;
477         }
478         ptr++;
479     }
480
481     if (!*ptr) return;
482
483     /* new header */
484     TRACE("got header %s:%s\n", debugstr_w(header), debugstr_w(value));
485
486     entry = heap_alloc(sizeof(*header));
487     entry->header = header;
488     entry->value  = value;
489     list_add_head(&This->respheaders, &entry->entry);
490 }
491
492 static HRESULT WINAPI BSCHttpNegotiate_OnResponse(IHttpNegotiate *iface, DWORD code,
493         LPCWSTR resp_headers, LPCWSTR req_headers, LPWSTR *add_reqheaders)
494 {
495     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
496
497     TRACE("(%p)->(%d %s %s %p)\n", This, code, debugstr_w(resp_headers),
498           debugstr_w(req_headers), add_reqheaders);
499
500     This->request->status = code;
501     /* store headers */
502     free_response_headers(This->request);
503     if (resp_headers)
504     {
505         const WCHAR *ptr, *line;
506
507         ptr = line = resp_headers;
508
509         /* skip status line */
510         while (*ptr)
511         {
512             if (*ptr == '\r' && *(ptr+1) == '\n')
513             {
514                 line = ++ptr+1;
515                 break;
516             }
517             ptr++;
518         }
519
520         /* store as unparsed string for now */
521         This->request->raw_respheaders = SysAllocString(line);
522     }
523
524     return S_OK;
525 }
526
527 static const IHttpNegotiateVtbl BSCHttpNegotiateVtbl = {
528     BSCHttpNegotiate_QueryInterface,
529     BSCHttpNegotiate_AddRef,
530     BSCHttpNegotiate_Release,
531     BSCHttpNegotiate_BeginningTransaction,
532     BSCHttpNegotiate_OnResponse
533 };
534
535 static HRESULT BindStatusCallback_create(httprequest* This, BindStatusCallback **obj, const VARIANT *body)
536 {
537     BindStatusCallback *bsc;
538     IBindCtx *pbc;
539     HRESULT hr;
540
541     hr = CreateBindCtx(0, &pbc);
542     if (hr != S_OK) return hr;
543
544     bsc = heap_alloc(sizeof(*bsc));
545     if (!bsc)
546     {
547         IBindCtx_Release(pbc);
548         return E_OUTOFMEMORY;
549     }
550
551     bsc->IBindStatusCallback_iface.lpVtbl = &BindStatusCallbackVtbl;
552     bsc->IHttpNegotiate_iface.lpVtbl = &BSCHttpNegotiateVtbl;
553     bsc->ref = 1;
554     bsc->request = This;
555     bsc->binding = NULL;
556     bsc->stream = NULL;
557     bsc->body = NULL;
558
559     TRACE("(%p)->(%p)\n", This, bsc);
560
561     This->use_utf8_content = FALSE;
562
563     if (This->verb != BINDVERB_GET)
564     {
565         if (V_VT(body) == (VT_VARIANT|VT_BYREF))
566             body = V_VARIANTREF(body);
567
568         switch (V_VT(body))
569         {
570         case VT_BSTR:
571         {
572             int len = SysStringLen(V_BSTR(body)), size;
573             const WCHAR *str = V_BSTR(body);
574             void *send_data, *ptr;
575             UINT i, cp = CP_ACP;
576
577             for (i = 0; i < len; i++)
578             {
579                 if (str[i] > 127)
580                 {
581                     cp = CP_UTF8;
582                     break;
583                 }
584             }
585
586             size = WideCharToMultiByte(cp, 0, str, len, NULL, 0, NULL, NULL);
587             if (!(ptr = heap_alloc(size)))
588             {
589                 heap_free(bsc);
590                 return E_OUTOFMEMORY;
591             }
592             WideCharToMultiByte(cp, 0, str, len, ptr, size, NULL, NULL);
593             if (cp == CP_UTF8) This->use_utf8_content = TRUE;
594
595             bsc->body = GlobalAlloc(GMEM_FIXED, size);
596             if (!bsc->body)
597             {
598                 heap_free(bsc);
599                 heap_free(ptr);
600                 return E_OUTOFMEMORY;
601             }
602
603             send_data = GlobalLock(bsc->body);
604             memcpy(send_data, ptr, size);
605             GlobalUnlock(bsc->body);
606             heap_free(ptr);
607             break;
608         }
609         default:
610             FIXME("unsupported body data type %d\n", V_VT(body));
611             break;
612         }
613     }
614
615     hr = RegisterBindStatusCallback(pbc, &bsc->IBindStatusCallback_iface, NULL, 0);
616     if (hr == S_OK)
617     {
618         IMoniker *moniker;
619
620         hr = CreateURLMoniker(NULL, This->url, &moniker);
621         if (hr == S_OK)
622         {
623             IStream *stream;
624
625             hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (void**)&stream);
626             IMoniker_Release(moniker);
627             if (stream) IStream_Release(stream);
628         }
629         IBindCtx_Release(pbc);
630     }
631
632     if (FAILED(hr))
633     {
634         IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
635         bsc = NULL;
636     }
637
638     *obj = bsc;
639     return hr;
640 }
641
642 static HRESULT WINAPI httprequest_QueryInterface(IXMLHTTPRequest *iface, REFIID riid, void **ppvObject)
643 {
644     httprequest *This = impl_from_IXMLHTTPRequest( iface );
645     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
646
647     if ( IsEqualGUID( riid, &IID_IXMLHTTPRequest) ||
648          IsEqualGUID( riid, &IID_IDispatch) ||
649          IsEqualGUID( riid, &IID_IUnknown) )
650     {
651         *ppvObject = iface;
652     }
653     else if (IsEqualGUID(&IID_IObjectWithSite, riid))
654     {
655         *ppvObject = &This->IObjectWithSite_iface;
656     }
657     else if (IsEqualGUID(&IID_IObjectSafety, riid))
658     {
659         *ppvObject = &This->IObjectSafety_iface;
660     }
661     else
662     {
663         TRACE("Unsupported interface %s\n", debugstr_guid(riid));
664         *ppvObject = NULL;
665         return E_NOINTERFACE;
666     }
667
668     IXMLHTTPRequest_AddRef( iface );
669
670     return S_OK;
671 }
672
673 static ULONG WINAPI httprequest_AddRef(IXMLHTTPRequest *iface)
674 {
675     httprequest *This = impl_from_IXMLHTTPRequest( iface );
676     ULONG ref = InterlockedIncrement( &This->ref );
677     TRACE("(%p)->(%u)\n", This, ref );
678     return ref;
679 }
680
681 static ULONG WINAPI httprequest_Release(IXMLHTTPRequest *iface)
682 {
683     httprequest *This = impl_from_IXMLHTTPRequest( iface );
684     ULONG ref = InterlockedDecrement( &This->ref );
685
686     TRACE("(%p)->(%u)\n", This, ref );
687
688     if ( ref == 0 )
689     {
690         struct httpheader *header, *header2;
691
692         if (This->site)
693             IUnknown_Release( This->site );
694
695         SysFreeString(This->url);
696         SysFreeString(This->user);
697         SysFreeString(This->password);
698
699         /* request headers */
700         LIST_FOR_EACH_ENTRY_SAFE(header, header2, &This->reqheaders, struct httpheader, entry)
701         {
702             list_remove(&header->entry);
703             SysFreeString(header->header);
704             SysFreeString(header->value);
705             heap_free(header);
706         }
707         /* response headers */
708         free_response_headers(This);
709
710         /* detach callback object */
711         BindStatusCallback_Detach(This->bsc);
712
713         if (This->sink) IDispatch_Release(This->sink);
714
715         heap_free( This );
716     }
717
718     return ref;
719 }
720
721 static HRESULT WINAPI httprequest_GetTypeInfoCount(IXMLHTTPRequest *iface, UINT *pctinfo)
722 {
723     httprequest *This = impl_from_IXMLHTTPRequest( iface );
724
725     TRACE("(%p)->(%p)\n", This, pctinfo);
726
727     *pctinfo = 1;
728
729     return S_OK;
730 }
731
732 static HRESULT WINAPI httprequest_GetTypeInfo(IXMLHTTPRequest *iface, UINT iTInfo,
733         LCID lcid, ITypeInfo **ppTInfo)
734 {
735     httprequest *This = impl_from_IXMLHTTPRequest( iface );
736
737     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
738
739     return get_typeinfo(IXMLHTTPRequest_tid, ppTInfo);
740 }
741
742 static HRESULT WINAPI httprequest_GetIDsOfNames(IXMLHTTPRequest *iface, REFIID riid,
743         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
744 {
745     httprequest *This = impl_from_IXMLHTTPRequest( iface );
746     ITypeInfo *typeinfo;
747     HRESULT hr;
748
749     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
750           lcid, rgDispId);
751
752     if(!rgszNames || cNames == 0 || !rgDispId)
753         return E_INVALIDARG;
754
755     hr = get_typeinfo(IXMLHTTPRequest_tid, &typeinfo);
756     if(SUCCEEDED(hr))
757     {
758         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
759         ITypeInfo_Release(typeinfo);
760     }
761
762     return hr;
763 }
764
765 static HRESULT WINAPI httprequest_Invoke(IXMLHTTPRequest *iface, DISPID dispIdMember, REFIID riid,
766         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
767         EXCEPINFO *pExcepInfo, UINT *puArgErr)
768 {
769     httprequest *This = impl_from_IXMLHTTPRequest( iface );
770     ITypeInfo *typeinfo;
771     HRESULT hr;
772
773     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
774           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
775
776     hr = get_typeinfo(IXMLHTTPRequest_tid, &typeinfo);
777     if(SUCCEEDED(hr))
778     {
779         hr = ITypeInfo_Invoke(typeinfo, &This->IXMLHTTPRequest_iface, dispIdMember, wFlags,
780                 pDispParams, pVarResult, pExcepInfo, puArgErr);
781         ITypeInfo_Release(typeinfo);
782     }
783
784     return hr;
785 }
786
787 static HRESULT WINAPI httprequest_open(IXMLHTTPRequest *iface, BSTR method, BSTR url,
788         VARIANT async, VARIANT user, VARIANT password)
789 {
790     httprequest *This = impl_from_IXMLHTTPRequest( iface );
791     HRESULT hr;
792     VARIANT str, is_async;
793
794     TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(method), debugstr_w(url),
795         debugstr_variant(&async));
796
797     if (!method || !url) return E_INVALIDARG;
798
799     /* free previously set data */
800     SysFreeString(This->url);
801     SysFreeString(This->user);
802     SysFreeString(This->password);
803     This->url = This->user = This->password = NULL;
804
805     if (lstrcmpiW(method, MethodGetW) == 0)
806     {
807         This->verb = BINDVERB_GET;
808     }
809     else if (lstrcmpiW(method, MethodPutW) == 0)
810     {
811         This->verb = BINDVERB_PUT;
812     }
813     else if (lstrcmpiW(method, MethodPostW) == 0)
814     {
815         This->verb = BINDVERB_POST;
816     }
817     else
818     {
819         FIXME("unsupported request type %s\n", debugstr_w(method));
820         This->verb = -1;
821         return E_FAIL;
822     }
823
824     This->url = SysAllocString(url);
825
826     VariantInit(&is_async);
827     hr = VariantChangeType(&is_async, &async, 0, VT_BOOL);
828     This->async = hr == S_OK && V_BOOL(&is_async) == VARIANT_TRUE;
829
830     VariantInit(&str);
831     hr = VariantChangeType(&str, &user, 0, VT_BSTR);
832     if (hr == S_OK)
833         This->user = V_BSTR(&str);
834
835     VariantInit(&str);
836     hr = VariantChangeType(&str, &password, 0, VT_BSTR);
837     if (hr == S_OK)
838         This->password = V_BSTR(&str);
839
840     httprequest_setreadystate(This, READYSTATE_LOADING);
841
842     return S_OK;
843 }
844
845 static HRESULT WINAPI httprequest_setRequestHeader(IXMLHTTPRequest *iface, BSTR header, BSTR value)
846 {
847     httprequest *This = impl_from_IXMLHTTPRequest( iface );
848     struct httpheader *entry;
849
850     TRACE("(%p)->(%s %s)\n", This, debugstr_w(header), debugstr_w(value));
851
852     if (!header || !*header) return E_INVALIDARG;
853     if (This->state != READYSTATE_LOADING) return E_FAIL;
854     if (!value) return E_INVALIDARG;
855
856     /* replace existing header value if already added */
857     LIST_FOR_EACH_ENTRY(entry, &This->reqheaders, struct httpheader, entry)
858     {
859         if (lstrcmpW(entry->header, header) == 0)
860         {
861             LONG length = SysStringLen(entry->value);
862             HRESULT hr;
863
864             hr = SysReAllocString(&entry->value, value) ? S_OK : E_OUTOFMEMORY;
865
866             if (hr == S_OK)
867                 This->reqheader_size += (SysStringLen(entry->value) - length);
868
869             return hr;
870         }
871     }
872
873     entry = heap_alloc(sizeof(*entry));
874     if (!entry) return E_OUTOFMEMORY;
875
876     /* new header */
877     entry->header = SysAllocString(header);
878     entry->value  = SysAllocString(value);
879
880     /* header length including null terminator */
881     This->reqheader_size += SysStringLen(entry->header) + sizeof(colspaceW)/sizeof(WCHAR) +
882                             SysStringLen(entry->value)  + sizeof(crlfW)/sizeof(WCHAR) - 1;
883
884     list_add_head(&This->reqheaders, &entry->entry);
885
886     return S_OK;
887 }
888
889 static HRESULT WINAPI httprequest_getResponseHeader(IXMLHTTPRequest *iface, BSTR header, BSTR *value)
890 {
891     httprequest *This = impl_from_IXMLHTTPRequest( iface );
892     struct httpheader *entry;
893
894     TRACE("(%p)->(%s %p)\n", This, debugstr_w(header), value);
895
896     if (!header || !value) return E_INVALIDARG;
897
898     if (This->raw_respheaders && list_empty(&This->respheaders))
899     {
900         WCHAR *ptr, *line;
901
902         ptr = line = This->raw_respheaders;
903         while (*ptr)
904         {
905             if (*ptr == '\r' && *(ptr+1) == '\n')
906             {
907                 add_response_header(This, line, ptr-line);
908                 ptr++; line = ++ptr;
909                 continue;
910             }
911             ptr++;
912         }
913     }
914
915     LIST_FOR_EACH_ENTRY(entry, &This->respheaders, struct httpheader, entry)
916     {
917         if (!strcmpiW(entry->header, header))
918         {
919             *value = SysAllocString(entry->value);
920             TRACE("header value %s\n", debugstr_w(*value));
921             return S_OK;
922         }
923     }
924
925     return S_FALSE;
926 }
927
928 static HRESULT WINAPI httprequest_getAllResponseHeaders(IXMLHTTPRequest *iface, BSTR *respheaders)
929 {
930     httprequest *This = impl_from_IXMLHTTPRequest( iface );
931
932     TRACE("(%p)->(%p)\n", This, respheaders);
933
934     if (!respheaders) return E_INVALIDARG;
935
936     *respheaders = SysAllocString(This->raw_respheaders);
937
938     return S_OK;
939 }
940
941 static HRESULT WINAPI httprequest_send(IXMLHTTPRequest *iface, VARIANT body)
942 {
943     httprequest *This = impl_from_IXMLHTTPRequest( iface );
944     BindStatusCallback *bsc = NULL;
945     HRESULT hr;
946
947     TRACE("(%p)->(%s)\n", This, debugstr_variant(&body));
948
949     if (This->state != READYSTATE_LOADING) return E_FAIL;
950
951     hr = BindStatusCallback_create(This, &bsc, &body);
952     if (FAILED(hr)) return hr;
953
954     BindStatusCallback_Detach(This->bsc);
955     This->bsc = bsc;
956
957     return hr;
958 }
959
960 static HRESULT WINAPI httprequest_abort(IXMLHTTPRequest *iface)
961 {
962     httprequest *This = impl_from_IXMLHTTPRequest( iface );
963
964     TRACE("(%p)\n", This);
965
966     BindStatusCallback_Detach(This->bsc);
967     This->bsc = NULL;
968
969     httprequest_setreadystate(This, READYSTATE_UNINITIALIZED);
970
971     return S_OK;
972 }
973
974 static HRESULT WINAPI httprequest_get_status(IXMLHTTPRequest *iface, LONG *status)
975 {
976     httprequest *This = impl_from_IXMLHTTPRequest( iface );
977
978     TRACE("(%p)->(%p)\n", This, status);
979
980     if (!status) return E_INVALIDARG;
981     if (This->state != READYSTATE_COMPLETE) return E_FAIL;
982
983     *status = This->status;
984
985     return S_OK;
986 }
987
988 static HRESULT WINAPI httprequest_get_statusText(IXMLHTTPRequest *iface, BSTR *pbstrStatus)
989 {
990     httprequest *This = impl_from_IXMLHTTPRequest( iface );
991
992     FIXME("stub %p %p\n", This, pbstrStatus);
993
994     return E_NOTIMPL;
995 }
996
997 static HRESULT WINAPI httprequest_get_responseXML(IXMLHTTPRequest *iface, IDispatch **body)
998 {
999     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1000     IXMLDOMDocument3 *doc;
1001     HRESULT hr;
1002     BSTR str;
1003
1004     TRACE("(%p)->(%p)\n", This, body);
1005
1006     if (!body) return E_INVALIDARG;
1007     if (This->state != READYSTATE_COMPLETE) return E_FAIL;
1008
1009     hr = DOMDocument_create(MSXML_DEFAULT, NULL, (void**)&doc);
1010     if (hr != S_OK) return hr;
1011
1012     hr = IXMLHTTPRequest_get_responseText(iface, &str);
1013     if (hr == S_OK)
1014     {
1015         VARIANT_BOOL ok;
1016
1017         hr = IXMLDOMDocument3_loadXML(doc, str, &ok);
1018         SysFreeString(str);
1019     }
1020
1021     IXMLDOMDocument3_QueryInterface(doc, &IID_IDispatch, (void**)body);
1022     IXMLDOMDocument3_Release(doc);
1023
1024     return hr;
1025 }
1026
1027 static HRESULT WINAPI httprequest_get_responseText(IXMLHTTPRequest *iface, BSTR *body)
1028 {
1029     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1030     HGLOBAL hglobal;
1031     HRESULT hr;
1032
1033     TRACE("(%p)->(%p)\n", This, body);
1034
1035     if (!body) return E_INVALIDARG;
1036     if (This->state != READYSTATE_COMPLETE) return E_FAIL;
1037
1038     hr = GetHGlobalFromStream(This->bsc->stream, &hglobal);
1039     if (hr == S_OK)
1040     {
1041         xmlChar *ptr = GlobalLock(hglobal);
1042         DWORD size = GlobalSize(hglobal);
1043         xmlCharEncoding encoding = XML_CHAR_ENCODING_UTF8;
1044
1045         /* try to determine data encoding */
1046         if (size >= 4)
1047         {
1048             encoding = xmlDetectCharEncoding(ptr, 4);
1049             TRACE("detected encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding)));
1050             if ( encoding != XML_CHAR_ENCODING_UTF8 &&
1051                  encoding != XML_CHAR_ENCODING_UTF16LE &&
1052                  encoding != XML_CHAR_ENCODING_NONE )
1053             {
1054                 FIXME("unsupported encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding)));
1055                 GlobalUnlock(hglobal);
1056                 return E_FAIL;
1057             }
1058         }
1059
1060         /* without BOM assume UTF-8 */
1061         if (encoding == XML_CHAR_ENCODING_UTF8 ||
1062             encoding == XML_CHAR_ENCODING_NONE )
1063         {
1064             DWORD length = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)ptr, size, NULL, 0);
1065
1066             *body = SysAllocStringLen(NULL, length);
1067             if (*body)
1068                 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)ptr, size, *body, length);
1069         }
1070         else
1071             *body = SysAllocStringByteLen((LPCSTR)ptr, size);
1072
1073         if (!*body) hr = E_OUTOFMEMORY;
1074         GlobalUnlock(hglobal);
1075     }
1076
1077     return hr;
1078 }
1079
1080 static HRESULT WINAPI httprequest_get_responseBody(IXMLHTTPRequest *iface, VARIANT *body)
1081 {
1082     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1083     HGLOBAL hglobal;
1084     HRESULT hr;
1085
1086     TRACE("(%p)->(%p)\n", This, body);
1087
1088     if (!body) return E_INVALIDARG;
1089     V_VT(body) = VT_EMPTY;
1090
1091     if (This->state != READYSTATE_COMPLETE) return E_PENDING;
1092
1093     hr = GetHGlobalFromStream(This->bsc->stream, &hglobal);
1094     if (hr == S_OK)
1095     {
1096         void *ptr = GlobalLock(hglobal);
1097         DWORD size = GlobalSize(hglobal);
1098
1099         SAFEARRAYBOUND bound;
1100         SAFEARRAY *array;
1101
1102         bound.lLbound = 0;
1103         bound.cElements = size;
1104         array = SafeArrayCreate(VT_UI1, 1, &bound);
1105
1106         if (array)
1107         {
1108             void *dest;
1109
1110             V_VT(body) = VT_ARRAY | VT_UI1;
1111             V_ARRAY(body) = array;
1112
1113             hr = SafeArrayAccessData(array, &dest);
1114             if (hr == S_OK)
1115             {
1116                 memcpy(dest, ptr, size);
1117                 SafeArrayUnaccessData(array);
1118             }
1119             else
1120             {
1121                 VariantClear(body);
1122             }
1123         }
1124         else
1125             hr = E_FAIL;
1126
1127         GlobalUnlock(hglobal);
1128     }
1129
1130     return hr;
1131 }
1132
1133 static HRESULT WINAPI httprequest_get_responseStream(IXMLHTTPRequest *iface, VARIANT *body)
1134 {
1135     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1136     LARGE_INTEGER move;
1137     IStream *stream;
1138     HRESULT hr;
1139
1140     TRACE("(%p)->(%p)\n", This, body);
1141
1142     if (!body) return E_INVALIDARG;
1143     V_VT(body) = VT_EMPTY;
1144
1145     if (This->state != READYSTATE_COMPLETE) return E_PENDING;
1146
1147     hr = IStream_Clone(This->bsc->stream, &stream);
1148
1149     move.QuadPart = 0;
1150     IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
1151
1152     V_VT(body) = VT_UNKNOWN;
1153     V_UNKNOWN(body) = (IUnknown*)stream;
1154
1155     return hr;
1156 }
1157
1158 static HRESULT WINAPI httprequest_get_readyState(IXMLHTTPRequest *iface, LONG *state)
1159 {
1160     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1161
1162     TRACE("(%p)->(%p)\n", This, state);
1163
1164     if (!state) return E_INVALIDARG;
1165
1166     *state = This->state;
1167     return S_OK;
1168 }
1169
1170 static HRESULT WINAPI httprequest_put_onreadystatechange(IXMLHTTPRequest *iface, IDispatch *sink)
1171 {
1172     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1173
1174     TRACE("(%p)->(%p)\n", This, sink);
1175
1176     if (This->sink) IDispatch_Release(This->sink);
1177     if ((This->sink = sink)) IDispatch_AddRef(This->sink);
1178
1179     return S_OK;
1180 }
1181
1182 static const struct IXMLHTTPRequestVtbl dimimpl_vtbl =
1183 {
1184     httprequest_QueryInterface,
1185     httprequest_AddRef,
1186     httprequest_Release,
1187     httprequest_GetTypeInfoCount,
1188     httprequest_GetTypeInfo,
1189     httprequest_GetIDsOfNames,
1190     httprequest_Invoke,
1191     httprequest_open,
1192     httprequest_setRequestHeader,
1193     httprequest_getResponseHeader,
1194     httprequest_getAllResponseHeaders,
1195     httprequest_send,
1196     httprequest_abort,
1197     httprequest_get_status,
1198     httprequest_get_statusText,
1199     httprequest_get_responseXML,
1200     httprequest_get_responseText,
1201     httprequest_get_responseBody,
1202     httprequest_get_responseStream,
1203     httprequest_get_readyState,
1204     httprequest_put_onreadystatechange
1205 };
1206
1207 /* IObjectWithSite */
1208 static HRESULT WINAPI
1209 httprequest_ObjectWithSite_QueryInterface( IObjectWithSite* iface, REFIID riid, void** ppvObject )
1210 {
1211     httprequest *This = impl_from_IObjectWithSite(iface);
1212     return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest *)This, riid, ppvObject );
1213 }
1214
1215 static ULONG WINAPI httprequest_ObjectWithSite_AddRef( IObjectWithSite* iface )
1216 {
1217     httprequest *This = impl_from_IObjectWithSite(iface);
1218     return IXMLHTTPRequest_AddRef((IXMLHTTPRequest *)This);
1219 }
1220
1221 static ULONG WINAPI httprequest_ObjectWithSite_Release( IObjectWithSite* iface )
1222 {
1223     httprequest *This = impl_from_IObjectWithSite(iface);
1224     return IXMLHTTPRequest_Release((IXMLHTTPRequest *)This);
1225 }
1226
1227 static HRESULT WINAPI httprequest_ObjectWithSite_GetSite( IObjectWithSite *iface, REFIID iid, void **ppvSite )
1228 {
1229     httprequest *This = impl_from_IObjectWithSite(iface);
1230
1231     TRACE("(%p)->(%s %p)\n", This, debugstr_guid( iid ), ppvSite );
1232
1233     if ( !This->site )
1234         return E_FAIL;
1235
1236     return IUnknown_QueryInterface( This->site, iid, ppvSite );
1237 }
1238
1239 static HRESULT WINAPI httprequest_ObjectWithSite_SetSite( IObjectWithSite *iface, IUnknown *punk )
1240 {
1241     httprequest *This = impl_from_IObjectWithSite(iface);
1242
1243     TRACE("(%p)->(%p)\n", iface, punk);
1244
1245     if (punk)
1246         IUnknown_AddRef( punk );
1247
1248     if(This->site)
1249         IUnknown_Release( This->site );
1250
1251     This->site = punk;
1252
1253     return S_OK;
1254 }
1255
1256 static const IObjectWithSiteVtbl httprequestObjectSite =
1257 {
1258     httprequest_ObjectWithSite_QueryInterface,
1259     httprequest_ObjectWithSite_AddRef,
1260     httprequest_ObjectWithSite_Release,
1261     httprequest_ObjectWithSite_SetSite,
1262     httprequest_ObjectWithSite_GetSite
1263 };
1264
1265 /* IObjectSafety */
1266 static HRESULT WINAPI httprequest_Safety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1267 {
1268     httprequest *This = impl_from_IObjectSafety(iface);
1269     return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest *)This, riid, ppv );
1270 }
1271
1272 static ULONG WINAPI httprequest_Safety_AddRef(IObjectSafety *iface)
1273 {
1274     httprequest *This = impl_from_IObjectSafety(iface);
1275     return IXMLHTTPRequest_AddRef((IXMLHTTPRequest *)This);
1276 }
1277
1278 static ULONG WINAPI httprequest_Safety_Release(IObjectSafety *iface)
1279 {
1280     httprequest *This = impl_from_IObjectSafety(iface);
1281     return IXMLHTTPRequest_Release((IXMLHTTPRequest *)This);
1282 }
1283
1284 #define SAFETY_SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER)
1285
1286 static HRESULT WINAPI httprequest_Safety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1287         DWORD *supported, DWORD *enabled)
1288 {
1289     httprequest *This = impl_from_IObjectSafety(iface);
1290
1291     TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), supported, enabled);
1292
1293     if(!supported || !enabled) return E_POINTER;
1294
1295     *supported = SAFETY_SUPPORTED_OPTIONS;
1296     *enabled = This->safeopt;
1297
1298     return S_OK;
1299 }
1300
1301 static HRESULT WINAPI httprequest_Safety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1302         DWORD mask, DWORD enabled)
1303 {
1304     httprequest *This = impl_from_IObjectSafety(iface);
1305     TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), mask, enabled);
1306
1307     if ((mask & ~SAFETY_SUPPORTED_OPTIONS) != 0)
1308         return E_FAIL;
1309
1310     This->safeopt = (This->safeopt & ~mask) | (mask & enabled);
1311
1312     return S_OK;
1313 }
1314
1315 #undef SAFETY_SUPPORTED_OPTIONS
1316
1317 static const IObjectSafetyVtbl httprequestObjectSafety = {
1318     httprequest_Safety_QueryInterface,
1319     httprequest_Safety_AddRef,
1320     httprequest_Safety_Release,
1321     httprequest_Safety_GetInterfaceSafetyOptions,
1322     httprequest_Safety_SetInterfaceSafetyOptions
1323 };
1324
1325 HRESULT XMLHTTPRequest_create(IUnknown *pUnkOuter, void **ppObj)
1326 {
1327     httprequest *req;
1328     HRESULT hr = S_OK;
1329
1330     TRACE("(%p,%p)\n", pUnkOuter, ppObj);
1331
1332     req = heap_alloc( sizeof (*req) );
1333     if( !req )
1334         return E_OUTOFMEMORY;
1335
1336     req->IXMLHTTPRequest_iface.lpVtbl = &dimimpl_vtbl;
1337     req->IObjectWithSite_iface.lpVtbl = &httprequestObjectSite;
1338     req->IObjectSafety_iface.lpVtbl = &httprequestObjectSafety;
1339     req->ref = 1;
1340
1341     req->async = FALSE;
1342     req->verb = -1;
1343     req->url = req->user = req->password = NULL;
1344
1345     req->state = READYSTATE_UNINITIALIZED;
1346     req->sink = NULL;
1347
1348     req->bsc = NULL;
1349     req->status = 0;
1350     req->reqheader_size = 0;
1351     req->raw_respheaders = NULL;
1352     req->use_utf8_content = FALSE;
1353
1354     list_init(&req->reqheaders);
1355     list_init(&req->respheaders);
1356
1357     req->site = NULL;
1358     req->safeopt = 0;
1359
1360     *ppObj = &req->IXMLHTTPRequest_iface;
1361
1362     TRACE("returning iface %p\n", *ppObj);
1363
1364     return hr;
1365 }
1366
1367 #else
1368
1369 HRESULT XMLHTTPRequest_create(IUnknown *pUnkOuter, void **ppObj)
1370 {
1371     MESSAGE("This program tried to use a XMLHTTPRequest object, but\n"
1372             "libxml2 support was not present at compile time.\n");
1373     return E_NOTIMPL;
1374 }
1375
1376 #endif