msxml3: Try mshtml container url as a base for relative request url.
[wine/multimedia.git] / dlls / msxml3 / httprequest.c
blobff4ab219a63cf49e3f37ce83603902f432f59c4a
1 /*
2 * IXMLHTTPRequest implementation
4 * Copyright 2008 Alistair Leslie-Hughes
5 * Copyright 2010-2012 Nikolay Sivov for CodeWeavers
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.
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.
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
22 #define COBJMACROS
23 #define NONAMELESSUNION
25 #include "config.h"
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
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"
47 #include "msxml_private.h"
49 #include "wine/debug.h"
50 #include "wine/list.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
54 #ifdef HAVE_LIBXML2
56 static const WCHAR colspaceW[] = {':',' ',0};
57 static const WCHAR crlfW[] = {'\r','\n',0};
59 typedef struct BindStatusCallback BindStatusCallback;
61 struct httpheader
63 struct list entry;
64 BSTR header;
65 BSTR value;
68 typedef struct
70 IXMLHTTPRequest IXMLHTTPRequest_iface;
71 IObjectWithSite IObjectWithSite_iface;
72 IObjectSafety IObjectSafety_iface;
73 LONG ref;
75 READYSTATE state;
76 IDispatch *sink;
78 /* request */
79 BINDVERB verb;
80 BSTR custom;
81 BSTR siteurl;
82 BSTR url;
83 BOOL async;
84 struct list reqheaders;
85 /* cached resulting custom request headers string length in WCHARs */
86 LONG reqheader_size;
87 /* use UTF-8 content type */
88 BOOL use_utf8_content;
90 /* response headers */
91 struct list respheaders;
92 BSTR raw_respheaders;
94 /* credentials */
95 BSTR user;
96 BSTR password;
98 /* bind callback */
99 BindStatusCallback *bsc;
100 LONG status;
102 /* IObjectWithSite*/
103 IUnknown *site;
105 /* IObjectSafety */
106 DWORD safeopt;
107 } httprequest;
109 static inline httprequest *impl_from_IXMLHTTPRequest( IXMLHTTPRequest *iface )
111 return CONTAINING_RECORD(iface, httprequest, IXMLHTTPRequest_iface);
114 static inline httprequest *impl_from_IObjectWithSite(IObjectWithSite *iface)
116 return CONTAINING_RECORD(iface, httprequest, IObjectWithSite_iface);
119 static inline httprequest *impl_from_IObjectSafety(IObjectSafety *iface)
121 return CONTAINING_RECORD(iface, httprequest, IObjectSafety_iface);
124 static void httprequest_setreadystate(httprequest *This, READYSTATE state)
126 READYSTATE last = This->state;
128 This->state = state;
130 if (This->sink && last != state)
132 DISPPARAMS params;
134 memset(&params, 0, sizeof(params));
135 IDispatch_Invoke(This->sink, 0, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &params, 0, 0, 0);
139 static void free_response_headers(httprequest *This)
141 struct httpheader *header, *header2;
143 LIST_FOR_EACH_ENTRY_SAFE(header, header2, &This->respheaders, struct httpheader, entry)
145 list_remove(&header->entry);
146 SysFreeString(header->header);
147 SysFreeString(header->value);
148 heap_free(header);
151 SysFreeString(This->raw_respheaders);
152 This->raw_respheaders = NULL;
155 struct BindStatusCallback
157 IBindStatusCallback IBindStatusCallback_iface;
158 IHttpNegotiate IHttpNegotiate_iface;
159 IAuthenticate IAuthenticate_iface;
160 LONG ref;
162 IBinding *binding;
163 httprequest *request;
165 /* response data */
166 IStream *stream;
168 /* request body data */
169 HGLOBAL body;
172 static inline BindStatusCallback *impl_from_IBindStatusCallback( IBindStatusCallback *iface )
174 return CONTAINING_RECORD(iface, BindStatusCallback, IBindStatusCallback_iface);
177 static inline BindStatusCallback *impl_from_IHttpNegotiate( IHttpNegotiate *iface )
179 return CONTAINING_RECORD(iface, BindStatusCallback, IHttpNegotiate_iface);
182 static inline BindStatusCallback *impl_from_IAuthenticate( IAuthenticate *iface )
184 return CONTAINING_RECORD(iface, BindStatusCallback, IAuthenticate_iface);
187 static void BindStatusCallback_Detach(BindStatusCallback *bsc)
189 if (bsc)
191 if (bsc->binding) IBinding_Abort(bsc->binding);
192 bsc->request = NULL;
193 IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
197 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
198 REFIID riid, void **ppv)
200 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
202 *ppv = NULL;
204 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
206 if (IsEqualGUID(&IID_IUnknown, riid) ||
207 IsEqualGUID(&IID_IBindStatusCallback, riid))
209 *ppv = &This->IBindStatusCallback_iface;
211 else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
213 *ppv = &This->IHttpNegotiate_iface;
215 else if (IsEqualGUID(&IID_IAuthenticate, riid))
217 *ppv = &This->IAuthenticate_iface;
219 else if (IsEqualGUID(&IID_IServiceProvider, riid) ||
220 IsEqualGUID(&IID_IBindStatusCallbackEx, riid) ||
221 IsEqualGUID(&IID_IInternetProtocol, riid) ||
222 IsEqualGUID(&IID_IHttpNegotiate2, riid))
224 return E_NOINTERFACE;
227 if (*ppv)
229 IBindStatusCallback_AddRef(iface);
230 return S_OK;
233 FIXME("Unsupported riid = %s\n", debugstr_guid(riid));
235 return E_NOINTERFACE;
238 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
240 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
241 LONG ref = InterlockedIncrement(&This->ref);
243 TRACE("(%p) ref = %d\n", This, ref);
245 return ref;
248 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
250 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
251 LONG ref = InterlockedDecrement(&This->ref);
253 TRACE("(%p) ref = %d\n", This, ref);
255 if (!ref)
257 if (This->binding) IBinding_Release(This->binding);
258 if (This->stream) IStream_Release(This->stream);
259 if (This->body) GlobalFree(This->body);
260 heap_free(This);
263 return ref;
266 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
267 DWORD reserved, IBinding *pbind)
269 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
271 TRACE("(%p)->(%d %p)\n", This, reserved, pbind);
273 if (!pbind) return E_INVALIDARG;
275 This->binding = pbind;
276 IBinding_AddRef(pbind);
278 httprequest_setreadystate(This->request, READYSTATE_LOADED);
280 return CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
283 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pPriority)
285 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
287 TRACE("(%p)->(%p)\n", This, pPriority);
289 return E_NOTIMPL;
292 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
294 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
296 TRACE("(%p)->(%d)\n", This, reserved);
298 return E_NOTIMPL;
301 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
302 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
304 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
306 TRACE("(%p)->(%u %u %u %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
307 debugstr_w(szStatusText));
309 return S_OK;
312 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
313 HRESULT hr, LPCWSTR error)
315 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
317 TRACE("(%p)->(0x%08x %s)\n", This, hr, debugstr_w(error));
319 if (This->binding)
321 IBinding_Release(This->binding);
322 This->binding = NULL;
325 if (hr == S_OK)
326 httprequest_setreadystate(This->request, READYSTATE_COMPLETE);
328 return S_OK;
331 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
332 DWORD *bind_flags, BINDINFO *pbindinfo)
334 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
336 TRACE("(%p)->(%p %p)\n", This, bind_flags, pbindinfo);
338 *bind_flags = 0;
339 if (This->request->async) *bind_flags |= BINDF_ASYNCHRONOUS;
341 if (This->request->verb != BINDVERB_GET && This->body)
343 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
344 pbindinfo->stgmedData.u.hGlobal = This->body;
345 pbindinfo->cbstgmedData = GlobalSize(This->body);
346 /* callback owns passed body pointer */
347 IBindStatusCallback_QueryInterface(iface, &IID_IUnknown, (void**)&pbindinfo->stgmedData.pUnkForRelease);
350 pbindinfo->dwBindVerb = This->request->verb;
351 if (This->request->verb == BINDVERB_CUSTOM)
353 pbindinfo->szCustomVerb = CoTaskMemAlloc(SysStringByteLen(This->request->custom));
354 strcpyW(pbindinfo->szCustomVerb, This->request->custom);
357 return S_OK;
360 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
361 DWORD flags, DWORD size, FORMATETC *format, STGMEDIUM *stgmed)
363 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
364 DWORD read, written;
365 BYTE buf[4096];
366 HRESULT hr;
368 TRACE("(%p)->(%08x %d %p %p)\n", This, flags, size, format, stgmed);
372 hr = IStream_Read(stgmed->u.pstm, buf, sizeof(buf), &read);
373 if (hr != S_OK) break;
375 hr = IStream_Write(This->stream, buf, read, &written);
376 } while((hr == S_OK) && written != 0 && read != 0);
378 httprequest_setreadystate(This->request, READYSTATE_INTERACTIVE);
380 return S_OK;
383 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
384 REFIID riid, IUnknown *punk)
386 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
388 FIXME("(%p)->(%s %p): stub\n", This, debugstr_guid(riid), punk);
390 return E_NOTIMPL;
393 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
394 BindStatusCallback_QueryInterface,
395 BindStatusCallback_AddRef,
396 BindStatusCallback_Release,
397 BindStatusCallback_OnStartBinding,
398 BindStatusCallback_GetPriority,
399 BindStatusCallback_OnLowResource,
400 BindStatusCallback_OnProgress,
401 BindStatusCallback_OnStopBinding,
402 BindStatusCallback_GetBindInfo,
403 BindStatusCallback_OnDataAvailable,
404 BindStatusCallback_OnObjectAvailable
407 static HRESULT WINAPI BSCHttpNegotiate_QueryInterface(IHttpNegotiate *iface,
408 REFIID riid, void **ppv)
410 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
411 return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
414 static ULONG WINAPI BSCHttpNegotiate_AddRef(IHttpNegotiate *iface)
416 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
417 return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
420 static ULONG WINAPI BSCHttpNegotiate_Release(IHttpNegotiate *iface)
422 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
423 return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
426 static HRESULT WINAPI BSCHttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
427 LPCWSTR url, LPCWSTR headers, DWORD reserved, LPWSTR *add_headers)
429 static const WCHAR content_type_utf8W[] = {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ',
430 't','e','x','t','/','p','l','a','i','n',';','c','h','a','r','s','e','t','=','u','t','f','-','8','\r','\n',0};
432 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
433 const struct httpheader *entry;
434 WCHAR *buff, *ptr;
435 int size = 0;
437 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(url), debugstr_w(headers), reserved, add_headers);
439 *add_headers = NULL;
441 if (This->request->use_utf8_content)
442 size = sizeof(content_type_utf8W);
444 if (!list_empty(&This->request->reqheaders))
445 size += This->request->reqheader_size*sizeof(WCHAR);
447 if (!size) return S_OK;
449 buff = CoTaskMemAlloc(size);
450 if (!buff) return E_OUTOFMEMORY;
452 ptr = buff;
453 if (This->request->use_utf8_content)
455 lstrcpyW(ptr, content_type_utf8W);
456 ptr += sizeof(content_type_utf8W)/sizeof(WCHAR)-1;
459 /* user headers */
460 LIST_FOR_EACH_ENTRY(entry, &This->request->reqheaders, struct httpheader, entry)
462 lstrcpyW(ptr, entry->header);
463 ptr += SysStringLen(entry->header);
465 lstrcpyW(ptr, colspaceW);
466 ptr += sizeof(colspaceW)/sizeof(WCHAR)-1;
468 lstrcpyW(ptr, entry->value);
469 ptr += SysStringLen(entry->value);
471 lstrcpyW(ptr, crlfW);
472 ptr += sizeof(crlfW)/sizeof(WCHAR)-1;
475 *add_headers = buff;
477 return S_OK;
480 static void add_response_header(httprequest *This, const WCHAR *data, int len)
482 struct httpheader *entry;
483 const WCHAR *ptr = data;
484 BSTR header, value;
486 while (*ptr)
488 if (*ptr == ':')
490 header = SysAllocStringLen(data, ptr-data);
491 /* skip leading spaces for a value */
492 while (*++ptr == ' ')
494 value = SysAllocStringLen(ptr, len-(ptr-data));
495 break;
497 ptr++;
500 if (!*ptr) return;
502 /* new header */
503 TRACE("got header %s:%s\n", debugstr_w(header), debugstr_w(value));
505 entry = heap_alloc(sizeof(*header));
506 entry->header = header;
507 entry->value = value;
508 list_add_head(&This->respheaders, &entry->entry);
511 static HRESULT WINAPI BSCHttpNegotiate_OnResponse(IHttpNegotiate *iface, DWORD code,
512 LPCWSTR resp_headers, LPCWSTR req_headers, LPWSTR *add_reqheaders)
514 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
516 TRACE("(%p)->(%d %s %s %p)\n", This, code, debugstr_w(resp_headers),
517 debugstr_w(req_headers), add_reqheaders);
519 This->request->status = code;
520 /* store headers */
521 free_response_headers(This->request);
522 if (resp_headers)
524 const WCHAR *ptr, *line;
526 ptr = line = resp_headers;
528 /* skip status line */
529 while (*ptr)
531 if (*ptr == '\r' && *(ptr+1) == '\n')
533 line = ++ptr+1;
534 break;
536 ptr++;
539 /* store as unparsed string for now */
540 This->request->raw_respheaders = SysAllocString(line);
543 return S_OK;
546 static const IHttpNegotiateVtbl BSCHttpNegotiateVtbl = {
547 BSCHttpNegotiate_QueryInterface,
548 BSCHttpNegotiate_AddRef,
549 BSCHttpNegotiate_Release,
550 BSCHttpNegotiate_BeginningTransaction,
551 BSCHttpNegotiate_OnResponse
554 static HRESULT WINAPI Authenticate_QueryInterface(IAuthenticate *iface,
555 REFIID riid, void **ppv)
557 BindStatusCallback *This = impl_from_IAuthenticate(iface);
558 return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
561 static ULONG WINAPI Authenticate_AddRef(IAuthenticate *iface)
563 BindStatusCallback *This = impl_from_IAuthenticate(iface);
564 return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
567 static ULONG WINAPI Authenticate_Release(IAuthenticate *iface)
569 BindStatusCallback *This = impl_from_IAuthenticate(iface);
570 return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
573 static HRESULT WINAPI Authenticate_Authenticate(IAuthenticate *iface,
574 HWND *hwnd, LPWSTR *username, LPWSTR *password)
576 BindStatusCallback *This = impl_from_IAuthenticate(iface);
577 FIXME("(%p)->(%p %p %p)\n", This, hwnd, username, password);
578 return E_NOTIMPL;
581 static const IAuthenticateVtbl AuthenticateVtbl = {
582 Authenticate_QueryInterface,
583 Authenticate_AddRef,
584 Authenticate_Release,
585 Authenticate_Authenticate
588 static HRESULT BindStatusCallback_create(httprequest* This, BindStatusCallback **obj, const VARIANT *body)
590 BindStatusCallback *bsc;
591 IBindCtx *pbc;
592 HRESULT hr;
593 int size;
595 hr = CreateBindCtx(0, &pbc);
596 if (hr != S_OK) return hr;
598 bsc = heap_alloc(sizeof(*bsc));
599 if (!bsc)
601 IBindCtx_Release(pbc);
602 return E_OUTOFMEMORY;
605 bsc->IBindStatusCallback_iface.lpVtbl = &BindStatusCallbackVtbl;
606 bsc->IHttpNegotiate_iface.lpVtbl = &BSCHttpNegotiateVtbl;
607 bsc->IAuthenticate_iface.lpVtbl = &AuthenticateVtbl;
608 bsc->ref = 1;
609 bsc->request = This;
610 bsc->binding = NULL;
611 bsc->stream = NULL;
612 bsc->body = NULL;
614 TRACE("(%p)->(%p)\n", This, bsc);
616 This->use_utf8_content = FALSE;
618 if (This->verb != BINDVERB_GET)
620 void *send_data, *ptr;
621 SAFEARRAY *sa = NULL;
623 if (V_VT(body) == (VT_VARIANT|VT_BYREF))
624 body = V_VARIANTREF(body);
626 switch (V_VT(body))
628 case VT_BSTR:
630 int len = SysStringLen(V_BSTR(body));
631 const WCHAR *str = V_BSTR(body);
632 UINT i, cp = CP_ACP;
634 for (i = 0; i < len; i++)
636 if (str[i] > 127)
638 cp = CP_UTF8;
639 break;
643 size = WideCharToMultiByte(cp, 0, str, len, NULL, 0, NULL, NULL);
644 if (!(ptr = heap_alloc(size)))
646 heap_free(bsc);
647 return E_OUTOFMEMORY;
649 WideCharToMultiByte(cp, 0, str, len, ptr, size, NULL, NULL);
650 if (cp == CP_UTF8) This->use_utf8_content = TRUE;
651 break;
653 case VT_ARRAY|VT_UI1:
655 sa = V_ARRAY(body);
656 if ((hr = SafeArrayAccessData(sa, (void **)&ptr)) != S_OK) return hr;
657 if ((hr = SafeArrayGetUBound(sa, 1, &size) != S_OK))
659 SafeArrayUnaccessData(sa);
660 return hr;
662 size++;
663 break;
665 case VT_EMPTY:
666 ptr = NULL;
667 size = 0;
668 break;
669 default:
670 FIXME("unsupported body data type %d\n", V_VT(body));
671 break;
674 bsc->body = GlobalAlloc(GMEM_FIXED, size);
675 if (!bsc->body)
677 if (V_VT(body) == VT_BSTR)
678 heap_free(ptr);
679 else if (V_VT(body) == (VT_ARRAY|VT_UI1))
680 SafeArrayUnaccessData(sa);
682 heap_free(bsc);
683 return E_OUTOFMEMORY;
686 send_data = GlobalLock(bsc->body);
687 memcpy(send_data, ptr, size);
688 GlobalUnlock(bsc->body);
690 if (V_VT(body) == VT_BSTR)
691 heap_free(ptr);
692 else if (V_VT(body) == (VT_ARRAY|VT_UI1))
693 SafeArrayUnaccessData(sa);
696 hr = RegisterBindStatusCallback(pbc, &bsc->IBindStatusCallback_iface, NULL, 0);
697 if (hr == S_OK)
699 IMoniker *moniker;
701 hr = CreateURLMoniker(NULL, This->url, &moniker);
702 if (hr == S_OK)
704 IStream *stream;
706 hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (void**)&stream);
707 IMoniker_Release(moniker);
708 if (stream) IStream_Release(stream);
710 IBindCtx_Release(pbc);
713 if (FAILED(hr))
715 IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
716 bsc = NULL;
719 *obj = bsc;
720 return hr;
723 static HRESULT WINAPI httprequest_QueryInterface(IXMLHTTPRequest *iface, REFIID riid, void **ppvObject)
725 httprequest *This = impl_from_IXMLHTTPRequest( iface );
726 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
728 if ( IsEqualGUID( riid, &IID_IXMLHTTPRequest) ||
729 IsEqualGUID( riid, &IID_IDispatch) ||
730 IsEqualGUID( riid, &IID_IUnknown) )
732 *ppvObject = iface;
734 else if (IsEqualGUID(&IID_IObjectWithSite, riid))
736 *ppvObject = &This->IObjectWithSite_iface;
738 else if (IsEqualGUID(&IID_IObjectSafety, riid))
740 *ppvObject = &This->IObjectSafety_iface;
742 else
744 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
745 *ppvObject = NULL;
746 return E_NOINTERFACE;
749 IXMLHTTPRequest_AddRef( iface );
751 return S_OK;
754 static ULONG WINAPI httprequest_AddRef(IXMLHTTPRequest *iface)
756 httprequest *This = impl_from_IXMLHTTPRequest( iface );
757 ULONG ref = InterlockedIncrement( &This->ref );
758 TRACE("(%p)->(%u)\n", This, ref );
759 return ref;
762 static ULONG WINAPI httprequest_Release(IXMLHTTPRequest *iface)
764 httprequest *This = impl_from_IXMLHTTPRequest( iface );
765 ULONG ref = InterlockedDecrement( &This->ref );
767 TRACE("(%p)->(%u)\n", This, ref );
769 if ( ref == 0 )
771 struct httpheader *header, *header2;
773 if (This->site)
774 IUnknown_Release( This->site );
776 SysFreeString(This->custom);
777 SysFreeString(This->siteurl);
778 SysFreeString(This->url);
779 SysFreeString(This->user);
780 SysFreeString(This->password);
782 /* request headers */
783 LIST_FOR_EACH_ENTRY_SAFE(header, header2, &This->reqheaders, struct httpheader, entry)
785 list_remove(&header->entry);
786 SysFreeString(header->header);
787 SysFreeString(header->value);
788 heap_free(header);
790 /* response headers */
791 free_response_headers(This);
793 /* detach callback object */
794 BindStatusCallback_Detach(This->bsc);
796 if (This->sink) IDispatch_Release(This->sink);
798 heap_free( This );
801 return ref;
804 static HRESULT WINAPI httprequest_GetTypeInfoCount(IXMLHTTPRequest *iface, UINT *pctinfo)
806 httprequest *This = impl_from_IXMLHTTPRequest( iface );
808 TRACE("(%p)->(%p)\n", This, pctinfo);
810 *pctinfo = 1;
812 return S_OK;
815 static HRESULT WINAPI httprequest_GetTypeInfo(IXMLHTTPRequest *iface, UINT iTInfo,
816 LCID lcid, ITypeInfo **ppTInfo)
818 httprequest *This = impl_from_IXMLHTTPRequest( iface );
820 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
822 return get_typeinfo(IXMLHTTPRequest_tid, ppTInfo);
825 static HRESULT WINAPI httprequest_GetIDsOfNames(IXMLHTTPRequest *iface, REFIID riid,
826 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
828 httprequest *This = impl_from_IXMLHTTPRequest( iface );
829 ITypeInfo *typeinfo;
830 HRESULT hr;
832 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
833 lcid, rgDispId);
835 if(!rgszNames || cNames == 0 || !rgDispId)
836 return E_INVALIDARG;
838 hr = get_typeinfo(IXMLHTTPRequest_tid, &typeinfo);
839 if(SUCCEEDED(hr))
841 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
842 ITypeInfo_Release(typeinfo);
845 return hr;
848 static HRESULT WINAPI httprequest_Invoke(IXMLHTTPRequest *iface, DISPID dispIdMember, REFIID riid,
849 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
850 EXCEPINFO *pExcepInfo, UINT *puArgErr)
852 httprequest *This = impl_from_IXMLHTTPRequest( iface );
853 ITypeInfo *typeinfo;
854 HRESULT hr;
856 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
857 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
859 hr = get_typeinfo(IXMLHTTPRequest_tid, &typeinfo);
860 if(SUCCEEDED(hr))
862 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLHTTPRequest_iface, dispIdMember, wFlags,
863 pDispParams, pVarResult, pExcepInfo, puArgErr);
864 ITypeInfo_Release(typeinfo);
867 return hr;
870 static HRESULT WINAPI httprequest_open(IXMLHTTPRequest *iface, BSTR method, BSTR url,
871 VARIANT async, VARIANT user, VARIANT password)
873 static const WCHAR MethodGetW[] = {'G','E','T',0};
874 static const WCHAR MethodPutW[] = {'P','U','T',0};
875 static const WCHAR MethodPostW[] = {'P','O','S','T',0};
876 static const WCHAR MethodDeleteW[] = {'D','E','L','E','T','E',0};
878 httprequest *This = impl_from_IXMLHTTPRequest( iface );
879 VARIANT str, is_async;
880 HRESULT hr;
882 TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(method), debugstr_w(url),
883 debugstr_variant(&async));
885 if (!method || !url) return E_INVALIDARG;
887 /* free previously set data */
888 SysFreeString(This->url);
889 SysFreeString(This->user);
890 SysFreeString(This->password);
891 This->url = This->user = This->password = NULL;
893 if (!strcmpiW(method, MethodGetW))
895 This->verb = BINDVERB_GET;
897 else if (!strcmpiW(method, MethodPutW))
899 This->verb = BINDVERB_PUT;
901 else if (!strcmpiW(method, MethodPostW))
903 This->verb = BINDVERB_POST;
905 else if (!strcmpiW(method, MethodDeleteW))
907 This->verb = BINDVERB_CUSTOM;
908 SysReAllocString(&This->custom, method);
910 else
912 FIXME("unsupported request type %s\n", debugstr_w(method));
913 This->verb = -1;
914 return E_FAIL;
917 /* try to combine with site url */
918 if (This->siteurl && PathIsRelativeW(url))
920 DWORD len = INTERNET_MAX_URL_LENGTH;
921 WCHAR *fullW = heap_alloc(len*sizeof(WCHAR));
923 hr = UrlCombineW(This->siteurl, url, fullW, &len, 0);
924 if (hr == S_OK)
926 TRACE("combined url %s\n", debugstr_w(fullW));
927 This->url = SysAllocString(fullW);
929 heap_free(fullW);
931 else
932 This->url = SysAllocString(url);
934 VariantInit(&is_async);
935 hr = VariantChangeType(&is_async, &async, 0, VT_BOOL);
936 This->async = hr == S_OK && V_BOOL(&is_async) == VARIANT_TRUE;
938 VariantInit(&str);
939 hr = VariantChangeType(&str, &user, 0, VT_BSTR);
940 if (hr == S_OK)
941 This->user = V_BSTR(&str);
943 VariantInit(&str);
944 hr = VariantChangeType(&str, &password, 0, VT_BSTR);
945 if (hr == S_OK)
946 This->password = V_BSTR(&str);
948 httprequest_setreadystate(This, READYSTATE_LOADING);
950 return S_OK;
953 static HRESULT WINAPI httprequest_setRequestHeader(IXMLHTTPRequest *iface, BSTR header, BSTR value)
955 httprequest *This = impl_from_IXMLHTTPRequest( iface );
956 struct httpheader *entry;
958 TRACE("(%p)->(%s %s)\n", This, debugstr_w(header), debugstr_w(value));
960 if (!header || !*header) return E_INVALIDARG;
961 if (This->state != READYSTATE_LOADING) return E_FAIL;
962 if (!value) return E_INVALIDARG;
964 /* replace existing header value if already added */
965 LIST_FOR_EACH_ENTRY(entry, &This->reqheaders, struct httpheader, entry)
967 if (lstrcmpW(entry->header, header) == 0)
969 LONG length = SysStringLen(entry->value);
970 HRESULT hr;
972 hr = SysReAllocString(&entry->value, value) ? S_OK : E_OUTOFMEMORY;
974 if (hr == S_OK)
975 This->reqheader_size += (SysStringLen(entry->value) - length);
977 return hr;
981 entry = heap_alloc(sizeof(*entry));
982 if (!entry) return E_OUTOFMEMORY;
984 /* new header */
985 entry->header = SysAllocString(header);
986 entry->value = SysAllocString(value);
988 /* header length including null terminator */
989 This->reqheader_size += SysStringLen(entry->header) + sizeof(colspaceW)/sizeof(WCHAR) +
990 SysStringLen(entry->value) + sizeof(crlfW)/sizeof(WCHAR) - 1;
992 list_add_head(&This->reqheaders, &entry->entry);
994 return S_OK;
997 static HRESULT WINAPI httprequest_getResponseHeader(IXMLHTTPRequest *iface, BSTR header, BSTR *value)
999 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1000 struct httpheader *entry;
1002 TRACE("(%p)->(%s %p)\n", This, debugstr_w(header), value);
1004 if (!header || !value) return E_INVALIDARG;
1006 if (This->raw_respheaders && list_empty(&This->respheaders))
1008 WCHAR *ptr, *line;
1010 ptr = line = This->raw_respheaders;
1011 while (*ptr)
1013 if (*ptr == '\r' && *(ptr+1) == '\n')
1015 add_response_header(This, line, ptr-line);
1016 ptr++; line = ++ptr;
1017 continue;
1019 ptr++;
1023 LIST_FOR_EACH_ENTRY(entry, &This->respheaders, struct httpheader, entry)
1025 if (!strcmpiW(entry->header, header))
1027 *value = SysAllocString(entry->value);
1028 TRACE("header value %s\n", debugstr_w(*value));
1029 return S_OK;
1033 return S_FALSE;
1036 static HRESULT WINAPI httprequest_getAllResponseHeaders(IXMLHTTPRequest *iface, BSTR *respheaders)
1038 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1040 TRACE("(%p)->(%p)\n", This, respheaders);
1042 if (!respheaders) return E_INVALIDARG;
1044 *respheaders = SysAllocString(This->raw_respheaders);
1046 return S_OK;
1049 static HRESULT WINAPI httprequest_send(IXMLHTTPRequest *iface, VARIANT body)
1051 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1052 BindStatusCallback *bsc = NULL;
1053 HRESULT hr;
1055 TRACE("(%p)->(%s)\n", This, debugstr_variant(&body));
1057 if (This->state != READYSTATE_LOADING) return E_FAIL;
1059 hr = BindStatusCallback_create(This, &bsc, &body);
1060 if (FAILED(hr)) return hr;
1062 BindStatusCallback_Detach(This->bsc);
1063 This->bsc = bsc;
1065 return hr;
1068 static HRESULT WINAPI httprequest_abort(IXMLHTTPRequest *iface)
1070 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1072 TRACE("(%p)\n", This);
1074 BindStatusCallback_Detach(This->bsc);
1075 This->bsc = NULL;
1077 httprequest_setreadystate(This, READYSTATE_UNINITIALIZED);
1079 return S_OK;
1082 static HRESULT WINAPI httprequest_get_status(IXMLHTTPRequest *iface, LONG *status)
1084 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1086 TRACE("(%p)->(%p)\n", This, status);
1088 if (!status) return E_INVALIDARG;
1089 if (This->state != READYSTATE_COMPLETE) return E_FAIL;
1091 *status = This->status;
1093 return S_OK;
1096 static HRESULT WINAPI httprequest_get_statusText(IXMLHTTPRequest *iface, BSTR *pbstrStatus)
1098 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1100 FIXME("stub %p %p\n", This, pbstrStatus);
1102 return E_NOTIMPL;
1105 static HRESULT WINAPI httprequest_get_responseXML(IXMLHTTPRequest *iface, IDispatch **body)
1107 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1108 IXMLDOMDocument3 *doc;
1109 HRESULT hr;
1110 BSTR str;
1112 TRACE("(%p)->(%p)\n", This, body);
1114 if (!body) return E_INVALIDARG;
1115 if (This->state != READYSTATE_COMPLETE) return E_FAIL;
1117 hr = DOMDocument_create(MSXML_DEFAULT, NULL, (void**)&doc);
1118 if (hr != S_OK) return hr;
1120 hr = IXMLHTTPRequest_get_responseText(iface, &str);
1121 if (hr == S_OK)
1123 VARIANT_BOOL ok;
1125 hr = IXMLDOMDocument3_loadXML(doc, str, &ok);
1126 SysFreeString(str);
1129 IXMLDOMDocument3_QueryInterface(doc, &IID_IDispatch, (void**)body);
1130 IXMLDOMDocument3_Release(doc);
1132 return hr;
1135 static HRESULT WINAPI httprequest_get_responseText(IXMLHTTPRequest *iface, BSTR *body)
1137 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1138 HGLOBAL hglobal;
1139 HRESULT hr;
1141 TRACE("(%p)->(%p)\n", This, body);
1143 if (!body) return E_INVALIDARG;
1144 if (This->state != READYSTATE_COMPLETE) return E_FAIL;
1146 hr = GetHGlobalFromStream(This->bsc->stream, &hglobal);
1147 if (hr == S_OK)
1149 xmlChar *ptr = GlobalLock(hglobal);
1150 DWORD size = GlobalSize(hglobal);
1151 xmlCharEncoding encoding = XML_CHAR_ENCODING_UTF8;
1153 /* try to determine data encoding */
1154 if (size >= 4)
1156 encoding = xmlDetectCharEncoding(ptr, 4);
1157 TRACE("detected encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding)));
1158 if ( encoding != XML_CHAR_ENCODING_UTF8 &&
1159 encoding != XML_CHAR_ENCODING_UTF16LE &&
1160 encoding != XML_CHAR_ENCODING_NONE )
1162 FIXME("unsupported encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding)));
1163 GlobalUnlock(hglobal);
1164 return E_FAIL;
1168 /* without BOM assume UTF-8 */
1169 if (encoding == XML_CHAR_ENCODING_UTF8 ||
1170 encoding == XML_CHAR_ENCODING_NONE )
1172 DWORD length = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)ptr, size, NULL, 0);
1174 *body = SysAllocStringLen(NULL, length);
1175 if (*body)
1176 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)ptr, size, *body, length);
1178 else
1179 *body = SysAllocStringByteLen((LPCSTR)ptr, size);
1181 if (!*body) hr = E_OUTOFMEMORY;
1182 GlobalUnlock(hglobal);
1185 return hr;
1188 static HRESULT WINAPI httprequest_get_responseBody(IXMLHTTPRequest *iface, VARIANT *body)
1190 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1191 HGLOBAL hglobal;
1192 HRESULT hr;
1194 TRACE("(%p)->(%p)\n", This, body);
1196 if (!body) return E_INVALIDARG;
1197 V_VT(body) = VT_EMPTY;
1199 if (This->state != READYSTATE_COMPLETE) return E_PENDING;
1201 hr = GetHGlobalFromStream(This->bsc->stream, &hglobal);
1202 if (hr == S_OK)
1204 void *ptr = GlobalLock(hglobal);
1205 DWORD size = GlobalSize(hglobal);
1207 SAFEARRAYBOUND bound;
1208 SAFEARRAY *array;
1210 bound.lLbound = 0;
1211 bound.cElements = size;
1212 array = SafeArrayCreate(VT_UI1, 1, &bound);
1214 if (array)
1216 void *dest;
1218 V_VT(body) = VT_ARRAY | VT_UI1;
1219 V_ARRAY(body) = array;
1221 hr = SafeArrayAccessData(array, &dest);
1222 if (hr == S_OK)
1224 memcpy(dest, ptr, size);
1225 SafeArrayUnaccessData(array);
1227 else
1229 VariantClear(body);
1232 else
1233 hr = E_FAIL;
1235 GlobalUnlock(hglobal);
1238 return hr;
1241 static HRESULT WINAPI httprequest_get_responseStream(IXMLHTTPRequest *iface, VARIANT *body)
1243 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1244 LARGE_INTEGER move;
1245 IStream *stream;
1246 HRESULT hr;
1248 TRACE("(%p)->(%p)\n", This, body);
1250 if (!body) return E_INVALIDARG;
1251 V_VT(body) = VT_EMPTY;
1253 if (This->state != READYSTATE_COMPLETE) return E_PENDING;
1255 hr = IStream_Clone(This->bsc->stream, &stream);
1257 move.QuadPart = 0;
1258 IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
1260 V_VT(body) = VT_UNKNOWN;
1261 V_UNKNOWN(body) = (IUnknown*)stream;
1263 return hr;
1266 static HRESULT WINAPI httprequest_get_readyState(IXMLHTTPRequest *iface, LONG *state)
1268 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1270 TRACE("(%p)->(%p)\n", This, state);
1272 if (!state) return E_INVALIDARG;
1274 *state = This->state;
1275 return S_OK;
1278 static HRESULT WINAPI httprequest_put_onreadystatechange(IXMLHTTPRequest *iface, IDispatch *sink)
1280 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1282 TRACE("(%p)->(%p)\n", This, sink);
1284 if (This->sink) IDispatch_Release(This->sink);
1285 if ((This->sink = sink)) IDispatch_AddRef(This->sink);
1287 return S_OK;
1290 static const struct IXMLHTTPRequestVtbl XMLHTTPRequestVtbl =
1292 httprequest_QueryInterface,
1293 httprequest_AddRef,
1294 httprequest_Release,
1295 httprequest_GetTypeInfoCount,
1296 httprequest_GetTypeInfo,
1297 httprequest_GetIDsOfNames,
1298 httprequest_Invoke,
1299 httprequest_open,
1300 httprequest_setRequestHeader,
1301 httprequest_getResponseHeader,
1302 httprequest_getAllResponseHeaders,
1303 httprequest_send,
1304 httprequest_abort,
1305 httprequest_get_status,
1306 httprequest_get_statusText,
1307 httprequest_get_responseXML,
1308 httprequest_get_responseText,
1309 httprequest_get_responseBody,
1310 httprequest_get_responseStream,
1311 httprequest_get_readyState,
1312 httprequest_put_onreadystatechange
1315 /* IObjectWithSite */
1316 static HRESULT WINAPI
1317 httprequest_ObjectWithSite_QueryInterface( IObjectWithSite* iface, REFIID riid, void** ppvObject )
1319 httprequest *This = impl_from_IObjectWithSite(iface);
1320 return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest *)This, riid, ppvObject );
1323 static ULONG WINAPI httprequest_ObjectWithSite_AddRef( IObjectWithSite* iface )
1325 httprequest *This = impl_from_IObjectWithSite(iface);
1326 return IXMLHTTPRequest_AddRef((IXMLHTTPRequest *)This);
1329 static ULONG WINAPI httprequest_ObjectWithSite_Release( IObjectWithSite* iface )
1331 httprequest *This = impl_from_IObjectWithSite(iface);
1332 return IXMLHTTPRequest_Release((IXMLHTTPRequest *)This);
1335 static HRESULT WINAPI httprequest_ObjectWithSite_GetSite( IObjectWithSite *iface, REFIID iid, void **ppvSite )
1337 httprequest *This = impl_from_IObjectWithSite(iface);
1339 TRACE("(%p)->(%s %p)\n", This, debugstr_guid( iid ), ppvSite );
1341 if ( !This->site )
1342 return E_FAIL;
1344 return IUnknown_QueryInterface( This->site, iid, ppvSite );
1347 static HRESULT WINAPI httprequest_ObjectWithSite_SetSite( IObjectWithSite *iface, IUnknown *punk )
1349 httprequest *This = impl_from_IObjectWithSite(iface);
1350 IServiceProvider *provider;
1351 HRESULT hr;
1353 TRACE("(%p)->(%p)\n", iface, punk);
1355 if (punk)
1356 IUnknown_AddRef( punk );
1358 if(This->site)
1359 IUnknown_Release( This->site );
1361 This->site = punk;
1363 hr = IUnknown_QueryInterface(This->site, &IID_IServiceProvider, (void**)&provider);
1364 if (hr == S_OK)
1366 IHTMLDocument2 *doc;
1368 hr = IServiceProvider_QueryService(provider, &SID_SContainerDispatch, &IID_IHTMLDocument2, (void**)&doc);
1369 if (hr == S_OK)
1371 SysFreeString(This->siteurl);
1373 hr = IHTMLDocument2_get_URL(doc, &This->siteurl);
1374 IHTMLDocument2_Release(doc);
1375 TRACE("host url %s, 0x%08x\n", debugstr_w(This->siteurl), hr);
1377 IServiceProvider_Release(provider);
1380 return S_OK;
1383 static const IObjectWithSiteVtbl ObjectWithSiteVtbl =
1385 httprequest_ObjectWithSite_QueryInterface,
1386 httprequest_ObjectWithSite_AddRef,
1387 httprequest_ObjectWithSite_Release,
1388 httprequest_ObjectWithSite_SetSite,
1389 httprequest_ObjectWithSite_GetSite
1392 /* IObjectSafety */
1393 static HRESULT WINAPI httprequest_Safety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1395 httprequest *This = impl_from_IObjectSafety(iface);
1396 return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest *)This, riid, ppv );
1399 static ULONG WINAPI httprequest_Safety_AddRef(IObjectSafety *iface)
1401 httprequest *This = impl_from_IObjectSafety(iface);
1402 return IXMLHTTPRequest_AddRef((IXMLHTTPRequest *)This);
1405 static ULONG WINAPI httprequest_Safety_Release(IObjectSafety *iface)
1407 httprequest *This = impl_from_IObjectSafety(iface);
1408 return IXMLHTTPRequest_Release((IXMLHTTPRequest *)This);
1411 #define SAFETY_SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER)
1413 static HRESULT WINAPI httprequest_Safety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1414 DWORD *supported, DWORD *enabled)
1416 httprequest *This = impl_from_IObjectSafety(iface);
1418 TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), supported, enabled);
1420 if(!supported || !enabled) return E_POINTER;
1422 *supported = SAFETY_SUPPORTED_OPTIONS;
1423 *enabled = This->safeopt;
1425 return S_OK;
1428 static HRESULT WINAPI httprequest_Safety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1429 DWORD mask, DWORD enabled)
1431 httprequest *This = impl_from_IObjectSafety(iface);
1432 TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), mask, enabled);
1434 if ((mask & ~SAFETY_SUPPORTED_OPTIONS) != 0)
1435 return E_FAIL;
1437 This->safeopt = (This->safeopt & ~mask) | (mask & enabled);
1439 return S_OK;
1442 #undef SAFETY_SUPPORTED_OPTIONS
1444 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
1445 httprequest_Safety_QueryInterface,
1446 httprequest_Safety_AddRef,
1447 httprequest_Safety_Release,
1448 httprequest_Safety_GetInterfaceSafetyOptions,
1449 httprequest_Safety_SetInterfaceSafetyOptions
1452 HRESULT XMLHTTPRequest_create(IUnknown *pUnkOuter, void **ppObj)
1454 httprequest *req;
1455 HRESULT hr = S_OK;
1457 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
1459 req = heap_alloc( sizeof (*req) );
1460 if( !req )
1461 return E_OUTOFMEMORY;
1463 req->IXMLHTTPRequest_iface.lpVtbl = &XMLHTTPRequestVtbl;
1464 req->IObjectWithSite_iface.lpVtbl = &ObjectWithSiteVtbl;
1465 req->IObjectSafety_iface.lpVtbl = &ObjectSafetyVtbl;
1466 req->ref = 1;
1468 req->async = FALSE;
1469 req->verb = -1;
1470 req->custom = NULL;
1471 req->url = req->siteurl = req->user = req->password = NULL;
1473 req->state = READYSTATE_UNINITIALIZED;
1474 req->sink = NULL;
1476 req->bsc = NULL;
1477 req->status = 0;
1478 req->reqheader_size = 0;
1479 req->raw_respheaders = NULL;
1480 req->use_utf8_content = FALSE;
1482 list_init(&req->reqheaders);
1483 list_init(&req->respheaders);
1485 req->site = NULL;
1486 req->safeopt = 0;
1488 *ppObj = &req->IXMLHTTPRequest_iface;
1490 TRACE("returning iface %p\n", *ppObj);
1492 return hr;
1495 #else
1497 HRESULT XMLHTTPRequest_create(IUnknown *pUnkOuter, void **ppObj)
1499 MESSAGE("This program tried to use a XMLHTTPRequest object, but\n"
1500 "libxml2 support was not present at compile time.\n");
1501 return E_NOTIMPL;
1504 #endif