uxtheme: Remove unused variable.
[wine] / dlls / msxml3 / httprequest.c
1 /*
2  *    IXMLHTTPRequest implementation
3  *
4  * Copyright 2008 Alistair Leslie-Hughes
5  * Copyright 2010-2012 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 "wingdi.h"
37 #include "wininet.h"
38 #include "winreg.h"
39 #include "winuser.h"
40 #include "ole2.h"
41 #include "mshtml.h"
42 #include "msxml6.h"
43 #include "objsafe.h"
44 #include "docobj.h"
45 #include "shlwapi.h"
46
47 #include "msxml_private.h"
48
49 #include "wine/debug.h"
50 #include "wine/list.h"
51
52 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
53
54 #ifdef HAVE_LIBXML2
55
56 static const WCHAR colspaceW[] = {':',' ',0};
57 static const WCHAR crlfW[] = {'\r','\n',0};
58 static const DWORD safety_supported_options =
59     INTERFACESAFE_FOR_UNTRUSTED_CALLER |
60     INTERFACESAFE_FOR_UNTRUSTED_DATA   |
61     INTERFACE_USES_SECURITY_MANAGER;
62
63 typedef struct BindStatusCallback BindStatusCallback;
64
65 struct httpheader
66 {
67     struct list entry;
68     BSTR header;
69     BSTR value;
70 };
71
72 typedef struct
73 {
74     IXMLHTTPRequest IXMLHTTPRequest_iface;
75     IObjectWithSite IObjectWithSite_iface;
76     IObjectSafety   IObjectSafety_iface;
77     LONG ref;
78
79     READYSTATE state;
80     IDispatch *sink;
81
82     /* request */
83     BINDVERB verb;
84     BSTR custom;
85     BSTR siteurl;
86     BSTR url;
87     BOOL async;
88     struct list reqheaders;
89     /* cached resulting custom request headers string length in WCHARs */
90     LONG reqheader_size;
91     /* use UTF-8 content type */
92     BOOL use_utf8_content;
93
94     /* response headers */
95     struct list respheaders;
96     BSTR raw_respheaders;
97
98     /* credentials */
99     BSTR user;
100     BSTR password;
101
102     /* bind callback */
103     BindStatusCallback *bsc;
104     LONG status;
105     BSTR status_text;
106
107     /* IObjectWithSite*/
108     IUnknown *site;
109
110     /* IObjectSafety */
111     DWORD safeopt;
112 } httprequest;
113
114 typedef struct
115 {
116     httprequest req;
117     IServerXMLHTTPRequest IServerXMLHTTPRequest_iface;
118     LONG ref;
119 } serverhttp;
120
121 static inline httprequest *impl_from_IXMLHTTPRequest( IXMLHTTPRequest *iface )
122 {
123     return CONTAINING_RECORD(iface, httprequest, IXMLHTTPRequest_iface);
124 }
125
126 static inline httprequest *impl_from_IObjectWithSite(IObjectWithSite *iface)
127 {
128     return CONTAINING_RECORD(iface, httprequest, IObjectWithSite_iface);
129 }
130
131 static inline httprequest *impl_from_IObjectSafety(IObjectSafety *iface)
132 {
133     return CONTAINING_RECORD(iface, httprequest, IObjectSafety_iface);
134 }
135
136 static inline serverhttp *impl_from_IServerXMLHTTPRequest(IServerXMLHTTPRequest *iface)
137 {
138     return CONTAINING_RECORD(iface, serverhttp, IServerXMLHTTPRequest_iface);
139 }
140
141 static void httprequest_setreadystate(httprequest *This, READYSTATE state)
142 {
143     READYSTATE last = This->state;
144
145     This->state = state;
146
147     if (This->sink && last != state)
148     {
149         DISPPARAMS params;
150
151         memset(&params, 0, sizeof(params));
152         IDispatch_Invoke(This->sink, 0, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &params, 0, 0, 0);
153     }
154 }
155
156 static void free_response_headers(httprequest *This)
157 {
158     struct httpheader *header, *header2;
159
160     LIST_FOR_EACH_ENTRY_SAFE(header, header2, &This->respheaders, struct httpheader, entry)
161     {
162         list_remove(&header->entry);
163         SysFreeString(header->header);
164         SysFreeString(header->value);
165         heap_free(header);
166     }
167
168     SysFreeString(This->raw_respheaders);
169     This->raw_respheaders = NULL;
170 }
171
172 struct BindStatusCallback
173 {
174     IBindStatusCallback IBindStatusCallback_iface;
175     IHttpNegotiate      IHttpNegotiate_iface;
176     IAuthenticate       IAuthenticate_iface;
177     LONG ref;
178
179     IBinding *binding;
180     httprequest *request;
181
182     /* response data */
183     IStream *stream;
184
185     /* request body data */
186     HGLOBAL body;
187 };
188
189 static inline BindStatusCallback *impl_from_IBindStatusCallback( IBindStatusCallback *iface )
190 {
191     return CONTAINING_RECORD(iface, BindStatusCallback, IBindStatusCallback_iface);
192 }
193
194 static inline BindStatusCallback *impl_from_IHttpNegotiate( IHttpNegotiate *iface )
195 {
196     return CONTAINING_RECORD(iface, BindStatusCallback, IHttpNegotiate_iface);
197 }
198
199 static inline BindStatusCallback *impl_from_IAuthenticate( IAuthenticate *iface )
200 {
201     return CONTAINING_RECORD(iface, BindStatusCallback, IAuthenticate_iface);
202 }
203
204 static void BindStatusCallback_Detach(BindStatusCallback *bsc)
205 {
206     if (bsc)
207     {
208         if (bsc->binding) IBinding_Abort(bsc->binding);
209         bsc->request = NULL;
210         IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
211     }
212 }
213
214 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
215         REFIID riid, void **ppv)
216 {
217     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
218
219     *ppv = NULL;
220
221     TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
222
223     if (IsEqualGUID(&IID_IUnknown, riid) ||
224         IsEqualGUID(&IID_IBindStatusCallback, riid))
225     {
226         *ppv = &This->IBindStatusCallback_iface;
227     }
228     else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
229     {
230         *ppv = &This->IHttpNegotiate_iface;
231     }
232     else if (IsEqualGUID(&IID_IAuthenticate, riid))
233     {
234         *ppv = &This->IAuthenticate_iface;
235     }
236     else if (IsEqualGUID(&IID_IServiceProvider, riid) ||
237              IsEqualGUID(&IID_IBindStatusCallbackEx, riid) ||
238              IsEqualGUID(&IID_IInternetProtocol, riid) ||
239              IsEqualGUID(&IID_IHttpNegotiate2, riid))
240     {
241         return E_NOINTERFACE;
242     }
243
244     if (*ppv)
245     {
246         IBindStatusCallback_AddRef(iface);
247         return S_OK;
248     }
249
250     FIXME("Unsupported riid = %s\n", debugstr_guid(riid));
251
252     return E_NOINTERFACE;
253 }
254
255 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
256 {
257     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
258     LONG ref = InterlockedIncrement(&This->ref);
259
260     TRACE("(%p) ref = %d\n", This, ref);
261
262     return ref;
263 }
264
265 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
266 {
267     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
268     LONG ref = InterlockedDecrement(&This->ref);
269
270     TRACE("(%p) ref = %d\n", This, ref);
271
272     if (!ref)
273     {
274         if (This->binding) IBinding_Release(This->binding);
275         if (This->stream) IStream_Release(This->stream);
276         if (This->body) GlobalFree(This->body);
277         heap_free(This);
278     }
279
280     return ref;
281 }
282
283 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
284         DWORD reserved, IBinding *pbind)
285 {
286     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
287
288     TRACE("(%p)->(%d %p)\n", This, reserved, pbind);
289
290     if (!pbind) return E_INVALIDARG;
291
292     This->binding = pbind;
293     IBinding_AddRef(pbind);
294
295     httprequest_setreadystate(This->request, READYSTATE_LOADED);
296
297     return CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
298 }
299
300 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pPriority)
301 {
302     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
303
304     TRACE("(%p)->(%p)\n", This, pPriority);
305
306     return E_NOTIMPL;
307 }
308
309 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
310 {
311     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
312
313     TRACE("(%p)->(%d)\n", This, reserved);
314
315     return E_NOTIMPL;
316 }
317
318 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
319         ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
320 {
321     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
322
323     TRACE("(%p)->(%u %u %u %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
324             debugstr_w(szStatusText));
325
326     return S_OK;
327 }
328
329 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
330         HRESULT hr, LPCWSTR error)
331 {
332     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
333
334     TRACE("(%p)->(0x%08x %s)\n", This, hr, debugstr_w(error));
335
336     if (This->binding)
337     {
338         IBinding_Release(This->binding);
339         This->binding = NULL;
340     }
341
342     if (hr == S_OK)
343         httprequest_setreadystate(This->request, READYSTATE_COMPLETE);
344
345     return S_OK;
346 }
347
348 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
349         DWORD *bind_flags, BINDINFO *pbindinfo)
350 {
351     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
352
353     TRACE("(%p)->(%p %p)\n", This, bind_flags, pbindinfo);
354
355     *bind_flags = 0;
356     if (This->request->async) *bind_flags |= BINDF_ASYNCHRONOUS;
357
358     if (This->request->verb != BINDVERB_GET && This->body)
359     {
360         pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
361         pbindinfo->stgmedData.u.hGlobal = This->body;
362         pbindinfo->cbstgmedData = GlobalSize(This->body);
363         /* callback owns passed body pointer */
364         IBindStatusCallback_QueryInterface(iface, &IID_IUnknown, (void**)&pbindinfo->stgmedData.pUnkForRelease);
365     }
366
367     pbindinfo->dwBindVerb = This->request->verb;
368     if (This->request->verb == BINDVERB_CUSTOM)
369     {
370         pbindinfo->szCustomVerb = CoTaskMemAlloc(SysStringByteLen(This->request->custom));
371         strcpyW(pbindinfo->szCustomVerb, This->request->custom);
372     }
373
374     return S_OK;
375 }
376
377 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
378         DWORD flags, DWORD size, FORMATETC *format, STGMEDIUM *stgmed)
379 {
380     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
381     DWORD read, written;
382     BYTE buf[4096];
383     HRESULT hr;
384
385     TRACE("(%p)->(%08x %d %p %p)\n", This, flags, size, format, stgmed);
386
387     do
388     {
389         hr = IStream_Read(stgmed->u.pstm, buf, sizeof(buf), &read);
390         if (hr != S_OK) break;
391
392         hr = IStream_Write(This->stream, buf, read, &written);
393     } while((hr == S_OK) && written != 0 && read != 0);
394
395     httprequest_setreadystate(This->request, READYSTATE_INTERACTIVE);
396
397     return S_OK;
398 }
399
400 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
401         REFIID riid, IUnknown *punk)
402 {
403     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
404
405     FIXME("(%p)->(%s %p): stub\n", This, debugstr_guid(riid), punk);
406
407     return E_NOTIMPL;
408 }
409
410 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
411     BindStatusCallback_QueryInterface,
412     BindStatusCallback_AddRef,
413     BindStatusCallback_Release,
414     BindStatusCallback_OnStartBinding,
415     BindStatusCallback_GetPriority,
416     BindStatusCallback_OnLowResource,
417     BindStatusCallback_OnProgress,
418     BindStatusCallback_OnStopBinding,
419     BindStatusCallback_GetBindInfo,
420     BindStatusCallback_OnDataAvailable,
421     BindStatusCallback_OnObjectAvailable
422 };
423
424 static HRESULT WINAPI BSCHttpNegotiate_QueryInterface(IHttpNegotiate *iface,
425         REFIID riid, void **ppv)
426 {
427     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
428     return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
429 }
430
431 static ULONG WINAPI BSCHttpNegotiate_AddRef(IHttpNegotiate *iface)
432 {
433     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
434     return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
435 }
436
437 static ULONG WINAPI BSCHttpNegotiate_Release(IHttpNegotiate *iface)
438 {
439     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
440     return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
441 }
442
443 static HRESULT WINAPI BSCHttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
444         LPCWSTR url, LPCWSTR headers, DWORD reserved, LPWSTR *add_headers)
445 {
446     static const WCHAR content_type_utf8W[] = {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ',
447         't','e','x','t','/','p','l','a','i','n',';','c','h','a','r','s','e','t','=','u','t','f','-','8','\r','\n',0};
448
449     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
450     const struct httpheader *entry;
451     WCHAR *buff, *ptr;
452     int size = 0;
453
454     TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(url), debugstr_w(headers), reserved, add_headers);
455
456     *add_headers = NULL;
457
458     if (This->request->use_utf8_content)
459         size = sizeof(content_type_utf8W);
460
461     if (!list_empty(&This->request->reqheaders))
462         size += This->request->reqheader_size*sizeof(WCHAR);
463
464     if (!size) return S_OK;
465
466     buff = CoTaskMemAlloc(size);
467     if (!buff) return E_OUTOFMEMORY;
468
469     ptr = buff;
470     if (This->request->use_utf8_content)
471     {
472         lstrcpyW(ptr, content_type_utf8W);
473         ptr += sizeof(content_type_utf8W)/sizeof(WCHAR)-1;
474     }
475
476     /* user headers */
477     LIST_FOR_EACH_ENTRY(entry, &This->request->reqheaders, struct httpheader, entry)
478     {
479         lstrcpyW(ptr, entry->header);
480         ptr += SysStringLen(entry->header);
481
482         lstrcpyW(ptr, colspaceW);
483         ptr += sizeof(colspaceW)/sizeof(WCHAR)-1;
484
485         lstrcpyW(ptr, entry->value);
486         ptr += SysStringLen(entry->value);
487
488         lstrcpyW(ptr, crlfW);
489         ptr += sizeof(crlfW)/sizeof(WCHAR)-1;
490     }
491
492     *add_headers = buff;
493
494     return S_OK;
495 }
496
497 static void add_response_header(httprequest *This, const WCHAR *data, int len)
498 {
499     struct httpheader *entry;
500     const WCHAR *ptr = data;
501     BSTR header, value;
502
503     while (*ptr)
504     {
505         if (*ptr == ':')
506         {
507             header = SysAllocStringLen(data, ptr-data);
508             /* skip leading spaces for a value */
509             while (*++ptr == ' ')
510                 ;
511             value = SysAllocStringLen(ptr, len-(ptr-data));
512             break;
513         }
514         ptr++;
515     }
516
517     if (!*ptr) return;
518
519     /* new header */
520     TRACE("got header %s:%s\n", debugstr_w(header), debugstr_w(value));
521
522     entry = heap_alloc(sizeof(*entry));
523     entry->header = header;
524     entry->value  = value;
525     list_add_head(&This->respheaders, &entry->entry);
526 }
527
528 static HRESULT WINAPI BSCHttpNegotiate_OnResponse(IHttpNegotiate *iface, DWORD code,
529         LPCWSTR resp_headers, LPCWSTR req_headers, LPWSTR *add_reqheaders)
530 {
531     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
532
533     TRACE("(%p)->(%d %s %s %p)\n", This, code, debugstr_w(resp_headers),
534           debugstr_w(req_headers), add_reqheaders);
535
536     This->request->status = code;
537     /* store headers and status text */
538     free_response_headers(This->request);
539     SysFreeString(This->request->status_text);
540     This->request->status_text = NULL;
541     if (resp_headers)
542     {
543         const WCHAR *ptr, *line, *status_text;
544
545         ptr = line = resp_headers;
546
547         /* skip HTTP-Version */
548         ptr = strchrW(ptr, ' ');
549         if (ptr)
550         {
551             /* skip Status-Code */
552             ptr = strchrW(++ptr, ' ');
553             if (ptr)
554             {
555                 status_text = ++ptr;
556                 /* now it supposed to end with CRLF */
557                 while (*ptr)
558                 {
559                     if (*ptr == '\r' && *(ptr+1) == '\n')
560                     {
561                         line = ptr + 2;
562                         This->request->status_text = SysAllocStringLen(status_text, ptr-status_text);
563                         TRACE("status text %s\n", debugstr_w(This->request->status_text));
564                         break;
565                     }
566                     ptr++;
567                 }
568             }
569         }
570
571         /* store as unparsed string for now */
572         This->request->raw_respheaders = SysAllocString(line);
573     }
574
575     return S_OK;
576 }
577
578 static const IHttpNegotiateVtbl BSCHttpNegotiateVtbl = {
579     BSCHttpNegotiate_QueryInterface,
580     BSCHttpNegotiate_AddRef,
581     BSCHttpNegotiate_Release,
582     BSCHttpNegotiate_BeginningTransaction,
583     BSCHttpNegotiate_OnResponse
584 };
585
586 static HRESULT WINAPI Authenticate_QueryInterface(IAuthenticate *iface,
587         REFIID riid, void **ppv)
588 {
589     BindStatusCallback *This = impl_from_IAuthenticate(iface);
590     return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
591 }
592
593 static ULONG WINAPI Authenticate_AddRef(IAuthenticate *iface)
594 {
595     BindStatusCallback *This = impl_from_IAuthenticate(iface);
596     return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
597 }
598
599 static ULONG WINAPI Authenticate_Release(IAuthenticate *iface)
600 {
601     BindStatusCallback *This = impl_from_IAuthenticate(iface);
602     return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
603 }
604
605 static HRESULT WINAPI Authenticate_Authenticate(IAuthenticate *iface,
606     HWND *hwnd, LPWSTR *username, LPWSTR *password)
607 {
608     BindStatusCallback *This = impl_from_IAuthenticate(iface);
609     FIXME("(%p)->(%p %p %p)\n", This, hwnd, username, password);
610     return E_NOTIMPL;
611 }
612
613 static const IAuthenticateVtbl AuthenticateVtbl = {
614     Authenticate_QueryInterface,
615     Authenticate_AddRef,
616     Authenticate_Release,
617     Authenticate_Authenticate
618 };
619
620 static HRESULT BindStatusCallback_create(httprequest* This, BindStatusCallback **obj, const VARIANT *body)
621 {
622     BindStatusCallback *bsc;
623     IBindCtx *pbc;
624     HRESULT hr;
625     int size;
626
627     hr = CreateBindCtx(0, &pbc);
628     if (hr != S_OK) return hr;
629
630     bsc = heap_alloc(sizeof(*bsc));
631     if (!bsc)
632     {
633         IBindCtx_Release(pbc);
634         return E_OUTOFMEMORY;
635     }
636
637     bsc->IBindStatusCallback_iface.lpVtbl = &BindStatusCallbackVtbl;
638     bsc->IHttpNegotiate_iface.lpVtbl = &BSCHttpNegotiateVtbl;
639     bsc->IAuthenticate_iface.lpVtbl = &AuthenticateVtbl;
640     bsc->ref = 1;
641     bsc->request = This;
642     bsc->binding = NULL;
643     bsc->stream = NULL;
644     bsc->body = NULL;
645
646     TRACE("(%p)->(%p)\n", This, bsc);
647
648     This->use_utf8_content = FALSE;
649
650     if (This->verb != BINDVERB_GET)
651     {
652         void *send_data, *ptr;
653         SAFEARRAY *sa = NULL;
654
655         if (V_VT(body) == (VT_VARIANT|VT_BYREF))
656             body = V_VARIANTREF(body);
657
658         switch (V_VT(body))
659         {
660         case VT_BSTR:
661         {
662             int len = SysStringLen(V_BSTR(body));
663             const WCHAR *str = V_BSTR(body);
664             UINT i, cp = CP_ACP;
665
666             for (i = 0; i < len; i++)
667             {
668                 if (str[i] > 127)
669                 {
670                     cp = CP_UTF8;
671                     break;
672                 }
673             }
674
675             size = WideCharToMultiByte(cp, 0, str, len, NULL, 0, NULL, NULL);
676             if (!(ptr = heap_alloc(size)))
677             {
678                 heap_free(bsc);
679                 return E_OUTOFMEMORY;
680             }
681             WideCharToMultiByte(cp, 0, str, len, ptr, size, NULL, NULL);
682             if (cp == CP_UTF8) This->use_utf8_content = TRUE;
683             break;
684         }
685         case VT_ARRAY|VT_UI1:
686         {
687             sa = V_ARRAY(body);
688             if ((hr = SafeArrayAccessData(sa, (void **)&ptr)) != S_OK)
689             {
690                 heap_free(bsc);
691                 return hr;
692             }
693             if ((hr = SafeArrayGetUBound(sa, 1, &size) != S_OK))
694             {
695                 SafeArrayUnaccessData(sa);
696                 heap_free(bsc);
697                 return hr;
698             }
699             size++;
700             break;
701         }
702         case VT_EMPTY:
703         case VT_ERROR:
704             ptr = NULL;
705             size = 0;
706             break;
707         default:
708             FIXME("unsupported body data type %d\n", V_VT(body));
709             break;
710         }
711
712         bsc->body = GlobalAlloc(GMEM_FIXED, size);
713         if (!bsc->body)
714         {
715             if (V_VT(body) == VT_BSTR)
716                 heap_free(ptr);
717             else if (V_VT(body) == (VT_ARRAY|VT_UI1))
718                 SafeArrayUnaccessData(sa);
719
720             heap_free(bsc);
721             return E_OUTOFMEMORY;
722         }
723
724         send_data = GlobalLock(bsc->body);
725         memcpy(send_data, ptr, size);
726         GlobalUnlock(bsc->body);
727
728         if (V_VT(body) == VT_BSTR)
729             heap_free(ptr);
730         else if (V_VT(body) == (VT_ARRAY|VT_UI1))
731             SafeArrayUnaccessData(sa);
732     }
733
734     hr = RegisterBindStatusCallback(pbc, &bsc->IBindStatusCallback_iface, NULL, 0);
735     if (hr == S_OK)
736     {
737         IMoniker *moniker;
738
739         hr = CreateURLMoniker(NULL, This->url, &moniker);
740         if (hr == S_OK)
741         {
742             IStream *stream;
743
744             hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (void**)&stream);
745             IMoniker_Release(moniker);
746             if (stream) IStream_Release(stream);
747         }
748         IBindCtx_Release(pbc);
749     }
750
751     if (FAILED(hr))
752     {
753         IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
754         bsc = NULL;
755     }
756
757     *obj = bsc;
758     return hr;
759 }
760
761 static HRESULT httprequest_open(httprequest *This, BSTR method, BSTR url,
762         VARIANT async, VARIANT user, VARIANT password)
763 {
764     static const WCHAR MethodGetW[] = {'G','E','T',0};
765     static const WCHAR MethodPutW[] = {'P','U','T',0};
766     static const WCHAR MethodPostW[] = {'P','O','S','T',0};
767     static const WCHAR MethodDeleteW[] = {'D','E','L','E','T','E',0};
768     static const WCHAR MethodPropFindW[] = {'P','R','O','P','F','I','N','D',0};
769     VARIANT str, is_async;
770     HRESULT hr;
771
772     if (!method || !url) return E_INVALIDARG;
773
774     /* free previously set data */
775     SysFreeString(This->url);
776     SysFreeString(This->user);
777     SysFreeString(This->password);
778     This->url = This->user = This->password = NULL;
779
780     if (!strcmpiW(method, MethodGetW))
781     {
782         This->verb = BINDVERB_GET;
783     }
784     else if (!strcmpiW(method, MethodPutW))
785     {
786         This->verb = BINDVERB_PUT;
787     }
788     else if (!strcmpiW(method, MethodPostW))
789     {
790         This->verb = BINDVERB_POST;
791     }
792     else if (!strcmpiW(method, MethodDeleteW) ||
793              !strcmpiW(method, MethodPropFindW))
794     {
795         This->verb = BINDVERB_CUSTOM;
796         SysReAllocString(&This->custom, method);
797     }
798     else
799     {
800         FIXME("unsupported request type %s\n", debugstr_w(method));
801         This->verb = -1;
802         return E_FAIL;
803     }
804
805     /* try to combine with site url */
806     if (This->siteurl && PathIsRelativeW(url))
807     {
808         DWORD len = INTERNET_MAX_URL_LENGTH;
809         WCHAR *fullW = heap_alloc(len*sizeof(WCHAR));
810
811         hr = UrlCombineW(This->siteurl, url, fullW, &len, 0);
812         if (hr == S_OK)
813         {
814             TRACE("combined url %s\n", debugstr_w(fullW));
815             This->url = SysAllocString(fullW);
816         }
817         heap_free(fullW);
818     }
819     else
820         This->url = SysAllocString(url);
821
822     VariantInit(&is_async);
823     hr = VariantChangeType(&is_async, &async, 0, VT_BOOL);
824     This->async = hr == S_OK && V_BOOL(&is_async);
825
826     VariantInit(&str);
827     hr = VariantChangeType(&str, &user, 0, VT_BSTR);
828     if (hr == S_OK)
829         This->user = V_BSTR(&str);
830
831     VariantInit(&str);
832     hr = VariantChangeType(&str, &password, 0, VT_BSTR);
833     if (hr == S_OK)
834         This->password = V_BSTR(&str);
835
836     httprequest_setreadystate(This, READYSTATE_LOADING);
837
838     return S_OK;
839 }
840
841 static HRESULT httprequest_setRequestHeader(httprequest *This, BSTR header, BSTR value)
842 {
843     struct httpheader *entry;
844
845     if (!header || !*header) return E_INVALIDARG;
846     if (This->state != READYSTATE_LOADING) return E_FAIL;
847     if (!value) return E_INVALIDARG;
848
849     /* replace existing header value if already added */
850     LIST_FOR_EACH_ENTRY(entry, &This->reqheaders, struct httpheader, entry)
851     {
852         if (lstrcmpW(entry->header, header) == 0)
853         {
854             LONG length = SysStringLen(entry->value);
855             HRESULT hr;
856
857             hr = SysReAllocString(&entry->value, value) ? S_OK : E_OUTOFMEMORY;
858
859             if (hr == S_OK)
860                 This->reqheader_size += (SysStringLen(entry->value) - length);
861
862             return hr;
863         }
864     }
865
866     entry = heap_alloc(sizeof(*entry));
867     if (!entry) return E_OUTOFMEMORY;
868
869     /* new header */
870     entry->header = SysAllocString(header);
871     entry->value  = SysAllocString(value);
872
873     /* header length including null terminator */
874     This->reqheader_size += SysStringLen(entry->header) + sizeof(colspaceW)/sizeof(WCHAR) +
875                             SysStringLen(entry->value)  + sizeof(crlfW)/sizeof(WCHAR) - 1;
876
877     list_add_head(&This->reqheaders, &entry->entry);
878
879     return S_OK;
880 }
881
882 static HRESULT httprequest_getResponseHeader(httprequest *This, BSTR header, BSTR *value)
883 {
884     struct httpheader *entry;
885
886     if (!header || !value) return E_INVALIDARG;
887
888     if (This->raw_respheaders && list_empty(&This->respheaders))
889     {
890         WCHAR *ptr, *line;
891
892         ptr = line = This->raw_respheaders;
893         while (*ptr)
894         {
895             if (*ptr == '\r' && *(ptr+1) == '\n')
896             {
897                 add_response_header(This, line, ptr-line);
898                 ptr++; line = ++ptr;
899                 continue;
900             }
901             ptr++;
902         }
903     }
904
905     LIST_FOR_EACH_ENTRY(entry, &This->respheaders, struct httpheader, entry)
906     {
907         if (!strcmpiW(entry->header, header))
908         {
909             *value = SysAllocString(entry->value);
910             TRACE("header value %s\n", debugstr_w(*value));
911             return S_OK;
912         }
913     }
914
915     return S_FALSE;
916 }
917
918 static HRESULT httprequest_getAllResponseHeaders(httprequest *This, BSTR *respheaders)
919 {
920     if (!respheaders) return E_INVALIDARG;
921
922     *respheaders = SysAllocString(This->raw_respheaders);
923
924     return S_OK;
925 }
926
927 static HRESULT httprequest_send(httprequest *This, VARIANT body)
928 {
929     BindStatusCallback *bsc = NULL;
930     HRESULT hr;
931
932     if (This->state != READYSTATE_LOADING) return E_FAIL;
933
934     hr = BindStatusCallback_create(This, &bsc, &body);
935     if (FAILED(hr)) return hr;
936
937     BindStatusCallback_Detach(This->bsc);
938     This->bsc = bsc;
939
940     return hr;
941 }
942
943 static HRESULT httprequest_abort(httprequest *This)
944 {
945     BindStatusCallback_Detach(This->bsc);
946     This->bsc = NULL;
947
948     httprequest_setreadystate(This, READYSTATE_UNINITIALIZED);
949
950     return S_OK;
951 }
952
953 static HRESULT httprequest_get_status(httprequest *This, LONG *status)
954 {
955     if (!status) return E_INVALIDARG;
956     if (This->state != READYSTATE_COMPLETE) return E_FAIL;
957
958     *status = This->status;
959
960     return S_OK;
961 }
962
963 static HRESULT httprequest_get_statusText(httprequest *This, BSTR *status)
964 {
965     if (!status) return E_INVALIDARG;
966     if (This->state != READYSTATE_COMPLETE) return E_FAIL;
967
968     *status = SysAllocString(This->status_text);
969
970     return S_OK;
971 }
972
973 static HRESULT httprequest_get_responseText(httprequest *This, BSTR *body)
974 {
975     HGLOBAL hglobal;
976     HRESULT hr;
977
978     if (!body) return E_INVALIDARG;
979     if (This->state != READYSTATE_COMPLETE) return E_FAIL;
980
981     hr = GetHGlobalFromStream(This->bsc->stream, &hglobal);
982     if (hr == S_OK)
983     {
984         xmlChar *ptr = GlobalLock(hglobal);
985         DWORD size = GlobalSize(hglobal);
986         xmlCharEncoding encoding = XML_CHAR_ENCODING_UTF8;
987
988         /* try to determine data encoding */
989         if (size >= 4)
990         {
991             encoding = xmlDetectCharEncoding(ptr, 4);
992             TRACE("detected encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding)));
993             if ( encoding != XML_CHAR_ENCODING_UTF8 &&
994                  encoding != XML_CHAR_ENCODING_UTF16LE &&
995                  encoding != XML_CHAR_ENCODING_NONE )
996             {
997                 FIXME("unsupported encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding)));
998                 GlobalUnlock(hglobal);
999                 return E_FAIL;
1000             }
1001         }
1002
1003         /* without BOM assume UTF-8 */
1004         if (encoding == XML_CHAR_ENCODING_UTF8 ||
1005             encoding == XML_CHAR_ENCODING_NONE )
1006         {
1007             DWORD length = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)ptr, size, NULL, 0);
1008
1009             *body = SysAllocStringLen(NULL, length);
1010             if (*body)
1011                 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)ptr, size, *body, length);
1012         }
1013         else
1014             *body = SysAllocStringByteLen((LPCSTR)ptr, size);
1015
1016         if (!*body) hr = E_OUTOFMEMORY;
1017         GlobalUnlock(hglobal);
1018     }
1019
1020     return hr;
1021 }
1022
1023 static HRESULT httprequest_get_responseXML(httprequest *This, IDispatch **body)
1024 {
1025     IXMLDOMDocument3 *doc;
1026     HRESULT hr;
1027     BSTR str;
1028
1029     if (!body) return E_INVALIDARG;
1030     if (This->state != READYSTATE_COMPLETE) return E_FAIL;
1031
1032     hr = DOMDocument_create(MSXML_DEFAULT, NULL, (void**)&doc);
1033     if (hr != S_OK) return hr;
1034
1035     hr = httprequest_get_responseText(This, &str);
1036     if (hr == S_OK)
1037     {
1038         VARIANT_BOOL ok;
1039
1040         hr = IXMLDOMDocument3_loadXML(doc, str, &ok);
1041         SysFreeString(str);
1042     }
1043
1044     IXMLDOMDocument3_QueryInterface(doc, &IID_IDispatch, (void**)body);
1045     IXMLDOMDocument3_Release(doc);
1046
1047     return hr;
1048 }
1049
1050 static HRESULT httprequest_get_responseBody(httprequest *This, VARIANT *body)
1051 {
1052     HGLOBAL hglobal;
1053     HRESULT hr;
1054
1055     if (!body) return E_INVALIDARG;
1056     V_VT(body) = VT_EMPTY;
1057
1058     if (This->state != READYSTATE_COMPLETE) return E_PENDING;
1059
1060     hr = GetHGlobalFromStream(This->bsc->stream, &hglobal);
1061     if (hr == S_OK)
1062     {
1063         void *ptr = GlobalLock(hglobal);
1064         DWORD size = GlobalSize(hglobal);
1065
1066         SAFEARRAYBOUND bound;
1067         SAFEARRAY *array;
1068
1069         bound.lLbound = 0;
1070         bound.cElements = size;
1071         array = SafeArrayCreate(VT_UI1, 1, &bound);
1072
1073         if (array)
1074         {
1075             void *dest;
1076
1077             V_VT(body) = VT_ARRAY | VT_UI1;
1078             V_ARRAY(body) = array;
1079
1080             hr = SafeArrayAccessData(array, &dest);
1081             if (hr == S_OK)
1082             {
1083                 memcpy(dest, ptr, size);
1084                 SafeArrayUnaccessData(array);
1085             }
1086             else
1087             {
1088                 VariantClear(body);
1089             }
1090         }
1091         else
1092             hr = E_FAIL;
1093
1094         GlobalUnlock(hglobal);
1095     }
1096
1097     return hr;
1098 }
1099
1100 static HRESULT httprequest_get_responseStream(httprequest *This, VARIANT *body)
1101 {
1102     LARGE_INTEGER move;
1103     IStream *stream;
1104     HRESULT hr;
1105
1106     if (!body) return E_INVALIDARG;
1107     V_VT(body) = VT_EMPTY;
1108
1109     if (This->state != READYSTATE_COMPLETE) return E_PENDING;
1110
1111     hr = IStream_Clone(This->bsc->stream, &stream);
1112
1113     move.QuadPart = 0;
1114     IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
1115
1116     V_VT(body) = VT_UNKNOWN;
1117     V_UNKNOWN(body) = (IUnknown*)stream;
1118
1119     return hr;
1120 }
1121
1122 static HRESULT httprequest_get_readyState(httprequest *This, LONG *state)
1123 {
1124     if (!state) return E_INVALIDARG;
1125
1126     *state = This->state;
1127     return S_OK;
1128 }
1129
1130 static HRESULT httprequest_put_onreadystatechange(httprequest *This, IDispatch *sink)
1131 {
1132     if (This->sink) IDispatch_Release(This->sink);
1133     if ((This->sink = sink)) IDispatch_AddRef(This->sink);
1134
1135     return S_OK;
1136 }
1137
1138 static void httprequest_release(httprequest *This)
1139 {
1140     struct httpheader *header, *header2;
1141
1142     if (This->site)
1143         IUnknown_Release( This->site );
1144
1145     SysFreeString(This->custom);
1146     SysFreeString(This->siteurl);
1147     SysFreeString(This->url);
1148     SysFreeString(This->user);
1149     SysFreeString(This->password);
1150
1151     /* request headers */
1152     LIST_FOR_EACH_ENTRY_SAFE(header, header2, &This->reqheaders, struct httpheader, entry)
1153     {
1154         list_remove(&header->entry);
1155         SysFreeString(header->header);
1156         SysFreeString(header->value);
1157         heap_free(header);
1158     }
1159     /* response headers */
1160     free_response_headers(This);
1161     SysFreeString(This->status_text);
1162
1163     /* detach callback object */
1164     BindStatusCallback_Detach(This->bsc);
1165
1166     if (This->sink) IDispatch_Release(This->sink);
1167 }
1168
1169 static HRESULT WINAPI XMLHTTPRequest_QueryInterface(IXMLHTTPRequest *iface, REFIID riid, void **ppvObject)
1170 {
1171     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1172     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
1173
1174     if ( IsEqualGUID( riid, &IID_IXMLHTTPRequest) ||
1175          IsEqualGUID( riid, &IID_IDispatch) ||
1176          IsEqualGUID( riid, &IID_IUnknown) )
1177     {
1178         *ppvObject = iface;
1179     }
1180     else if (IsEqualGUID(&IID_IObjectWithSite, riid))
1181     {
1182         *ppvObject = &This->IObjectWithSite_iface;
1183     }
1184     else if (IsEqualGUID(&IID_IObjectSafety, riid))
1185     {
1186         *ppvObject = &This->IObjectSafety_iface;
1187     }
1188     else
1189     {
1190         TRACE("Unsupported interface %s\n", debugstr_guid(riid));
1191         *ppvObject = NULL;
1192         return E_NOINTERFACE;
1193     }
1194
1195     IXMLHTTPRequest_AddRef( iface );
1196
1197     return S_OK;
1198 }
1199
1200 static ULONG WINAPI XMLHTTPRequest_AddRef(IXMLHTTPRequest *iface)
1201 {
1202     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1203     ULONG ref = InterlockedIncrement( &This->ref );
1204     TRACE("(%p)->(%u)\n", This, ref );
1205     return ref;
1206 }
1207
1208 static ULONG WINAPI XMLHTTPRequest_Release(IXMLHTTPRequest *iface)
1209 {
1210     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1211     ULONG ref = InterlockedDecrement( &This->ref );
1212
1213     TRACE("(%p)->(%u)\n", This, ref );
1214
1215     if ( ref == 0 )
1216     {
1217         httprequest_release( This );
1218         heap_free( This );
1219     }
1220
1221     return ref;
1222 }
1223
1224 static HRESULT WINAPI XMLHTTPRequest_GetTypeInfoCount(IXMLHTTPRequest *iface, UINT *pctinfo)
1225 {
1226     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1227
1228     TRACE("(%p)->(%p)\n", This, pctinfo);
1229
1230     *pctinfo = 1;
1231
1232     return S_OK;
1233 }
1234
1235 static HRESULT WINAPI XMLHTTPRequest_GetTypeInfo(IXMLHTTPRequest *iface, UINT iTInfo,
1236         LCID lcid, ITypeInfo **ti)
1237 {
1238     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1239     HRESULT hr;
1240
1241     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ti);
1242
1243     hr = get_typeinfo(IXMLHTTPRequest_tid, ti);
1244     ITypeInfo_AddRef(*ti);
1245     return hr;
1246 }
1247
1248 static HRESULT WINAPI XMLHTTPRequest_GetIDsOfNames(IXMLHTTPRequest *iface, REFIID riid,
1249         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1250 {
1251     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1252     ITypeInfo *typeinfo;
1253     HRESULT hr;
1254
1255     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1256           lcid, rgDispId);
1257
1258     if(!rgszNames || cNames == 0 || !rgDispId)
1259         return E_INVALIDARG;
1260
1261     hr = get_typeinfo(IXMLHTTPRequest_tid, &typeinfo);
1262     if(SUCCEEDED(hr))
1263         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1264
1265     return hr;
1266 }
1267
1268 static HRESULT WINAPI XMLHTTPRequest_Invoke(IXMLHTTPRequest *iface, DISPID dispIdMember, REFIID riid,
1269         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1270         EXCEPINFO *pExcepInfo, UINT *puArgErr)
1271 {
1272     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1273     ITypeInfo *typeinfo;
1274     HRESULT hr;
1275
1276     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1277           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1278
1279     hr = get_typeinfo(IXMLHTTPRequest_tid, &typeinfo);
1280     if(SUCCEEDED(hr))
1281         hr = ITypeInfo_Invoke(typeinfo, &This->IXMLHTTPRequest_iface, dispIdMember, wFlags,
1282                 pDispParams, pVarResult, pExcepInfo, puArgErr);
1283
1284     return hr;
1285 }
1286
1287 static HRESULT WINAPI XMLHTTPRequest_open(IXMLHTTPRequest *iface, BSTR method, BSTR url,
1288         VARIANT async, VARIANT user, VARIANT password)
1289 {
1290     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1291     TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(method), debugstr_w(url),
1292         debugstr_variant(&async));
1293     return httprequest_open(This, method, url, async, user, password);
1294 }
1295
1296 static HRESULT WINAPI XMLHTTPRequest_setRequestHeader(IXMLHTTPRequest *iface, BSTR header, BSTR value)
1297 {
1298     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1299     TRACE("(%p)->(%s %s)\n", This, debugstr_w(header), debugstr_w(value));
1300     return httprequest_setRequestHeader(This, header, value);
1301 }
1302
1303 static HRESULT WINAPI XMLHTTPRequest_getResponseHeader(IXMLHTTPRequest *iface, BSTR header, BSTR *value)
1304 {
1305     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1306     TRACE("(%p)->(%s %p)\n", This, debugstr_w(header), value);
1307     return httprequest_getResponseHeader(This, header, value);
1308 }
1309
1310 static HRESULT WINAPI XMLHTTPRequest_getAllResponseHeaders(IXMLHTTPRequest *iface, BSTR *respheaders)
1311 {
1312     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1313     TRACE("(%p)->(%p)\n", This, respheaders);
1314     return httprequest_getAllResponseHeaders(This, respheaders);
1315 }
1316
1317 static HRESULT WINAPI XMLHTTPRequest_send(IXMLHTTPRequest *iface, VARIANT body)
1318 {
1319     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1320     TRACE("(%p)->(%s)\n", This, debugstr_variant(&body));
1321     return httprequest_send(This, body);
1322 }
1323
1324 static HRESULT WINAPI XMLHTTPRequest_abort(IXMLHTTPRequest *iface)
1325 {
1326     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1327     TRACE("(%p)\n", This);
1328     return httprequest_abort(This);
1329 }
1330
1331 static HRESULT WINAPI XMLHTTPRequest_get_status(IXMLHTTPRequest *iface, LONG *status)
1332 {
1333     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1334     TRACE("(%p)->(%p)\n", This, status);
1335     return httprequest_get_status(This, status);
1336 }
1337
1338 static HRESULT WINAPI XMLHTTPRequest_get_statusText(IXMLHTTPRequest *iface, BSTR *status)
1339 {
1340     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1341     TRACE("(%p)->(%p)\n", This, status);
1342     return httprequest_get_statusText(This, status);
1343 }
1344
1345 static HRESULT WINAPI XMLHTTPRequest_get_responseXML(IXMLHTTPRequest *iface, IDispatch **body)
1346 {
1347     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1348     TRACE("(%p)->(%p)\n", This, body);
1349     return httprequest_get_responseXML(This, body);
1350 }
1351
1352 static HRESULT WINAPI XMLHTTPRequest_get_responseText(IXMLHTTPRequest *iface, BSTR *body)
1353 {
1354     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1355     TRACE("(%p)->(%p)\n", This, body);
1356     return httprequest_get_responseText(This, body);
1357 }
1358
1359 static HRESULT WINAPI XMLHTTPRequest_get_responseBody(IXMLHTTPRequest *iface, VARIANT *body)
1360 {
1361     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1362     TRACE("(%p)->(%p)\n", This, body);
1363     return httprequest_get_responseBody(This, body);
1364 }
1365
1366 static HRESULT WINAPI XMLHTTPRequest_get_responseStream(IXMLHTTPRequest *iface, VARIANT *body)
1367 {
1368     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1369     TRACE("(%p)->(%p)\n", This, body);
1370     return httprequest_get_responseStream(This, body);
1371 }
1372
1373 static HRESULT WINAPI XMLHTTPRequest_get_readyState(IXMLHTTPRequest *iface, LONG *state)
1374 {
1375     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1376     TRACE("(%p)->(%p)\n", This, state);
1377     return httprequest_get_readyState(This, state);
1378 }
1379
1380 static HRESULT WINAPI XMLHTTPRequest_put_onreadystatechange(IXMLHTTPRequest *iface, IDispatch *sink)
1381 {
1382     httprequest *This = impl_from_IXMLHTTPRequest( iface );
1383     TRACE("(%p)->(%p)\n", This, sink);
1384     return httprequest_put_onreadystatechange(This, sink);
1385 }
1386
1387 static const struct IXMLHTTPRequestVtbl XMLHTTPRequestVtbl =
1388 {
1389     XMLHTTPRequest_QueryInterface,
1390     XMLHTTPRequest_AddRef,
1391     XMLHTTPRequest_Release,
1392     XMLHTTPRequest_GetTypeInfoCount,
1393     XMLHTTPRequest_GetTypeInfo,
1394     XMLHTTPRequest_GetIDsOfNames,
1395     XMLHTTPRequest_Invoke,
1396     XMLHTTPRequest_open,
1397     XMLHTTPRequest_setRequestHeader,
1398     XMLHTTPRequest_getResponseHeader,
1399     XMLHTTPRequest_getAllResponseHeaders,
1400     XMLHTTPRequest_send,
1401     XMLHTTPRequest_abort,
1402     XMLHTTPRequest_get_status,
1403     XMLHTTPRequest_get_statusText,
1404     XMLHTTPRequest_get_responseXML,
1405     XMLHTTPRequest_get_responseText,
1406     XMLHTTPRequest_get_responseBody,
1407     XMLHTTPRequest_get_responseStream,
1408     XMLHTTPRequest_get_readyState,
1409     XMLHTTPRequest_put_onreadystatechange
1410 };
1411
1412 /* IObjectWithSite */
1413 static HRESULT WINAPI
1414 httprequest_ObjectWithSite_QueryInterface( IObjectWithSite* iface, REFIID riid, void** ppvObject )
1415 {
1416     httprequest *This = impl_from_IObjectWithSite(iface);
1417     return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest *)This, riid, ppvObject );
1418 }
1419
1420 static ULONG WINAPI httprequest_ObjectWithSite_AddRef( IObjectWithSite* iface )
1421 {
1422     httprequest *This = impl_from_IObjectWithSite(iface);
1423     return IXMLHTTPRequest_AddRef((IXMLHTTPRequest *)This);
1424 }
1425
1426 static ULONG WINAPI httprequest_ObjectWithSite_Release( IObjectWithSite* iface )
1427 {
1428     httprequest *This = impl_from_IObjectWithSite(iface);
1429     return IXMLHTTPRequest_Release((IXMLHTTPRequest *)This);
1430 }
1431
1432 static HRESULT WINAPI httprequest_ObjectWithSite_GetSite( IObjectWithSite *iface, REFIID iid, void **ppvSite )
1433 {
1434     httprequest *This = impl_from_IObjectWithSite(iface);
1435
1436     TRACE("(%p)->(%s %p)\n", This, debugstr_guid( iid ), ppvSite );
1437
1438     if ( !This->site )
1439         return E_FAIL;
1440
1441     return IUnknown_QueryInterface( This->site, iid, ppvSite );
1442 }
1443
1444 static HRESULT WINAPI httprequest_ObjectWithSite_SetSite( IObjectWithSite *iface, IUnknown *punk )
1445 {
1446     httprequest *This = impl_from_IObjectWithSite(iface);
1447
1448     TRACE("(%p)->(%p)\n", This, punk);
1449
1450     if(This->site)
1451         IUnknown_Release( This->site );
1452
1453     SysFreeString(This->siteurl);
1454     This->siteurl = NULL;
1455     This->site = punk;
1456
1457     if (punk)
1458     {
1459         IServiceProvider *provider;
1460         HRESULT hr;
1461
1462         IUnknown_AddRef( punk );
1463
1464         hr = IUnknown_QueryInterface(This->site, &IID_IServiceProvider, (void**)&provider);
1465         if (hr == S_OK)
1466         {
1467             IHTMLDocument2 *doc;
1468
1469             hr = IServiceProvider_QueryService(provider, &SID_SContainerDispatch, &IID_IHTMLDocument2, (void**)&doc);
1470             if (hr == S_OK)
1471             {
1472                 hr = IHTMLDocument2_get_URL(doc, &This->siteurl);
1473                 IHTMLDocument2_Release(doc);
1474                 TRACE("host url %s, 0x%08x\n", debugstr_w(This->siteurl), hr);
1475             }
1476             IServiceProvider_Release(provider);
1477         }
1478     }
1479
1480     return S_OK;
1481 }
1482
1483 static const IObjectWithSiteVtbl ObjectWithSiteVtbl =
1484 {
1485     httprequest_ObjectWithSite_QueryInterface,
1486     httprequest_ObjectWithSite_AddRef,
1487     httprequest_ObjectWithSite_Release,
1488     httprequest_ObjectWithSite_SetSite,
1489     httprequest_ObjectWithSite_GetSite
1490 };
1491
1492 /* IObjectSafety */
1493 static HRESULT WINAPI httprequest_Safety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1494 {
1495     httprequest *This = impl_from_IObjectSafety(iface);
1496     return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest *)This, riid, ppv );
1497 }
1498
1499 static ULONG WINAPI httprequest_Safety_AddRef(IObjectSafety *iface)
1500 {
1501     httprequest *This = impl_from_IObjectSafety(iface);
1502     return IXMLHTTPRequest_AddRef((IXMLHTTPRequest *)This);
1503 }
1504
1505 static ULONG WINAPI httprequest_Safety_Release(IObjectSafety *iface)
1506 {
1507     httprequest *This = impl_from_IObjectSafety(iface);
1508     return IXMLHTTPRequest_Release((IXMLHTTPRequest *)This);
1509 }
1510
1511 static HRESULT WINAPI httprequest_Safety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1512         DWORD *supported, DWORD *enabled)
1513 {
1514     httprequest *This = impl_from_IObjectSafety(iface);
1515
1516     TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), supported, enabled);
1517
1518     if(!supported || !enabled) return E_POINTER;
1519
1520     *supported = safety_supported_options;
1521     *enabled = This->safeopt;
1522
1523     return S_OK;
1524 }
1525
1526 static HRESULT WINAPI httprequest_Safety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1527         DWORD mask, DWORD enabled)
1528 {
1529     httprequest *This = impl_from_IObjectSafety(iface);
1530     TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), mask, enabled);
1531
1532     if ((mask & ~safety_supported_options))
1533         return E_FAIL;
1534
1535     This->safeopt = (This->safeopt & ~mask) | (mask & enabled);
1536
1537     return S_OK;
1538 }
1539
1540 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
1541     httprequest_Safety_QueryInterface,
1542     httprequest_Safety_AddRef,
1543     httprequest_Safety_Release,
1544     httprequest_Safety_GetInterfaceSafetyOptions,
1545     httprequest_Safety_SetInterfaceSafetyOptions
1546 };
1547
1548 /* IServerXMLHTTPRequest */
1549 static HRESULT WINAPI ServerXMLHTTPRequest_QueryInterface(IServerXMLHTTPRequest *iface, REFIID riid, void **obj)
1550 {
1551     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1552
1553     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
1554
1555     if ( IsEqualGUID( riid, &IID_IServerXMLHTTPRequest) ||
1556          IsEqualGUID( riid, &IID_IXMLHTTPRequest) ||
1557          IsEqualGUID( riid, &IID_IDispatch) ||
1558          IsEqualGUID( riid, &IID_IUnknown) )
1559     {
1560         *obj = iface;
1561     }
1562     else
1563     {
1564         TRACE("Unsupported interface %s\n", debugstr_guid(riid));
1565         *obj = NULL;
1566         return E_NOINTERFACE;
1567     }
1568
1569     IServerXMLHTTPRequest_AddRef( iface );
1570
1571     return S_OK;
1572 }
1573
1574 static ULONG WINAPI ServerXMLHTTPRequest_AddRef(IServerXMLHTTPRequest *iface)
1575 {
1576     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1577     ULONG ref = InterlockedIncrement( &This->ref );
1578     TRACE("(%p)->(%u)\n", This, ref );
1579     return ref;
1580 }
1581
1582 static ULONG WINAPI ServerXMLHTTPRequest_Release(IServerXMLHTTPRequest *iface)
1583 {
1584     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1585     ULONG ref = InterlockedDecrement( &This->ref );
1586
1587     TRACE("(%p)->(%u)\n", This, ref );
1588
1589     if ( ref == 0 )
1590     {
1591         httprequest_release( &This->req );
1592         heap_free( This );
1593     }
1594
1595     return ref;
1596 }
1597
1598 static HRESULT WINAPI ServerXMLHTTPRequest_GetTypeInfoCount(IServerXMLHTTPRequest *iface, UINT *pctinfo)
1599 {
1600     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1601
1602     TRACE("(%p)->(%p)\n", This, pctinfo);
1603     *pctinfo = 1;
1604
1605     return S_OK;
1606 }
1607
1608 static HRESULT WINAPI ServerXMLHTTPRequest_GetTypeInfo(IServerXMLHTTPRequest *iface, UINT iTInfo,
1609         LCID lcid, ITypeInfo **ti)
1610 {
1611     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1612     HRESULT hr;
1613
1614     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ti);
1615
1616     hr = get_typeinfo(IServerXMLHTTPRequest_tid, ti);
1617     ITypeInfo_AddRef(*ti);
1618     return hr;
1619 }
1620
1621 static HRESULT WINAPI ServerXMLHTTPRequest_GetIDsOfNames(IServerXMLHTTPRequest *iface, REFIID riid,
1622         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1623 {
1624     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1625     ITypeInfo *typeinfo;
1626     HRESULT hr;
1627
1628     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1629           lcid, rgDispId);
1630
1631     if(!rgszNames || cNames == 0 || !rgDispId)
1632         return E_INVALIDARG;
1633
1634     hr = get_typeinfo(IServerXMLHTTPRequest_tid, &typeinfo);
1635     if(SUCCEEDED(hr))
1636         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1637
1638     return hr;
1639 }
1640
1641 static HRESULT WINAPI ServerXMLHTTPRequest_Invoke(IServerXMLHTTPRequest *iface, DISPID dispIdMember, REFIID riid,
1642         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1643         EXCEPINFO *pExcepInfo, UINT *puArgErr)
1644 {
1645     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1646     ITypeInfo *typeinfo;
1647     HRESULT hr;
1648
1649     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1650           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1651
1652     hr = get_typeinfo(IServerXMLHTTPRequest_tid, &typeinfo);
1653     if(SUCCEEDED(hr))
1654         hr = ITypeInfo_Invoke(typeinfo, &This->IServerXMLHTTPRequest_iface, dispIdMember, wFlags,
1655                 pDispParams, pVarResult, pExcepInfo, puArgErr);
1656
1657     return hr;
1658 }
1659
1660 static HRESULT WINAPI ServerXMLHTTPRequest_open(IServerXMLHTTPRequest *iface, BSTR method, BSTR url,
1661         VARIANT async, VARIANT user, VARIANT password)
1662 {
1663     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1664     TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(method), debugstr_w(url),
1665         debugstr_variant(&async));
1666     return httprequest_open(&This->req, method, url, async, user, password);
1667 }
1668
1669 static HRESULT WINAPI ServerXMLHTTPRequest_setRequestHeader(IServerXMLHTTPRequest *iface, BSTR header, BSTR value)
1670 {
1671     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1672     TRACE("(%p)->(%s %s)\n", This, debugstr_w(header), debugstr_w(value));
1673     return httprequest_setRequestHeader(&This->req, header, value);
1674 }
1675
1676 static HRESULT WINAPI ServerXMLHTTPRequest_getResponseHeader(IServerXMLHTTPRequest *iface, BSTR header, BSTR *value)
1677 {
1678     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1679     TRACE("(%p)->(%s %p)\n", This, debugstr_w(header), value);
1680     return httprequest_getResponseHeader(&This->req, header, value);
1681 }
1682
1683 static HRESULT WINAPI ServerXMLHTTPRequest_getAllResponseHeaders(IServerXMLHTTPRequest *iface, BSTR *respheaders)
1684 {
1685     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1686     TRACE("(%p)->(%p)\n", This, respheaders);
1687     return httprequest_getAllResponseHeaders(&This->req, respheaders);
1688 }
1689
1690 static HRESULT WINAPI ServerXMLHTTPRequest_send(IServerXMLHTTPRequest *iface, VARIANT body)
1691 {
1692     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1693     TRACE("(%p)->(%s)\n", This, debugstr_variant(&body));
1694     return httprequest_send(&This->req, body);
1695 }
1696
1697 static HRESULT WINAPI ServerXMLHTTPRequest_abort(IServerXMLHTTPRequest *iface)
1698 {
1699     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1700     TRACE("(%p)\n", This);
1701     return httprequest_abort(&This->req);
1702 }
1703
1704 static HRESULT WINAPI ServerXMLHTTPRequest_get_status(IServerXMLHTTPRequest *iface, LONG *status)
1705 {
1706     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1707     TRACE("(%p)->(%p)\n", This, status);
1708     return httprequest_get_status(&This->req, status);
1709 }
1710
1711 static HRESULT WINAPI ServerXMLHTTPRequest_get_statusText(IServerXMLHTTPRequest *iface, BSTR *status)
1712 {
1713     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1714     TRACE("(%p)->(%p)\n", This, status);
1715     return httprequest_get_statusText(&This->req, status);
1716 }
1717
1718 static HRESULT WINAPI ServerXMLHTTPRequest_get_responseXML(IServerXMLHTTPRequest *iface, IDispatch **body)
1719 {
1720     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1721     TRACE("(%p)->(%p)\n", This, body);
1722     return httprequest_get_responseXML(&This->req, body);
1723 }
1724
1725 static HRESULT WINAPI ServerXMLHTTPRequest_get_responseText(IServerXMLHTTPRequest *iface, BSTR *body)
1726 {
1727     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1728     TRACE("(%p)->(%p)\n", This, body);
1729     return httprequest_get_responseText(&This->req, body);
1730 }
1731
1732 static HRESULT WINAPI ServerXMLHTTPRequest_get_responseBody(IServerXMLHTTPRequest *iface, VARIANT *body)
1733 {
1734     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1735     TRACE("(%p)->(%p)\n", This, body);
1736     return httprequest_get_responseBody(&This->req, body);
1737 }
1738
1739 static HRESULT WINAPI ServerXMLHTTPRequest_get_responseStream(IServerXMLHTTPRequest *iface, VARIANT *body)
1740 {
1741     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1742     TRACE("(%p)->(%p)\n", This, body);
1743     return httprequest_get_responseStream(&This->req, body);
1744 }
1745
1746 static HRESULT WINAPI ServerXMLHTTPRequest_get_readyState(IServerXMLHTTPRequest *iface, LONG *state)
1747 {
1748     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1749     TRACE("(%p)->(%p)\n", This, state);
1750     return httprequest_get_readyState(&This->req, state);
1751 }
1752
1753 static HRESULT WINAPI ServerXMLHTTPRequest_put_onreadystatechange(IServerXMLHTTPRequest *iface, IDispatch *sink)
1754 {
1755     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1756     TRACE("(%p)->(%p)\n", This, sink);
1757     return httprequest_put_onreadystatechange(&This->req, sink);
1758 }
1759
1760 static HRESULT WINAPI ServerXMLHTTPRequest_setTimeouts(IServerXMLHTTPRequest *iface, LONG resolveTimeout, LONG connectTimeout,
1761     LONG sendTimeout, LONG receiveTimeout)
1762 {
1763     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1764     FIXME("(%p)->(%d %d %d %d): stub\n", This, resolveTimeout, connectTimeout, sendTimeout, receiveTimeout);
1765     return E_NOTIMPL;
1766 }
1767
1768 static HRESULT WINAPI ServerXMLHTTPRequest_waitForResponse(IServerXMLHTTPRequest *iface, VARIANT timeout, VARIANT_BOOL *isSuccessful)
1769 {
1770     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1771     FIXME("(%p)->(%s %p): stub\n", This, debugstr_variant(&timeout), isSuccessful);
1772     return E_NOTIMPL;
1773 }
1774
1775 static HRESULT WINAPI ServerXMLHTTPRequest_getOption(IServerXMLHTTPRequest *iface, SERVERXMLHTTP_OPTION option, VARIANT *value)
1776 {
1777     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1778     FIXME("(%p)->(%d %p): stub\n", This, option, value);
1779     return E_NOTIMPL;
1780 }
1781
1782 static HRESULT WINAPI ServerXMLHTTPRequest_setOption(IServerXMLHTTPRequest *iface, SERVERXMLHTTP_OPTION option, VARIANT value)
1783 {
1784     serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1785     FIXME("(%p)->(%d %s): stub\n", This, option, debugstr_variant(&value));
1786     return E_NOTIMPL;
1787 }
1788
1789 static const struct IServerXMLHTTPRequestVtbl ServerXMLHTTPRequestVtbl =
1790 {
1791     ServerXMLHTTPRequest_QueryInterface,
1792     ServerXMLHTTPRequest_AddRef,
1793     ServerXMLHTTPRequest_Release,
1794     ServerXMLHTTPRequest_GetTypeInfoCount,
1795     ServerXMLHTTPRequest_GetTypeInfo,
1796     ServerXMLHTTPRequest_GetIDsOfNames,
1797     ServerXMLHTTPRequest_Invoke,
1798     ServerXMLHTTPRequest_open,
1799     ServerXMLHTTPRequest_setRequestHeader,
1800     ServerXMLHTTPRequest_getResponseHeader,
1801     ServerXMLHTTPRequest_getAllResponseHeaders,
1802     ServerXMLHTTPRequest_send,
1803     ServerXMLHTTPRequest_abort,
1804     ServerXMLHTTPRequest_get_status,
1805     ServerXMLHTTPRequest_get_statusText,
1806     ServerXMLHTTPRequest_get_responseXML,
1807     ServerXMLHTTPRequest_get_responseText,
1808     ServerXMLHTTPRequest_get_responseBody,
1809     ServerXMLHTTPRequest_get_responseStream,
1810     ServerXMLHTTPRequest_get_readyState,
1811     ServerXMLHTTPRequest_put_onreadystatechange,
1812     ServerXMLHTTPRequest_setTimeouts,
1813     ServerXMLHTTPRequest_waitForResponse,
1814     ServerXMLHTTPRequest_getOption,
1815     ServerXMLHTTPRequest_setOption
1816 };
1817
1818 static void init_httprequest(httprequest *req)
1819 {
1820     req->IXMLHTTPRequest_iface.lpVtbl = &XMLHTTPRequestVtbl;
1821     req->IObjectWithSite_iface.lpVtbl = &ObjectWithSiteVtbl;
1822     req->IObjectSafety_iface.lpVtbl = &ObjectSafetyVtbl;
1823     req->ref = 1;
1824
1825     req->async = FALSE;
1826     req->verb = -1;
1827     req->custom = NULL;
1828     req->url = req->siteurl = req->user = req->password = NULL;
1829
1830     req->state = READYSTATE_UNINITIALIZED;
1831     req->sink = NULL;
1832
1833     req->bsc = NULL;
1834     req->status = 0;
1835     req->status_text = NULL;
1836     req->reqheader_size = 0;
1837     req->raw_respheaders = NULL;
1838     req->use_utf8_content = FALSE;
1839
1840     list_init(&req->reqheaders);
1841     list_init(&req->respheaders);
1842
1843     req->site = NULL;
1844     req->safeopt = 0;
1845 }
1846
1847 HRESULT XMLHTTPRequest_create(IUnknown *outer, void **obj)
1848 {
1849     httprequest *req;
1850
1851     TRACE("(%p, %p)\n", outer, obj);
1852
1853     req = heap_alloc( sizeof (*req) );
1854     if( !req )
1855         return E_OUTOFMEMORY;
1856
1857     init_httprequest(req);
1858     *obj = &req->IXMLHTTPRequest_iface;
1859
1860     TRACE("returning iface %p\n", *obj);
1861
1862     return S_OK;
1863 }
1864
1865 HRESULT ServerXMLHTTP_create(IUnknown *outer, void **obj)
1866 {
1867     serverhttp *req;
1868
1869     TRACE("(%p, %p)\n", outer, obj);
1870
1871     req = heap_alloc( sizeof (*req) );
1872     if( !req )
1873         return E_OUTOFMEMORY;
1874
1875     init_httprequest(&req->req);
1876     req->IServerXMLHTTPRequest_iface.lpVtbl = &ServerXMLHTTPRequestVtbl;
1877     req->ref = 1;
1878
1879     *obj = &req->IServerXMLHTTPRequest_iface;
1880
1881     TRACE("returning iface %p\n", *obj);
1882
1883     return S_OK;
1884 }
1885
1886 #else
1887
1888 HRESULT XMLHTTPRequest_create(IUnknown *pUnkOuter, void **ppObj)
1889 {
1890     MESSAGE("This program tried to use a XMLHTTPRequest object, but\n"
1891             "libxml2 support was not present at compile time.\n");
1892     return E_NOTIMPL;
1893 }
1894
1895 HRESULT ServerXMLHTTP_create(IUnknown *outer, void **obj)
1896 {
1897     MESSAGE("This program tried to use a ServerXMLHTTP object, but\n"
1898             "libxml2 support was not present at compile time.\n");
1899     return E_NOTIMPL;
1900 }
1901
1902 #endif