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"
53 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
55 static const WCHAR colspaceW
[] = {':',' ',0};
56 static const WCHAR crlfW
[] = {'\r','\n',0};
57 static const DWORD safety_supported_options
=
58 INTERFACESAFE_FOR_UNTRUSTED_CALLER
|
59 INTERFACESAFE_FOR_UNTRUSTED_DATA
|
60 INTERFACE_USES_SECURITY_MANAGER
;
62 typedef struct BindStatusCallback BindStatusCallback
;
73 IXMLHTTPRequest IXMLHTTPRequest_iface
;
74 IObjectWithSite IObjectWithSite_iface
;
75 IObjectSafety IObjectSafety_iface
;
87 struct list reqheaders
;
88 /* cached resulting custom request headers string length in WCHARs */
90 /* use UTF-8 content type */
91 BOOL use_utf8_content
;
93 /* response headers */
94 struct list respheaders
;
102 BindStatusCallback
*bsc
;
116 IServerXMLHTTPRequest IServerXMLHTTPRequest_iface
;
120 static inline httprequest
*impl_from_IXMLHTTPRequest( IXMLHTTPRequest
*iface
)
122 return CONTAINING_RECORD(iface
, httprequest
, IXMLHTTPRequest_iface
);
125 static inline httprequest
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
127 return CONTAINING_RECORD(iface
, httprequest
, IObjectWithSite_iface
);
130 static inline httprequest
*impl_from_IObjectSafety(IObjectSafety
*iface
)
132 return CONTAINING_RECORD(iface
, httprequest
, IObjectSafety_iface
);
135 static inline serverhttp
*impl_from_IServerXMLHTTPRequest(IServerXMLHTTPRequest
*iface
)
137 return CONTAINING_RECORD(iface
, serverhttp
, IServerXMLHTTPRequest_iface
);
140 static void httprequest_setreadystate(httprequest
*This
, READYSTATE state
)
142 READYSTATE last
= This
->state
;
143 static const char* readystates
[] = {
144 "READYSTATE_UNINITIALIZED",
145 "READYSTATE_LOADING",
147 "READYSTATE_INTERACTIVE",
148 "READYSTATE_COMPLETE"};
152 TRACE("state %s\n", readystates
[state
]);
154 if (This
->sink
&& last
!= state
)
158 memset(¶ms
, 0, sizeof(params
));
159 IDispatch_Invoke(This
->sink
, 0, &IID_NULL
, LOCALE_SYSTEM_DEFAULT
, DISPATCH_METHOD
, ¶ms
, 0, 0, 0);
163 static void free_response_headers(httprequest
*This
)
165 struct httpheader
*header
, *header2
;
167 LIST_FOR_EACH_ENTRY_SAFE(header
, header2
, &This
->respheaders
, struct httpheader
, entry
)
169 list_remove(&header
->entry
);
170 SysFreeString(header
->header
);
171 SysFreeString(header
->value
);
175 SysFreeString(This
->raw_respheaders
);
176 This
->raw_respheaders
= NULL
;
179 static void free_request_headers(httprequest
*This
)
181 struct httpheader
*header
, *header2
;
183 LIST_FOR_EACH_ENTRY_SAFE(header
, header2
, &This
->reqheaders
, struct httpheader
, entry
)
185 list_remove(&header
->entry
);
186 SysFreeString(header
->header
);
187 SysFreeString(header
->value
);
192 struct BindStatusCallback
194 IBindStatusCallback IBindStatusCallback_iface
;
195 IHttpNegotiate IHttpNegotiate_iface
;
196 IAuthenticate IAuthenticate_iface
;
200 httprequest
*request
;
205 /* request body data */
209 static inline BindStatusCallback
*impl_from_IBindStatusCallback( IBindStatusCallback
*iface
)
211 return CONTAINING_RECORD(iface
, BindStatusCallback
, IBindStatusCallback_iface
);
214 static inline BindStatusCallback
*impl_from_IHttpNegotiate( IHttpNegotiate
*iface
)
216 return CONTAINING_RECORD(iface
, BindStatusCallback
, IHttpNegotiate_iface
);
219 static inline BindStatusCallback
*impl_from_IAuthenticate( IAuthenticate
*iface
)
221 return CONTAINING_RECORD(iface
, BindStatusCallback
, IAuthenticate_iface
);
224 static void BindStatusCallback_Detach(BindStatusCallback
*bsc
)
228 if (bsc
->binding
) IBinding_Abort(bsc
->binding
);
229 bsc
->request
->bsc
= NULL
;
231 IBindStatusCallback_Release(&bsc
->IBindStatusCallback_iface
);
235 static HRESULT WINAPI
BindStatusCallback_QueryInterface(IBindStatusCallback
*iface
,
236 REFIID riid
, void **ppv
)
238 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
242 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
244 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
245 IsEqualGUID(&IID_IBindStatusCallback
, riid
))
247 *ppv
= &This
->IBindStatusCallback_iface
;
249 else if (IsEqualGUID(&IID_IHttpNegotiate
, riid
))
251 *ppv
= &This
->IHttpNegotiate_iface
;
253 else if (IsEqualGUID(&IID_IAuthenticate
, riid
))
255 *ppv
= &This
->IAuthenticate_iface
;
257 else if (IsEqualGUID(&IID_IServiceProvider
, riid
) ||
258 IsEqualGUID(&IID_IBindStatusCallbackEx
, riid
) ||
259 IsEqualGUID(&IID_IInternetProtocol
, riid
) ||
260 IsEqualGUID(&IID_IHttpNegotiate2
, riid
))
262 return E_NOINTERFACE
;
267 IBindStatusCallback_AddRef(iface
);
271 FIXME("Unsupported riid = %s\n", debugstr_guid(riid
));
273 return E_NOINTERFACE
;
276 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
278 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
279 LONG ref
= InterlockedIncrement(&This
->ref
);
281 TRACE("(%p) ref = %d\n", This
, ref
);
286 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
288 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
289 LONG ref
= InterlockedDecrement(&This
->ref
);
291 TRACE("(%p) ref = %d\n", This
, ref
);
295 if (This
->binding
) IBinding_Release(This
->binding
);
296 if (This
->stream
) IStream_Release(This
->stream
);
297 if (This
->body
) GlobalFree(This
->body
);
304 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
305 DWORD reserved
, IBinding
*pbind
)
307 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
309 TRACE("(%p)->(%d %p)\n", This
, reserved
, pbind
);
311 if (!pbind
) return E_INVALIDARG
;
313 This
->binding
= pbind
;
314 IBinding_AddRef(pbind
);
316 httprequest_setreadystate(This
->request
, READYSTATE_LOADED
);
318 return CreateStreamOnHGlobal(NULL
, TRUE
, &This
->stream
);
321 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
, LONG
*pPriority
)
323 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
325 TRACE("(%p)->(%p)\n", This
, pPriority
);
330 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
, DWORD reserved
)
332 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
334 TRACE("(%p)->(%d)\n", This
, reserved
);
339 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
340 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
342 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
344 TRACE("(%p)->(%u %u %u %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
345 debugstr_w(szStatusText
));
350 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
351 HRESULT hr
, LPCWSTR error
)
353 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
355 TRACE("(%p)->(0x%08x %s)\n", This
, hr
, debugstr_w(error
));
359 IBinding_Release(This
->binding
);
360 This
->binding
= NULL
;
365 BindStatusCallback_Detach(This
->request
->bsc
);
366 This
->request
->bsc
= This
;
367 httprequest_setreadystate(This
->request
, READYSTATE_COMPLETE
);
373 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
374 DWORD
*bind_flags
, BINDINFO
*pbindinfo
)
376 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
378 TRACE("(%p)->(%p %p)\n", This
, bind_flags
, pbindinfo
);
381 if (This
->request
->async
) *bind_flags
|= BINDF_ASYNCHRONOUS
;
383 if (This
->request
->verb
!= BINDVERB_GET
&& This
->body
)
385 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
386 pbindinfo
->stgmedData
.u
.hGlobal
= This
->body
;
387 pbindinfo
->cbstgmedData
= GlobalSize(This
->body
);
388 /* callback owns passed body pointer */
389 IBindStatusCallback_QueryInterface(iface
, &IID_IUnknown
, (void**)&pbindinfo
->stgmedData
.pUnkForRelease
);
392 pbindinfo
->dwBindVerb
= This
->request
->verb
;
393 if (This
->request
->verb
== BINDVERB_CUSTOM
)
395 pbindinfo
->szCustomVerb
= CoTaskMemAlloc(SysStringByteLen(This
->request
->custom
));
396 strcpyW(pbindinfo
->szCustomVerb
, This
->request
->custom
);
402 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
403 DWORD flags
, DWORD size
, FORMATETC
*format
, STGMEDIUM
*stgmed
)
405 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
410 TRACE("(%p)->(%08x %d %p %p)\n", This
, flags
, size
, format
, stgmed
);
414 hr
= IStream_Read(stgmed
->u
.pstm
, buf
, sizeof(buf
), &read
);
415 if (hr
!= S_OK
) break;
417 hr
= IStream_Write(This
->stream
, buf
, read
, &written
);
418 } while((hr
== S_OK
) && written
!= 0 && read
!= 0);
420 httprequest_setreadystate(This
->request
, READYSTATE_INTERACTIVE
);
425 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
426 REFIID riid
, IUnknown
*punk
)
428 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
430 FIXME("(%p)->(%s %p): stub\n", This
, debugstr_guid(riid
), punk
);
435 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
436 BindStatusCallback_QueryInterface
,
437 BindStatusCallback_AddRef
,
438 BindStatusCallback_Release
,
439 BindStatusCallback_OnStartBinding
,
440 BindStatusCallback_GetPriority
,
441 BindStatusCallback_OnLowResource
,
442 BindStatusCallback_OnProgress
,
443 BindStatusCallback_OnStopBinding
,
444 BindStatusCallback_GetBindInfo
,
445 BindStatusCallback_OnDataAvailable
,
446 BindStatusCallback_OnObjectAvailable
449 static HRESULT WINAPI
BSCHttpNegotiate_QueryInterface(IHttpNegotiate
*iface
,
450 REFIID riid
, void **ppv
)
452 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
453 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
456 static ULONG WINAPI
BSCHttpNegotiate_AddRef(IHttpNegotiate
*iface
)
458 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
459 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
462 static ULONG WINAPI
BSCHttpNegotiate_Release(IHttpNegotiate
*iface
)
464 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
465 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
468 static HRESULT WINAPI
BSCHttpNegotiate_BeginningTransaction(IHttpNegotiate
*iface
,
469 LPCWSTR url
, LPCWSTR headers
, DWORD reserved
, LPWSTR
*add_headers
)
471 static const WCHAR content_type_utf8W
[] = {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ',
472 't','e','x','t','/','p','l','a','i','n',';','c','h','a','r','s','e','t','=','u','t','f','-','8','\r','\n',0};
473 static const WCHAR refererW
[] = {'R','e','f','e','r','e','r',':',' ',0};
475 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
476 const struct httpheader
*entry
;
477 BSTR base_uri
= NULL
;
481 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(url
), debugstr_w(headers
), reserved
, add_headers
);
485 if (This
->request
->use_utf8_content
)
486 size
= sizeof(content_type_utf8W
);
488 if (!list_empty(&This
->request
->reqheaders
))
489 size
+= This
->request
->reqheader_size
*sizeof(WCHAR
);
491 if (This
->request
->base_uri
)
493 IUri_GetRawUri(This
->request
->base_uri
, &base_uri
);
494 size
+= SysStringLen(base_uri
)*sizeof(WCHAR
) + sizeof(refererW
) + sizeof(crlfW
);
499 SysFreeString(base_uri
);
503 buff
= CoTaskMemAlloc(size
);
506 SysFreeString(base_uri
);
507 return E_OUTOFMEMORY
;
511 if (This
->request
->use_utf8_content
)
513 lstrcpyW(ptr
, content_type_utf8W
);
514 ptr
+= sizeof(content_type_utf8W
)/sizeof(WCHAR
)-1;
519 strcpyW(ptr
, refererW
);
520 strcatW(ptr
, base_uri
);
522 ptr
+= strlenW(refererW
) + SysStringLen(base_uri
) + strlenW(crlfW
);
523 SysFreeString(base_uri
);
527 LIST_FOR_EACH_ENTRY(entry
, &This
->request
->reqheaders
, struct httpheader
, entry
)
529 lstrcpyW(ptr
, entry
->header
);
530 ptr
+= SysStringLen(entry
->header
);
532 lstrcpyW(ptr
, colspaceW
);
533 ptr
+= sizeof(colspaceW
)/sizeof(WCHAR
)-1;
535 lstrcpyW(ptr
, entry
->value
);
536 ptr
+= SysStringLen(entry
->value
);
538 lstrcpyW(ptr
, crlfW
);
539 ptr
+= sizeof(crlfW
)/sizeof(WCHAR
)-1;
547 static void add_response_header(httprequest
*This
, const WCHAR
*data
, int len
)
549 struct httpheader
*entry
;
550 const WCHAR
*ptr
= data
;
557 header
= SysAllocStringLen(data
, ptr
-data
);
558 /* skip leading spaces for a value */
559 while (*++ptr
== ' ')
561 value
= SysAllocStringLen(ptr
, len
-(ptr
-data
));
570 TRACE("got header %s:%s\n", debugstr_w(header
), debugstr_w(value
));
572 entry
= heap_alloc(sizeof(*entry
));
573 entry
->header
= header
;
574 entry
->value
= value
;
575 list_add_head(&This
->respheaders
, &entry
->entry
);
578 static HRESULT WINAPI
BSCHttpNegotiate_OnResponse(IHttpNegotiate
*iface
, DWORD code
,
579 LPCWSTR resp_headers
, LPCWSTR req_headers
, LPWSTR
*add_reqheaders
)
581 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
583 TRACE("(%p)->(%d %s %s %p)\n", This
, code
, debugstr_w(resp_headers
),
584 debugstr_w(req_headers
), add_reqheaders
);
586 This
->request
->status
= code
;
587 /* store headers and status text */
588 free_response_headers(This
->request
);
589 SysFreeString(This
->request
->status_text
);
590 This
->request
->status_text
= NULL
;
593 const WCHAR
*ptr
, *line
, *status_text
;
595 ptr
= line
= resp_headers
;
597 /* skip HTTP-Version */
598 ptr
= strchrW(ptr
, ' ');
601 /* skip Status-Code */
602 ptr
= strchrW(++ptr
, ' ');
606 /* now it supposed to end with CRLF */
609 if (*ptr
== '\r' && *(ptr
+1) == '\n')
612 This
->request
->status_text
= SysAllocStringLen(status_text
, ptr
-status_text
);
613 TRACE("status text %s\n", debugstr_w(This
->request
->status_text
));
621 /* store as unparsed string for now */
622 This
->request
->raw_respheaders
= SysAllocString(line
);
628 static const IHttpNegotiateVtbl BSCHttpNegotiateVtbl
= {
629 BSCHttpNegotiate_QueryInterface
,
630 BSCHttpNegotiate_AddRef
,
631 BSCHttpNegotiate_Release
,
632 BSCHttpNegotiate_BeginningTransaction
,
633 BSCHttpNegotiate_OnResponse
636 static HRESULT WINAPI
Authenticate_QueryInterface(IAuthenticate
*iface
,
637 REFIID riid
, void **ppv
)
639 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
640 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
643 static ULONG WINAPI
Authenticate_AddRef(IAuthenticate
*iface
)
645 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
646 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
649 static ULONG WINAPI
Authenticate_Release(IAuthenticate
*iface
)
651 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
652 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
655 static HRESULT WINAPI
Authenticate_Authenticate(IAuthenticate
*iface
,
656 HWND
*hwnd
, LPWSTR
*username
, LPWSTR
*password
)
658 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
659 httprequest
*request
= This
->request
;
661 TRACE("(%p)->(%p %p %p)\n", This
, hwnd
, username
, password
);
663 if (request
->user
&& *request
->user
)
665 if (hwnd
) *hwnd
= NULL
;
666 *username
= CoTaskMemAlloc(SysStringByteLen(request
->user
)+sizeof(WCHAR
));
667 *password
= CoTaskMemAlloc(SysStringByteLen(request
->password
)+sizeof(WCHAR
));
668 if (!*username
|| !*password
)
670 CoTaskMemFree(*username
);
671 CoTaskMemFree(*password
);
672 return E_OUTOFMEMORY
;
675 memcpy(*username
, request
->user
, SysStringByteLen(request
->user
)+sizeof(WCHAR
));
676 memcpy(*password
, request
->password
, SysStringByteLen(request
->password
)+sizeof(WCHAR
));
682 static const IAuthenticateVtbl AuthenticateVtbl
= {
683 Authenticate_QueryInterface
,
685 Authenticate_Release
,
686 Authenticate_Authenticate
689 static HRESULT
BindStatusCallback_create(httprequest
* This
, BindStatusCallback
**obj
, const VARIANT
*body
)
691 BindStatusCallback
*bsc
;
696 hr
= CreateBindCtx(0, &pbc
);
697 if (hr
!= S_OK
) return hr
;
699 bsc
= heap_alloc(sizeof(*bsc
));
702 IBindCtx_Release(pbc
);
703 return E_OUTOFMEMORY
;
706 bsc
->IBindStatusCallback_iface
.lpVtbl
= &BindStatusCallbackVtbl
;
707 bsc
->IHttpNegotiate_iface
.lpVtbl
= &BSCHttpNegotiateVtbl
;
708 bsc
->IAuthenticate_iface
.lpVtbl
= &AuthenticateVtbl
;
715 TRACE("(%p)->(%p)\n", This
, bsc
);
717 This
->use_utf8_content
= FALSE
;
719 if (This
->verb
!= BINDVERB_GET
)
721 void *send_data
, *ptr
;
722 SAFEARRAY
*sa
= NULL
;
724 if (V_VT(body
) == (VT_VARIANT
|VT_BYREF
))
725 body
= V_VARIANTREF(body
);
731 int len
= SysStringLen(V_BSTR(body
));
732 const WCHAR
*str
= V_BSTR(body
);
735 for (i
= 0; i
< len
; i
++)
744 size
= WideCharToMultiByte(cp
, 0, str
, len
, NULL
, 0, NULL
, NULL
);
745 if (!(ptr
= heap_alloc(size
)))
748 return E_OUTOFMEMORY
;
750 WideCharToMultiByte(cp
, 0, str
, len
, ptr
, size
, NULL
, NULL
);
751 if (cp
== CP_UTF8
) This
->use_utf8_content
= TRUE
;
754 case VT_ARRAY
|VT_UI1
:
757 if ((hr
= SafeArrayAccessData(sa
, (void **)&ptr
)) != S_OK
)
762 if ((hr
= SafeArrayGetUBound(sa
, 1, &size
)) != S_OK
)
764 SafeArrayUnaccessData(sa
);
772 FIXME("unsupported body data type %d\n", V_VT(body
));
784 bsc
->body
= GlobalAlloc(GMEM_FIXED
, size
);
787 if (V_VT(body
) == VT_BSTR
)
789 else if (V_VT(body
) == (VT_ARRAY
|VT_UI1
))
790 SafeArrayUnaccessData(sa
);
793 return E_OUTOFMEMORY
;
796 send_data
= GlobalLock(bsc
->body
);
797 memcpy(send_data
, ptr
, size
);
798 GlobalUnlock(bsc
->body
);
801 if (V_VT(body
) == VT_BSTR
)
803 else if (V_VT(body
) == (VT_ARRAY
|VT_UI1
))
804 SafeArrayUnaccessData(sa
);
807 hr
= RegisterBindStatusCallback(pbc
, &bsc
->IBindStatusCallback_iface
, NULL
, 0);
812 hr
= CreateURLMonikerEx2(NULL
, This
->uri
, &moniker
, URL_MK_UNIFORM
);
817 hr
= IMoniker_BindToStorage(moniker
, pbc
, NULL
, &IID_IStream
, (void**)&stream
);
818 IMoniker_Release(moniker
);
819 if (stream
) IStream_Release(stream
);
821 IBindCtx_Release(pbc
);
826 IBindStatusCallback_Release(&bsc
->IBindStatusCallback_iface
);
834 static HRESULT
verify_uri(httprequest
*This
, IUri
*uri
)
836 DWORD scheme
, base_scheme
;
837 BSTR host
, base_host
;
840 if(!(This
->safeopt
& INTERFACESAFE_FOR_UNTRUSTED_DATA
))
844 return E_ACCESSDENIED
;
846 hr
= IUri_GetScheme(uri
, &scheme
);
850 hr
= IUri_GetScheme(This
->base_uri
, &base_scheme
);
854 if(scheme
!= base_scheme
) {
855 WARN("Schemes don't match\n");
856 return E_ACCESSDENIED
;
859 if(scheme
== INTERNET_SCHEME_UNKNOWN
) {
860 FIXME("Unknown scheme\n");
861 return E_ACCESSDENIED
;
864 hr
= IUri_GetHost(uri
, &host
);
868 hr
= IUri_GetHost(This
->base_uri
, &base_host
);
870 if(strcmpiW(host
, base_host
)) {
871 WARN("Hosts don't match\n");
874 SysFreeString(base_host
);
881 static HRESULT
httprequest_open(httprequest
*This
, BSTR method
, BSTR url
,
882 VARIANT async
, VARIANT user
, VARIANT password
)
884 static const WCHAR MethodGetW
[] = {'G','E','T',0};
885 static const WCHAR MethodPutW
[] = {'P','U','T',0};
886 static const WCHAR MethodPostW
[] = {'P','O','S','T',0};
887 static const WCHAR MethodDeleteW
[] = {'D','E','L','E','T','E',0};
888 static const WCHAR MethodPropFindW
[] = {'P','R','O','P','F','I','N','D',0};
889 VARIANT str
, is_async
;
893 if (!method
|| !url
) return E_INVALIDARG
;
895 /* free previously set data */
897 IUri_Release(This
->uri
);
901 SysFreeString(This
->user
);
902 SysFreeString(This
->password
);
903 This
->user
= This
->password
= NULL
;
904 free_request_headers(This
);
906 if (!strcmpiW(method
, MethodGetW
))
908 This
->verb
= BINDVERB_GET
;
910 else if (!strcmpiW(method
, MethodPutW
))
912 This
->verb
= BINDVERB_PUT
;
914 else if (!strcmpiW(method
, MethodPostW
))
916 This
->verb
= BINDVERB_POST
;
918 else if (!strcmpiW(method
, MethodDeleteW
) ||
919 !strcmpiW(method
, MethodPropFindW
))
921 This
->verb
= BINDVERB_CUSTOM
;
922 SysReAllocString(&This
->custom
, method
);
926 FIXME("unsupported request type %s\n", debugstr_w(method
));
932 hr
= CoInternetCombineUrlEx(This
->base_uri
, url
, 0, &uri
, 0);
934 hr
= CreateUri(url
, 0, 0, &uri
);
936 WARN("Could not create IUri object: %08x\n", hr
);
940 hr
= verify_uri(This
, uri
);
947 hr
= VariantChangeType(&str
, &user
, 0, VT_BSTR
);
949 This
->user
= V_BSTR(&str
);
952 hr
= VariantChangeType(&str
, &password
, 0, VT_BSTR
);
954 This
->password
= V_BSTR(&str
);
956 /* add authentication info */
957 if (This
->user
&& *This
->user
)
959 IUriBuilder
*builder
;
961 hr
= CreateIUriBuilder(uri
, 0, 0, &builder
);
966 IUriBuilder_SetUserName(builder
, This
->user
);
967 IUriBuilder_SetPassword(builder
, This
->password
);
968 hr
= IUriBuilder_CreateUri(builder
, -1, 0, 0, &full_uri
);
975 WARN("failed to create modified uri, 0x%08x\n", hr
);
976 IUriBuilder_Release(builder
);
979 WARN("IUriBuilder creation failed, 0x%08x\n", hr
);
984 VariantInit(&is_async
);
985 hr
= VariantChangeType(&is_async
, &async
, 0, VT_BOOL
);
986 This
->async
= hr
== S_OK
&& V_BOOL(&is_async
);
988 httprequest_setreadystate(This
, READYSTATE_LOADING
);
993 static HRESULT
httprequest_setRequestHeader(httprequest
*This
, BSTR header
, BSTR value
)
995 struct httpheader
*entry
;
997 if (!header
|| !*header
) return E_INVALIDARG
;
998 if (This
->state
!= READYSTATE_LOADING
) return E_FAIL
;
999 if (!value
) return E_INVALIDARG
;
1001 /* replace existing header value if already added */
1002 LIST_FOR_EACH_ENTRY(entry
, &This
->reqheaders
, struct httpheader
, entry
)
1004 if (lstrcmpW(entry
->header
, header
) == 0)
1006 LONG length
= SysStringLen(entry
->value
);
1009 hr
= SysReAllocString(&entry
->value
, value
) ? S_OK
: E_OUTOFMEMORY
;
1012 This
->reqheader_size
+= (SysStringLen(entry
->value
) - length
);
1018 entry
= heap_alloc(sizeof(*entry
));
1019 if (!entry
) return E_OUTOFMEMORY
;
1022 entry
->header
= SysAllocString(header
);
1023 entry
->value
= SysAllocString(value
);
1025 /* header length including null terminator */
1026 This
->reqheader_size
+= SysStringLen(entry
->header
) + sizeof(colspaceW
)/sizeof(WCHAR
) +
1027 SysStringLen(entry
->value
) + sizeof(crlfW
)/sizeof(WCHAR
) - 1;
1029 list_add_head(&This
->reqheaders
, &entry
->entry
);
1034 static HRESULT
httprequest_getResponseHeader(httprequest
*This
, BSTR header
, BSTR
*value
)
1036 struct httpheader
*entry
;
1038 if (!header
) return E_INVALIDARG
;
1039 if (!value
) return E_POINTER
;
1041 if (This
->raw_respheaders
&& list_empty(&This
->respheaders
))
1045 ptr
= line
= This
->raw_respheaders
;
1048 if (*ptr
== '\r' && *(ptr
+1) == '\n')
1050 add_response_header(This
, line
, ptr
-line
);
1051 ptr
++; line
= ++ptr
;
1058 LIST_FOR_EACH_ENTRY(entry
, &This
->respheaders
, struct httpheader
, entry
)
1060 if (!strcmpiW(entry
->header
, header
))
1062 *value
= SysAllocString(entry
->value
);
1063 TRACE("header value %s\n", debugstr_w(*value
));
1071 static HRESULT
httprequest_getAllResponseHeaders(httprequest
*This
, BSTR
*respheaders
)
1073 if (!respheaders
) return E_POINTER
;
1075 *respheaders
= SysAllocString(This
->raw_respheaders
);
1080 static HRESULT
httprequest_send(httprequest
*This
, VARIANT body
)
1082 BindStatusCallback
*bsc
= NULL
;
1085 if (This
->state
!= READYSTATE_LOADING
) return E_FAIL
;
1087 hr
= BindStatusCallback_create(This
, &bsc
, &body
);
1089 /* success path to detach it is OnStopBinding call */
1090 BindStatusCallback_Detach(bsc
);
1095 static HRESULT
httprequest_abort(httprequest
*This
)
1097 BindStatusCallback_Detach(This
->bsc
);
1099 httprequest_setreadystate(This
, READYSTATE_UNINITIALIZED
);
1104 static HRESULT
httprequest_get_status(httprequest
*This
, LONG
*status
)
1106 if (!status
) return E_POINTER
;
1108 *status
= This
->status
;
1110 return This
->state
== READYSTATE_COMPLETE
? S_OK
: E_FAIL
;
1113 static HRESULT
httprequest_get_statusText(httprequest
*This
, BSTR
*status
)
1115 if (!status
) return E_POINTER
;
1116 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
1118 *status
= SysAllocString(This
->status_text
);
1123 static HRESULT
httprequest_get_responseText(httprequest
*This
, BSTR
*body
)
1128 if (!body
) return E_POINTER
;
1129 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
1131 hr
= GetHGlobalFromStream(This
->bsc
->stream
, &hglobal
);
1134 xmlChar
*ptr
= GlobalLock(hglobal
);
1135 DWORD size
= GlobalSize(hglobal
);
1136 xmlCharEncoding encoding
= XML_CHAR_ENCODING_UTF8
;
1138 /* try to determine data encoding */
1141 encoding
= xmlDetectCharEncoding(ptr
, 4);
1142 TRACE("detected encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding
)));
1143 if ( encoding
!= XML_CHAR_ENCODING_UTF8
&&
1144 encoding
!= XML_CHAR_ENCODING_UTF16LE
&&
1145 encoding
!= XML_CHAR_ENCODING_NONE
)
1147 FIXME("unsupported encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding
)));
1148 GlobalUnlock(hglobal
);
1153 /* without BOM assume UTF-8 */
1154 if (encoding
== XML_CHAR_ENCODING_UTF8
||
1155 encoding
== XML_CHAR_ENCODING_NONE
)
1157 DWORD length
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)ptr
, size
, NULL
, 0);
1159 *body
= SysAllocStringLen(NULL
, length
);
1161 MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
)ptr
, size
, *body
, length
);
1164 *body
= SysAllocStringByteLen((LPCSTR
)ptr
, size
);
1166 if (!*body
) hr
= E_OUTOFMEMORY
;
1167 GlobalUnlock(hglobal
);
1173 static HRESULT
httprequest_get_responseXML(httprequest
*This
, IDispatch
**body
)
1175 IXMLDOMDocument3
*doc
;
1179 if (!body
) return E_INVALIDARG
;
1180 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
1182 hr
= DOMDocument_create(MSXML_DEFAULT
, (void**)&doc
);
1183 if (hr
!= S_OK
) return hr
;
1185 hr
= httprequest_get_responseText(This
, &str
);
1190 hr
= IXMLDOMDocument3_loadXML(doc
, str
, &ok
);
1194 IXMLDOMDocument3_QueryInterface(doc
, &IID_IDispatch
, (void**)body
);
1195 IXMLDOMDocument3_Release(doc
);
1200 static HRESULT
httprequest_get_responseBody(httprequest
*This
, VARIANT
*body
)
1205 if (!body
) return E_INVALIDARG
;
1206 V_VT(body
) = VT_EMPTY
;
1208 if (This
->state
!= READYSTATE_COMPLETE
) return E_PENDING
;
1210 hr
= GetHGlobalFromStream(This
->bsc
->stream
, &hglobal
);
1213 void *ptr
= GlobalLock(hglobal
);
1214 DWORD size
= GlobalSize(hglobal
);
1216 SAFEARRAYBOUND bound
;
1220 bound
.cElements
= size
;
1221 array
= SafeArrayCreate(VT_UI1
, 1, &bound
);
1227 V_VT(body
) = VT_ARRAY
| VT_UI1
;
1228 V_ARRAY(body
) = array
;
1230 hr
= SafeArrayAccessData(array
, &dest
);
1233 memcpy(dest
, ptr
, size
);
1234 SafeArrayUnaccessData(array
);
1244 GlobalUnlock(hglobal
);
1250 static HRESULT
httprequest_get_responseStream(httprequest
*This
, VARIANT
*body
)
1256 if (!body
) return E_INVALIDARG
;
1257 V_VT(body
) = VT_EMPTY
;
1259 if (This
->state
!= READYSTATE_COMPLETE
) return E_PENDING
;
1261 hr
= IStream_Clone(This
->bsc
->stream
, &stream
);
1264 IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
1266 V_VT(body
) = VT_UNKNOWN
;
1267 V_UNKNOWN(body
) = (IUnknown
*)stream
;
1272 static HRESULT
httprequest_get_readyState(httprequest
*This
, LONG
*state
)
1274 if (!state
) return E_POINTER
;
1276 *state
= This
->state
;
1280 static HRESULT
httprequest_put_onreadystatechange(httprequest
*This
, IDispatch
*sink
)
1282 if (This
->sink
) IDispatch_Release(This
->sink
);
1283 if ((This
->sink
= sink
)) IDispatch_AddRef(This
->sink
);
1288 static void httprequest_release(httprequest
*This
)
1291 IUnknown_Release( This
->site
);
1293 IUri_Release(This
->uri
);
1295 IUri_Release(This
->base_uri
);
1297 SysFreeString(This
->custom
);
1298 SysFreeString(This
->user
);
1299 SysFreeString(This
->password
);
1301 /* cleanup headers lists */
1302 free_request_headers(This
);
1303 free_response_headers(This
);
1304 SysFreeString(This
->status_text
);
1306 /* detach callback object */
1307 BindStatusCallback_Detach(This
->bsc
);
1309 if (This
->sink
) IDispatch_Release(This
->sink
);
1312 static HRESULT WINAPI
XMLHTTPRequest_QueryInterface(IXMLHTTPRequest
*iface
, REFIID riid
, void **ppvObject
)
1314 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1315 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1317 if ( IsEqualGUID( riid
, &IID_IXMLHTTPRequest
) ||
1318 IsEqualGUID( riid
, &IID_IDispatch
) ||
1319 IsEqualGUID( riid
, &IID_IUnknown
) )
1323 else if (IsEqualGUID(&IID_IObjectWithSite
, riid
))
1325 *ppvObject
= &This
->IObjectWithSite_iface
;
1327 else if (IsEqualGUID(&IID_IObjectSafety
, riid
))
1329 *ppvObject
= &This
->IObjectSafety_iface
;
1333 TRACE("Unsupported interface %s\n", debugstr_guid(riid
));
1335 return E_NOINTERFACE
;
1338 IXMLHTTPRequest_AddRef( iface
);
1343 static ULONG WINAPI
XMLHTTPRequest_AddRef(IXMLHTTPRequest
*iface
)
1345 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1346 ULONG ref
= InterlockedIncrement( &This
->ref
);
1347 TRACE("(%p)->(%u)\n", This
, ref
);
1351 static ULONG WINAPI
XMLHTTPRequest_Release(IXMLHTTPRequest
*iface
)
1353 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1354 ULONG ref
= InterlockedDecrement( &This
->ref
);
1356 TRACE("(%p)->(%u)\n", This
, ref
);
1360 httprequest_release( This
);
1367 static HRESULT WINAPI
XMLHTTPRequest_GetTypeInfoCount(IXMLHTTPRequest
*iface
, UINT
*pctinfo
)
1369 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1371 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1378 static HRESULT WINAPI
XMLHTTPRequest_GetTypeInfo(IXMLHTTPRequest
*iface
, UINT iTInfo
,
1379 LCID lcid
, ITypeInfo
**ppTInfo
)
1381 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1383 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1385 return get_typeinfo(IXMLHTTPRequest_tid
, ppTInfo
);
1388 static HRESULT WINAPI
XMLHTTPRequest_GetIDsOfNames(IXMLHTTPRequest
*iface
, REFIID riid
,
1389 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1391 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1392 ITypeInfo
*typeinfo
;
1395 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1398 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1399 return E_INVALIDARG
;
1401 hr
= get_typeinfo(IXMLHTTPRequest_tid
, &typeinfo
);
1404 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1405 ITypeInfo_Release(typeinfo
);
1411 static HRESULT WINAPI
XMLHTTPRequest_Invoke(IXMLHTTPRequest
*iface
, DISPID dispIdMember
, REFIID riid
,
1412 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1413 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1415 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1416 ITypeInfo
*typeinfo
;
1419 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1420 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1422 hr
= get_typeinfo(IXMLHTTPRequest_tid
, &typeinfo
);
1425 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLHTTPRequest_iface
, dispIdMember
, wFlags
,
1426 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1427 ITypeInfo_Release(typeinfo
);
1433 static HRESULT WINAPI
XMLHTTPRequest_open(IXMLHTTPRequest
*iface
, BSTR method
, BSTR url
,
1434 VARIANT async
, VARIANT user
, VARIANT password
)
1436 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1437 TRACE("(%p)->(%s %s %s)\n", This
, debugstr_w(method
), debugstr_w(url
),
1438 debugstr_variant(&async
));
1439 return httprequest_open(This
, method
, url
, async
, user
, password
);
1442 static HRESULT WINAPI
XMLHTTPRequest_setRequestHeader(IXMLHTTPRequest
*iface
, BSTR header
, BSTR value
)
1444 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1445 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(header
), debugstr_w(value
));
1446 return httprequest_setRequestHeader(This
, header
, value
);
1449 static HRESULT WINAPI
XMLHTTPRequest_getResponseHeader(IXMLHTTPRequest
*iface
, BSTR header
, BSTR
*value
)
1451 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1452 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(header
), value
);
1453 return httprequest_getResponseHeader(This
, header
, value
);
1456 static HRESULT WINAPI
XMLHTTPRequest_getAllResponseHeaders(IXMLHTTPRequest
*iface
, BSTR
*respheaders
)
1458 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1459 TRACE("(%p)->(%p)\n", This
, respheaders
);
1460 return httprequest_getAllResponseHeaders(This
, respheaders
);
1463 static HRESULT WINAPI
XMLHTTPRequest_send(IXMLHTTPRequest
*iface
, VARIANT body
)
1465 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1466 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&body
));
1467 return httprequest_send(This
, body
);
1470 static HRESULT WINAPI
XMLHTTPRequest_abort(IXMLHTTPRequest
*iface
)
1472 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1473 TRACE("(%p)\n", This
);
1474 return httprequest_abort(This
);
1477 static HRESULT WINAPI
XMLHTTPRequest_get_status(IXMLHTTPRequest
*iface
, LONG
*status
)
1479 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1480 TRACE("(%p)->(%p)\n", This
, status
);
1481 return httprequest_get_status(This
, status
);
1484 static HRESULT WINAPI
XMLHTTPRequest_get_statusText(IXMLHTTPRequest
*iface
, BSTR
*status
)
1486 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1487 TRACE("(%p)->(%p)\n", This
, status
);
1488 return httprequest_get_statusText(This
, status
);
1491 static HRESULT WINAPI
XMLHTTPRequest_get_responseXML(IXMLHTTPRequest
*iface
, IDispatch
**body
)
1493 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1494 TRACE("(%p)->(%p)\n", This
, body
);
1495 return httprequest_get_responseXML(This
, body
);
1498 static HRESULT WINAPI
XMLHTTPRequest_get_responseText(IXMLHTTPRequest
*iface
, BSTR
*body
)
1500 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1501 TRACE("(%p)->(%p)\n", This
, body
);
1502 return httprequest_get_responseText(This
, body
);
1505 static HRESULT WINAPI
XMLHTTPRequest_get_responseBody(IXMLHTTPRequest
*iface
, VARIANT
*body
)
1507 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1508 TRACE("(%p)->(%p)\n", This
, body
);
1509 return httprequest_get_responseBody(This
, body
);
1512 static HRESULT WINAPI
XMLHTTPRequest_get_responseStream(IXMLHTTPRequest
*iface
, VARIANT
*body
)
1514 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1515 TRACE("(%p)->(%p)\n", This
, body
);
1516 return httprequest_get_responseStream(This
, body
);
1519 static HRESULT WINAPI
XMLHTTPRequest_get_readyState(IXMLHTTPRequest
*iface
, LONG
*state
)
1521 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1522 TRACE("(%p)->(%p)\n", This
, state
);
1523 return httprequest_get_readyState(This
, state
);
1526 static HRESULT WINAPI
XMLHTTPRequest_put_onreadystatechange(IXMLHTTPRequest
*iface
, IDispatch
*sink
)
1528 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1529 TRACE("(%p)->(%p)\n", This
, sink
);
1530 return httprequest_put_onreadystatechange(This
, sink
);
1533 static const struct IXMLHTTPRequestVtbl XMLHTTPRequestVtbl
=
1535 XMLHTTPRequest_QueryInterface
,
1536 XMLHTTPRequest_AddRef
,
1537 XMLHTTPRequest_Release
,
1538 XMLHTTPRequest_GetTypeInfoCount
,
1539 XMLHTTPRequest_GetTypeInfo
,
1540 XMLHTTPRequest_GetIDsOfNames
,
1541 XMLHTTPRequest_Invoke
,
1542 XMLHTTPRequest_open
,
1543 XMLHTTPRequest_setRequestHeader
,
1544 XMLHTTPRequest_getResponseHeader
,
1545 XMLHTTPRequest_getAllResponseHeaders
,
1546 XMLHTTPRequest_send
,
1547 XMLHTTPRequest_abort
,
1548 XMLHTTPRequest_get_status
,
1549 XMLHTTPRequest_get_statusText
,
1550 XMLHTTPRequest_get_responseXML
,
1551 XMLHTTPRequest_get_responseText
,
1552 XMLHTTPRequest_get_responseBody
,
1553 XMLHTTPRequest_get_responseStream
,
1554 XMLHTTPRequest_get_readyState
,
1555 XMLHTTPRequest_put_onreadystatechange
1558 /* IObjectWithSite */
1559 static HRESULT WINAPI
1560 httprequest_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
1562 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1563 return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest
*)This
, riid
, ppvObject
);
1566 static ULONG WINAPI
httprequest_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
1568 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1569 return IXMLHTTPRequest_AddRef((IXMLHTTPRequest
*)This
);
1572 static ULONG WINAPI
httprequest_ObjectWithSite_Release( IObjectWithSite
* iface
)
1574 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1575 return IXMLHTTPRequest_Release((IXMLHTTPRequest
*)This
);
1578 static HRESULT WINAPI
httprequest_ObjectWithSite_GetSite( IObjectWithSite
*iface
, REFIID iid
, void **ppvSite
)
1580 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1582 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid( iid
), ppvSite
);
1587 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
1590 static void get_base_uri(httprequest
*This
)
1592 IServiceProvider
*provider
;
1593 IHTMLDocument2
*doc
;
1598 hr
= IUnknown_QueryInterface(This
->site
, &IID_IServiceProvider
, (void**)&provider
);
1602 hr
= IServiceProvider_QueryService(provider
, &SID_SContainerDispatch
, &IID_IHTMLDocument2
, (void**)&doc
);
1604 hr
= IServiceProvider_QueryService(provider
, &SID_SInternetHostSecurityManager
, &IID_IHTMLDocument2
, (void**)&doc
);
1605 IServiceProvider_Release(provider
);
1609 hr
= IHTMLDocument2_get_URL(doc
, &url
);
1610 IHTMLDocument2_Release(doc
);
1611 if(FAILED(hr
) || !url
|| !*url
)
1614 TRACE("host url %s\n", debugstr_w(url
));
1616 hr
= CreateUri(url
, 0, 0, &uri
);
1621 This
->base_uri
= uri
;
1624 static HRESULT WINAPI
httprequest_ObjectWithSite_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
1626 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1628 TRACE("(%p)->(%p)\n", This
, punk
);
1631 IUnknown_Release( This
->site
);
1633 IUri_Release(This
->base_uri
);
1639 IUnknown_AddRef( punk
);
1646 static const IObjectWithSiteVtbl ObjectWithSiteVtbl
=
1648 httprequest_ObjectWithSite_QueryInterface
,
1649 httprequest_ObjectWithSite_AddRef
,
1650 httprequest_ObjectWithSite_Release
,
1651 httprequest_ObjectWithSite_SetSite
,
1652 httprequest_ObjectWithSite_GetSite
1656 static HRESULT WINAPI
httprequest_Safety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
1658 httprequest
*This
= impl_from_IObjectSafety(iface
);
1659 return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest
*)This
, riid
, ppv
);
1662 static ULONG WINAPI
httprequest_Safety_AddRef(IObjectSafety
*iface
)
1664 httprequest
*This
= impl_from_IObjectSafety(iface
);
1665 return IXMLHTTPRequest_AddRef((IXMLHTTPRequest
*)This
);
1668 static ULONG WINAPI
httprequest_Safety_Release(IObjectSafety
*iface
)
1670 httprequest
*This
= impl_from_IObjectSafety(iface
);
1671 return IXMLHTTPRequest_Release((IXMLHTTPRequest
*)This
);
1674 static HRESULT WINAPI
httprequest_Safety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1675 DWORD
*supported
, DWORD
*enabled
)
1677 httprequest
*This
= impl_from_IObjectSafety(iface
);
1679 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), supported
, enabled
);
1681 if(!supported
|| !enabled
) return E_POINTER
;
1683 *supported
= safety_supported_options
;
1684 *enabled
= This
->safeopt
;
1689 static HRESULT WINAPI
httprequest_Safety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1690 DWORD mask
, DWORD enabled
)
1692 httprequest
*This
= impl_from_IObjectSafety(iface
);
1693 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), mask
, enabled
);
1695 if ((mask
& ~safety_supported_options
))
1698 This
->safeopt
= (This
->safeopt
& ~mask
) | (mask
& enabled
);
1703 static const IObjectSafetyVtbl ObjectSafetyVtbl
= {
1704 httprequest_Safety_QueryInterface
,
1705 httprequest_Safety_AddRef
,
1706 httprequest_Safety_Release
,
1707 httprequest_Safety_GetInterfaceSafetyOptions
,
1708 httprequest_Safety_SetInterfaceSafetyOptions
1711 /* IServerXMLHTTPRequest */
1712 static HRESULT WINAPI
ServerXMLHTTPRequest_QueryInterface(IServerXMLHTTPRequest
*iface
, REFIID riid
, void **obj
)
1714 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1716 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1718 if ( IsEqualGUID( riid
, &IID_IServerXMLHTTPRequest
) ||
1719 IsEqualGUID( riid
, &IID_IXMLHTTPRequest
) ||
1720 IsEqualGUID( riid
, &IID_IDispatch
) ||
1721 IsEqualGUID( riid
, &IID_IUnknown
) )
1727 TRACE("Unsupported interface %s\n", debugstr_guid(riid
));
1729 return E_NOINTERFACE
;
1732 IServerXMLHTTPRequest_AddRef( iface
);
1737 static ULONG WINAPI
ServerXMLHTTPRequest_AddRef(IServerXMLHTTPRequest
*iface
)
1739 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1740 ULONG ref
= InterlockedIncrement( &This
->ref
);
1741 TRACE("(%p)->(%u)\n", This
, ref
);
1745 static ULONG WINAPI
ServerXMLHTTPRequest_Release(IServerXMLHTTPRequest
*iface
)
1747 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1748 ULONG ref
= InterlockedDecrement( &This
->ref
);
1750 TRACE("(%p)->(%u)\n", This
, ref
);
1754 httprequest_release( &This
->req
);
1761 static HRESULT WINAPI
ServerXMLHTTPRequest_GetTypeInfoCount(IServerXMLHTTPRequest
*iface
, UINT
*pctinfo
)
1763 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1765 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1771 static HRESULT WINAPI
ServerXMLHTTPRequest_GetTypeInfo(IServerXMLHTTPRequest
*iface
, UINT iTInfo
,
1772 LCID lcid
, ITypeInfo
**ppTInfo
)
1774 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1776 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1778 return get_typeinfo(IServerXMLHTTPRequest_tid
, ppTInfo
);
1781 static HRESULT WINAPI
ServerXMLHTTPRequest_GetIDsOfNames(IServerXMLHTTPRequest
*iface
, REFIID riid
,
1782 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1784 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1785 ITypeInfo
*typeinfo
;
1788 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1791 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1792 return E_INVALIDARG
;
1794 hr
= get_typeinfo(IServerXMLHTTPRequest_tid
, &typeinfo
);
1797 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1798 ITypeInfo_Release(typeinfo
);
1804 static HRESULT WINAPI
ServerXMLHTTPRequest_Invoke(IServerXMLHTTPRequest
*iface
, DISPID dispIdMember
, REFIID riid
,
1805 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1806 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1808 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1809 ITypeInfo
*typeinfo
;
1812 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1813 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1815 hr
= get_typeinfo(IServerXMLHTTPRequest_tid
, &typeinfo
);
1818 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IServerXMLHTTPRequest_iface
, dispIdMember
, wFlags
,
1819 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1820 ITypeInfo_Release(typeinfo
);
1826 static HRESULT WINAPI
ServerXMLHTTPRequest_open(IServerXMLHTTPRequest
*iface
, BSTR method
, BSTR url
,
1827 VARIANT async
, VARIANT user
, VARIANT password
)
1829 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1830 TRACE("(%p)->(%s %s %s)\n", This
, debugstr_w(method
), debugstr_w(url
),
1831 debugstr_variant(&async
));
1832 return httprequest_open(&This
->req
, method
, url
, async
, user
, password
);
1835 static HRESULT WINAPI
ServerXMLHTTPRequest_setRequestHeader(IServerXMLHTTPRequest
*iface
, BSTR header
, BSTR value
)
1837 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1838 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(header
), debugstr_w(value
));
1839 return httprequest_setRequestHeader(&This
->req
, header
, value
);
1842 static HRESULT WINAPI
ServerXMLHTTPRequest_getResponseHeader(IServerXMLHTTPRequest
*iface
, BSTR header
, BSTR
*value
)
1844 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1845 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(header
), value
);
1846 return httprequest_getResponseHeader(&This
->req
, header
, value
);
1849 static HRESULT WINAPI
ServerXMLHTTPRequest_getAllResponseHeaders(IServerXMLHTTPRequest
*iface
, BSTR
*respheaders
)
1851 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1852 TRACE("(%p)->(%p)\n", This
, respheaders
);
1853 return httprequest_getAllResponseHeaders(&This
->req
, respheaders
);
1856 static HRESULT WINAPI
ServerXMLHTTPRequest_send(IServerXMLHTTPRequest
*iface
, VARIANT body
)
1858 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1859 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&body
));
1860 return httprequest_send(&This
->req
, body
);
1863 static HRESULT WINAPI
ServerXMLHTTPRequest_abort(IServerXMLHTTPRequest
*iface
)
1865 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1866 TRACE("(%p)\n", This
);
1867 return httprequest_abort(&This
->req
);
1870 static HRESULT WINAPI
ServerXMLHTTPRequest_get_status(IServerXMLHTTPRequest
*iface
, LONG
*status
)
1872 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1873 TRACE("(%p)->(%p)\n", This
, status
);
1874 return httprequest_get_status(&This
->req
, status
);
1877 static HRESULT WINAPI
ServerXMLHTTPRequest_get_statusText(IServerXMLHTTPRequest
*iface
, BSTR
*status
)
1879 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1880 TRACE("(%p)->(%p)\n", This
, status
);
1881 return httprequest_get_statusText(&This
->req
, status
);
1884 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseXML(IServerXMLHTTPRequest
*iface
, IDispatch
**body
)
1886 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1887 TRACE("(%p)->(%p)\n", This
, body
);
1888 return httprequest_get_responseXML(&This
->req
, body
);
1891 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseText(IServerXMLHTTPRequest
*iface
, BSTR
*body
)
1893 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1894 TRACE("(%p)->(%p)\n", This
, body
);
1895 return httprequest_get_responseText(&This
->req
, body
);
1898 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseBody(IServerXMLHTTPRequest
*iface
, VARIANT
*body
)
1900 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1901 TRACE("(%p)->(%p)\n", This
, body
);
1902 return httprequest_get_responseBody(&This
->req
, body
);
1905 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseStream(IServerXMLHTTPRequest
*iface
, VARIANT
*body
)
1907 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1908 TRACE("(%p)->(%p)\n", This
, body
);
1909 return httprequest_get_responseStream(&This
->req
, body
);
1912 static HRESULT WINAPI
ServerXMLHTTPRequest_get_readyState(IServerXMLHTTPRequest
*iface
, LONG
*state
)
1914 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1915 TRACE("(%p)->(%p)\n", This
, state
);
1916 return httprequest_get_readyState(&This
->req
, state
);
1919 static HRESULT WINAPI
ServerXMLHTTPRequest_put_onreadystatechange(IServerXMLHTTPRequest
*iface
, IDispatch
*sink
)
1921 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1922 TRACE("(%p)->(%p)\n", This
, sink
);
1923 return httprequest_put_onreadystatechange(&This
->req
, sink
);
1926 static HRESULT WINAPI
ServerXMLHTTPRequest_setTimeouts(IServerXMLHTTPRequest
*iface
, LONG resolveTimeout
, LONG connectTimeout
,
1927 LONG sendTimeout
, LONG receiveTimeout
)
1929 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1930 FIXME("(%p)->(%d %d %d %d): stub\n", This
, resolveTimeout
, connectTimeout
, sendTimeout
, receiveTimeout
);
1934 static HRESULT WINAPI
ServerXMLHTTPRequest_waitForResponse(IServerXMLHTTPRequest
*iface
, VARIANT timeout
, VARIANT_BOOL
*isSuccessful
)
1936 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1937 FIXME("(%p)->(%s %p): stub\n", This
, debugstr_variant(&timeout
), isSuccessful
);
1941 static HRESULT WINAPI
ServerXMLHTTPRequest_getOption(IServerXMLHTTPRequest
*iface
, SERVERXMLHTTP_OPTION option
, VARIANT
*value
)
1943 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1944 FIXME("(%p)->(%d %p): stub\n", This
, option
, value
);
1948 static HRESULT WINAPI
ServerXMLHTTPRequest_setOption(IServerXMLHTTPRequest
*iface
, SERVERXMLHTTP_OPTION option
, VARIANT value
)
1950 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1951 FIXME("(%p)->(%d %s): stub\n", This
, option
, debugstr_variant(&value
));
1955 static const struct IServerXMLHTTPRequestVtbl ServerXMLHTTPRequestVtbl
=
1957 ServerXMLHTTPRequest_QueryInterface
,
1958 ServerXMLHTTPRequest_AddRef
,
1959 ServerXMLHTTPRequest_Release
,
1960 ServerXMLHTTPRequest_GetTypeInfoCount
,
1961 ServerXMLHTTPRequest_GetTypeInfo
,
1962 ServerXMLHTTPRequest_GetIDsOfNames
,
1963 ServerXMLHTTPRequest_Invoke
,
1964 ServerXMLHTTPRequest_open
,
1965 ServerXMLHTTPRequest_setRequestHeader
,
1966 ServerXMLHTTPRequest_getResponseHeader
,
1967 ServerXMLHTTPRequest_getAllResponseHeaders
,
1968 ServerXMLHTTPRequest_send
,
1969 ServerXMLHTTPRequest_abort
,
1970 ServerXMLHTTPRequest_get_status
,
1971 ServerXMLHTTPRequest_get_statusText
,
1972 ServerXMLHTTPRequest_get_responseXML
,
1973 ServerXMLHTTPRequest_get_responseText
,
1974 ServerXMLHTTPRequest_get_responseBody
,
1975 ServerXMLHTTPRequest_get_responseStream
,
1976 ServerXMLHTTPRequest_get_readyState
,
1977 ServerXMLHTTPRequest_put_onreadystatechange
,
1978 ServerXMLHTTPRequest_setTimeouts
,
1979 ServerXMLHTTPRequest_waitForResponse
,
1980 ServerXMLHTTPRequest_getOption
,
1981 ServerXMLHTTPRequest_setOption
1984 static void init_httprequest(httprequest
*req
)
1986 req
->IXMLHTTPRequest_iface
.lpVtbl
= &XMLHTTPRequestVtbl
;
1987 req
->IObjectWithSite_iface
.lpVtbl
= &ObjectWithSiteVtbl
;
1988 req
->IObjectSafety_iface
.lpVtbl
= &ObjectSafetyVtbl
;
1994 req
->uri
= req
->base_uri
= NULL
;
1995 req
->user
= req
->password
= NULL
;
1997 req
->state
= READYSTATE_UNINITIALIZED
;
2002 req
->status_text
= NULL
;
2003 req
->reqheader_size
= 0;
2004 req
->raw_respheaders
= NULL
;
2005 req
->use_utf8_content
= FALSE
;
2007 list_init(&req
->reqheaders
);
2008 list_init(&req
->respheaders
);
2014 HRESULT
XMLHTTPRequest_create(void **obj
)
2018 TRACE("(%p)\n", obj
);
2020 req
= heap_alloc( sizeof (*req
) );
2022 return E_OUTOFMEMORY
;
2024 init_httprequest(req
);
2025 *obj
= &req
->IXMLHTTPRequest_iface
;
2027 TRACE("returning iface %p\n", *obj
);
2032 HRESULT
ServerXMLHTTP_create(void **obj
)
2036 TRACE("(%p)\n", obj
);
2038 req
= heap_alloc( sizeof (*req
) );
2040 return E_OUTOFMEMORY
;
2042 init_httprequest(&req
->req
);
2043 req
->IServerXMLHTTPRequest_iface
.lpVtbl
= &ServerXMLHTTPRequestVtbl
;
2046 *obj
= &req
->IServerXMLHTTPRequest_iface
;
2048 TRACE("returning iface %p\n", *obj
);
2055 HRESULT
XMLHTTPRequest_create(void **ppObj
)
2057 MESSAGE("This program tried to use a XMLHTTPRequest object, but\n"
2058 "libxml2 support was not present at compile time.\n");
2062 HRESULT
ServerXMLHTTP_create(void **obj
)
2064 MESSAGE("This program tried to use a ServerXMLHTTP object, but\n"
2065 "libxml2 support was not present at compile time.\n");