2 * IXMLHTTPRequest implementation
4 * Copyright 2008 Alistair Leslie-Hughes
5 * Copyright 2010-2012 Nikolay Sivov for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_NO_STATUS
26 #define NONAMELESSUNION
32 # include <libxml/parser.h>
33 //# include <libxml/xmlerror.h>
34 //# include <libxml/encoding.h>
42 //#include "winuser.h"
50 #include "msxml_private.h"
52 #include <wine/debug.h>
53 #include <wine/list.h>
55 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
59 static const WCHAR colspaceW
[] = {':',' ',0};
60 static const WCHAR crlfW
[] = {'\r','\n',0};
61 static const DWORD safety_supported_options
=
62 INTERFACESAFE_FOR_UNTRUSTED_CALLER
|
63 INTERFACESAFE_FOR_UNTRUSTED_DATA
|
64 INTERFACE_USES_SECURITY_MANAGER
;
66 typedef struct BindStatusCallback BindStatusCallback
;
77 IXMLHTTPRequest IXMLHTTPRequest_iface
;
78 IObjectWithSite IObjectWithSite_iface
;
79 IObjectSafety IObjectSafety_iface
;
91 struct list reqheaders
;
92 /* cached resulting custom request headers string length in WCHARs */
94 /* use UTF-8 content type */
95 BOOL use_utf8_content
;
97 /* response headers */
98 struct list respheaders
;
106 BindStatusCallback
*bsc
;
120 IServerXMLHTTPRequest IServerXMLHTTPRequest_iface
;
124 static inline httprequest
*impl_from_IXMLHTTPRequest( IXMLHTTPRequest
*iface
)
126 return CONTAINING_RECORD(iface
, httprequest
, IXMLHTTPRequest_iface
);
129 static inline httprequest
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
131 return CONTAINING_RECORD(iface
, httprequest
, IObjectWithSite_iface
);
134 static inline httprequest
*impl_from_IObjectSafety(IObjectSafety
*iface
)
136 return CONTAINING_RECORD(iface
, httprequest
, IObjectSafety_iface
);
139 static inline serverhttp
*impl_from_IServerXMLHTTPRequest(IServerXMLHTTPRequest
*iface
)
141 return CONTAINING_RECORD(iface
, serverhttp
, IServerXMLHTTPRequest_iface
);
144 static void httprequest_setreadystate(httprequest
*This
, READYSTATE state
)
146 READYSTATE last
= This
->state
;
147 static const char* readystates
[] = {
148 "READYSTATE_UNINITIALIZED",
149 "READYSTATE_LOADING",
151 "READYSTATE_INTERACTIVE",
152 "READYSTATE_COMPLETE"};
156 TRACE("state %s\n", readystates
[state
]);
158 if (This
->sink
&& last
!= state
)
162 memset(¶ms
, 0, sizeof(params
));
163 IDispatch_Invoke(This
->sink
, 0, &IID_NULL
, LOCALE_SYSTEM_DEFAULT
, DISPATCH_METHOD
, ¶ms
, 0, 0, 0);
167 static void free_response_headers(httprequest
*This
)
169 struct httpheader
*header
, *header2
;
171 LIST_FOR_EACH_ENTRY_SAFE(header
, header2
, &This
->respheaders
, struct httpheader
, entry
)
173 list_remove(&header
->entry
);
174 SysFreeString(header
->header
);
175 SysFreeString(header
->value
);
179 SysFreeString(This
->raw_respheaders
);
180 This
->raw_respheaders
= NULL
;
183 struct BindStatusCallback
185 IBindStatusCallback IBindStatusCallback_iface
;
186 IHttpNegotiate IHttpNegotiate_iface
;
187 IAuthenticate IAuthenticate_iface
;
191 httprequest
*request
;
196 /* request body data */
200 static inline BindStatusCallback
*impl_from_IBindStatusCallback( IBindStatusCallback
*iface
)
202 return CONTAINING_RECORD(iface
, BindStatusCallback
, IBindStatusCallback_iface
);
205 static inline BindStatusCallback
*impl_from_IHttpNegotiate( IHttpNegotiate
*iface
)
207 return CONTAINING_RECORD(iface
, BindStatusCallback
, IHttpNegotiate_iface
);
210 static inline BindStatusCallback
*impl_from_IAuthenticate( IAuthenticate
*iface
)
212 return CONTAINING_RECORD(iface
, BindStatusCallback
, IAuthenticate_iface
);
215 static void BindStatusCallback_Detach(BindStatusCallback
*bsc
)
219 if (bsc
->binding
) IBinding_Abort(bsc
->binding
);
220 bsc
->request
->bsc
= NULL
;
222 IBindStatusCallback_Release(&bsc
->IBindStatusCallback_iface
);
226 static HRESULT WINAPI
BindStatusCallback_QueryInterface(IBindStatusCallback
*iface
,
227 REFIID riid
, void **ppv
)
229 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
233 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
235 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
236 IsEqualGUID(&IID_IBindStatusCallback
, riid
))
238 *ppv
= &This
->IBindStatusCallback_iface
;
240 else if (IsEqualGUID(&IID_IHttpNegotiate
, riid
))
242 *ppv
= &This
->IHttpNegotiate_iface
;
244 else if (IsEqualGUID(&IID_IAuthenticate
, riid
))
246 *ppv
= &This
->IAuthenticate_iface
;
248 else if (IsEqualGUID(&IID_IServiceProvider
, riid
) ||
249 IsEqualGUID(&IID_IBindStatusCallbackEx
, riid
) ||
250 IsEqualGUID(&IID_IInternetProtocol
, riid
) ||
251 IsEqualGUID(&IID_IHttpNegotiate2
, riid
))
253 return E_NOINTERFACE
;
258 IBindStatusCallback_AddRef(iface
);
262 FIXME("Unsupported riid = %s\n", debugstr_guid(riid
));
264 return E_NOINTERFACE
;
267 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
269 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
270 LONG ref
= InterlockedIncrement(&This
->ref
);
272 TRACE("(%p) ref = %d\n", This
, ref
);
277 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
279 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
280 LONG ref
= InterlockedDecrement(&This
->ref
);
282 TRACE("(%p) ref = %d\n", This
, ref
);
286 if (This
->binding
) IBinding_Release(This
->binding
);
287 if (This
->stream
) IStream_Release(This
->stream
);
288 if (This
->body
) GlobalFree(This
->body
);
295 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
296 DWORD reserved
, IBinding
*pbind
)
298 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
300 TRACE("(%p)->(%d %p)\n", This
, reserved
, pbind
);
302 if (!pbind
) return E_INVALIDARG
;
304 This
->binding
= pbind
;
305 IBinding_AddRef(pbind
);
307 httprequest_setreadystate(This
->request
, READYSTATE_LOADED
);
309 return CreateStreamOnHGlobal(NULL
, TRUE
, &This
->stream
);
312 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
, LONG
*pPriority
)
314 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
316 TRACE("(%p)->(%p)\n", This
, pPriority
);
321 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
, DWORD reserved
)
323 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
325 TRACE("(%p)->(%d)\n", This
, reserved
);
330 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
331 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
333 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
335 TRACE("(%p)->(%u %u %u %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
336 debugstr_w(szStatusText
));
341 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
342 HRESULT hr
, LPCWSTR error
)
344 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
346 TRACE("(%p)->(0x%08x %s)\n", This
, hr
, debugstr_w(error
));
350 IBinding_Release(This
->binding
);
351 This
->binding
= NULL
;
356 BindStatusCallback_Detach(This
->request
->bsc
);
357 This
->request
->bsc
= This
;
358 httprequest_setreadystate(This
->request
, READYSTATE_COMPLETE
);
364 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
365 DWORD
*bind_flags
, BINDINFO
*pbindinfo
)
367 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
369 TRACE("(%p)->(%p %p)\n", This
, bind_flags
, pbindinfo
);
372 if (This
->request
->async
) *bind_flags
|= BINDF_ASYNCHRONOUS
;
374 if (This
->request
->verb
!= BINDVERB_GET
&& This
->body
)
376 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
377 pbindinfo
->stgmedData
.u
.hGlobal
= This
->body
;
378 pbindinfo
->cbstgmedData
= GlobalSize(This
->body
);
379 /* callback owns passed body pointer */
380 IBindStatusCallback_QueryInterface(iface
, &IID_IUnknown
, (void**)&pbindinfo
->stgmedData
.pUnkForRelease
);
383 pbindinfo
->dwBindVerb
= This
->request
->verb
;
384 if (This
->request
->verb
== BINDVERB_CUSTOM
)
386 pbindinfo
->szCustomVerb
= CoTaskMemAlloc(SysStringByteLen(This
->request
->custom
));
387 strcpyW(pbindinfo
->szCustomVerb
, This
->request
->custom
);
393 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
394 DWORD flags
, DWORD size
, FORMATETC
*format
, STGMEDIUM
*stgmed
)
396 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
401 TRACE("(%p)->(%08x %d %p %p)\n", This
, flags
, size
, format
, stgmed
);
405 hr
= IStream_Read(stgmed
->u
.pstm
, buf
, sizeof(buf
), &read
);
406 if (hr
!= S_OK
) break;
408 hr
= IStream_Write(This
->stream
, buf
, read
, &written
);
409 } while((hr
== S_OK
) && written
!= 0 && read
!= 0);
411 httprequest_setreadystate(This
->request
, READYSTATE_INTERACTIVE
);
416 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
417 REFIID riid
, IUnknown
*punk
)
419 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
421 FIXME("(%p)->(%s %p): stub\n", This
, debugstr_guid(riid
), punk
);
426 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
427 BindStatusCallback_QueryInterface
,
428 BindStatusCallback_AddRef
,
429 BindStatusCallback_Release
,
430 BindStatusCallback_OnStartBinding
,
431 BindStatusCallback_GetPriority
,
432 BindStatusCallback_OnLowResource
,
433 BindStatusCallback_OnProgress
,
434 BindStatusCallback_OnStopBinding
,
435 BindStatusCallback_GetBindInfo
,
436 BindStatusCallback_OnDataAvailable
,
437 BindStatusCallback_OnObjectAvailable
440 static HRESULT WINAPI
BSCHttpNegotiate_QueryInterface(IHttpNegotiate
*iface
,
441 REFIID riid
, void **ppv
)
443 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
444 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
447 static ULONG WINAPI
BSCHttpNegotiate_AddRef(IHttpNegotiate
*iface
)
449 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
450 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
453 static ULONG WINAPI
BSCHttpNegotiate_Release(IHttpNegotiate
*iface
)
455 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
456 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
459 static HRESULT WINAPI
BSCHttpNegotiate_BeginningTransaction(IHttpNegotiate
*iface
,
460 LPCWSTR url
, LPCWSTR headers
, DWORD reserved
, LPWSTR
*add_headers
)
462 static const WCHAR content_type_utf8W
[] = {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ',
463 't','e','x','t','/','p','l','a','i','n',';','c','h','a','r','s','e','t','=','u','t','f','-','8','\r','\n',0};
465 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
466 const struct httpheader
*entry
;
470 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(url
), debugstr_w(headers
), reserved
, add_headers
);
474 if (This
->request
->use_utf8_content
)
475 size
= sizeof(content_type_utf8W
);
477 if (!list_empty(&This
->request
->reqheaders
))
478 size
+= This
->request
->reqheader_size
*sizeof(WCHAR
);
480 if (!size
) return S_OK
;
482 buff
= CoTaskMemAlloc(size
);
483 if (!buff
) return E_OUTOFMEMORY
;
486 if (This
->request
->use_utf8_content
)
488 lstrcpyW(ptr
, content_type_utf8W
);
489 ptr
+= sizeof(content_type_utf8W
)/sizeof(WCHAR
)-1;
493 LIST_FOR_EACH_ENTRY(entry
, &This
->request
->reqheaders
, struct httpheader
, entry
)
495 lstrcpyW(ptr
, entry
->header
);
496 ptr
+= SysStringLen(entry
->header
);
498 lstrcpyW(ptr
, colspaceW
);
499 ptr
+= sizeof(colspaceW
)/sizeof(WCHAR
)-1;
501 lstrcpyW(ptr
, entry
->value
);
502 ptr
+= SysStringLen(entry
->value
);
504 lstrcpyW(ptr
, crlfW
);
505 ptr
+= sizeof(crlfW
)/sizeof(WCHAR
)-1;
513 static void add_response_header(httprequest
*This
, const WCHAR
*data
, int len
)
515 struct httpheader
*entry
;
516 const WCHAR
*ptr
= data
;
523 header
= SysAllocStringLen(data
, ptr
-data
);
524 /* skip leading spaces for a value */
525 while (*++ptr
== ' ')
527 value
= SysAllocStringLen(ptr
, len
-(ptr
-data
));
536 TRACE("got header %s:%s\n", debugstr_w(header
), debugstr_w(value
));
538 entry
= heap_alloc(sizeof(*entry
));
539 entry
->header
= header
;
540 entry
->value
= value
;
541 list_add_head(&This
->respheaders
, &entry
->entry
);
544 static HRESULT WINAPI
BSCHttpNegotiate_OnResponse(IHttpNegotiate
*iface
, DWORD code
,
545 LPCWSTR resp_headers
, LPCWSTR req_headers
, LPWSTR
*add_reqheaders
)
547 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
549 TRACE("(%p)->(%d %s %s %p)\n", This
, code
, debugstr_w(resp_headers
),
550 debugstr_w(req_headers
), add_reqheaders
);
552 This
->request
->status
= code
;
553 /* store headers and status text */
554 free_response_headers(This
->request
);
555 SysFreeString(This
->request
->status_text
);
556 This
->request
->status_text
= NULL
;
559 const WCHAR
*ptr
, *line
, *status_text
;
561 ptr
= line
= resp_headers
;
563 /* skip HTTP-Version */
564 ptr
= strchrW(ptr
, ' ');
567 /* skip Status-Code */
568 ptr
= strchrW(++ptr
, ' ');
572 /* now it supposed to end with CRLF */
575 if (*ptr
== '\r' && *(ptr
+1) == '\n')
578 This
->request
->status_text
= SysAllocStringLen(status_text
, ptr
-status_text
);
579 TRACE("status text %s\n", debugstr_w(This
->request
->status_text
));
587 /* store as unparsed string for now */
588 This
->request
->raw_respheaders
= SysAllocString(line
);
594 static const IHttpNegotiateVtbl BSCHttpNegotiateVtbl
= {
595 BSCHttpNegotiate_QueryInterface
,
596 BSCHttpNegotiate_AddRef
,
597 BSCHttpNegotiate_Release
,
598 BSCHttpNegotiate_BeginningTransaction
,
599 BSCHttpNegotiate_OnResponse
602 static HRESULT WINAPI
Authenticate_QueryInterface(IAuthenticate
*iface
,
603 REFIID riid
, void **ppv
)
605 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
606 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
609 static ULONG WINAPI
Authenticate_AddRef(IAuthenticate
*iface
)
611 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
612 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
615 static ULONG WINAPI
Authenticate_Release(IAuthenticate
*iface
)
617 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
618 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
621 static HRESULT WINAPI
Authenticate_Authenticate(IAuthenticate
*iface
,
622 HWND
*hwnd
, LPWSTR
*username
, LPWSTR
*password
)
624 BindStatusCallback
*This
= impl_from_IAuthenticate(iface
);
625 FIXME("(%p)->(%p %p %p)\n", This
, hwnd
, username
, password
);
629 static const IAuthenticateVtbl AuthenticateVtbl
= {
630 Authenticate_QueryInterface
,
632 Authenticate_Release
,
633 Authenticate_Authenticate
636 static HRESULT
BindStatusCallback_create(httprequest
* This
, BindStatusCallback
**obj
, const VARIANT
*body
)
638 BindStatusCallback
*bsc
;
643 hr
= CreateBindCtx(0, &pbc
);
644 if (hr
!= S_OK
) return hr
;
646 bsc
= heap_alloc(sizeof(*bsc
));
649 IBindCtx_Release(pbc
);
650 return E_OUTOFMEMORY
;
653 bsc
->IBindStatusCallback_iface
.lpVtbl
= &BindStatusCallbackVtbl
;
654 bsc
->IHttpNegotiate_iface
.lpVtbl
= &BSCHttpNegotiateVtbl
;
655 bsc
->IAuthenticate_iface
.lpVtbl
= &AuthenticateVtbl
;
662 TRACE("(%p)->(%p)\n", This
, bsc
);
664 This
->use_utf8_content
= FALSE
;
666 if (This
->verb
!= BINDVERB_GET
)
668 void *send_data
, *ptr
;
669 SAFEARRAY
*sa
= NULL
;
671 if (V_VT(body
) == (VT_VARIANT
|VT_BYREF
))
672 body
= V_VARIANTREF(body
);
678 int len
= SysStringLen(V_BSTR(body
));
679 const WCHAR
*str
= V_BSTR(body
);
682 for (i
= 0; i
< len
; i
++)
691 size
= WideCharToMultiByte(cp
, 0, str
, len
, NULL
, 0, NULL
, NULL
);
692 if (!(ptr
= heap_alloc(size
)))
695 return E_OUTOFMEMORY
;
697 WideCharToMultiByte(cp
, 0, str
, len
, ptr
, size
, NULL
, NULL
);
698 if (cp
== CP_UTF8
) This
->use_utf8_content
= TRUE
;
701 case VT_ARRAY
|VT_UI1
:
704 if ((hr
= SafeArrayAccessData(sa
, (void **)&ptr
)) != S_OK
)
709 if ((hr
= SafeArrayGetUBound(sa
, 1, &size
) != S_OK
))
711 SafeArrayUnaccessData(sa
);
719 FIXME("unsupported body data type %d\n", V_VT(body
));
728 bsc
->body
= GlobalAlloc(GMEM_FIXED
, size
);
731 if (V_VT(body
) == VT_BSTR
)
733 else if (V_VT(body
) == (VT_ARRAY
|VT_UI1
))
734 SafeArrayUnaccessData(sa
);
737 return E_OUTOFMEMORY
;
740 send_data
= GlobalLock(bsc
->body
);
741 memcpy(send_data
, ptr
, size
);
742 GlobalUnlock(bsc
->body
);
744 if (V_VT(body
) == VT_BSTR
)
746 else if (V_VT(body
) == (VT_ARRAY
|VT_UI1
))
747 SafeArrayUnaccessData(sa
);
750 hr
= RegisterBindStatusCallback(pbc
, &bsc
->IBindStatusCallback_iface
, NULL
, 0);
755 hr
= CreateURLMonikerEx2(NULL
, This
->uri
, &moniker
, URL_MK_UNIFORM
);
760 hr
= IMoniker_BindToStorage(moniker
, pbc
, NULL
, &IID_IStream
, (void**)&stream
);
761 IMoniker_Release(moniker
);
762 if (stream
) IStream_Release(stream
);
764 IBindCtx_Release(pbc
);
769 IBindStatusCallback_Release(&bsc
->IBindStatusCallback_iface
);
777 static HRESULT
verify_uri(httprequest
*This
, IUri
*uri
)
779 DWORD scheme
, base_scheme
;
780 BSTR host
, base_host
;
783 if(!(This
->safeopt
& INTERFACESAFE_FOR_UNTRUSTED_DATA
))
787 return E_ACCESSDENIED
;
789 hr
= IUri_GetScheme(uri
, &scheme
);
793 hr
= IUri_GetScheme(This
->base_uri
, &base_scheme
);
797 if(scheme
!= base_scheme
) {
798 WARN("Schemes don't match\n");
799 return E_ACCESSDENIED
;
802 if(scheme
== INTERNET_SCHEME_UNKNOWN
) {
803 FIXME("Unknown scheme\n");
804 return E_ACCESSDENIED
;
807 hr
= IUri_GetHost(uri
, &host
);
811 hr
= IUri_GetHost(This
->base_uri
, &base_host
);
813 if(strcmpiW(host
, base_host
)) {
814 WARN("Hosts don't match\n");
817 SysFreeString(base_host
);
824 static HRESULT
httprequest_open(httprequest
*This
, BSTR method
, BSTR url
,
825 VARIANT async
, VARIANT user
, VARIANT password
)
827 static const WCHAR MethodGetW
[] = {'G','E','T',0};
828 static const WCHAR MethodPutW
[] = {'P','U','T',0};
829 static const WCHAR MethodPostW
[] = {'P','O','S','T',0};
830 static const WCHAR MethodDeleteW
[] = {'D','E','L','E','T','E',0};
831 static const WCHAR MethodPropFindW
[] = {'P','R','O','P','F','I','N','D',0};
832 VARIANT str
, is_async
;
836 if (!method
|| !url
) return E_INVALIDARG
;
838 /* free previously set data */
840 IUri_Release(This
->uri
);
844 SysFreeString(This
->user
);
845 SysFreeString(This
->password
);
846 This
->user
= This
->password
= NULL
;
848 if (!strcmpiW(method
, MethodGetW
))
850 This
->verb
= BINDVERB_GET
;
852 else if (!strcmpiW(method
, MethodPutW
))
854 This
->verb
= BINDVERB_PUT
;
856 else if (!strcmpiW(method
, MethodPostW
))
858 This
->verb
= BINDVERB_POST
;
860 else if (!strcmpiW(method
, MethodDeleteW
) ||
861 !strcmpiW(method
, MethodPropFindW
))
863 This
->verb
= BINDVERB_CUSTOM
;
864 SysReAllocString(&This
->custom
, method
);
868 FIXME("unsupported request type %s\n", debugstr_w(method
));
874 hr
= CoInternetCombineUrlEx(This
->base_uri
, url
, 0, &uri
, 0);
876 hr
= CreateUri(url
, 0, 0, &uri
);
878 WARN("Could not create IUri object: %08x\n", hr
);
882 hr
= verify_uri(This
, uri
);
890 VariantInit(&is_async
);
891 hr
= VariantChangeType(&is_async
, &async
, 0, VT_BOOL
);
892 This
->async
= hr
== S_OK
&& V_BOOL(&is_async
);
895 hr
= VariantChangeType(&str
, &user
, 0, VT_BSTR
);
897 This
->user
= V_BSTR(&str
);
900 hr
= VariantChangeType(&str
, &password
, 0, VT_BSTR
);
902 This
->password
= V_BSTR(&str
);
904 httprequest_setreadystate(This
, READYSTATE_LOADING
);
909 static HRESULT
httprequest_setRequestHeader(httprequest
*This
, BSTR header
, BSTR value
)
911 struct httpheader
*entry
;
913 if (!header
|| !*header
) return E_INVALIDARG
;
914 if (This
->state
!= READYSTATE_LOADING
) return E_FAIL
;
915 if (!value
) return E_INVALIDARG
;
917 /* replace existing header value if already added */
918 LIST_FOR_EACH_ENTRY(entry
, &This
->reqheaders
, struct httpheader
, entry
)
920 if (lstrcmpW(entry
->header
, header
) == 0)
922 LONG length
= SysStringLen(entry
->value
);
925 hr
= SysReAllocString(&entry
->value
, value
) ? S_OK
: E_OUTOFMEMORY
;
928 This
->reqheader_size
+= (SysStringLen(entry
->value
) - length
);
934 entry
= heap_alloc(sizeof(*entry
));
935 if (!entry
) return E_OUTOFMEMORY
;
938 entry
->header
= SysAllocString(header
);
939 entry
->value
= SysAllocString(value
);
941 /* header length including null terminator */
942 This
->reqheader_size
+= SysStringLen(entry
->header
) + sizeof(colspaceW
)/sizeof(WCHAR
) +
943 SysStringLen(entry
->value
) + sizeof(crlfW
)/sizeof(WCHAR
) - 1;
945 list_add_head(&This
->reqheaders
, &entry
->entry
);
950 static HRESULT
httprequest_getResponseHeader(httprequest
*This
, BSTR header
, BSTR
*value
)
952 struct httpheader
*entry
;
954 if (!header
) return E_INVALIDARG
;
955 if (!value
) return E_POINTER
;
957 if (This
->raw_respheaders
&& list_empty(&This
->respheaders
))
961 ptr
= line
= This
->raw_respheaders
;
964 if (*ptr
== '\r' && *(ptr
+1) == '\n')
966 add_response_header(This
, line
, ptr
-line
);
974 LIST_FOR_EACH_ENTRY(entry
, &This
->respheaders
, struct httpheader
, entry
)
976 if (!strcmpiW(entry
->header
, header
))
978 *value
= SysAllocString(entry
->value
);
979 TRACE("header value %s\n", debugstr_w(*value
));
987 static HRESULT
httprequest_getAllResponseHeaders(httprequest
*This
, BSTR
*respheaders
)
989 if (!respheaders
) return E_POINTER
;
991 *respheaders
= SysAllocString(This
->raw_respheaders
);
996 static HRESULT
httprequest_send(httprequest
*This
, VARIANT body
)
998 BindStatusCallback
*bsc
= NULL
;
1001 if (This
->state
!= READYSTATE_LOADING
) return E_FAIL
;
1003 hr
= BindStatusCallback_create(This
, &bsc
, &body
);
1005 /* success path to detach it is OnStopBinding call */
1006 BindStatusCallback_Detach(bsc
);
1011 static HRESULT
httprequest_abort(httprequest
*This
)
1013 BindStatusCallback_Detach(This
->bsc
);
1015 httprequest_setreadystate(This
, READYSTATE_UNINITIALIZED
);
1020 static HRESULT
httprequest_get_status(httprequest
*This
, LONG
*status
)
1022 if (!status
) return E_POINTER
;
1024 *status
= This
->status
;
1026 return This
->state
== READYSTATE_COMPLETE
? S_OK
: E_FAIL
;
1029 static HRESULT
httprequest_get_statusText(httprequest
*This
, BSTR
*status
)
1031 if (!status
) return E_POINTER
;
1032 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
1034 *status
= SysAllocString(This
->status_text
);
1039 static HRESULT
httprequest_get_responseText(httprequest
*This
, BSTR
*body
)
1044 if (!body
) return E_POINTER
;
1045 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
1047 hr
= GetHGlobalFromStream(This
->bsc
->stream
, &hglobal
);
1050 xmlChar
*ptr
= GlobalLock(hglobal
);
1051 DWORD size
= GlobalSize(hglobal
);
1052 xmlCharEncoding encoding
= XML_CHAR_ENCODING_UTF8
;
1054 /* try to determine data encoding */
1057 encoding
= xmlDetectCharEncoding(ptr
, 4);
1058 TRACE("detected encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding
)));
1059 if ( encoding
!= XML_CHAR_ENCODING_UTF8
&&
1060 encoding
!= XML_CHAR_ENCODING_UTF16LE
&&
1061 encoding
!= XML_CHAR_ENCODING_NONE
)
1063 FIXME("unsupported encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding
)));
1064 GlobalUnlock(hglobal
);
1069 /* without BOM assume UTF-8 */
1070 if (encoding
== XML_CHAR_ENCODING_UTF8
||
1071 encoding
== XML_CHAR_ENCODING_NONE
)
1073 DWORD length
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)ptr
, size
, NULL
, 0);
1075 *body
= SysAllocStringLen(NULL
, length
);
1077 MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
)ptr
, size
, *body
, length
);
1080 *body
= SysAllocStringByteLen((LPCSTR
)ptr
, size
);
1082 if (!*body
) hr
= E_OUTOFMEMORY
;
1083 GlobalUnlock(hglobal
);
1089 static HRESULT
httprequest_get_responseXML(httprequest
*This
, IDispatch
**body
)
1091 IXMLDOMDocument3
*doc
;
1095 if (!body
) return E_INVALIDARG
;
1096 if (This
->state
!= READYSTATE_COMPLETE
) return E_FAIL
;
1098 hr
= DOMDocument_create(MSXML_DEFAULT
, NULL
, (void**)&doc
);
1099 if (hr
!= S_OK
) return hr
;
1101 hr
= httprequest_get_responseText(This
, &str
);
1106 hr
= IXMLDOMDocument3_loadXML(doc
, str
, &ok
);
1110 IXMLDOMDocument3_QueryInterface(doc
, &IID_IDispatch
, (void**)body
);
1111 IXMLDOMDocument3_Release(doc
);
1116 static HRESULT
httprequest_get_responseBody(httprequest
*This
, VARIANT
*body
)
1121 if (!body
) return E_INVALIDARG
;
1122 V_VT(body
) = VT_EMPTY
;
1124 if (This
->state
!= READYSTATE_COMPLETE
) return E_PENDING
;
1126 hr
= GetHGlobalFromStream(This
->bsc
->stream
, &hglobal
);
1129 void *ptr
= GlobalLock(hglobal
);
1130 DWORD size
= GlobalSize(hglobal
);
1132 SAFEARRAYBOUND bound
;
1136 bound
.cElements
= size
;
1137 array
= SafeArrayCreate(VT_UI1
, 1, &bound
);
1143 V_VT(body
) = VT_ARRAY
| VT_UI1
;
1144 V_ARRAY(body
) = array
;
1146 hr
= SafeArrayAccessData(array
, &dest
);
1149 memcpy(dest
, ptr
, size
);
1150 SafeArrayUnaccessData(array
);
1160 GlobalUnlock(hglobal
);
1166 static HRESULT
httprequest_get_responseStream(httprequest
*This
, VARIANT
*body
)
1172 if (!body
) return E_INVALIDARG
;
1173 V_VT(body
) = VT_EMPTY
;
1175 if (This
->state
!= READYSTATE_COMPLETE
) return E_PENDING
;
1177 hr
= IStream_Clone(This
->bsc
->stream
, &stream
);
1180 IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
1182 V_VT(body
) = VT_UNKNOWN
;
1183 V_UNKNOWN(body
) = (IUnknown
*)stream
;
1188 static HRESULT
httprequest_get_readyState(httprequest
*This
, LONG
*state
)
1190 if (!state
) return E_POINTER
;
1192 *state
= This
->state
;
1196 static HRESULT
httprequest_put_onreadystatechange(httprequest
*This
, IDispatch
*sink
)
1198 if (This
->sink
) IDispatch_Release(This
->sink
);
1199 if ((This
->sink
= sink
)) IDispatch_AddRef(This
->sink
);
1204 static void httprequest_release(httprequest
*This
)
1206 struct httpheader
*header
, *header2
;
1209 IUnknown_Release( This
->site
);
1211 IUri_Release(This
->uri
);
1213 IUri_Release(This
->base_uri
);
1215 SysFreeString(This
->custom
);
1216 SysFreeString(This
->user
);
1217 SysFreeString(This
->password
);
1219 /* request headers */
1220 LIST_FOR_EACH_ENTRY_SAFE(header
, header2
, &This
->reqheaders
, struct httpheader
, entry
)
1222 list_remove(&header
->entry
);
1223 SysFreeString(header
->header
);
1224 SysFreeString(header
->value
);
1227 /* response headers */
1228 free_response_headers(This
);
1229 SysFreeString(This
->status_text
);
1231 /* detach callback object */
1232 BindStatusCallback_Detach(This
->bsc
);
1234 if (This
->sink
) IDispatch_Release(This
->sink
);
1237 static HRESULT WINAPI
XMLHTTPRequest_QueryInterface(IXMLHTTPRequest
*iface
, REFIID riid
, void **ppvObject
)
1239 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1240 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1242 if ( IsEqualGUID( riid
, &IID_IXMLHTTPRequest
) ||
1243 IsEqualGUID( riid
, &IID_IDispatch
) ||
1244 IsEqualGUID( riid
, &IID_IUnknown
) )
1248 else if (IsEqualGUID(&IID_IObjectWithSite
, riid
))
1250 *ppvObject
= &This
->IObjectWithSite_iface
;
1252 else if (IsEqualGUID(&IID_IObjectSafety
, riid
))
1254 *ppvObject
= &This
->IObjectSafety_iface
;
1258 TRACE("Unsupported interface %s\n", debugstr_guid(riid
));
1260 return E_NOINTERFACE
;
1263 IXMLHTTPRequest_AddRef( iface
);
1268 static ULONG WINAPI
XMLHTTPRequest_AddRef(IXMLHTTPRequest
*iface
)
1270 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1271 ULONG ref
= InterlockedIncrement( &This
->ref
);
1272 TRACE("(%p)->(%u)\n", This
, ref
);
1276 static ULONG WINAPI
XMLHTTPRequest_Release(IXMLHTTPRequest
*iface
)
1278 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1279 ULONG ref
= InterlockedDecrement( &This
->ref
);
1281 TRACE("(%p)->(%u)\n", This
, ref
);
1285 httprequest_release( This
);
1292 static HRESULT WINAPI
XMLHTTPRequest_GetTypeInfoCount(IXMLHTTPRequest
*iface
, UINT
*pctinfo
)
1294 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1296 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1303 static HRESULT WINAPI
XMLHTTPRequest_GetTypeInfo(IXMLHTTPRequest
*iface
, UINT iTInfo
,
1304 LCID lcid
, ITypeInfo
**ppTInfo
)
1306 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1308 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1310 return get_typeinfo(IXMLHTTPRequest_tid
, ppTInfo
);
1313 static HRESULT WINAPI
XMLHTTPRequest_GetIDsOfNames(IXMLHTTPRequest
*iface
, REFIID riid
,
1314 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1316 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1317 ITypeInfo
*typeinfo
;
1320 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1323 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1324 return E_INVALIDARG
;
1326 hr
= get_typeinfo(IXMLHTTPRequest_tid
, &typeinfo
);
1329 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1330 ITypeInfo_Release(typeinfo
);
1336 static HRESULT WINAPI
XMLHTTPRequest_Invoke(IXMLHTTPRequest
*iface
, DISPID dispIdMember
, REFIID riid
,
1337 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1338 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1340 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1341 ITypeInfo
*typeinfo
;
1344 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1345 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1347 hr
= get_typeinfo(IXMLHTTPRequest_tid
, &typeinfo
);
1350 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLHTTPRequest_iface
, dispIdMember
, wFlags
,
1351 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1352 ITypeInfo_Release(typeinfo
);
1358 static HRESULT WINAPI
XMLHTTPRequest_open(IXMLHTTPRequest
*iface
, BSTR method
, BSTR url
,
1359 VARIANT async
, VARIANT user
, VARIANT password
)
1361 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1362 TRACE("(%p)->(%s %s %s)\n", This
, debugstr_w(method
), debugstr_w(url
),
1363 debugstr_variant(&async
));
1364 return httprequest_open(This
, method
, url
, async
, user
, password
);
1367 static HRESULT WINAPI
XMLHTTPRequest_setRequestHeader(IXMLHTTPRequest
*iface
, BSTR header
, BSTR value
)
1369 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1370 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(header
), debugstr_w(value
));
1371 return httprequest_setRequestHeader(This
, header
, value
);
1374 static HRESULT WINAPI
XMLHTTPRequest_getResponseHeader(IXMLHTTPRequest
*iface
, BSTR header
, BSTR
*value
)
1376 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1377 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(header
), value
);
1378 return httprequest_getResponseHeader(This
, header
, value
);
1381 static HRESULT WINAPI
XMLHTTPRequest_getAllResponseHeaders(IXMLHTTPRequest
*iface
, BSTR
*respheaders
)
1383 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1384 TRACE("(%p)->(%p)\n", This
, respheaders
);
1385 return httprequest_getAllResponseHeaders(This
, respheaders
);
1388 static HRESULT WINAPI
XMLHTTPRequest_send(IXMLHTTPRequest
*iface
, VARIANT body
)
1390 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1391 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&body
));
1392 return httprequest_send(This
, body
);
1395 static HRESULT WINAPI
XMLHTTPRequest_abort(IXMLHTTPRequest
*iface
)
1397 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1398 TRACE("(%p)\n", This
);
1399 return httprequest_abort(This
);
1402 static HRESULT WINAPI
XMLHTTPRequest_get_status(IXMLHTTPRequest
*iface
, LONG
*status
)
1404 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1405 TRACE("(%p)->(%p)\n", This
, status
);
1406 return httprequest_get_status(This
, status
);
1409 static HRESULT WINAPI
XMLHTTPRequest_get_statusText(IXMLHTTPRequest
*iface
, BSTR
*status
)
1411 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1412 TRACE("(%p)->(%p)\n", This
, status
);
1413 return httprequest_get_statusText(This
, status
);
1416 static HRESULT WINAPI
XMLHTTPRequest_get_responseXML(IXMLHTTPRequest
*iface
, IDispatch
**body
)
1418 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1419 TRACE("(%p)->(%p)\n", This
, body
);
1420 return httprequest_get_responseXML(This
, body
);
1423 static HRESULT WINAPI
XMLHTTPRequest_get_responseText(IXMLHTTPRequest
*iface
, BSTR
*body
)
1425 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1426 TRACE("(%p)->(%p)\n", This
, body
);
1427 return httprequest_get_responseText(This
, body
);
1430 static HRESULT WINAPI
XMLHTTPRequest_get_responseBody(IXMLHTTPRequest
*iface
, VARIANT
*body
)
1432 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1433 TRACE("(%p)->(%p)\n", This
, body
);
1434 return httprequest_get_responseBody(This
, body
);
1437 static HRESULT WINAPI
XMLHTTPRequest_get_responseStream(IXMLHTTPRequest
*iface
, VARIANT
*body
)
1439 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1440 TRACE("(%p)->(%p)\n", This
, body
);
1441 return httprequest_get_responseStream(This
, body
);
1444 static HRESULT WINAPI
XMLHTTPRequest_get_readyState(IXMLHTTPRequest
*iface
, LONG
*state
)
1446 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1447 TRACE("(%p)->(%p)\n", This
, state
);
1448 return httprequest_get_readyState(This
, state
);
1451 static HRESULT WINAPI
XMLHTTPRequest_put_onreadystatechange(IXMLHTTPRequest
*iface
, IDispatch
*sink
)
1453 httprequest
*This
= impl_from_IXMLHTTPRequest( iface
);
1454 TRACE("(%p)->(%p)\n", This
, sink
);
1455 return httprequest_put_onreadystatechange(This
, sink
);
1458 static const struct IXMLHTTPRequestVtbl XMLHTTPRequestVtbl
=
1460 XMLHTTPRequest_QueryInterface
,
1461 XMLHTTPRequest_AddRef
,
1462 XMLHTTPRequest_Release
,
1463 XMLHTTPRequest_GetTypeInfoCount
,
1464 XMLHTTPRequest_GetTypeInfo
,
1465 XMLHTTPRequest_GetIDsOfNames
,
1466 XMLHTTPRequest_Invoke
,
1467 XMLHTTPRequest_open
,
1468 XMLHTTPRequest_setRequestHeader
,
1469 XMLHTTPRequest_getResponseHeader
,
1470 XMLHTTPRequest_getAllResponseHeaders
,
1471 XMLHTTPRequest_send
,
1472 XMLHTTPRequest_abort
,
1473 XMLHTTPRequest_get_status
,
1474 XMLHTTPRequest_get_statusText
,
1475 XMLHTTPRequest_get_responseXML
,
1476 XMLHTTPRequest_get_responseText
,
1477 XMLHTTPRequest_get_responseBody
,
1478 XMLHTTPRequest_get_responseStream
,
1479 XMLHTTPRequest_get_readyState
,
1480 XMLHTTPRequest_put_onreadystatechange
1483 /* IObjectWithSite */
1484 static HRESULT WINAPI
1485 httprequest_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
1487 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1488 return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest
*)This
, riid
, ppvObject
);
1491 static ULONG WINAPI
httprequest_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
1493 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1494 return IXMLHTTPRequest_AddRef((IXMLHTTPRequest
*)This
);
1497 static ULONG WINAPI
httprequest_ObjectWithSite_Release( IObjectWithSite
* iface
)
1499 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1500 return IXMLHTTPRequest_Release((IXMLHTTPRequest
*)This
);
1503 static HRESULT WINAPI
httprequest_ObjectWithSite_GetSite( IObjectWithSite
*iface
, REFIID iid
, void **ppvSite
)
1505 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1507 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid( iid
), ppvSite
);
1512 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
1515 static void get_base_uri(httprequest
*This
)
1517 IServiceProvider
*provider
;
1518 IHTMLDocument2
*doc
;
1523 hr
= IUnknown_QueryInterface(This
->site
, &IID_IServiceProvider
, (void**)&provider
);
1527 hr
= IServiceProvider_QueryService(provider
, &SID_SContainerDispatch
, &IID_IHTMLDocument2
, (void**)&doc
);
1528 IServiceProvider_Release(provider
);
1532 hr
= IHTMLDocument2_get_URL(doc
, &url
);
1533 IHTMLDocument2_Release(doc
);
1534 if(FAILED(hr
) || !url
|| !*url
)
1537 TRACE("host url %s\n", debugstr_w(url
));
1539 hr
= CreateUri(url
, 0, 0, &uri
);
1544 This
->base_uri
= uri
;
1547 static HRESULT WINAPI
httprequest_ObjectWithSite_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
1549 httprequest
*This
= impl_from_IObjectWithSite(iface
);
1551 TRACE("(%p)->(%p)\n", This
, punk
);
1554 IUnknown_Release( This
->site
);
1556 IUri_Release(This
->base_uri
);
1562 IUnknown_AddRef( punk
);
1569 static const IObjectWithSiteVtbl ObjectWithSiteVtbl
=
1571 httprequest_ObjectWithSite_QueryInterface
,
1572 httprequest_ObjectWithSite_AddRef
,
1573 httprequest_ObjectWithSite_Release
,
1574 httprequest_ObjectWithSite_SetSite
,
1575 httprequest_ObjectWithSite_GetSite
1579 static HRESULT WINAPI
httprequest_Safety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
1581 httprequest
*This
= impl_from_IObjectSafety(iface
);
1582 return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest
*)This
, riid
, ppv
);
1585 static ULONG WINAPI
httprequest_Safety_AddRef(IObjectSafety
*iface
)
1587 httprequest
*This
= impl_from_IObjectSafety(iface
);
1588 return IXMLHTTPRequest_AddRef((IXMLHTTPRequest
*)This
);
1591 static ULONG WINAPI
httprequest_Safety_Release(IObjectSafety
*iface
)
1593 httprequest
*This
= impl_from_IObjectSafety(iface
);
1594 return IXMLHTTPRequest_Release((IXMLHTTPRequest
*)This
);
1597 static HRESULT WINAPI
httprequest_Safety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1598 DWORD
*supported
, DWORD
*enabled
)
1600 httprequest
*This
= impl_from_IObjectSafety(iface
);
1602 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), supported
, enabled
);
1604 if(!supported
|| !enabled
) return E_POINTER
;
1606 *supported
= safety_supported_options
;
1607 *enabled
= This
->safeopt
;
1612 static HRESULT WINAPI
httprequest_Safety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1613 DWORD mask
, DWORD enabled
)
1615 httprequest
*This
= impl_from_IObjectSafety(iface
);
1616 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), mask
, enabled
);
1618 if ((mask
& ~safety_supported_options
))
1621 This
->safeopt
= (This
->safeopt
& ~mask
) | (mask
& enabled
);
1626 static const IObjectSafetyVtbl ObjectSafetyVtbl
= {
1627 httprequest_Safety_QueryInterface
,
1628 httprequest_Safety_AddRef
,
1629 httprequest_Safety_Release
,
1630 httprequest_Safety_GetInterfaceSafetyOptions
,
1631 httprequest_Safety_SetInterfaceSafetyOptions
1634 /* IServerXMLHTTPRequest */
1635 static HRESULT WINAPI
ServerXMLHTTPRequest_QueryInterface(IServerXMLHTTPRequest
*iface
, REFIID riid
, void **obj
)
1637 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1639 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1641 if ( IsEqualGUID( riid
, &IID_IServerXMLHTTPRequest
) ||
1642 IsEqualGUID( riid
, &IID_IXMLHTTPRequest
) ||
1643 IsEqualGUID( riid
, &IID_IDispatch
) ||
1644 IsEqualGUID( riid
, &IID_IUnknown
) )
1650 TRACE("Unsupported interface %s\n", debugstr_guid(riid
));
1652 return E_NOINTERFACE
;
1655 IServerXMLHTTPRequest_AddRef( iface
);
1660 static ULONG WINAPI
ServerXMLHTTPRequest_AddRef(IServerXMLHTTPRequest
*iface
)
1662 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1663 ULONG ref
= InterlockedIncrement( &This
->ref
);
1664 TRACE("(%p)->(%u)\n", This
, ref
);
1668 static ULONG WINAPI
ServerXMLHTTPRequest_Release(IServerXMLHTTPRequest
*iface
)
1670 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1671 ULONG ref
= InterlockedDecrement( &This
->ref
);
1673 TRACE("(%p)->(%u)\n", This
, ref
);
1677 httprequest_release( &This
->req
);
1684 static HRESULT WINAPI
ServerXMLHTTPRequest_GetTypeInfoCount(IServerXMLHTTPRequest
*iface
, UINT
*pctinfo
)
1686 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1688 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1694 static HRESULT WINAPI
ServerXMLHTTPRequest_GetTypeInfo(IServerXMLHTTPRequest
*iface
, UINT iTInfo
,
1695 LCID lcid
, ITypeInfo
**ppTInfo
)
1697 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1699 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1701 return get_typeinfo(IServerXMLHTTPRequest_tid
, ppTInfo
);
1704 static HRESULT WINAPI
ServerXMLHTTPRequest_GetIDsOfNames(IServerXMLHTTPRequest
*iface
, REFIID riid
,
1705 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1707 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1708 ITypeInfo
*typeinfo
;
1711 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1714 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1715 return E_INVALIDARG
;
1717 hr
= get_typeinfo(IServerXMLHTTPRequest_tid
, &typeinfo
);
1720 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1721 ITypeInfo_Release(typeinfo
);
1727 static HRESULT WINAPI
ServerXMLHTTPRequest_Invoke(IServerXMLHTTPRequest
*iface
, DISPID dispIdMember
, REFIID riid
,
1728 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
1729 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1731 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1732 ITypeInfo
*typeinfo
;
1735 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1736 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1738 hr
= get_typeinfo(IServerXMLHTTPRequest_tid
, &typeinfo
);
1741 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IServerXMLHTTPRequest_iface
, dispIdMember
, wFlags
,
1742 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1743 ITypeInfo_Release(typeinfo
);
1749 static HRESULT WINAPI
ServerXMLHTTPRequest_open(IServerXMLHTTPRequest
*iface
, BSTR method
, BSTR url
,
1750 VARIANT async
, VARIANT user
, VARIANT password
)
1752 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1753 TRACE("(%p)->(%s %s %s)\n", This
, debugstr_w(method
), debugstr_w(url
),
1754 debugstr_variant(&async
));
1755 return httprequest_open(&This
->req
, method
, url
, async
, user
, password
);
1758 static HRESULT WINAPI
ServerXMLHTTPRequest_setRequestHeader(IServerXMLHTTPRequest
*iface
, BSTR header
, BSTR value
)
1760 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1761 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(header
), debugstr_w(value
));
1762 return httprequest_setRequestHeader(&This
->req
, header
, value
);
1765 static HRESULT WINAPI
ServerXMLHTTPRequest_getResponseHeader(IServerXMLHTTPRequest
*iface
, BSTR header
, BSTR
*value
)
1767 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1768 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(header
), value
);
1769 return httprequest_getResponseHeader(&This
->req
, header
, value
);
1772 static HRESULT WINAPI
ServerXMLHTTPRequest_getAllResponseHeaders(IServerXMLHTTPRequest
*iface
, BSTR
*respheaders
)
1774 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1775 TRACE("(%p)->(%p)\n", This
, respheaders
);
1776 return httprequest_getAllResponseHeaders(&This
->req
, respheaders
);
1779 static HRESULT WINAPI
ServerXMLHTTPRequest_send(IServerXMLHTTPRequest
*iface
, VARIANT body
)
1781 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1782 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&body
));
1783 return httprequest_send(&This
->req
, body
);
1786 static HRESULT WINAPI
ServerXMLHTTPRequest_abort(IServerXMLHTTPRequest
*iface
)
1788 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1789 TRACE("(%p)\n", This
);
1790 return httprequest_abort(&This
->req
);
1793 static HRESULT WINAPI
ServerXMLHTTPRequest_get_status(IServerXMLHTTPRequest
*iface
, LONG
*status
)
1795 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1796 TRACE("(%p)->(%p)\n", This
, status
);
1797 return httprequest_get_status(&This
->req
, status
);
1800 static HRESULT WINAPI
ServerXMLHTTPRequest_get_statusText(IServerXMLHTTPRequest
*iface
, BSTR
*status
)
1802 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1803 TRACE("(%p)->(%p)\n", This
, status
);
1804 return httprequest_get_statusText(&This
->req
, status
);
1807 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseXML(IServerXMLHTTPRequest
*iface
, IDispatch
**body
)
1809 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1810 TRACE("(%p)->(%p)\n", This
, body
);
1811 return httprequest_get_responseXML(&This
->req
, body
);
1814 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseText(IServerXMLHTTPRequest
*iface
, BSTR
*body
)
1816 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1817 TRACE("(%p)->(%p)\n", This
, body
);
1818 return httprequest_get_responseText(&This
->req
, body
);
1821 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseBody(IServerXMLHTTPRequest
*iface
, VARIANT
*body
)
1823 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1824 TRACE("(%p)->(%p)\n", This
, body
);
1825 return httprequest_get_responseBody(&This
->req
, body
);
1828 static HRESULT WINAPI
ServerXMLHTTPRequest_get_responseStream(IServerXMLHTTPRequest
*iface
, VARIANT
*body
)
1830 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1831 TRACE("(%p)->(%p)\n", This
, body
);
1832 return httprequest_get_responseStream(&This
->req
, body
);
1835 static HRESULT WINAPI
ServerXMLHTTPRequest_get_readyState(IServerXMLHTTPRequest
*iface
, LONG
*state
)
1837 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1838 TRACE("(%p)->(%p)\n", This
, state
);
1839 return httprequest_get_readyState(&This
->req
, state
);
1842 static HRESULT WINAPI
ServerXMLHTTPRequest_put_onreadystatechange(IServerXMLHTTPRequest
*iface
, IDispatch
*sink
)
1844 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1845 TRACE("(%p)->(%p)\n", This
, sink
);
1846 return httprequest_put_onreadystatechange(&This
->req
, sink
);
1849 static HRESULT WINAPI
ServerXMLHTTPRequest_setTimeouts(IServerXMLHTTPRequest
*iface
, LONG resolveTimeout
, LONG connectTimeout
,
1850 LONG sendTimeout
, LONG receiveTimeout
)
1852 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1853 FIXME("(%p)->(%d %d %d %d): stub\n", This
, resolveTimeout
, connectTimeout
, sendTimeout
, receiveTimeout
);
1857 static HRESULT WINAPI
ServerXMLHTTPRequest_waitForResponse(IServerXMLHTTPRequest
*iface
, VARIANT timeout
, VARIANT_BOOL
*isSuccessful
)
1859 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1860 FIXME("(%p)->(%s %p): stub\n", This
, debugstr_variant(&timeout
), isSuccessful
);
1864 static HRESULT WINAPI
ServerXMLHTTPRequest_getOption(IServerXMLHTTPRequest
*iface
, SERVERXMLHTTP_OPTION option
, VARIANT
*value
)
1866 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1867 FIXME("(%p)->(%d %p): stub\n", This
, option
, value
);
1871 static HRESULT WINAPI
ServerXMLHTTPRequest_setOption(IServerXMLHTTPRequest
*iface
, SERVERXMLHTTP_OPTION option
, VARIANT value
)
1873 serverhttp
*This
= impl_from_IServerXMLHTTPRequest( iface
);
1874 FIXME("(%p)->(%d %s): stub\n", This
, option
, debugstr_variant(&value
));
1878 static const struct IServerXMLHTTPRequestVtbl ServerXMLHTTPRequestVtbl
=
1880 ServerXMLHTTPRequest_QueryInterface
,
1881 ServerXMLHTTPRequest_AddRef
,
1882 ServerXMLHTTPRequest_Release
,
1883 ServerXMLHTTPRequest_GetTypeInfoCount
,
1884 ServerXMLHTTPRequest_GetTypeInfo
,
1885 ServerXMLHTTPRequest_GetIDsOfNames
,
1886 ServerXMLHTTPRequest_Invoke
,
1887 ServerXMLHTTPRequest_open
,
1888 ServerXMLHTTPRequest_setRequestHeader
,
1889 ServerXMLHTTPRequest_getResponseHeader
,
1890 ServerXMLHTTPRequest_getAllResponseHeaders
,
1891 ServerXMLHTTPRequest_send
,
1892 ServerXMLHTTPRequest_abort
,
1893 ServerXMLHTTPRequest_get_status
,
1894 ServerXMLHTTPRequest_get_statusText
,
1895 ServerXMLHTTPRequest_get_responseXML
,
1896 ServerXMLHTTPRequest_get_responseText
,
1897 ServerXMLHTTPRequest_get_responseBody
,
1898 ServerXMLHTTPRequest_get_responseStream
,
1899 ServerXMLHTTPRequest_get_readyState
,
1900 ServerXMLHTTPRequest_put_onreadystatechange
,
1901 ServerXMLHTTPRequest_setTimeouts
,
1902 ServerXMLHTTPRequest_waitForResponse
,
1903 ServerXMLHTTPRequest_getOption
,
1904 ServerXMLHTTPRequest_setOption
1907 static void init_httprequest(httprequest
*req
)
1909 req
->IXMLHTTPRequest_iface
.lpVtbl
= &XMLHTTPRequestVtbl
;
1910 req
->IObjectWithSite_iface
.lpVtbl
= &ObjectWithSiteVtbl
;
1911 req
->IObjectSafety_iface
.lpVtbl
= &ObjectSafetyVtbl
;
1917 req
->uri
= req
->base_uri
= NULL
;
1918 req
->user
= req
->password
= NULL
;
1920 req
->state
= READYSTATE_UNINITIALIZED
;
1925 req
->status_text
= NULL
;
1926 req
->reqheader_size
= 0;
1927 req
->raw_respheaders
= NULL
;
1928 req
->use_utf8_content
= FALSE
;
1930 list_init(&req
->reqheaders
);
1931 list_init(&req
->respheaders
);
1937 HRESULT
XMLHTTPRequest_create(IUnknown
*outer
, void **obj
)
1941 TRACE("(%p, %p)\n", outer
, obj
);
1943 req
= heap_alloc( sizeof (*req
) );
1945 return E_OUTOFMEMORY
;
1947 init_httprequest(req
);
1948 *obj
= &req
->IXMLHTTPRequest_iface
;
1950 TRACE("returning iface %p\n", *obj
);
1955 HRESULT
ServerXMLHTTP_create(IUnknown
*outer
, void **obj
)
1959 TRACE("(%p, %p)\n", outer
, obj
);
1961 req
= heap_alloc( sizeof (*req
) );
1963 return E_OUTOFMEMORY
;
1965 init_httprequest(&req
->req
);
1966 req
->IServerXMLHTTPRequest_iface
.lpVtbl
= &ServerXMLHTTPRequestVtbl
;
1969 *obj
= &req
->IServerXMLHTTPRequest_iface
;
1971 TRACE("returning iface %p\n", *obj
);
1978 HRESULT
XMLHTTPRequest_create(IUnknown
*pUnkOuter
, void **ppObj
)
1980 MESSAGE("This program tried to use a XMLHTTPRequest object, but\n"
1981 "libxml2 support was not present at compile time.\n");
1985 HRESULT
ServerXMLHTTP_create(IUnknown
*outer
, void **obj
)
1987 MESSAGE("This program tried to use a ServerXMLHTTP object, but\n"
1988 "libxml2 support was not present at compile time.\n");