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
;
76 ISupportErrorInfo ISupportErrorInfo_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
;
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 httprequest
*impl_from_ISupportErrorInfo(ISupportErrorInfo
*iface
)
137 return CONTAINING_RECORD(iface
, httprequest
, ISupportErrorInfo_iface
);
140 static inline serverhttp
*impl_from_IServerXMLHTTPRequest(IServerXMLHTTPRequest
*iface
)
142 return CONTAINING_RECORD(iface
, serverhttp
, IServerXMLHTTPRequest_iface
);
145 static void httprequest_setreadystate(httprequest
*This
, READYSTATE state
)
147 READYSTATE last
= This
->state
;
148 static const char* readystates
[] = {
149 "READYSTATE_UNINITIALIZED",
150 "READYSTATE_LOADING",
152 "READYSTATE_INTERACTIVE",
153 "READYSTATE_COMPLETE"};
157 TRACE("state %s\n", readystates
[state
]);
159 if (This
->sink
&& last
!= state
)
163 memset(¶ms
, 0, sizeof(params
));
164 IDispatch_Invoke(This
->sink
, 0, &IID_NULL
, LOCALE_SYSTEM_DEFAULT
, DISPATCH_METHOD
, ¶ms
, 0, 0, 0);
168 static void free_response_headers(httprequest
*This
)
170 struct httpheader
*header
, *header2
;
172 LIST_FOR_EACH_ENTRY_SAFE(header
, header2
, &This
->respheaders
, struct httpheader
, entry
)
174 list_remove(&header
->entry
);
175 SysFreeString(header
->header
);
176 SysFreeString(header
->value
);
180 SysFreeString(This
->raw_respheaders
);
181 This
->raw_respheaders
= NULL
;
184 static void free_request_headers(httprequest
*This
)
186 struct httpheader
*header
, *header2
;
188 LIST_FOR_EACH_ENTRY_SAFE(header
, header2
, &This
->reqheaders
, struct httpheader
, entry
)
190 list_remove(&header
->entry
);
191 SysFreeString(header
->header
);
192 SysFreeString(header
->value
);
197 struct BindStatusCallback
199 IBindStatusCallback IBindStatusCallback_iface
;
200 IHttpNegotiate IHttpNegotiate_iface
;
201 IAuthenticate IAuthenticate_iface
;
205 httprequest
*request
;
210 /* request body data */
214 static inline BindStatusCallback
*impl_from_IBindStatusCallback( IBindStatusCallback
*iface
)
216 return CONTAINING_RECORD(iface
, BindStatusCallback
, IBindStatusCallback_iface
);
219 static inline BindStatusCallback
*impl_from_IHttpNegotiate( IHttpNegotiate
*iface
)
221 return CONTAINING_RECORD(iface
, BindStatusCallback
, IHttpNegotiate_iface
);
224 static inline BindStatusCallback
*impl_from_IAuthenticate( IAuthenticate
*iface
)
226 return CONTAINING_RECORD(iface
, BindStatusCallback
, IAuthenticate_iface
);
229 static void BindStatusCallback_Detach(BindStatusCallback
*bsc
)
233 if (bsc
->binding
) IBinding_Abort(bsc
->binding
);
234 bsc
->request
->bsc
= NULL
;
236 IBindStatusCallback_Release(&bsc
->IBindStatusCallback_iface
);
240 static HRESULT WINAPI
BindStatusCallback_QueryInterface(IBindStatusCallback
*iface
,
241 REFIID riid
, void **ppv
)
243 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
247 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
249 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
250 IsEqualGUID(&IID_IBindStatusCallback
, riid
))
252 *ppv
= &This
->IBindStatusCallback_iface
;
254 else if (IsEqualGUID(&IID_IHttpNegotiate
, riid
))
256 *ppv
= &This
->IHttpNegotiate_iface
;
258 else if (IsEqualGUID(&IID_IAuthenticate
, riid
))
260 *ppv
= &This
->IAuthenticate_iface
;
262 else if (IsEqualGUID(&IID_IServiceProvider
, riid
) ||
263 IsEqualGUID(&IID_IBindStatusCallbackEx
, riid
) ||
264 IsEqualGUID(&IID_IInternetProtocol
, riid
) ||
265 IsEqualGUID(&IID_IHttpNegotiate2
, riid
))
267 return E_NOINTERFACE
;
272 IBindStatusCallback_AddRef(iface
);
276 FIXME("Unsupported riid = %s\n", debugstr_guid(riid
));
278 return E_NOINTERFACE
;
281 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
283 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
284 LONG ref
= InterlockedIncrement(&This
->ref
);
286 TRACE("(%p) ref = %d\n", This
, ref
);
291 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
293 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
294 LONG ref
= InterlockedDecrement(&This
->ref
);
296 TRACE("(%p) ref = %d\n", This
, ref
);
300 if (This
->binding
) IBinding_Release(This
->binding
);
301 if (This
->stream
) IStream_Release(This
->stream
);
302 if (This
->body
) GlobalFree(This
->body
);
309 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
310 DWORD reserved
, IBinding
*pbind
)
312 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
314 TRACE("(%p)->(%d %p)\n", This
, reserved
, pbind
);
316 if (!pbind
) return E_INVALIDARG
;
318 This
->binding
= pbind
;
319 IBinding_AddRef(pbind
);
321 httprequest_setreadystate(This
->request
, READYSTATE_LOADED
);
323 return CreateStreamOnHGlobal(NULL
, TRUE
, &This
->stream
);
326 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
, LONG
*pPriority
)
328 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
330 TRACE("(%p)->(%p)\n", This
, pPriority
);
335 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
, DWORD reserved
)
337 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
339 TRACE("(%p)->(%d)\n", This
, reserved
);
344 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
345 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
347 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
349 TRACE("(%p)->(%u %u %u %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
350 debugstr_w(szStatusText
));
355 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
356 HRESULT hr
, LPCWSTR error
)
358 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
360 TRACE("(%p)->(0x%08x %s)\n", This
, hr
, debugstr_w(error
));
364 IBinding_Release(This
->binding
);
365 This
->binding
= NULL
;
370 BindStatusCallback_Detach(This
->request
->bsc
);
371 This
->request
->bsc
= This
;
372 httprequest_setreadystate(This
->request
, READYSTATE_COMPLETE
);
378 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
379 DWORD
*bind_flags
, BINDINFO
*pbindinfo
)
381 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
383 TRACE("(%p)->(%p %p)\n", This
, bind_flags
, pbindinfo
);
386 if (This
->request
->async
) *bind_flags
|= BINDF_ASYNCHRONOUS
;
388 if (This
->request
->verb
!= BINDVERB_GET
&& This
->body
)
390 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
391 pbindinfo
->stgmedData
.u
.hGlobal
= This
->body
;
392 pbindinfo
->cbstgmedData
= GlobalSize(This
->body
);
393 /* callback owns passed body pointer */
394 IBindStatusCallback_QueryInterface(iface
, &IID_IUnknown
, (void**)&pbindinfo
->stgmedData
.pUnkForRelease
);
397 pbindinfo
->dwBindVerb
= This
->request
->verb
;
398 if (This
->request
->verb
== BINDVERB_CUSTOM
)
400 pbindinfo
->szCustomVerb
= CoTaskMemAlloc(SysStringByteLen(This
->request
->custom
)+sizeof(WCHAR
));
401 strcpyW(pbindinfo
->szCustomVerb
, This
->request
->custom
);
407 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
408 DWORD flags
, DWORD size
, FORMATETC
*format
, STGMEDIUM
*stgmed
)
410 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
415 TRACE("(%p)->(%08x %d %p %p)\n", This
, flags
, size
, format
, stgmed
);
419 hr
= IStream_Read(stgmed
->u
.pstm
, buf
, sizeof(buf
), &read
);
420 if (hr
!= S_OK
) break;
422 hr
= IStream_Write(This
->stream
, buf
, read
, &written
);
423 } while((hr
== S_OK
) && written
!= 0 && read
!= 0);
425 httprequest_setreadystate(This
->request
, READYSTATE_INTERACTIVE
);
430 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
431 REFIID riid
, IUnknown
*punk
)
433 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
435 FIXME("(%p)->(%s %p): stub\n", This
, debugstr_guid(riid
), punk
);
440 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
441 BindStatusCallback_QueryInterface
,
442 BindStatusCallback_AddRef
,
443 BindStatusCallback_Release
,
444 BindStatusCallback_OnStartBinding
,
445 BindStatusCallback_GetPriority
,
446 BindStatusCallback_OnLowResource
,
447 BindStatusCallback_OnProgress
,
448 BindStatusCallback_OnStopBinding
,
449 BindStatusCallback_GetBindInfo
,
450 BindStatusCallback_OnDataAvailable
,
451 BindStatusCallback_OnObjectAvailable
454 static HRESULT WINAPI
BSCHttpNegotiate_QueryInterface(IHttpNegotiate
*iface
,
455 REFIID riid
, void **ppv
)
457 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
458 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
461 static ULONG WINAPI
BSCHttpNegotiate_AddRef(IHttpNegotiate
*iface
)
463 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
464 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
467 static ULONG WINAPI
BSCHttpNegotiate_Release(IHttpNegotiate
*iface
)
469 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
470 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
473 static HRESULT WINAPI
BSCHttpNegotiate_BeginningTransaction(IHttpNegotiate
*iface
,
474 LPCWSTR url
, LPCWSTR headers
, DWORD reserved
, LPWSTR
*add_headers
)
476 static const WCHAR content_type_utf8W
[] = {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ',
477 't','e','x','t','/','p','l','a','i','n',';','c','h','a','r','s','e','t','=','u','t','f','-','8','\r','\n',0};
478 static const WCHAR refererW
[] = {'R','e','f','e','r','e','r',':',' ',0};
480 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
481 const struct httpheader
*entry
;
482 BSTR base_uri
= NULL
;
486 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(url
), debugstr_w(headers
), reserved
, add_headers
);
490 if (This
->request
->use_utf8_content
)
491 size
= sizeof(content_type_utf8W
);
493 if (!list_empty(&This
->request
->reqheaders
))
494 size
+= This
->request
->reqheader_size
*sizeof(WCHAR
);
496 if (This
->request
->base_uri
)
498 IUri_GetRawUri(This
->request
->base_uri
, &base_uri
);
499 size
+= SysStringLen(base_uri
)*sizeof(WCHAR
) + sizeof(refererW
) + sizeof(crlfW
);
504 SysFreeString(base_uri
);
508 buff
= CoTaskMemAlloc(size
);
511 SysFreeString(base_uri
);
512 return E_OUTOFMEMORY
;
516 if (This
->request
->use_utf8_content
)
518 lstrcpyW(ptr
, content_type_utf8W
);
519 ptr
+= ARRAY_SIZE(content_type_utf8W
) - 1;
524 strcpyW(ptr
, refererW
);
525 strcatW(ptr
, base_uri
);
527 ptr
+= strlenW(refererW
) + SysStringLen(base_uri
) + strlenW(crlfW
);
528 SysFreeString(base_uri
);
532 LIST_FOR_EACH_ENTRY(entry
, &This
->request
->reqheaders
, struct httpheader
, entry
)
534 lstrcpyW(ptr
, entry
->header
);
535 ptr
+= SysStringLen(entry
->header
);
537 lstrcpyW(ptr
, colspaceW
);
538 ptr
+= ARRAY_SIZE(colspaceW
) - 1;
540 lstrcpyW(ptr
, entry
->value
);
541 ptr
+= SysStringLen(entry
->value
);
543 lstrcpyW(ptr
, crlfW
);
544 ptr
+= ARRAY_SIZE(crlfW
) - 1;
552 static void add_response_header(httprequest
*This
, const WCHAR
*data
, int len
)
554 struct httpheader
*entry
;
555 const WCHAR
*ptr
= data
;
562 header
= SysAllocStringLen(data
, ptr
-data
);
563 /* skip leading spaces for a value */
564 while (*++ptr
== ' ')
566 value
= SysAllocStringLen(ptr
, len
-(ptr
-data
));
575 TRACE("got header %s:%s\n", debugstr_w(header
), debugstr_w(value
));
577 entry
= heap_alloc(sizeof(*entry
));
578 entry
->header
= header
;
579 entry
->value
= value
;
580 list_add_head(&This
->respheaders
, &entry
->entry
);
583 static HRESULT WINAPI
BSCHttpNegotiate_OnResponse(IHttpNegotiate
*iface
, DWORD code
,
584 LPCWSTR resp_headers
, LPCWSTR req_headers
, LPWSTR
*add_reqheaders
)
586 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
588 TRACE("(%p)->(%d %s %s %p)\n", This
, code
, debugstr_w(resp_headers
),
589 debugstr_w(req_headers
), add_reqheaders
);
591 This
->request
->status
= code
;
592 /* store headers and status text */
593 free_response_headers(This
->request
);
594 SysFreeString(This
->request
->status_text
);
595 This
->request
->status_text
= NULL
;
598 const WCHAR
*ptr
, *line
, *status_text
;
600 ptr
= line
= resp_headers
;
602 /* skip HTTP-Version */
603 ptr
= strchrW(ptr
, ' ');
606 /* skip Status-Code */
607 ptr
= strchrW(++ptr
, ' ');
611 /* now it supposed to end with CRLF */
614 if (*ptr
== '\r' && *(ptr
+1) == '\n')
617 This
->request
->status_text
= SysAllocStringLen(status_text
, ptr
-status_text
);
618 TRACE("status text %s\n", debugstr_w(This
->request
->status_text
));
626 /* store as unparsed string for now */
627 This
->request
->raw_respheaders
= SysAllocString(line
);
633 static const IHttpNegotiateVtbl BSCHttpNegotiateVtbl
= {
634 BSCHttpNegotiate_QueryInterface
,
635 BSCHttpNegotiate_AddRef
,
636 BSCHttpNegotiate_Release
,
637 BSCHttpNegotiate_BeginningTransaction
,
638 BSCHttpNegotiate_OnResponse
641 static HRESULT WINAPI
Authenticate_QueryInterface(IAuthenticate
*iface
,
642 REFIID riid
, void **ppv
)
644 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
645 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
648 static ULONG WINAPI
Authenticate_AddRef(IAuthenticate
*iface
)
650 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
651 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
654 static ULONG WINAPI
Authenticate_Release(IAuthenticate
*iface
)
656 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
657 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
660 static HRESULT WINAPI
Authenticate_Authenticate(IAuthenticate
*iface
,
661 HWND
*hwnd
, LPWSTR
*username
, LPWSTR
*password
)
663 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
664 httprequest
*request
= This
->request
;
666 TRACE("(%p)->(%p %p %p)\n", This
, hwnd
, username
, password
);
668 if (request
->user
&& *request
->user
)
670 if (hwnd
) *hwnd
= NULL
;
671 *username
= CoTaskMemAlloc(SysStringByteLen(request
->user
)+sizeof(WCHAR
));
672 *password
= CoTaskMemAlloc(SysStringByteLen(request
->password
)+sizeof(WCHAR
));
673 if (!*username
|| !*password
)
675 CoTaskMemFree(*username
);
676 CoTaskMemFree(*password
);
677 return E_OUTOFMEMORY
;
680 memcpy(*username
, request
->user
, SysStringByteLen(request
->user
)+sizeof(WCHAR
));
681 memcpy(*password
, request
->password
, SysStringByteLen(request
->password
)+sizeof(WCHAR
));
687 static const IAuthenticateVtbl AuthenticateVtbl
= {
688 Authenticate_QueryInterface
,
690 Authenticate_Release
,
691 Authenticate_Authenticate
694 static HRESULT
BindStatusCallback_create(httprequest
* This
, BindStatusCallback
**obj
, const VARIANT
*body
)
696 BindStatusCallback
*bsc
;
701 hr
= CreateBindCtx(0, &pbc
);
702 if (hr
!= S_OK
) return hr
;
704 bsc
= heap_alloc(sizeof(*bsc
));
707 IBindCtx_Release(pbc
);
708 return E_OUTOFMEMORY
;
711 bsc
->IBindStatusCallback_iface
.lpVtbl
= &BindStatusCallbackVtbl
;
712 bsc
->IHttpNegotiate_iface
.lpVtbl
= &BSCHttpNegotiateVtbl
;
713 bsc
->IAuthenticate_iface
.lpVtbl
= &AuthenticateVtbl
;
720 TRACE("(%p)->(%p)\n", This
, bsc
);
722 This
->use_utf8_content
= FALSE
;
724 if (This
->verb
!= BINDVERB_GET
)
726 void *send_data
, *ptr
;
727 SAFEARRAY
*sa
= NULL
;
729 if (V_VT(body
) == (VT_VARIANT
|VT_BYREF
))
730 body
= V_VARIANTREF(body
);
736 int len
= SysStringLen(V_BSTR(body
));
737 const WCHAR
*str
= V_BSTR(body
);
740 for (i
= 0; i
< len
; i
++)
749 size
= WideCharToMultiByte(cp
, 0, str
, len
, NULL
, 0, NULL
, NULL
);
750 if (!(ptr
= heap_alloc(size
)))
753 return E_OUTOFMEMORY
;
755 WideCharToMultiByte(cp
, 0, str
, len
, ptr
, size
, NULL
, NULL
);
756 if (cp
== CP_UTF8
) This
->use_utf8_content
= TRUE
;
759 case VT_ARRAY
|VT_UI1
:
762 if ((hr
= SafeArrayAccessData(sa
, &ptr
)) != S_OK
)
767 if ((hr
= SafeArrayGetUBound(sa
, 1, &size
)) != S_OK
)
769 SafeArrayUnaccessData(sa
);
777 FIXME("unsupported body data type %d\n", V_VT(body
));
789 bsc
->body
= GlobalAlloc(GMEM_FIXED
, size
);
792 if (V_VT(body
) == VT_BSTR
)
794 else if (V_VT(body
) == (VT_ARRAY
|VT_UI1
))
795 SafeArrayUnaccessData(sa
);
798 return E_OUTOFMEMORY
;
801 send_data
= GlobalLock(bsc
->body
);
802 memcpy(send_data
, ptr
, size
);
803 GlobalUnlock(bsc
->body
);
806 if (V_VT(body
) == VT_BSTR
)
808 else if (V_VT(body
) == (VT_ARRAY
|VT_UI1
))
809 SafeArrayUnaccessData(sa
);
812 hr
= RegisterBindStatusCallback(pbc
, &bsc
->IBindStatusCallback_iface
, NULL
, 0);
817 hr
= CreateURLMonikerEx2(NULL
, This
->uri
, &moniker
, URL_MK_UNIFORM
);
822 hr
= IMoniker_BindToStorage(moniker
, pbc
, NULL
, &IID_IStream
, (void**)&stream
);
823 IMoniker_Release(moniker
);
824 if (stream
) IStream_Release(stream
);
826 IBindCtx_Release(pbc
);
831 IBindStatusCallback_Release(&bsc
->IBindStatusCallback_iface
);
839 static HRESULT
verify_uri(httprequest
*This
, IUri
*uri
)
841 DWORD scheme
, base_scheme
;
842 BSTR host
, base_host
;
845 if(!(This
->safeopt
& INTERFACESAFE_FOR_UNTRUSTED_DATA
))
849 return E_ACCESSDENIED
;
851 hr
= IUri_GetScheme(uri
, &scheme
);
855 hr
= IUri_GetScheme(This
->base_uri
, &base_scheme
);
859 if(scheme
!= base_scheme
) {
860 WARN("Schemes don't match\n");
861 return E_ACCESSDENIED
;
864 if(scheme
== INTERNET_SCHEME_UNKNOWN
) {
865 FIXME("Unknown scheme\n");
866 return E_ACCESSDENIED
;
869 hr
= IUri_GetHost(uri
, &host
);
873 hr
= IUri_GetHost(This
->base_uri
, &base_host
);
875 if(strcmpiW(host
, base_host
)) {
876 WARN("Hosts don't match\n");
879 SysFreeString(base_host
);
886 static HRESULT
httprequest_open(httprequest
*This
, BSTR method
, BSTR url
,
887 VARIANT async
, VARIANT user
, VARIANT password
)
889 static const WCHAR MethodHeadW
[] = {'H','E','A','D',0};
890 static const WCHAR MethodGetW
[] = {'G','E','T',0};
891 static const WCHAR MethodPutW
[] = {'P','U','T',0};
892 static const WCHAR MethodPostW
[] = {'P','O','S','T',0};
893 static const WCHAR MethodDeleteW
[] = {'D','E','L','E','T','E',0};
894 static const WCHAR MethodPropFindW
[] = {'P','R','O','P','F','I','N','D',0};
895 VARIANT str
, is_async
;
899 if (!method
|| !url
) return E_INVALIDARG
;
901 /* free previously set data */
903 IUri_Release(This
->uri
);
907 SysFreeString(This
->user
);
908 SysFreeString(This
->password
);
909 This
->user
= This
->password
= NULL
;
910 free_request_headers(This
);
912 if (!strcmpiW(method
, MethodGetW
))
914 This
->verb
= BINDVERB_GET
;
916 else if (!strcmpiW(method
, MethodPutW
))
918 This
->verb
= BINDVERB_PUT
;
920 else if (!strcmpiW(method
, MethodPostW
))
922 This
->verb
= BINDVERB_POST
;
924 else if (!strcmpiW(method
, MethodDeleteW
) ||
925 !strcmpiW(method
, MethodHeadW
) ||
926 !strcmpiW(method
, MethodPropFindW
))
928 This
->verb
= BINDVERB_CUSTOM
;
929 SysReAllocString(&This
->custom
, method
);
933 FIXME("unsupported request type %s\n", debugstr_w(method
));
939 hr
= CoInternetCombineUrlEx(This
->base_uri
, url
, 0, &uri
, 0);
941 hr
= CreateUri(url
, 0, 0, &uri
);
943 WARN("Could not create IUri object: %08x\n", hr
);
947 hr
= verify_uri(This
, uri
);
954 hr
= VariantChangeType(&str
, &user
, 0, VT_BSTR
);
956 This
->user
= V_BSTR(&str
);
959 hr
= VariantChangeType(&str
, &password
, 0, VT_BSTR
);
961 This
->password
= V_BSTR(&str
);
963 /* add authentication info */
964 if (This
->user
&& *This
->user
)
966 IUriBuilder
*builder
;
968 hr
= CreateIUriBuilder(uri
, 0, 0, &builder
);
973 IUriBuilder_SetUserName(builder
, This
->user
);
974 IUriBuilder_SetPassword(builder
, This
->password
);
975 hr
= IUriBuilder_CreateUri(builder
, -1, 0, 0, &full_uri
);
982 WARN("failed to create modified uri, 0x%08x\n", hr
);
983 IUriBuilder_Release(builder
);
986 WARN("IUriBuilder creation failed, 0x%08x\n", hr
);
991 VariantInit(&is_async
);
992 hr
= VariantChangeType(&is_async
, &async
, 0, VT_BOOL
);
993 This
->async
= hr
== S_OK
&& V_BOOL(&is_async
);
995 httprequest_setreadystate(This
, READYSTATE_LOADING
);
1000 static HRESULT
httprequest_setRequestHeader(httprequest
*This
, BSTR header
, BSTR value
)
1002 struct httpheader
*entry
;
1004 if (!header
|| !*header
) return E_INVALIDARG
;
1005 if (This
->state
!= READYSTATE_LOADING
) return E_FAIL
;
1006 if (!value
) return E_INVALIDARG
;
1008 /* replace existing header value if already added */
1009 LIST_FOR_EACH_ENTRY(entry
, &This
->reqheaders
, struct httpheader
, entry
)
1011 if (lstrcmpW(entry
->header
, header
) == 0)
1013 LONG length
= SysStringLen(entry
->value
);
1016 hr
= SysReAllocString(&entry
->value
, value
) ? S_OK
: E_OUTOFMEMORY
;
1019 This
->reqheader_size
+= (SysStringLen(entry
->value
) - length
);
1025 entry
= heap_alloc(sizeof(*entry
));
1026 if (!entry
) return E_OUTOFMEMORY
;
1029 entry
->header
= SysAllocString(header
);
1030 entry
->value
= SysAllocString(value
);
1032 /* header length including null terminator */
1033 This
->reqheader_size
+= SysStringLen(entry
->header
) + ARRAY_SIZE(colspaceW
) +
1034 SysStringLen(entry
->value
) + ARRAY_SIZE(crlfW
) - 1;
1036 list_add_head(&This
->reqheaders
, &entry
->entry
);
1041 static HRESULT
httprequest_getResponseHeader(httprequest
*This
, BSTR header
, BSTR
*value
)
1043 struct httpheader
*entry
;
1045 if (!header
) return E_INVALIDARG
;
1046 if (!value
) return E_POINTER
;
1048 if (This
->raw_respheaders
&& list_empty(&This
->respheaders
))
1052 ptr
= line
= This
->raw_respheaders
;
1055 if (*ptr
== '\r' && *(ptr
+1) == '\n')
1057 add_response_header(This
, line
, ptr
-line
);
1058 ptr
++; line
= ++ptr
;
1065 LIST_FOR_EACH_ENTRY(entry
, &This
->respheaders
, struct httpheader
, entry
)
1067 if (!strcmpiW(entry
->header
, header
))
1069 *value
= SysAllocString(entry
->value
);
1070 TRACE("header value %s\n", debugstr_w(*value
));
1078 static HRESULT
httprequest_getAllResponseHeaders(httprequest
*This
, BSTR
*respheaders
)
1080 if (!respheaders
) return E_POINTER
;
1082 *respheaders
= SysAllocString(This
->raw_respheaders
);
1087 static HRESULT
httprequest_send(httprequest
*This
, VARIANT body
)
1089 BindStatusCallback
*bsc
= NULL
;
1092 if (This
->state
!= READYSTATE_LOADING
) return E_FAIL
;
1094 hr
= BindStatusCallback_create(This
, &bsc
, &body
);
1096 /* success path to detach it is OnStopBinding call */
1097 BindStatusCallback_Detach(bsc
);
1102 static HRESULT
httprequest_abort(httprequest
*This
)
1104 BindStatusCallback_Detach(This
->bsc
);
1106 httprequest_setreadystate(This
, READYSTATE_UNINITIALIZED
);
1111 static HRESULT
httprequest_get_status(httprequest
*This
, LONG
*status
)
1113 if (!status
) return E_POINTER
;
1115 *status
= This
->status
;
1117 return This
->state
== READYSTATE_COMPLETE
? S_OK
: E_FAIL
;
1120 static HRESULT
httprequest_get_statusText(httprequest
*This
, BSTR
*status
)
1122 if (!status
) return E_POINTER
;
1123 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
1125 *status
= SysAllocString(This
->status_text
);
1130 static HRESULT
httprequest_get_responseText(httprequest
*This
, BSTR
*body
)
1135 if (!body
) return E_POINTER
;
1136 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
1138 hr
= GetHGlobalFromStream(This
->bsc
->stream
, &hglobal
);
1141 xmlChar
*ptr
= GlobalLock(hglobal
);
1142 DWORD size
= GlobalSize(hglobal
);
1143 xmlCharEncoding encoding
= XML_CHAR_ENCODING_UTF8
;
1145 /* try to determine data encoding */
1148 encoding
= xmlDetectCharEncoding(ptr
, 4);
1149 TRACE("detected encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding
)));
1150 if ( encoding
!= XML_CHAR_ENCODING_UTF8
&&
1151 encoding
!= XML_CHAR_ENCODING_UTF16LE
&&
1152 encoding
!= XML_CHAR_ENCODING_NONE
)
1154 FIXME("unsupported encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding
)));
1155 GlobalUnlock(hglobal
);
1160 /* without BOM assume UTF-8 */
1161 if (encoding
== XML_CHAR_ENCODING_UTF8
||
1162 encoding
== XML_CHAR_ENCODING_NONE
)
1164 DWORD length
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)ptr
, size
, NULL
, 0);
1166 *body
= SysAllocStringLen(NULL
, length
);
1168 MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
)ptr
, size
, *body
, length
);
1171 *body
= SysAllocStringByteLen((LPCSTR
)ptr
, size
);
1173 if (!*body
) hr
= E_OUTOFMEMORY
;
1174 GlobalUnlock(hglobal
);
1180 static HRESULT
httprequest_get_responseXML(httprequest
*This
, IDispatch
**body
)
1182 IXMLDOMDocument3
*doc
;
1186 if (!body
) return E_INVALIDARG
;
1187 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
1189 hr
= DOMDocument_create(MSXML_DEFAULT
, (void**)&doc
);
1190 if (hr
!= S_OK
) return hr
;
1192 hr
= httprequest_get_responseText(This
, &str
);
1197 hr
= IXMLDOMDocument3_loadXML(doc
, str
, &ok
);
1201 IXMLDOMDocument3_QueryInterface(doc
, &IID_IDispatch
, (void**)body
);
1202 IXMLDOMDocument3_Release(doc
);
1207 static HRESULT
httprequest_get_responseBody(httprequest
*This
, VARIANT
*body
)
1212 if (!body
) return E_INVALIDARG
;
1213 V_VT(body
) = VT_EMPTY
;
1215 if (This
->state
!= READYSTATE_COMPLETE
) return E_PENDING
;
1217 hr
= GetHGlobalFromStream(This
->bsc
->stream
, &hglobal
);
1220 void *ptr
= GlobalLock(hglobal
);
1221 DWORD size
= GlobalSize(hglobal
);
1223 SAFEARRAYBOUND bound
;
1227 bound
.cElements
= size
;
1228 array
= SafeArrayCreate(VT_UI1
, 1, &bound
);
1234 V_VT(body
) = VT_ARRAY
| VT_UI1
;
1235 V_ARRAY(body
) = array
;
1237 hr
= SafeArrayAccessData(array
, &dest
);
1240 memcpy(dest
, ptr
, size
);
1241 SafeArrayUnaccessData(array
);
1251 GlobalUnlock(hglobal
);
1257 static HRESULT
httprequest_get_responseStream(httprequest
*This
, VARIANT
*body
)
1263 if (!body
) return E_INVALIDARG
;
1264 V_VT(body
) = VT_EMPTY
;
1266 if (This
->state
!= READYSTATE_COMPLETE
) return E_PENDING
;
1268 hr
= IStream_Clone(This
->bsc
->stream
, &stream
);
1271 IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
1273 V_VT(body
) = VT_UNKNOWN
;
1274 V_UNKNOWN(body
) = (IUnknown
*)stream
;
1279 static HRESULT
httprequest_get_readyState(httprequest
*This
, LONG
*state
)
1281 if (!state
) return E_POINTER
;
1283 *state
= This
->state
;
1287 static HRESULT
httprequest_put_onreadystatechange(httprequest
*This
, IDispatch
*sink
)
1289 if (This
->sink
) IDispatch_Release(This
->sink
);
1290 if ((This
->sink
= sink
)) IDispatch_AddRef(This
->sink
);
1295 static void httprequest_release(httprequest
*This
)
1298 IUnknown_Release( This
->site
);
1300 IUri_Release(This
->uri
);
1302 IUri_Release(This
->base_uri
);
1304 SysFreeString(This
->custom
);
1305 SysFreeString(This
->user
);
1306 SysFreeString(This
->password
);
1308 /* cleanup headers lists */
1309 free_request_headers(This
);
1310 free_response_headers(This
);
1311 SysFreeString(This
->status_text
);
1313 /* detach callback object */
1314 BindStatusCallback_Detach(This
->bsc
);
1316 if (This
->sink
) IDispatch_Release(This
->sink
);
1319 static HRESULT WINAPI
XMLHTTPRequest_QueryInterface(IXMLHTTPRequest
*iface
, REFIID riid
, void **ppvObject
)
1321 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1322 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1324 if ( IsEqualGUID( riid
, &IID_IXMLHTTPRequest
) ||
1325 IsEqualGUID( riid
, &IID_IDispatch
) ||
1326 IsEqualGUID( riid
, &IID_IUnknown
) )
1330 else if (IsEqualGUID(&IID_IObjectWithSite
, riid
))
1332 *ppvObject
= &This
->IObjectWithSite_iface
;
1334 else if (IsEqualGUID(&IID_IObjectSafety
, riid
))
1336 *ppvObject
= &This
->IObjectSafety_iface
;
1338 else if (IsEqualGUID(&IID_ISupportErrorInfo
, riid
))
1340 *ppvObject
= &This
->ISupportErrorInfo_iface
;
1344 TRACE("Unsupported interface %s\n", debugstr_guid(riid
));
1346 return E_NOINTERFACE
;
1349 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1354 static ULONG WINAPI
XMLHTTPRequest_AddRef(IXMLHTTPRequest
*iface
)
1356 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1357 ULONG ref
= InterlockedIncrement( &This
->ref
);
1358 TRACE("(%p)->(%u)\n", This
, ref
);
1362 static ULONG WINAPI
XMLHTTPRequest_Release(IXMLHTTPRequest
*iface
)
1364 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1365 ULONG ref
= InterlockedDecrement( &This
->ref
);
1367 TRACE("(%p)->(%u)\n", This
, ref
);
1371 httprequest_release( This
);
1378 static HRESULT WINAPI
XMLHTTPRequest_GetTypeInfoCount(IXMLHTTPRequest
*iface
, UINT
*pctinfo
)
1380 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1382 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1389 static HRESULT WINAPI
XMLHTTPRequest_GetTypeInfo(IXMLHTTPRequest
*iface
, UINT iTInfo
,
1390 LCID lcid
, ITypeInfo
**ppTInfo
)
1392 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1394 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1396 return get_typeinfo(IXMLHTTPRequest_tid
, ppTInfo
);
1399 static HRESULT WINAPI
XMLHTTPRequest_GetIDsOfNames(IXMLHTTPRequest
*iface
, REFIID riid
,
1400 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1402 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1403 ITypeInfo
*typeinfo
;
1406 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1409 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1410 return E_INVALIDARG
;
1412 hr
= get_typeinfo(IXMLHTTPRequest_tid
, &typeinfo
);
1415 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1416 ITypeInfo_Release(typeinfo
);
1422 static HRESULT WINAPI
XMLHTTPRequest_Invoke(IXMLHTTPRequest
*iface
, DISPID dispIdMember
, REFIID riid
,
1423 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1424 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1426 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1427 ITypeInfo
*typeinfo
;
1430 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1431 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1433 hr
= get_typeinfo(IXMLHTTPRequest_tid
, &typeinfo
);
1436 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLHTTPRequest_iface
, dispIdMember
, wFlags
,
1437 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1438 ITypeInfo_Release(typeinfo
);
1444 static HRESULT WINAPI
XMLHTTPRequest_open(IXMLHTTPRequest
*iface
, BSTR method
, BSTR url
,
1445 VARIANT async
, VARIANT user
, VARIANT password
)
1447 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1448 TRACE("(%p)->(%s %s %s)\n", This
, debugstr_w(method
), debugstr_w(url
),
1449 debugstr_variant(&async
));
1450 return httprequest_open(This
, method
, url
, async
, user
, password
);
1453 static HRESULT WINAPI
XMLHTTPRequest_setRequestHeader(IXMLHTTPRequest
*iface
, BSTR header
, BSTR value
)
1455 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1456 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(header
), debugstr_w(value
));
1457 return httprequest_setRequestHeader(This
, header
, value
);
1460 static HRESULT WINAPI
XMLHTTPRequest_getResponseHeader(IXMLHTTPRequest
*iface
, BSTR header
, BSTR
*value
)
1462 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1463 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(header
), value
);
1464 return httprequest_getResponseHeader(This
, header
, value
);
1467 static HRESULT WINAPI
XMLHTTPRequest_getAllResponseHeaders(IXMLHTTPRequest
*iface
, BSTR
*respheaders
)
1469 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1470 TRACE("(%p)->(%p)\n", This
, respheaders
);
1471 return httprequest_getAllResponseHeaders(This
, respheaders
);
1474 static HRESULT WINAPI
XMLHTTPRequest_send(IXMLHTTPRequest
*iface
, VARIANT body
)
1476 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1477 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&body
));
1478 return httprequest_send(This
, body
);
1481 static HRESULT WINAPI
XMLHTTPRequest_abort(IXMLHTTPRequest
*iface
)
1483 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1484 TRACE("(%p)\n", This
);
1485 return httprequest_abort(This
);
1488 static HRESULT WINAPI
XMLHTTPRequest_get_status(IXMLHTTPRequest
*iface
, LONG
*status
)
1490 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1491 TRACE("(%p)->(%p)\n", This
, status
);
1492 return httprequest_get_status(This
, status
);
1495 static HRESULT WINAPI
XMLHTTPRequest_get_statusText(IXMLHTTPRequest
*iface
, BSTR
*status
)
1497 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1498 TRACE("(%p)->(%p)\n", This
, status
);
1499 return httprequest_get_statusText(This
, status
);
1502 static HRESULT WINAPI
XMLHTTPRequest_get_responseXML(IXMLHTTPRequest
*iface
, IDispatch
**body
)
1504 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1505 TRACE("(%p)->(%p)\n", This
, body
);
1506 return httprequest_get_responseXML(This
, body
);
1509 static HRESULT WINAPI
XMLHTTPRequest_get_responseText(IXMLHTTPRequest
*iface
, BSTR
*body
)
1511 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1512 TRACE("(%p)->(%p)\n", This
, body
);
1513 return httprequest_get_responseText(This
, body
);
1516 static HRESULT WINAPI
XMLHTTPRequest_get_responseBody(IXMLHTTPRequest
*iface
, VARIANT
*body
)
1518 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1519 TRACE("(%p)->(%p)\n", This
, body
);
1520 return httprequest_get_responseBody(This
, body
);
1523 static HRESULT WINAPI
XMLHTTPRequest_get_responseStream(IXMLHTTPRequest
*iface
, VARIANT
*body
)
1525 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1526 TRACE("(%p)->(%p)\n", This
, body
);
1527 return httprequest_get_responseStream(This
, body
);
1530 static HRESULT WINAPI
XMLHTTPRequest_get_readyState(IXMLHTTPRequest
*iface
, LONG
*state
)
1532 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1533 TRACE("(%p)->(%p)\n", This
, state
);
1534 return httprequest_get_readyState(This
, state
);
1537 static HRESULT WINAPI
XMLHTTPRequest_put_onreadystatechange(IXMLHTTPRequest
*iface
, IDispatch
*sink
)
1539 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1540 TRACE("(%p)->(%p)\n", This
, sink
);
1541 return httprequest_put_onreadystatechange(This
, sink
);
1544 static const struct IXMLHTTPRequestVtbl XMLHTTPRequestVtbl
=
1546 XMLHTTPRequest_QueryInterface
,
1547 XMLHTTPRequest_AddRef
,
1548 XMLHTTPRequest_Release
,
1549 XMLHTTPRequest_GetTypeInfoCount
,
1550 XMLHTTPRequest_GetTypeInfo
,
1551 XMLHTTPRequest_GetIDsOfNames
,
1552 XMLHTTPRequest_Invoke
,
1553 XMLHTTPRequest_open
,
1554 XMLHTTPRequest_setRequestHeader
,
1555 XMLHTTPRequest_getResponseHeader
,
1556 XMLHTTPRequest_getAllResponseHeaders
,
1557 XMLHTTPRequest_send
,
1558 XMLHTTPRequest_abort
,
1559 XMLHTTPRequest_get_status
,
1560 XMLHTTPRequest_get_statusText
,
1561 XMLHTTPRequest_get_responseXML
,
1562 XMLHTTPRequest_get_responseText
,
1563 XMLHTTPRequest_get_responseBody
,
1564 XMLHTTPRequest_get_responseStream
,
1565 XMLHTTPRequest_get_readyState
,
1566 XMLHTTPRequest_put_onreadystatechange
1569 /* IObjectWithSite */
1570 static HRESULT WINAPI
1571 httprequest_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
1573 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1574 return IXMLHTTPRequest_QueryInterface(&This
->IXMLHTTPRequest_iface
, riid
, ppvObject
);
1577 static ULONG WINAPI
httprequest_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
1579 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1580 return IXMLHTTPRequest_AddRef(&This
->IXMLHTTPRequest_iface
);
1583 static ULONG WINAPI
httprequest_ObjectWithSite_Release( IObjectWithSite
* iface
)
1585 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1586 return IXMLHTTPRequest_Release(&This
->IXMLHTTPRequest_iface
);
1589 static HRESULT WINAPI
httprequest_ObjectWithSite_GetSite( IObjectWithSite
*iface
, REFIID iid
, void **ppvSite
)
1591 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1593 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid( iid
), ppvSite
);
1598 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
1601 IUri
*get_base_uri(IUnknown
*site
)
1603 IServiceProvider
*provider
;
1604 IHTMLDocument2
*doc
;
1609 hr
= IUnknown_QueryInterface(site
, &IID_IServiceProvider
, (void**)&provider
);
1613 hr
= IServiceProvider_QueryService(provider
, &SID_SContainerDispatch
, &IID_IHTMLDocument2
, (void**)&doc
);
1615 hr
= IServiceProvider_QueryService(provider
, &SID_SInternetHostSecurityManager
, &IID_IHTMLDocument2
, (void**)&doc
);
1616 IServiceProvider_Release(provider
);
1620 hr
= IHTMLDocument2_get_URL(doc
, &url
);
1621 IHTMLDocument2_Release(doc
);
1622 if(FAILED(hr
) || !url
|| !*url
)
1625 TRACE("host url %s\n", debugstr_w(url
));
1627 hr
= CreateUri(url
, 0, 0, &uri
);
1635 static HRESULT WINAPI
httprequest_ObjectWithSite_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
1637 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1639 TRACE("(%p)->(%p)\n", This
, punk
);
1642 IUnknown_Release( This
->site
);
1644 IUri_Release(This
->base_uri
);
1650 IUnknown_AddRef( punk
);
1651 This
->base_uri
= get_base_uri(This
->site
);
1657 static const IObjectWithSiteVtbl ObjectWithSiteVtbl
=
1659 httprequest_ObjectWithSite_QueryInterface
,
1660 httprequest_ObjectWithSite_AddRef
,
1661 httprequest_ObjectWithSite_Release
,
1662 httprequest_ObjectWithSite_SetSite
,
1663 httprequest_ObjectWithSite_GetSite
1667 static HRESULT WINAPI
httprequest_Safety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
1669 httprequest
*This
= impl_from_IObjectSafety(iface
);
1670 return IXMLHTTPRequest_QueryInterface(&This
->IXMLHTTPRequest_iface
, riid
, ppv
);
1673 static ULONG WINAPI
httprequest_Safety_AddRef(IObjectSafety
*iface
)
1675 httprequest
*This
= impl_from_IObjectSafety(iface
);
1676 return IXMLHTTPRequest_AddRef(&This
->IXMLHTTPRequest_iface
);
1679 static ULONG WINAPI
httprequest_Safety_Release(IObjectSafety
*iface
)
1681 httprequest
*This
= impl_from_IObjectSafety(iface
);
1682 return IXMLHTTPRequest_Release(&This
->IXMLHTTPRequest_iface
);
1685 static HRESULT WINAPI
httprequest_Safety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1686 DWORD
*supported
, DWORD
*enabled
)
1688 httprequest
*This
= impl_from_IObjectSafety(iface
);
1690 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), supported
, enabled
);
1692 if(!supported
|| !enabled
) return E_POINTER
;
1694 *supported
= safety_supported_options
;
1695 *enabled
= This
->safeopt
;
1700 static HRESULT WINAPI
httprequest_Safety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1701 DWORD mask
, DWORD enabled
)
1703 httprequest
*This
= impl_from_IObjectSafety(iface
);
1704 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), mask
, enabled
);
1706 if ((mask
& ~safety_supported_options
))
1709 This
->safeopt
= (This
->safeopt
& ~mask
) | (mask
& enabled
);
1714 static const IObjectSafetyVtbl ObjectSafetyVtbl
= {
1715 httprequest_Safety_QueryInterface
,
1716 httprequest_Safety_AddRef
,
1717 httprequest_Safety_Release
,
1718 httprequest_Safety_GetInterfaceSafetyOptions
,
1719 httprequest_Safety_SetInterfaceSafetyOptions
1722 static HRESULT WINAPI
SupportErrorInfo_QueryInterface(ISupportErrorInfo
*iface
, REFIID riid
, void **obj
)
1724 httprequest
*This
= impl_from_ISupportErrorInfo(iface
);
1725 return IXMLHTTPRequest_QueryInterface(&This
->IXMLHTTPRequest_iface
, riid
, obj
);
1728 static ULONG WINAPI
SupportErrorInfo_AddRef(ISupportErrorInfo
*iface
)
1730 httprequest
*This
= impl_from_ISupportErrorInfo(iface
);
1731 return IXMLHTTPRequest_AddRef(&This
->IXMLHTTPRequest_iface
);
1734 static ULONG WINAPI
SupportErrorInfo_Release(ISupportErrorInfo
*iface
)
1736 httprequest
*This
= impl_from_ISupportErrorInfo(iface
);
1737 return IXMLHTTPRequest_Release(&This
->IXMLHTTPRequest_iface
);
1740 static HRESULT WINAPI
SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo
*iface
, REFIID riid
)
1742 httprequest
*This
= impl_from_ISupportErrorInfo(iface
);
1744 FIXME("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1749 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl
=
1751 SupportErrorInfo_QueryInterface
,
1752 SupportErrorInfo_AddRef
,
1753 SupportErrorInfo_Release
,
1754 SupportErrorInfo_InterfaceSupportsErrorInfo
,
1757 /* IServerXMLHTTPRequest */
1758 static HRESULT WINAPI
ServerXMLHTTPRequest_QueryInterface(IServerXMLHTTPRequest
*iface
, REFIID riid
, void **obj
)
1760 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1762 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1764 if ( IsEqualGUID( riid
, &IID_IServerXMLHTTPRequest
) ||
1765 IsEqualGUID( riid
, &IID_IXMLHTTPRequest
) ||
1766 IsEqualGUID( riid
, &IID_IDispatch
) ||
1767 IsEqualGUID( riid
, &IID_IUnknown
) )
1771 else if ( IsEqualGUID( riid
, &IID_ISupportErrorInfo
))
1773 *obj
= &This
->req
.ISupportErrorInfo_iface
;
1777 TRACE("Unsupported interface %s\n", debugstr_guid(riid
));
1779 return E_NOINTERFACE
;
1782 IUnknown_AddRef( (IUnknown
*)*obj
);
1787 static ULONG WINAPI
ServerXMLHTTPRequest_AddRef(IServerXMLHTTPRequest
*iface
)
1789 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1790 ULONG ref
= InterlockedIncrement( &This
->req
.ref
);
1791 TRACE("(%p)->(%u)\n", This
, ref
);
1795 static ULONG WINAPI
ServerXMLHTTPRequest_Release(IServerXMLHTTPRequest
*iface
)
1797 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1798 ULONG ref
= InterlockedDecrement( &This
->req
.ref
);
1800 TRACE("(%p)->(%u)\n", This
, ref
);
1804 httprequest_release( &This
->req
);
1811 static HRESULT WINAPI
ServerXMLHTTPRequest_GetTypeInfoCount(IServerXMLHTTPRequest
*iface
, UINT
*pctinfo
)
1813 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1815 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1821 static HRESULT WINAPI
ServerXMLHTTPRequest_GetTypeInfo(IServerXMLHTTPRequest
*iface
, UINT iTInfo
,
1822 LCID lcid
, ITypeInfo
**ppTInfo
)
1824 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1826 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1828 return get_typeinfo(IServerXMLHTTPRequest_tid
, ppTInfo
);
1831 static HRESULT WINAPI
ServerXMLHTTPRequest_GetIDsOfNames(IServerXMLHTTPRequest
*iface
, REFIID riid
,
1832 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1834 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1835 ITypeInfo
*typeinfo
;
1838 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1841 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1842 return E_INVALIDARG
;
1844 hr
= get_typeinfo(IServerXMLHTTPRequest_tid
, &typeinfo
);
1847 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1848 ITypeInfo_Release(typeinfo
);
1854 static HRESULT WINAPI
ServerXMLHTTPRequest_Invoke(IServerXMLHTTPRequest
*iface
, DISPID dispIdMember
, REFIID riid
,
1855 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1856 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1858 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1859 ITypeInfo
*typeinfo
;
1862 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1863 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1865 hr
= get_typeinfo(IServerXMLHTTPRequest_tid
, &typeinfo
);
1868 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IServerXMLHTTPRequest_iface
, dispIdMember
, wFlags
,
1869 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1870 ITypeInfo_Release(typeinfo
);
1876 static HRESULT WINAPI
ServerXMLHTTPRequest_open(IServerXMLHTTPRequest
*iface
, BSTR method
, BSTR url
,
1877 VARIANT async
, VARIANT user
, VARIANT password
)
1879 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1880 TRACE("(%p)->(%s %s %s)\n", This
, debugstr_w(method
), debugstr_w(url
),
1881 debugstr_variant(&async
));
1882 return httprequest_open(&This
->req
, method
, url
, async
, user
, password
);
1885 static HRESULT WINAPI
ServerXMLHTTPRequest_setRequestHeader(IServerXMLHTTPRequest
*iface
, BSTR header
, BSTR value
)
1887 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1888 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(header
), debugstr_w(value
));
1889 return httprequest_setRequestHeader(&This
->req
, header
, value
);
1892 static HRESULT WINAPI
ServerXMLHTTPRequest_getResponseHeader(IServerXMLHTTPRequest
*iface
, BSTR header
, BSTR
*value
)
1894 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1895 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(header
), value
);
1896 return httprequest_getResponseHeader(&This
->req
, header
, value
);
1899 static HRESULT WINAPI
ServerXMLHTTPRequest_getAllResponseHeaders(IServerXMLHTTPRequest
*iface
, BSTR
*respheaders
)
1901 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1902 TRACE("(%p)->(%p)\n", This
, respheaders
);
1903 return httprequest_getAllResponseHeaders(&This
->req
, respheaders
);
1906 static HRESULT WINAPI
ServerXMLHTTPRequest_send(IServerXMLHTTPRequest
*iface
, VARIANT body
)
1908 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1909 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&body
));
1910 return httprequest_send(&This
->req
, body
);
1913 static HRESULT WINAPI
ServerXMLHTTPRequest_abort(IServerXMLHTTPRequest
*iface
)
1915 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1916 TRACE("(%p)\n", This
);
1917 return httprequest_abort(&This
->req
);
1920 static HRESULT WINAPI
ServerXMLHTTPRequest_get_status(IServerXMLHTTPRequest
*iface
, LONG
*status
)
1922 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1923 TRACE("(%p)->(%p)\n", This
, status
);
1924 return httprequest_get_status(&This
->req
, status
);
1927 static HRESULT WINAPI
ServerXMLHTTPRequest_get_statusText(IServerXMLHTTPRequest
*iface
, BSTR
*status
)
1929 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1930 TRACE("(%p)->(%p)\n", This
, status
);
1931 return httprequest_get_statusText(&This
->req
, status
);
1934 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseXML(IServerXMLHTTPRequest
*iface
, IDispatch
**body
)
1936 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1937 TRACE("(%p)->(%p)\n", This
, body
);
1938 return httprequest_get_responseXML(&This
->req
, body
);
1941 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseText(IServerXMLHTTPRequest
*iface
, BSTR
*body
)
1943 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1944 TRACE("(%p)->(%p)\n", This
, body
);
1945 return httprequest_get_responseText(&This
->req
, body
);
1948 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseBody(IServerXMLHTTPRequest
*iface
, VARIANT
*body
)
1950 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1951 TRACE("(%p)->(%p)\n", This
, body
);
1952 return httprequest_get_responseBody(&This
->req
, body
);
1955 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseStream(IServerXMLHTTPRequest
*iface
, VARIANT
*body
)
1957 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1958 TRACE("(%p)->(%p)\n", This
, body
);
1959 return httprequest_get_responseStream(&This
->req
, body
);
1962 static HRESULT WINAPI
ServerXMLHTTPRequest_get_readyState(IServerXMLHTTPRequest
*iface
, LONG
*state
)
1964 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1965 TRACE("(%p)->(%p)\n", This
, state
);
1966 return httprequest_get_readyState(&This
->req
, state
);
1969 static HRESULT WINAPI
ServerXMLHTTPRequest_put_onreadystatechange(IServerXMLHTTPRequest
*iface
, IDispatch
*sink
)
1971 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1972 TRACE("(%p)->(%p)\n", This
, sink
);
1973 return httprequest_put_onreadystatechange(&This
->req
, sink
);
1976 static HRESULT WINAPI
ServerXMLHTTPRequest_setTimeouts(IServerXMLHTTPRequest
*iface
, LONG resolveTimeout
, LONG connectTimeout
,
1977 LONG sendTimeout
, LONG receiveTimeout
)
1979 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1980 FIXME("(%p)->(%d %d %d %d): stub\n", This
, resolveTimeout
, connectTimeout
, sendTimeout
, receiveTimeout
);
1984 static HRESULT WINAPI
ServerXMLHTTPRequest_waitForResponse(IServerXMLHTTPRequest
*iface
, VARIANT timeout
, VARIANT_BOOL
*isSuccessful
)
1986 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1987 FIXME("(%p)->(%s %p): stub\n", This
, debugstr_variant(&timeout
), isSuccessful
);
1991 static HRESULT WINAPI
ServerXMLHTTPRequest_getOption(IServerXMLHTTPRequest
*iface
, SERVERXMLHTTP_OPTION option
, VARIANT
*value
)
1993 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1994 FIXME("(%p)->(%d %p): stub\n", This
, option
, value
);
1998 static HRESULT WINAPI
ServerXMLHTTPRequest_setOption(IServerXMLHTTPRequest
*iface
, SERVERXMLHTTP_OPTION option
, VARIANT value
)
2000 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
2001 FIXME("(%p)->(%d %s): stub\n", This
, option
, debugstr_variant(&value
));
2005 static const struct IServerXMLHTTPRequestVtbl ServerXMLHTTPRequestVtbl
=
2007 ServerXMLHTTPRequest_QueryInterface
,
2008 ServerXMLHTTPRequest_AddRef
,
2009 ServerXMLHTTPRequest_Release
,
2010 ServerXMLHTTPRequest_GetTypeInfoCount
,
2011 ServerXMLHTTPRequest_GetTypeInfo
,
2012 ServerXMLHTTPRequest_GetIDsOfNames
,
2013 ServerXMLHTTPRequest_Invoke
,
2014 ServerXMLHTTPRequest_open
,
2015 ServerXMLHTTPRequest_setRequestHeader
,
2016 ServerXMLHTTPRequest_getResponseHeader
,
2017 ServerXMLHTTPRequest_getAllResponseHeaders
,
2018 ServerXMLHTTPRequest_send
,
2019 ServerXMLHTTPRequest_abort
,
2020 ServerXMLHTTPRequest_get_status
,
2021 ServerXMLHTTPRequest_get_statusText
,
2022 ServerXMLHTTPRequest_get_responseXML
,
2023 ServerXMLHTTPRequest_get_responseText
,
2024 ServerXMLHTTPRequest_get_responseBody
,
2025 ServerXMLHTTPRequest_get_responseStream
,
2026 ServerXMLHTTPRequest_get_readyState
,
2027 ServerXMLHTTPRequest_put_onreadystatechange
,
2028 ServerXMLHTTPRequest_setTimeouts
,
2029 ServerXMLHTTPRequest_waitForResponse
,
2030 ServerXMLHTTPRequest_getOption
,
2031 ServerXMLHTTPRequest_setOption
2034 static void init_httprequest(httprequest
*req
)
2036 req
->IXMLHTTPRequest_iface
.lpVtbl
= &XMLHTTPRequestVtbl
;
2037 req
->IObjectWithSite_iface
.lpVtbl
= &ObjectWithSiteVtbl
;
2038 req
->IObjectSafety_iface
.lpVtbl
= &ObjectSafetyVtbl
;
2039 req
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
2045 req
->uri
= req
->base_uri
= NULL
;
2046 req
->user
= req
->password
= NULL
;
2048 req
->state
= READYSTATE_UNINITIALIZED
;
2053 req
->status_text
= NULL
;
2054 req
->reqheader_size
= 0;
2055 req
->raw_respheaders
= NULL
;
2056 req
->use_utf8_content
= FALSE
;
2058 list_init(&req
->reqheaders
);
2059 list_init(&req
->respheaders
);
2065 HRESULT
XMLHTTPRequest_create(void **obj
)
2069 TRACE("(%p)\n", obj
);
2071 req
= heap_alloc( sizeof (*req
) );
2073 return E_OUTOFMEMORY
;
2075 init_httprequest(req
);
2076 *obj
= &req
->IXMLHTTPRequest_iface
;
2078 TRACE("returning iface %p\n", *obj
);
2083 HRESULT
ServerXMLHTTP_create(void **obj
)
2087 TRACE("(%p)\n", obj
);
2089 req
= heap_alloc( sizeof (*req
) );
2091 return E_OUTOFMEMORY
;
2093 init_httprequest(&req
->req
);
2094 req
->IServerXMLHTTPRequest_iface
.lpVtbl
= &ServerXMLHTTPRequestVtbl
;
2096 *obj
= &req
->IServerXMLHTTPRequest_iface
;
2098 TRACE("returning iface %p\n", *obj
);
2105 HRESULT
XMLHTTPRequest_create(void **ppObj
)
2107 MESSAGE("This program tried to use a XMLHTTPRequest object, but\n"
2108 "libxml2 support was not present at compile time.\n");
2112 HRESULT
ServerXMLHTTP_create(void **obj
)
2114 MESSAGE("This program tried to use a ServerXMLHTTP object, but\n"
2115 "libxml2 support was not present at compile time.\n");