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
23 #define NONAMELESSUNION
29 # include <libxml/parser.h>
30 # include <libxml/xmlerror.h>
31 # include <libxml/encoding.h>
47 #include "msxml_private.h"
49 #include "wine/debug.h"
50 #include "wine/list.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
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
;
63 typedef struct BindStatusCallback BindStatusCallback
;
74 IXMLHTTPRequest IXMLHTTPRequest_iface
;
75 IObjectWithSite IObjectWithSite_iface
;
76 IObjectSafety IObjectSafety_iface
;
88 struct list reqheaders
;
89 /* cached resulting custom request headers string length in WCHARs */
91 /* use UTF-8 content type */
92 BOOL use_utf8_content
;
94 /* response headers */
95 struct list respheaders
;
103 BindStatusCallback
*bsc
;
117 IServerXMLHTTPRequest IServerXMLHTTPRequest_iface
;
121 static inline httprequest
*impl_from_IXMLHTTPRequest( IXMLHTTPRequest
*iface
)
123 return CONTAINING_RECORD(iface
, httprequest
, IXMLHTTPRequest_iface
);
126 static inline httprequest
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
128 return CONTAINING_RECORD(iface
, httprequest
, IObjectWithSite_iface
);
131 static inline httprequest
*impl_from_IObjectSafety(IObjectSafety
*iface
)
133 return CONTAINING_RECORD(iface
, httprequest
, IObjectSafety_iface
);
136 static inline serverhttp
*impl_from_IServerXMLHTTPRequest(IServerXMLHTTPRequest
*iface
)
138 return CONTAINING_RECORD(iface
, serverhttp
, IServerXMLHTTPRequest_iface
);
141 static void httprequest_setreadystate(httprequest
*This
, READYSTATE state
)
143 READYSTATE last
= This
->state
;
147 if (This
->sink
&& last
!= state
)
151 memset(¶ms
, 0, sizeof(params
));
152 IDispatch_Invoke(This
->sink
, 0, &IID_NULL
, LOCALE_SYSTEM_DEFAULT
, DISPATCH_METHOD
, ¶ms
, 0, 0, 0);
156 static void free_response_headers(httprequest
*This
)
158 struct httpheader
*header
, *header2
;
160 LIST_FOR_EACH_ENTRY_SAFE(header
, header2
, &This
->respheaders
, struct httpheader
, entry
)
162 list_remove(&header
->entry
);
163 SysFreeString(header
->header
);
164 SysFreeString(header
->value
);
168 SysFreeString(This
->raw_respheaders
);
169 This
->raw_respheaders
= NULL
;
172 struct BindStatusCallback
174 IBindStatusCallback IBindStatusCallback_iface
;
175 IHttpNegotiate IHttpNegotiate_iface
;
176 IAuthenticate IAuthenticate_iface
;
180 httprequest
*request
;
185 /* request body data */
189 static inline BindStatusCallback
*impl_from_IBindStatusCallback( IBindStatusCallback
*iface
)
191 return CONTAINING_RECORD(iface
, BindStatusCallback
, IBindStatusCallback_iface
);
194 static inline BindStatusCallback
*impl_from_IHttpNegotiate( IHttpNegotiate
*iface
)
196 return CONTAINING_RECORD(iface
, BindStatusCallback
, IHttpNegotiate_iface
);
199 static inline BindStatusCallback
*impl_from_IAuthenticate( IAuthenticate
*iface
)
201 return CONTAINING_RECORD(iface
, BindStatusCallback
, IAuthenticate_iface
);
204 static void BindStatusCallback_Detach(BindStatusCallback
*bsc
)
208 if (bsc
->binding
) IBinding_Abort(bsc
->binding
);
210 IBindStatusCallback_Release(&bsc
->IBindStatusCallback_iface
);
214 static HRESULT WINAPI
BindStatusCallback_QueryInterface(IBindStatusCallback
*iface
,
215 REFIID riid
, void **ppv
)
217 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
221 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
223 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
224 IsEqualGUID(&IID_IBindStatusCallback
, riid
))
226 *ppv
= &This
->IBindStatusCallback_iface
;
228 else if (IsEqualGUID(&IID_IHttpNegotiate
, riid
))
230 *ppv
= &This
->IHttpNegotiate_iface
;
232 else if (IsEqualGUID(&IID_IAuthenticate
, riid
))
234 *ppv
= &This
->IAuthenticate_iface
;
236 else if (IsEqualGUID(&IID_IServiceProvider
, riid
) ||
237 IsEqualGUID(&IID_IBindStatusCallbackEx
, riid
) ||
238 IsEqualGUID(&IID_IInternetProtocol
, riid
) ||
239 IsEqualGUID(&IID_IHttpNegotiate2
, riid
))
241 return E_NOINTERFACE
;
246 IBindStatusCallback_AddRef(iface
);
250 FIXME("Unsupported riid = %s\n", debugstr_guid(riid
));
252 return E_NOINTERFACE
;
255 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
257 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
258 LONG ref
= InterlockedIncrement(&This
->ref
);
260 TRACE("(%p) ref = %d\n", This
, ref
);
265 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
267 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
268 LONG ref
= InterlockedDecrement(&This
->ref
);
270 TRACE("(%p) ref = %d\n", This
, ref
);
274 if (This
->binding
) IBinding_Release(This
->binding
);
275 if (This
->stream
) IStream_Release(This
->stream
);
276 if (This
->body
) GlobalFree(This
->body
);
283 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
284 DWORD reserved
, IBinding
*pbind
)
286 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
288 TRACE("(%p)->(%d %p)\n", This
, reserved
, pbind
);
290 if (!pbind
) return E_INVALIDARG
;
292 This
->binding
= pbind
;
293 IBinding_AddRef(pbind
);
295 httprequest_setreadystate(This
->request
, READYSTATE_LOADED
);
297 return CreateStreamOnHGlobal(NULL
, TRUE
, &This
->stream
);
300 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
, LONG
*pPriority
)
302 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
304 TRACE("(%p)->(%p)\n", This
, pPriority
);
309 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
, DWORD reserved
)
311 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
313 TRACE("(%p)->(%d)\n", This
, reserved
);
318 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
319 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
321 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
323 TRACE("(%p)->(%u %u %u %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
324 debugstr_w(szStatusText
));
329 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
330 HRESULT hr
, LPCWSTR error
)
332 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
334 TRACE("(%p)->(0x%08x %s)\n", This
, hr
, debugstr_w(error
));
338 IBinding_Release(This
->binding
);
339 This
->binding
= NULL
;
343 httprequest_setreadystate(This
->request
, READYSTATE_COMPLETE
);
348 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
349 DWORD
*bind_flags
, BINDINFO
*pbindinfo
)
351 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
353 TRACE("(%p)->(%p %p)\n", This
, bind_flags
, pbindinfo
);
356 if (This
->request
->async
) *bind_flags
|= BINDF_ASYNCHRONOUS
;
358 if (This
->request
->verb
!= BINDVERB_GET
&& This
->body
)
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
);
367 pbindinfo
->dwBindVerb
= This
->request
->verb
;
368 if (This
->request
->verb
== BINDVERB_CUSTOM
)
370 pbindinfo
->szCustomVerb
= CoTaskMemAlloc(SysStringByteLen(This
->request
->custom
));
371 strcpyW(pbindinfo
->szCustomVerb
, This
->request
->custom
);
377 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
378 DWORD flags
, DWORD size
, FORMATETC
*format
, STGMEDIUM
*stgmed
)
380 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
385 TRACE("(%p)->(%08x %d %p %p)\n", This
, flags
, size
, format
, stgmed
);
389 hr
= IStream_Read(stgmed
->u
.pstm
, buf
, sizeof(buf
), &read
);
390 if (hr
!= S_OK
) break;
392 hr
= IStream_Write(This
->stream
, buf
, read
, &written
);
393 } while((hr
== S_OK
) && written
!= 0 && read
!= 0);
395 httprequest_setreadystate(This
->request
, READYSTATE_INTERACTIVE
);
400 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
401 REFIID riid
, IUnknown
*punk
)
403 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
405 FIXME("(%p)->(%s %p): stub\n", This
, debugstr_guid(riid
), punk
);
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
424 static HRESULT WINAPI
BSCHttpNegotiate_QueryInterface(IHttpNegotiate
*iface
,
425 REFIID riid
, void **ppv
)
427 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
428 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
431 static ULONG WINAPI
BSCHttpNegotiate_AddRef(IHttpNegotiate
*iface
)
433 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
434 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
437 static ULONG WINAPI
BSCHttpNegotiate_Release(IHttpNegotiate
*iface
)
439 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
440 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
443 static HRESULT WINAPI
BSCHttpNegotiate_BeginningTransaction(IHttpNegotiate
*iface
,
444 LPCWSTR url
, LPCWSTR headers
, DWORD reserved
, LPWSTR
*add_headers
)
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};
449 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
450 const struct httpheader
*entry
;
454 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(url
), debugstr_w(headers
), reserved
, add_headers
);
458 if (This
->request
->use_utf8_content
)
459 size
= sizeof(content_type_utf8W
);
461 if (!list_empty(&This
->request
->reqheaders
))
462 size
+= This
->request
->reqheader_size
*sizeof(WCHAR
);
464 if (!size
) return S_OK
;
466 buff
= CoTaskMemAlloc(size
);
467 if (!buff
) return E_OUTOFMEMORY
;
470 if (This
->request
->use_utf8_content
)
472 lstrcpyW(ptr
, content_type_utf8W
);
473 ptr
+= sizeof(content_type_utf8W
)/sizeof(WCHAR
)-1;
477 LIST_FOR_EACH_ENTRY(entry
, &This
->request
->reqheaders
, struct httpheader
, entry
)
479 lstrcpyW(ptr
, entry
->header
);
480 ptr
+= SysStringLen(entry
->header
);
482 lstrcpyW(ptr
, colspaceW
);
483 ptr
+= sizeof(colspaceW
)/sizeof(WCHAR
)-1;
485 lstrcpyW(ptr
, entry
->value
);
486 ptr
+= SysStringLen(entry
->value
);
488 lstrcpyW(ptr
, crlfW
);
489 ptr
+= sizeof(crlfW
)/sizeof(WCHAR
)-1;
497 static void add_response_header(httprequest
*This
, const WCHAR
*data
, int len
)
499 struct httpheader
*entry
;
500 const WCHAR
*ptr
= data
;
507 header
= SysAllocStringLen(data
, ptr
-data
);
508 /* skip leading spaces for a value */
509 while (*++ptr
== ' ')
511 value
= SysAllocStringLen(ptr
, len
-(ptr
-data
));
520 TRACE("got header %s:%s\n", debugstr_w(header
), debugstr_w(value
));
522 entry
= heap_alloc(sizeof(*entry
));
523 entry
->header
= header
;
524 entry
->value
= value
;
525 list_add_head(&This
->respheaders
, &entry
->entry
);
528 static HRESULT WINAPI
BSCHttpNegotiate_OnResponse(IHttpNegotiate
*iface
, DWORD code
,
529 LPCWSTR resp_headers
, LPCWSTR req_headers
, LPWSTR
*add_reqheaders
)
531 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
533 TRACE("(%p)->(%d %s %s %p)\n", This
, code
, debugstr_w(resp_headers
),
534 debugstr_w(req_headers
), add_reqheaders
);
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
;
543 const WCHAR
*ptr
, *line
, *status_text
;
545 ptr
= line
= resp_headers
;
547 /* skip HTTP-Version */
548 ptr
= strchrW(ptr
, ' ');
551 /* skip Status-Code */
552 ptr
= strchrW(++ptr
, ' ');
556 /* now it supposed to end with CRLF */
559 if (*ptr
== '\r' && *(ptr
+1) == '\n')
562 This
->request
->status_text
= SysAllocStringLen(status_text
, ptr
-status_text
);
563 TRACE("status text %s\n", debugstr_w(This
->request
->status_text
));
571 /* store as unparsed string for now */
572 This
->request
->raw_respheaders
= SysAllocString(line
);
578 static const IHttpNegotiateVtbl BSCHttpNegotiateVtbl
= {
579 BSCHttpNegotiate_QueryInterface
,
580 BSCHttpNegotiate_AddRef
,
581 BSCHttpNegotiate_Release
,
582 BSCHttpNegotiate_BeginningTransaction
,
583 BSCHttpNegotiate_OnResponse
586 static HRESULT WINAPI
Authenticate_QueryInterface(IAuthenticate
*iface
,
587 REFIID riid
, void **ppv
)
589 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
590 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
593 static ULONG WINAPI
Authenticate_AddRef(IAuthenticate
*iface
)
595 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
596 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
599 static ULONG WINAPI
Authenticate_Release(IAuthenticate
*iface
)
601 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
602 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
605 static HRESULT WINAPI
Authenticate_Authenticate(IAuthenticate
*iface
,
606 HWND
*hwnd
, LPWSTR
*username
, LPWSTR
*password
)
608 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
609 FIXME("(%p)->(%p %p %p)\n", This
, hwnd
, username
, password
);
613 static const IAuthenticateVtbl AuthenticateVtbl
= {
614 Authenticate_QueryInterface
,
616 Authenticate_Release
,
617 Authenticate_Authenticate
620 static HRESULT
BindStatusCallback_create(httprequest
* This
, BindStatusCallback
**obj
, const VARIANT
*body
)
622 BindStatusCallback
*bsc
;
627 hr
= CreateBindCtx(0, &pbc
);
628 if (hr
!= S_OK
) return hr
;
630 bsc
= heap_alloc(sizeof(*bsc
));
633 IBindCtx_Release(pbc
);
634 return E_OUTOFMEMORY
;
637 bsc
->IBindStatusCallback_iface
.lpVtbl
= &BindStatusCallbackVtbl
;
638 bsc
->IHttpNegotiate_iface
.lpVtbl
= &BSCHttpNegotiateVtbl
;
639 bsc
->IAuthenticate_iface
.lpVtbl
= &AuthenticateVtbl
;
646 TRACE("(%p)->(%p)\n", This
, bsc
);
648 This
->use_utf8_content
= FALSE
;
650 if (This
->verb
!= BINDVERB_GET
)
652 void *send_data
, *ptr
;
653 SAFEARRAY
*sa
= NULL
;
655 if (V_VT(body
) == (VT_VARIANT
|VT_BYREF
))
656 body
= V_VARIANTREF(body
);
662 int len
= SysStringLen(V_BSTR(body
));
663 const WCHAR
*str
= V_BSTR(body
);
666 for (i
= 0; i
< len
; i
++)
675 size
= WideCharToMultiByte(cp
, 0, str
, len
, NULL
, 0, NULL
, NULL
);
676 if (!(ptr
= heap_alloc(size
)))
679 return E_OUTOFMEMORY
;
681 WideCharToMultiByte(cp
, 0, str
, len
, ptr
, size
, NULL
, NULL
);
682 if (cp
== CP_UTF8
) This
->use_utf8_content
= TRUE
;
685 case VT_ARRAY
|VT_UI1
:
688 if ((hr
= SafeArrayAccessData(sa
, (void **)&ptr
)) != S_OK
) return hr
;
689 if ((hr
= SafeArrayGetUBound(sa
, 1, &size
) != S_OK
))
691 SafeArrayUnaccessData(sa
);
703 FIXME("unsupported body data type %d\n", V_VT(body
));
707 bsc
->body
= GlobalAlloc(GMEM_FIXED
, size
);
710 if (V_VT(body
) == VT_BSTR
)
712 else if (V_VT(body
) == (VT_ARRAY
|VT_UI1
))
713 SafeArrayUnaccessData(sa
);
716 return E_OUTOFMEMORY
;
719 send_data
= GlobalLock(bsc
->body
);
720 memcpy(send_data
, ptr
, size
);
721 GlobalUnlock(bsc
->body
);
723 if (V_VT(body
) == VT_BSTR
)
725 else if (V_VT(body
) == (VT_ARRAY
|VT_UI1
))
726 SafeArrayUnaccessData(sa
);
729 hr
= RegisterBindStatusCallback(pbc
, &bsc
->IBindStatusCallback_iface
, NULL
, 0);
734 hr
= CreateURLMoniker(NULL
, This
->url
, &moniker
);
739 hr
= IMoniker_BindToStorage(moniker
, pbc
, NULL
, &IID_IStream
, (void**)&stream
);
740 IMoniker_Release(moniker
);
741 if (stream
) IStream_Release(stream
);
743 IBindCtx_Release(pbc
);
748 IBindStatusCallback_Release(&bsc
->IBindStatusCallback_iface
);
756 static HRESULT
httprequest_open(httprequest
*This
, BSTR method
, BSTR url
,
757 VARIANT async
, VARIANT user
, VARIANT password
)
759 static const WCHAR MethodGetW
[] = {'G','E','T',0};
760 static const WCHAR MethodPutW
[] = {'P','U','T',0};
761 static const WCHAR MethodPostW
[] = {'P','O','S','T',0};
762 static const WCHAR MethodDeleteW
[] = {'D','E','L','E','T','E',0};
763 static const WCHAR MethodPropFindW
[] = {'P','R','O','P','F','I','N','D',0};
764 VARIANT str
, is_async
;
767 if (!method
|| !url
) return E_INVALIDARG
;
769 /* free previously set data */
770 SysFreeString(This
->url
);
771 SysFreeString(This
->user
);
772 SysFreeString(This
->password
);
773 This
->url
= This
->user
= This
->password
= NULL
;
775 if (!strcmpiW(method
, MethodGetW
))
777 This
->verb
= BINDVERB_GET
;
779 else if (!strcmpiW(method
, MethodPutW
))
781 This
->verb
= BINDVERB_PUT
;
783 else if (!strcmpiW(method
, MethodPostW
))
785 This
->verb
= BINDVERB_POST
;
787 else if (!strcmpiW(method
, MethodDeleteW
) ||
788 !strcmpiW(method
, MethodPropFindW
))
790 This
->verb
= BINDVERB_CUSTOM
;
791 SysReAllocString(&This
->custom
, method
);
795 FIXME("unsupported request type %s\n", debugstr_w(method
));
800 /* try to combine with site url */
801 if (This
->siteurl
&& PathIsRelativeW(url
))
803 DWORD len
= INTERNET_MAX_URL_LENGTH
;
804 WCHAR
*fullW
= heap_alloc(len
*sizeof(WCHAR
));
806 hr
= UrlCombineW(This
->siteurl
, url
, fullW
, &len
, 0);
809 TRACE("combined url %s\n", debugstr_w(fullW
));
810 This
->url
= SysAllocString(fullW
);
815 This
->url
= SysAllocString(url
);
817 VariantInit(&is_async
);
818 hr
= VariantChangeType(&is_async
, &async
, 0, VT_BOOL
);
819 This
->async
= hr
== S_OK
&& V_BOOL(&is_async
);
822 hr
= VariantChangeType(&str
, &user
, 0, VT_BSTR
);
824 This
->user
= V_BSTR(&str
);
827 hr
= VariantChangeType(&str
, &password
, 0, VT_BSTR
);
829 This
->password
= V_BSTR(&str
);
831 httprequest_setreadystate(This
, READYSTATE_LOADING
);
836 static HRESULT
httprequest_setRequestHeader(httprequest
*This
, BSTR header
, BSTR value
)
838 struct httpheader
*entry
;
840 if (!header
|| !*header
) return E_INVALIDARG
;
841 if (This
->state
!= READYSTATE_LOADING
) return E_FAIL
;
842 if (!value
) return E_INVALIDARG
;
844 /* replace existing header value if already added */
845 LIST_FOR_EACH_ENTRY(entry
, &This
->reqheaders
, struct httpheader
, entry
)
847 if (lstrcmpW(entry
->header
, header
) == 0)
849 LONG length
= SysStringLen(entry
->value
);
852 hr
= SysReAllocString(&entry
->value
, value
) ? S_OK
: E_OUTOFMEMORY
;
855 This
->reqheader_size
+= (SysStringLen(entry
->value
) - length
);
861 entry
= heap_alloc(sizeof(*entry
));
862 if (!entry
) return E_OUTOFMEMORY
;
865 entry
->header
= SysAllocString(header
);
866 entry
->value
= SysAllocString(value
);
868 /* header length including null terminator */
869 This
->reqheader_size
+= SysStringLen(entry
->header
) + sizeof(colspaceW
)/sizeof(WCHAR
) +
870 SysStringLen(entry
->value
) + sizeof(crlfW
)/sizeof(WCHAR
) - 1;
872 list_add_head(&This
->reqheaders
, &entry
->entry
);
877 static HRESULT
httprequest_getResponseHeader(httprequest
*This
, BSTR header
, BSTR
*value
)
879 struct httpheader
*entry
;
881 if (!header
|| !value
) return E_INVALIDARG
;
883 if (This
->raw_respheaders
&& list_empty(&This
->respheaders
))
887 ptr
= line
= This
->raw_respheaders
;
890 if (*ptr
== '\r' && *(ptr
+1) == '\n')
892 add_response_header(This
, line
, ptr
-line
);
900 LIST_FOR_EACH_ENTRY(entry
, &This
->respheaders
, struct httpheader
, entry
)
902 if (!strcmpiW(entry
->header
, header
))
904 *value
= SysAllocString(entry
->value
);
905 TRACE("header value %s\n", debugstr_w(*value
));
913 static HRESULT
httprequest_getAllResponseHeaders(httprequest
*This
, BSTR
*respheaders
)
915 if (!respheaders
) return E_INVALIDARG
;
917 *respheaders
= SysAllocString(This
->raw_respheaders
);
922 static HRESULT
httprequest_send(httprequest
*This
, VARIANT body
)
924 BindStatusCallback
*bsc
= NULL
;
927 if (This
->state
!= READYSTATE_LOADING
) return E_FAIL
;
929 hr
= BindStatusCallback_create(This
, &bsc
, &body
);
930 if (FAILED(hr
)) return hr
;
932 BindStatusCallback_Detach(This
->bsc
);
938 static HRESULT
httprequest_abort(httprequest
*This
)
940 BindStatusCallback_Detach(This
->bsc
);
943 httprequest_setreadystate(This
, READYSTATE_UNINITIALIZED
);
948 static HRESULT
httprequest_get_status(httprequest
*This
, LONG
*status
)
950 if (!status
) return E_INVALIDARG
;
951 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
953 *status
= This
->status
;
958 static HRESULT
httprequest_get_statusText(httprequest
*This
, BSTR
*status
)
960 if (!status
) return E_INVALIDARG
;
961 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
963 *status
= SysAllocString(This
->status_text
);
968 static HRESULT
httprequest_get_responseText(httprequest
*This
, BSTR
*body
)
973 if (!body
) return E_INVALIDARG
;
974 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
976 hr
= GetHGlobalFromStream(This
->bsc
->stream
, &hglobal
);
979 xmlChar
*ptr
= GlobalLock(hglobal
);
980 DWORD size
= GlobalSize(hglobal
);
981 xmlCharEncoding encoding
= XML_CHAR_ENCODING_UTF8
;
983 /* try to determine data encoding */
986 encoding
= xmlDetectCharEncoding(ptr
, 4);
987 TRACE("detected encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding
)));
988 if ( encoding
!= XML_CHAR_ENCODING_UTF8
&&
989 encoding
!= XML_CHAR_ENCODING_UTF16LE
&&
990 encoding
!= XML_CHAR_ENCODING_NONE
)
992 FIXME("unsupported encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding
)));
993 GlobalUnlock(hglobal
);
998 /* without BOM assume UTF-8 */
999 if (encoding
== XML_CHAR_ENCODING_UTF8
||
1000 encoding
== XML_CHAR_ENCODING_NONE
)
1002 DWORD length
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)ptr
, size
, NULL
, 0);
1004 *body
= SysAllocStringLen(NULL
, length
);
1006 MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
)ptr
, size
, *body
, length
);
1009 *body
= SysAllocStringByteLen((LPCSTR
)ptr
, size
);
1011 if (!*body
) hr
= E_OUTOFMEMORY
;
1012 GlobalUnlock(hglobal
);
1018 static HRESULT
httprequest_get_responseXML(httprequest
*This
, IDispatch
**body
)
1020 IXMLDOMDocument3
*doc
;
1024 if (!body
) return E_INVALIDARG
;
1025 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
1027 hr
= DOMDocument_create(MSXML_DEFAULT
, NULL
, (void**)&doc
);
1028 if (hr
!= S_OK
) return hr
;
1030 hr
= httprequest_get_responseText(This
, &str
);
1035 hr
= IXMLDOMDocument3_loadXML(doc
, str
, &ok
);
1039 IXMLDOMDocument3_QueryInterface(doc
, &IID_IDispatch
, (void**)body
);
1040 IXMLDOMDocument3_Release(doc
);
1045 static HRESULT
httprequest_get_responseBody(httprequest
*This
, VARIANT
*body
)
1050 if (!body
) return E_INVALIDARG
;
1051 V_VT(body
) = VT_EMPTY
;
1053 if (This
->state
!= READYSTATE_COMPLETE
) return E_PENDING
;
1055 hr
= GetHGlobalFromStream(This
->bsc
->stream
, &hglobal
);
1058 void *ptr
= GlobalLock(hglobal
);
1059 DWORD size
= GlobalSize(hglobal
);
1061 SAFEARRAYBOUND bound
;
1065 bound
.cElements
= size
;
1066 array
= SafeArrayCreate(VT_UI1
, 1, &bound
);
1072 V_VT(body
) = VT_ARRAY
| VT_UI1
;
1073 V_ARRAY(body
) = array
;
1075 hr
= SafeArrayAccessData(array
, &dest
);
1078 memcpy(dest
, ptr
, size
);
1079 SafeArrayUnaccessData(array
);
1089 GlobalUnlock(hglobal
);
1095 static HRESULT
httprequest_get_responseStream(httprequest
*This
, VARIANT
*body
)
1101 if (!body
) return E_INVALIDARG
;
1102 V_VT(body
) = VT_EMPTY
;
1104 if (This
->state
!= READYSTATE_COMPLETE
) return E_PENDING
;
1106 hr
= IStream_Clone(This
->bsc
->stream
, &stream
);
1109 IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
1111 V_VT(body
) = VT_UNKNOWN
;
1112 V_UNKNOWN(body
) = (IUnknown
*)stream
;
1117 static HRESULT
httprequest_get_readyState(httprequest
*This
, LONG
*state
)
1119 if (!state
) return E_INVALIDARG
;
1121 *state
= This
->state
;
1125 static HRESULT
httprequest_put_onreadystatechange(httprequest
*This
, IDispatch
*sink
)
1127 if (This
->sink
) IDispatch_Release(This
->sink
);
1128 if ((This
->sink
= sink
)) IDispatch_AddRef(This
->sink
);
1133 static void httprequest_release(httprequest
*This
)
1135 struct httpheader
*header
, *header2
;
1138 IUnknown_Release( This
->site
);
1140 SysFreeString(This
->custom
);
1141 SysFreeString(This
->siteurl
);
1142 SysFreeString(This
->url
);
1143 SysFreeString(This
->user
);
1144 SysFreeString(This
->password
);
1146 /* request headers */
1147 LIST_FOR_EACH_ENTRY_SAFE(header
, header2
, &This
->reqheaders
, struct httpheader
, entry
)
1149 list_remove(&header
->entry
);
1150 SysFreeString(header
->header
);
1151 SysFreeString(header
->value
);
1154 /* response headers */
1155 free_response_headers(This
);
1156 SysFreeString(This
->status_text
);
1158 /* detach callback object */
1159 BindStatusCallback_Detach(This
->bsc
);
1161 if (This
->sink
) IDispatch_Release(This
->sink
);
1164 static HRESULT WINAPI
XMLHTTPRequest_QueryInterface(IXMLHTTPRequest
*iface
, REFIID riid
, void **ppvObject
)
1166 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1167 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1169 if ( IsEqualGUID( riid
, &IID_IXMLHTTPRequest
) ||
1170 IsEqualGUID( riid
, &IID_IDispatch
) ||
1171 IsEqualGUID( riid
, &IID_IUnknown
) )
1175 else if (IsEqualGUID(&IID_IObjectWithSite
, riid
))
1177 *ppvObject
= &This
->IObjectWithSite_iface
;
1179 else if (IsEqualGUID(&IID_IObjectSafety
, riid
))
1181 *ppvObject
= &This
->IObjectSafety_iface
;
1185 TRACE("Unsupported interface %s\n", debugstr_guid(riid
));
1187 return E_NOINTERFACE
;
1190 IXMLHTTPRequest_AddRef( iface
);
1195 static ULONG WINAPI
XMLHTTPRequest_AddRef(IXMLHTTPRequest
*iface
)
1197 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1198 ULONG ref
= InterlockedIncrement( &This
->ref
);
1199 TRACE("(%p)->(%u)\n", This
, ref
);
1203 static ULONG WINAPI
XMLHTTPRequest_Release(IXMLHTTPRequest
*iface
)
1205 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1206 ULONG ref
= InterlockedDecrement( &This
->ref
);
1208 TRACE("(%p)->(%u)\n", This
, ref
);
1212 httprequest_release( This
);
1219 static HRESULT WINAPI
XMLHTTPRequest_GetTypeInfoCount(IXMLHTTPRequest
*iface
, UINT
*pctinfo
)
1221 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1223 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1230 static HRESULT WINAPI
XMLHTTPRequest_GetTypeInfo(IXMLHTTPRequest
*iface
, UINT iTInfo
,
1231 LCID lcid
, ITypeInfo
**ppTInfo
)
1233 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1235 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1237 return get_typeinfo(IXMLHTTPRequest_tid
, ppTInfo
);
1240 static HRESULT WINAPI
XMLHTTPRequest_GetIDsOfNames(IXMLHTTPRequest
*iface
, REFIID riid
,
1241 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1243 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1244 ITypeInfo
*typeinfo
;
1247 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1250 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1251 return E_INVALIDARG
;
1253 hr
= get_typeinfo(IXMLHTTPRequest_tid
, &typeinfo
);
1256 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1257 ITypeInfo_Release(typeinfo
);
1263 static HRESULT WINAPI
XMLHTTPRequest_Invoke(IXMLHTTPRequest
*iface
, DISPID dispIdMember
, REFIID riid
,
1264 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1265 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1267 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1268 ITypeInfo
*typeinfo
;
1271 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1272 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1274 hr
= get_typeinfo(IXMLHTTPRequest_tid
, &typeinfo
);
1277 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLHTTPRequest_iface
, dispIdMember
, wFlags
,
1278 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1279 ITypeInfo_Release(typeinfo
);
1285 static HRESULT WINAPI
XMLHTTPRequest_open(IXMLHTTPRequest
*iface
, BSTR method
, BSTR url
,
1286 VARIANT async
, VARIANT user
, VARIANT password
)
1288 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1289 TRACE("(%p)->(%s %s %s)\n", This
, debugstr_w(method
), debugstr_w(url
),
1290 debugstr_variant(&async
));
1291 return httprequest_open(This
, method
, url
, async
, user
, password
);
1294 static HRESULT WINAPI
XMLHTTPRequest_setRequestHeader(IXMLHTTPRequest
*iface
, BSTR header
, BSTR value
)
1296 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1297 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(header
), debugstr_w(value
));
1298 return httprequest_setRequestHeader(This
, header
, value
);
1301 static HRESULT WINAPI
XMLHTTPRequest_getResponseHeader(IXMLHTTPRequest
*iface
, BSTR header
, BSTR
*value
)
1303 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1304 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(header
), value
);
1305 return httprequest_getResponseHeader(This
, header
, value
);
1308 static HRESULT WINAPI
XMLHTTPRequest_getAllResponseHeaders(IXMLHTTPRequest
*iface
, BSTR
*respheaders
)
1310 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1311 TRACE("(%p)->(%p)\n", This
, respheaders
);
1312 return httprequest_getAllResponseHeaders(This
, respheaders
);
1315 static HRESULT WINAPI
XMLHTTPRequest_send(IXMLHTTPRequest
*iface
, VARIANT body
)
1317 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1318 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&body
));
1319 return httprequest_send(This
, body
);
1322 static HRESULT WINAPI
XMLHTTPRequest_abort(IXMLHTTPRequest
*iface
)
1324 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1325 TRACE("(%p)\n", This
);
1326 return httprequest_abort(This
);
1329 static HRESULT WINAPI
XMLHTTPRequest_get_status(IXMLHTTPRequest
*iface
, LONG
*status
)
1331 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1332 TRACE("(%p)->(%p)\n", This
, status
);
1333 return httprequest_get_status(This
, status
);
1336 static HRESULT WINAPI
XMLHTTPRequest_get_statusText(IXMLHTTPRequest
*iface
, BSTR
*status
)
1338 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1339 TRACE("(%p)->(%p)\n", This
, status
);
1340 return httprequest_get_statusText(This
, status
);
1343 static HRESULT WINAPI
XMLHTTPRequest_get_responseXML(IXMLHTTPRequest
*iface
, IDispatch
**body
)
1345 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1346 TRACE("(%p)->(%p)\n", This
, body
);
1347 return httprequest_get_responseXML(This
, body
);
1350 static HRESULT WINAPI
XMLHTTPRequest_get_responseText(IXMLHTTPRequest
*iface
, BSTR
*body
)
1352 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1353 TRACE("(%p)->(%p)\n", This
, body
);
1354 return httprequest_get_responseText(This
, body
);
1357 static HRESULT WINAPI
XMLHTTPRequest_get_responseBody(IXMLHTTPRequest
*iface
, VARIANT
*body
)
1359 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1360 TRACE("(%p)->(%p)\n", This
, body
);
1361 return httprequest_get_responseBody(This
, body
);
1364 static HRESULT WINAPI
XMLHTTPRequest_get_responseStream(IXMLHTTPRequest
*iface
, VARIANT
*body
)
1366 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1367 TRACE("(%p)->(%p)\n", This
, body
);
1368 return httprequest_get_responseStream(This
, body
);
1371 static HRESULT WINAPI
XMLHTTPRequest_get_readyState(IXMLHTTPRequest
*iface
, LONG
*state
)
1373 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1374 TRACE("(%p)->(%p)\n", This
, state
);
1375 return httprequest_get_readyState(This
, state
);
1378 static HRESULT WINAPI
XMLHTTPRequest_put_onreadystatechange(IXMLHTTPRequest
*iface
, IDispatch
*sink
)
1380 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1381 TRACE("(%p)->(%p)\n", This
, sink
);
1382 return httprequest_put_onreadystatechange(This
, sink
);
1385 static const struct IXMLHTTPRequestVtbl XMLHTTPRequestVtbl
=
1387 XMLHTTPRequest_QueryInterface
,
1388 XMLHTTPRequest_AddRef
,
1389 XMLHTTPRequest_Release
,
1390 XMLHTTPRequest_GetTypeInfoCount
,
1391 XMLHTTPRequest_GetTypeInfo
,
1392 XMLHTTPRequest_GetIDsOfNames
,
1393 XMLHTTPRequest_Invoke
,
1394 XMLHTTPRequest_open
,
1395 XMLHTTPRequest_setRequestHeader
,
1396 XMLHTTPRequest_getResponseHeader
,
1397 XMLHTTPRequest_getAllResponseHeaders
,
1398 XMLHTTPRequest_send
,
1399 XMLHTTPRequest_abort
,
1400 XMLHTTPRequest_get_status
,
1401 XMLHTTPRequest_get_statusText
,
1402 XMLHTTPRequest_get_responseXML
,
1403 XMLHTTPRequest_get_responseText
,
1404 XMLHTTPRequest_get_responseBody
,
1405 XMLHTTPRequest_get_responseStream
,
1406 XMLHTTPRequest_get_readyState
,
1407 XMLHTTPRequest_put_onreadystatechange
1410 /* IObjectWithSite */
1411 static HRESULT WINAPI
1412 httprequest_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
1414 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1415 return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest
*)This
, riid
, ppvObject
);
1418 static ULONG WINAPI
httprequest_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
1420 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1421 return IXMLHTTPRequest_AddRef((IXMLHTTPRequest
*)This
);
1424 static ULONG WINAPI
httprequest_ObjectWithSite_Release( IObjectWithSite
* iface
)
1426 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1427 return IXMLHTTPRequest_Release((IXMLHTTPRequest
*)This
);
1430 static HRESULT WINAPI
httprequest_ObjectWithSite_GetSite( IObjectWithSite
*iface
, REFIID iid
, void **ppvSite
)
1432 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1434 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid( iid
), ppvSite
);
1439 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
1442 static HRESULT WINAPI
httprequest_ObjectWithSite_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
1444 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1445 IServiceProvider
*provider
;
1448 TRACE("(%p)->(%p)\n", iface
, punk
);
1451 IUnknown_AddRef( punk
);
1454 IUnknown_Release( This
->site
);
1458 hr
= IUnknown_QueryInterface(This
->site
, &IID_IServiceProvider
, (void**)&provider
);
1461 IHTMLDocument2
*doc
;
1463 hr
= IServiceProvider_QueryService(provider
, &SID_SContainerDispatch
, &IID_IHTMLDocument2
, (void**)&doc
);
1466 SysFreeString(This
->siteurl
);
1468 hr
= IHTMLDocument2_get_URL(doc
, &This
->siteurl
);
1469 IHTMLDocument2_Release(doc
);
1470 TRACE("host url %s, 0x%08x\n", debugstr_w(This
->siteurl
), hr
);
1472 IServiceProvider_Release(provider
);
1478 static const IObjectWithSiteVtbl ObjectWithSiteVtbl
=
1480 httprequest_ObjectWithSite_QueryInterface
,
1481 httprequest_ObjectWithSite_AddRef
,
1482 httprequest_ObjectWithSite_Release
,
1483 httprequest_ObjectWithSite_SetSite
,
1484 httprequest_ObjectWithSite_GetSite
1488 static HRESULT WINAPI
httprequest_Safety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
1490 httprequest
*This
= impl_from_IObjectSafety(iface
);
1491 return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest
*)This
, riid
, ppv
);
1494 static ULONG WINAPI
httprequest_Safety_AddRef(IObjectSafety
*iface
)
1496 httprequest
*This
= impl_from_IObjectSafety(iface
);
1497 return IXMLHTTPRequest_AddRef((IXMLHTTPRequest
*)This
);
1500 static ULONG WINAPI
httprequest_Safety_Release(IObjectSafety
*iface
)
1502 httprequest
*This
= impl_from_IObjectSafety(iface
);
1503 return IXMLHTTPRequest_Release((IXMLHTTPRequest
*)This
);
1506 static HRESULT WINAPI
httprequest_Safety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1507 DWORD
*supported
, DWORD
*enabled
)
1509 httprequest
*This
= impl_from_IObjectSafety(iface
);
1511 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), supported
, enabled
);
1513 if(!supported
|| !enabled
) return E_POINTER
;
1515 *supported
= safety_supported_options
;
1516 *enabled
= This
->safeopt
;
1521 static HRESULT WINAPI
httprequest_Safety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1522 DWORD mask
, DWORD enabled
)
1524 httprequest
*This
= impl_from_IObjectSafety(iface
);
1525 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), mask
, enabled
);
1527 if ((mask
& ~safety_supported_options
))
1530 This
->safeopt
= (This
->safeopt
& ~mask
) | (mask
& enabled
);
1535 static const IObjectSafetyVtbl ObjectSafetyVtbl
= {
1536 httprequest_Safety_QueryInterface
,
1537 httprequest_Safety_AddRef
,
1538 httprequest_Safety_Release
,
1539 httprequest_Safety_GetInterfaceSafetyOptions
,
1540 httprequest_Safety_SetInterfaceSafetyOptions
1543 /* IServerXMLHTTPRequest */
1544 static HRESULT WINAPI
ServerXMLHTTPRequest_QueryInterface(IServerXMLHTTPRequest
*iface
, REFIID riid
, void **obj
)
1546 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1548 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1550 if ( IsEqualGUID( riid
, &IID_IServerXMLHTTPRequest
) ||
1551 IsEqualGUID( riid
, &IID_IXMLHTTPRequest
) ||
1552 IsEqualGUID( riid
, &IID_IDispatch
) ||
1553 IsEqualGUID( riid
, &IID_IUnknown
) )
1559 TRACE("Unsupported interface %s\n", debugstr_guid(riid
));
1561 return E_NOINTERFACE
;
1564 IServerXMLHTTPRequest_AddRef( iface
);
1569 static ULONG WINAPI
ServerXMLHTTPRequest_AddRef(IServerXMLHTTPRequest
*iface
)
1571 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1572 ULONG ref
= InterlockedIncrement( &This
->ref
);
1573 TRACE("(%p)->(%u)\n", This
, ref
);
1577 static ULONG WINAPI
ServerXMLHTTPRequest_Release(IServerXMLHTTPRequest
*iface
)
1579 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1580 ULONG ref
= InterlockedDecrement( &This
->ref
);
1582 TRACE("(%p)->(%u)\n", This
, ref
);
1586 httprequest_release( &This
->req
);
1593 static HRESULT WINAPI
ServerXMLHTTPRequest_GetTypeInfoCount(IServerXMLHTTPRequest
*iface
, UINT
*pctinfo
)
1595 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1597 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1603 static HRESULT WINAPI
ServerXMLHTTPRequest_GetTypeInfo(IServerXMLHTTPRequest
*iface
, UINT iTInfo
,
1604 LCID lcid
, ITypeInfo
**ppTInfo
)
1606 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1608 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1610 return get_typeinfo(IServerXMLHTTPRequest_tid
, ppTInfo
);
1613 static HRESULT WINAPI
ServerXMLHTTPRequest_GetIDsOfNames(IServerXMLHTTPRequest
*iface
, REFIID riid
,
1614 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1616 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1617 ITypeInfo
*typeinfo
;
1620 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1623 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1624 return E_INVALIDARG
;
1626 hr
= get_typeinfo(IServerXMLHTTPRequest_tid
, &typeinfo
);
1629 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1630 ITypeInfo_Release(typeinfo
);
1636 static HRESULT WINAPI
ServerXMLHTTPRequest_Invoke(IServerXMLHTTPRequest
*iface
, DISPID dispIdMember
, REFIID riid
,
1637 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1638 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1640 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1641 ITypeInfo
*typeinfo
;
1644 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1645 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1647 hr
= get_typeinfo(IServerXMLHTTPRequest_tid
, &typeinfo
);
1650 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IServerXMLHTTPRequest_iface
, dispIdMember
, wFlags
,
1651 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1652 ITypeInfo_Release(typeinfo
);
1658 static HRESULT WINAPI
ServerXMLHTTPRequest_open(IServerXMLHTTPRequest
*iface
, BSTR method
, BSTR url
,
1659 VARIANT async
, VARIANT user
, VARIANT password
)
1661 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1662 TRACE("(%p)->(%s %s %s)\n", This
, debugstr_w(method
), debugstr_w(url
),
1663 debugstr_variant(&async
));
1664 return httprequest_open(&This
->req
, method
, url
, async
, user
, password
);
1667 static HRESULT WINAPI
ServerXMLHTTPRequest_setRequestHeader(IServerXMLHTTPRequest
*iface
, BSTR header
, BSTR value
)
1669 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1670 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(header
), debugstr_w(value
));
1671 return httprequest_setRequestHeader(&This
->req
, header
, value
);
1674 static HRESULT WINAPI
ServerXMLHTTPRequest_getResponseHeader(IServerXMLHTTPRequest
*iface
, BSTR header
, BSTR
*value
)
1676 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1677 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(header
), value
);
1678 return httprequest_getResponseHeader(&This
->req
, header
, value
);
1681 static HRESULT WINAPI
ServerXMLHTTPRequest_getAllResponseHeaders(IServerXMLHTTPRequest
*iface
, BSTR
*respheaders
)
1683 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1684 TRACE("(%p)->(%p)\n", This
, respheaders
);
1685 return httprequest_getAllResponseHeaders(&This
->req
, respheaders
);
1688 static HRESULT WINAPI
ServerXMLHTTPRequest_send(IServerXMLHTTPRequest
*iface
, VARIANT body
)
1690 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1691 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&body
));
1692 return httprequest_send(&This
->req
, body
);
1695 static HRESULT WINAPI
ServerXMLHTTPRequest_abort(IServerXMLHTTPRequest
*iface
)
1697 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1698 TRACE("(%p)\n", This
);
1699 return httprequest_abort(&This
->req
);
1702 static HRESULT WINAPI
ServerXMLHTTPRequest_get_status(IServerXMLHTTPRequest
*iface
, LONG
*status
)
1704 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1705 TRACE("(%p)->(%p)\n", This
, status
);
1706 return httprequest_get_status(&This
->req
, status
);
1709 static HRESULT WINAPI
ServerXMLHTTPRequest_get_statusText(IServerXMLHTTPRequest
*iface
, BSTR
*status
)
1711 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1712 TRACE("(%p)->(%p)\n", This
, status
);
1713 return httprequest_get_statusText(&This
->req
, status
);
1716 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseXML(IServerXMLHTTPRequest
*iface
, IDispatch
**body
)
1718 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1719 TRACE("(%p)->(%p)\n", This
, body
);
1720 return httprequest_get_responseXML(&This
->req
, body
);
1723 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseText(IServerXMLHTTPRequest
*iface
, BSTR
*body
)
1725 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1726 TRACE("(%p)->(%p)\n", This
, body
);
1727 return httprequest_get_responseText(&This
->req
, body
);
1730 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseBody(IServerXMLHTTPRequest
*iface
, VARIANT
*body
)
1732 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1733 TRACE("(%p)->(%p)\n", This
, body
);
1734 return httprequest_get_responseBody(&This
->req
, body
);
1737 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseStream(IServerXMLHTTPRequest
*iface
, VARIANT
*body
)
1739 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1740 TRACE("(%p)->(%p)\n", This
, body
);
1741 return httprequest_get_responseStream(&This
->req
, body
);
1744 static HRESULT WINAPI
ServerXMLHTTPRequest_get_readyState(IServerXMLHTTPRequest
*iface
, LONG
*state
)
1746 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1747 TRACE("(%p)->(%p)\n", This
, state
);
1748 return httprequest_get_readyState(&This
->req
, state
);
1751 static HRESULT WINAPI
ServerXMLHTTPRequest_put_onreadystatechange(IServerXMLHTTPRequest
*iface
, IDispatch
*sink
)
1753 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1754 TRACE("(%p)->(%p)\n", This
, sink
);
1755 return httprequest_put_onreadystatechange(&This
->req
, sink
);
1758 static HRESULT WINAPI
ServerXMLHTTPRequest_setTimeouts(IServerXMLHTTPRequest
*iface
, LONG resolveTimeout
, LONG connectTimeout
,
1759 LONG sendTimeout
, LONG receiveTimeout
)
1761 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1762 FIXME("(%p)->(%d %d %d %d): stub\n", This
, resolveTimeout
, connectTimeout
, sendTimeout
, receiveTimeout
);
1766 static HRESULT WINAPI
ServerXMLHTTPRequest_waitForResponse(IServerXMLHTTPRequest
*iface
, VARIANT timeout
, VARIANT_BOOL
*isSuccessful
)
1768 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1769 FIXME("(%p)->(%s %p): stub\n", This
, debugstr_variant(&timeout
), isSuccessful
);
1773 static HRESULT WINAPI
ServerXMLHTTPRequest_getOption(IServerXMLHTTPRequest
*iface
, SERVERXMLHTTP_OPTION option
, VARIANT
*value
)
1775 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1776 FIXME("(%p)->(%d %p): stub\n", This
, option
, value
);
1780 static HRESULT WINAPI
ServerXMLHTTPRequest_setOption(IServerXMLHTTPRequest
*iface
, SERVERXMLHTTP_OPTION option
, VARIANT value
)
1782 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1783 FIXME("(%p)->(%d %s): stub\n", This
, option
, debugstr_variant(&value
));
1787 static const struct IServerXMLHTTPRequestVtbl ServerXMLHTTPRequestVtbl
=
1789 ServerXMLHTTPRequest_QueryInterface
,
1790 ServerXMLHTTPRequest_AddRef
,
1791 ServerXMLHTTPRequest_Release
,
1792 ServerXMLHTTPRequest_GetTypeInfoCount
,
1793 ServerXMLHTTPRequest_GetTypeInfo
,
1794 ServerXMLHTTPRequest_GetIDsOfNames
,
1795 ServerXMLHTTPRequest_Invoke
,
1796 ServerXMLHTTPRequest_open
,
1797 ServerXMLHTTPRequest_setRequestHeader
,
1798 ServerXMLHTTPRequest_getResponseHeader
,
1799 ServerXMLHTTPRequest_getAllResponseHeaders
,
1800 ServerXMLHTTPRequest_send
,
1801 ServerXMLHTTPRequest_abort
,
1802 ServerXMLHTTPRequest_get_status
,
1803 ServerXMLHTTPRequest_get_statusText
,
1804 ServerXMLHTTPRequest_get_responseXML
,
1805 ServerXMLHTTPRequest_get_responseText
,
1806 ServerXMLHTTPRequest_get_responseBody
,
1807 ServerXMLHTTPRequest_get_responseStream
,
1808 ServerXMLHTTPRequest_get_readyState
,
1809 ServerXMLHTTPRequest_put_onreadystatechange
,
1810 ServerXMLHTTPRequest_setTimeouts
,
1811 ServerXMLHTTPRequest_waitForResponse
,
1812 ServerXMLHTTPRequest_getOption
,
1813 ServerXMLHTTPRequest_setOption
1816 static void init_httprequest(httprequest
*req
)
1818 req
->IXMLHTTPRequest_iface
.lpVtbl
= &XMLHTTPRequestVtbl
;
1819 req
->IObjectWithSite_iface
.lpVtbl
= &ObjectWithSiteVtbl
;
1820 req
->IObjectSafety_iface
.lpVtbl
= &ObjectSafetyVtbl
;
1826 req
->url
= req
->siteurl
= req
->user
= req
->password
= NULL
;
1828 req
->state
= READYSTATE_UNINITIALIZED
;
1833 req
->status_text
= NULL
;
1834 req
->reqheader_size
= 0;
1835 req
->raw_respheaders
= NULL
;
1836 req
->use_utf8_content
= FALSE
;
1838 list_init(&req
->reqheaders
);
1839 list_init(&req
->respheaders
);
1845 HRESULT
XMLHTTPRequest_create(IUnknown
*outer
, void **obj
)
1849 TRACE("(%p, %p)\n", outer
, obj
);
1851 req
= heap_alloc( sizeof (*req
) );
1853 return E_OUTOFMEMORY
;
1855 init_httprequest(req
);
1856 *obj
= &req
->IXMLHTTPRequest_iface
;
1858 TRACE("returning iface %p\n", *obj
);
1863 HRESULT
ServerXMLHTTP_create(IUnknown
*outer
, void **obj
)
1867 TRACE("(%p, %p)\n", outer
, obj
);
1869 req
= heap_alloc( sizeof (*req
) );
1871 return E_OUTOFMEMORY
;
1873 init_httprequest(&req
->req
);
1874 req
->IServerXMLHTTPRequest_iface
.lpVtbl
= &ServerXMLHTTPRequestVtbl
;
1877 *obj
= &req
->IServerXMLHTTPRequest_iface
;
1879 TRACE("returning iface %p\n", *obj
);
1886 HRESULT
XMLHTTPRequest_create(IUnknown
*pUnkOuter
, void **ppObj
)
1888 MESSAGE("This program tried to use a XMLHTTPRequest object, but\n"
1889 "libxml2 support was not present at compile time.\n");
1893 HRESULT
ServerXMLHTTP_create(IUnknown
*outer
, void **obj
)
1895 MESSAGE("This program tried to use a ServerXMLHTTP object, but\n"
1896 "libxml2 support was not present at compile time.\n");