Sunc with trunk revision 58971.
[reactos.git] / dll / win32 / msxml3 / httprequest.c
1 /*
2 * IXMLHTTPRequest implementation
3 *
4 * Copyright 2008 Alistair Leslie-Hughes
5 * Copyright 2010-2012 Nikolay Sivov for CodeWeavers
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #define WIN32_NO_STATUS
23 #define _INC_WINDOWS
24
25 #define COBJMACROS
26 #define NONAMELESSUNION
27
28 #include <config.h>
29
30 //#include <stdarg.h>
31 #ifdef HAVE_LIBXML2
32 # include <libxml/parser.h>
33 //# include <libxml/xmlerror.h>
34 //# include <libxml/encoding.h>
35 #endif
36
37 #include <windef.h>
38 #include <winbase.h>
39 #include <wingdi.h>
40 #include <wininet.h>
41 #include <winreg.h>
42 //#include "winuser.h"
43 #include <ole2.h>
44 #include <mshtml.h>
45 #include <msxml6.h>
46 #include <objsafe.h>
47 #include <docobj.h>
48 #include <shlwapi.h>
49
50 #include "msxml_private.h"
51
52 #include <wine/debug.h>
53 #include <wine/list.h>
54
55 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
56
57 #ifdef HAVE_LIBXML2
58
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;
65
66 typedef struct BindStatusCallback BindStatusCallback;
67
68 struct httpheader
69 {
70 struct list entry;
71 BSTR header;
72 BSTR value;
73 };
74
75 typedef struct
76 {
77 IXMLHTTPRequest IXMLHTTPRequest_iface;
78 IObjectWithSite IObjectWithSite_iface;
79 IObjectSafety IObjectSafety_iface;
80 LONG ref;
81
82 READYSTATE state;
83 IDispatch *sink;
84
85 /* request */
86 BINDVERB verb;
87 BSTR custom;
88 IUri *uri;
89 IUri *base_uri;
90 BOOL async;
91 struct list reqheaders;
92 /* cached resulting custom request headers string length in WCHARs */
93 LONG reqheader_size;
94 /* use UTF-8 content type */
95 BOOL use_utf8_content;
96
97 /* response headers */
98 struct list respheaders;
99 BSTR raw_respheaders;
100
101 /* credentials */
102 BSTR user;
103 BSTR password;
104
105 /* bind callback */
106 BindStatusCallback *bsc;
107 LONG status;
108 BSTR status_text;
109
110 /* IObjectWithSite*/
111 IUnknown *site;
112
113 /* IObjectSafety */
114 DWORD safeopt;
115 } httprequest;
116
117 typedef struct
118 {
119 httprequest req;
120 IServerXMLHTTPRequest IServerXMLHTTPRequest_iface;
121 LONG ref;
122 } serverhttp;
123
124 static inline httprequest *impl_from_IXMLHTTPRequest( IXMLHTTPRequest *iface )
125 {
126 return CONTAINING_RECORD(iface, httprequest, IXMLHTTPRequest_iface);
127 }
128
129 static inline httprequest *impl_from_IObjectWithSite(IObjectWithSite *iface)
130 {
131 return CONTAINING_RECORD(iface, httprequest, IObjectWithSite_iface);
132 }
133
134 static inline httprequest *impl_from_IObjectSafety(IObjectSafety *iface)
135 {
136 return CONTAINING_RECORD(iface, httprequest, IObjectSafety_iface);
137 }
138
139 static inline serverhttp *impl_from_IServerXMLHTTPRequest(IServerXMLHTTPRequest *iface)
140 {
141 return CONTAINING_RECORD(iface, serverhttp, IServerXMLHTTPRequest_iface);
142 }
143
144 static void httprequest_setreadystate(httprequest *This, READYSTATE state)
145 {
146 READYSTATE last = This->state;
147 static const char* readystates[] = {
148 "READYSTATE_UNINITIALIZED",
149 "READYSTATE_LOADING",
150 "READYSTATE_LOADED",
151 "READYSTATE_INTERACTIVE",
152 "READYSTATE_COMPLETE"};
153
154 This->state = state;
155
156 TRACE("state %s\n", readystates[state]);
157
158 if (This->sink && last != state)
159 {
160 DISPPARAMS params;
161
162 memset(&params, 0, sizeof(params));
163 IDispatch_Invoke(This->sink, 0, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &params, 0, 0, 0);
164 }
165 }
166
167 static void free_response_headers(httprequest *This)
168 {
169 struct httpheader *header, *header2;
170
171 LIST_FOR_EACH_ENTRY_SAFE(header, header2, &This->respheaders, struct httpheader, entry)
172 {
173 list_remove(&header->entry);
174 SysFreeString(header->header);
175 SysFreeString(header->value);
176 heap_free(header);
177 }
178
179 SysFreeString(This->raw_respheaders);
180 This->raw_respheaders = NULL;
181 }
182
183 struct BindStatusCallback
184 {
185 IBindStatusCallback IBindStatusCallback_iface;
186 IHttpNegotiate IHttpNegotiate_iface;
187 IAuthenticate IAuthenticate_iface;
188 LONG ref;
189
190 IBinding *binding;
191 httprequest *request;
192
193 /* response data */
194 IStream *stream;
195
196 /* request body data */
197 HGLOBAL body;
198 };
199
200 static inline BindStatusCallback *impl_from_IBindStatusCallback( IBindStatusCallback *iface )
201 {
202 return CONTAINING_RECORD(iface, BindStatusCallback, IBindStatusCallback_iface);
203 }
204
205 static inline BindStatusCallback *impl_from_IHttpNegotiate( IHttpNegotiate *iface )
206 {
207 return CONTAINING_RECORD(iface, BindStatusCallback, IHttpNegotiate_iface);
208 }
209
210 static inline BindStatusCallback *impl_from_IAuthenticate( IAuthenticate *iface )
211 {
212 return CONTAINING_RECORD(iface, BindStatusCallback, IAuthenticate_iface);
213 }
214
215 static void BindStatusCallback_Detach(BindStatusCallback *bsc)
216 {
217 if (bsc)
218 {
219 if (bsc->binding) IBinding_Abort(bsc->binding);
220 bsc->request->bsc = NULL;
221 bsc->request = NULL;
222 IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
223 }
224 }
225
226 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
227 REFIID riid, void **ppv)
228 {
229 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
230
231 *ppv = NULL;
232
233 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
234
235 if (IsEqualGUID(&IID_IUnknown, riid) ||
236 IsEqualGUID(&IID_IBindStatusCallback, riid))
237 {
238 *ppv = &This->IBindStatusCallback_iface;
239 }
240 else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
241 {
242 *ppv = &This->IHttpNegotiate_iface;
243 }
244 else if (IsEqualGUID(&IID_IAuthenticate, riid))
245 {
246 *ppv = &This->IAuthenticate_iface;
247 }
248 else if (IsEqualGUID(&IID_IServiceProvider, riid) ||
249 IsEqualGUID(&IID_IBindStatusCallbackEx, riid) ||
250 IsEqualGUID(&IID_IInternetProtocol, riid) ||
251 IsEqualGUID(&IID_IHttpNegotiate2, riid))
252 {
253 return E_NOINTERFACE;
254 }
255
256 if (*ppv)
257 {
258 IBindStatusCallback_AddRef(iface);
259 return S_OK;
260 }
261
262 FIXME("Unsupported riid = %s\n", debugstr_guid(riid));
263
264 return E_NOINTERFACE;
265 }
266
267 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
268 {
269 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
270 LONG ref = InterlockedIncrement(&This->ref);
271
272 TRACE("(%p) ref = %d\n", This, ref);
273
274 return ref;
275 }
276
277 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
278 {
279 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
280 LONG ref = InterlockedDecrement(&This->ref);
281
282 TRACE("(%p) ref = %d\n", This, ref);
283
284 if (!ref)
285 {
286 if (This->binding) IBinding_Release(This->binding);
287 if (This->stream) IStream_Release(This->stream);
288 if (This->body) GlobalFree(This->body);
289 heap_free(This);
290 }
291
292 return ref;
293 }
294
295 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
296 DWORD reserved, IBinding *pbind)
297 {
298 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
299
300 TRACE("(%p)->(%d %p)\n", This, reserved, pbind);
301
302 if (!pbind) return E_INVALIDARG;
303
304 This->binding = pbind;
305 IBinding_AddRef(pbind);
306
307 httprequest_setreadystate(This->request, READYSTATE_LOADED);
308
309 return CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
310 }
311
312 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pPriority)
313 {
314 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
315
316 TRACE("(%p)->(%p)\n", This, pPriority);
317
318 return E_NOTIMPL;
319 }
320
321 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
322 {
323 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
324
325 TRACE("(%p)->(%d)\n", This, reserved);
326
327 return E_NOTIMPL;
328 }
329
330 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
331 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
332 {
333 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
334
335 TRACE("(%p)->(%u %u %u %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
336 debugstr_w(szStatusText));
337
338 return S_OK;
339 }
340
341 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
342 HRESULT hr, LPCWSTR error)
343 {
344 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
345
346 TRACE("(%p)->(0x%08x %s)\n", This, hr, debugstr_w(error));
347
348 if (This->binding)
349 {
350 IBinding_Release(This->binding);
351 This->binding = NULL;
352 }
353
354 if (hr == S_OK)
355 {
356 BindStatusCallback_Detach(This->request->bsc);
357 This->request->bsc = This;
358 httprequest_setreadystate(This->request, READYSTATE_COMPLETE);
359 }
360
361 return S_OK;
362 }
363
364 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
365 DWORD *bind_flags, BINDINFO *pbindinfo)
366 {
367 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
368
369 TRACE("(%p)->(%p %p)\n", This, bind_flags, pbindinfo);
370
371 *bind_flags = 0;
372 if (This->request->async) *bind_flags |= BINDF_ASYNCHRONOUS;
373
374 if (This->request->verb != BINDVERB_GET && This->body)
375 {
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);
381 }
382
383 pbindinfo->dwBindVerb = This->request->verb;
384 if (This->request->verb == BINDVERB_CUSTOM)
385 {
386 pbindinfo->szCustomVerb = CoTaskMemAlloc(SysStringByteLen(This->request->custom));
387 strcpyW(pbindinfo->szCustomVerb, This->request->custom);
388 }
389
390 return S_OK;
391 }
392
393 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
394 DWORD flags, DWORD size, FORMATETC *format, STGMEDIUM *stgmed)
395 {
396 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
397 DWORD read, written;
398 BYTE buf[4096];
399 HRESULT hr;
400
401 TRACE("(%p)->(%08x %d %p %p)\n", This, flags, size, format, stgmed);
402
403 do
404 {
405 hr = IStream_Read(stgmed->u.pstm, buf, sizeof(buf), &read);
406 if (hr != S_OK) break;
407
408 hr = IStream_Write(This->stream, buf, read, &written);
409 } while((hr == S_OK) && written != 0 && read != 0);
410
411 httprequest_setreadystate(This->request, READYSTATE_INTERACTIVE);
412
413 return S_OK;
414 }
415
416 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
417 REFIID riid, IUnknown *punk)
418 {
419 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
420
421 FIXME("(%p)->(%s %p): stub\n", This, debugstr_guid(riid), punk);
422
423 return E_NOTIMPL;
424 }
425
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
438 };
439
440 static HRESULT WINAPI BSCHttpNegotiate_QueryInterface(IHttpNegotiate *iface,
441 REFIID riid, void **ppv)
442 {
443 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
444 return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
445 }
446
447 static ULONG WINAPI BSCHttpNegotiate_AddRef(IHttpNegotiate *iface)
448 {
449 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
450 return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
451 }
452
453 static ULONG WINAPI BSCHttpNegotiate_Release(IHttpNegotiate *iface)
454 {
455 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
456 return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
457 }
458
459 static HRESULT WINAPI BSCHttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
460 LPCWSTR url, LPCWSTR headers, DWORD reserved, LPWSTR *add_headers)
461 {
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};
464
465 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
466 const struct httpheader *entry;
467 WCHAR *buff, *ptr;
468 int size = 0;
469
470 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(url), debugstr_w(headers), reserved, add_headers);
471
472 *add_headers = NULL;
473
474 if (This->request->use_utf8_content)
475 size = sizeof(content_type_utf8W);
476
477 if (!list_empty(&This->request->reqheaders))
478 size += This->request->reqheader_size*sizeof(WCHAR);
479
480 if (!size) return S_OK;
481
482 buff = CoTaskMemAlloc(size);
483 if (!buff) return E_OUTOFMEMORY;
484
485 ptr = buff;
486 if (This->request->use_utf8_content)
487 {
488 lstrcpyW(ptr, content_type_utf8W);
489 ptr += sizeof(content_type_utf8W)/sizeof(WCHAR)-1;
490 }
491
492 /* user headers */
493 LIST_FOR_EACH_ENTRY(entry, &This->request->reqheaders, struct httpheader, entry)
494 {
495 lstrcpyW(ptr, entry->header);
496 ptr += SysStringLen(entry->header);
497
498 lstrcpyW(ptr, colspaceW);
499 ptr += sizeof(colspaceW)/sizeof(WCHAR)-1;
500
501 lstrcpyW(ptr, entry->value);
502 ptr += SysStringLen(entry->value);
503
504 lstrcpyW(ptr, crlfW);
505 ptr += sizeof(crlfW)/sizeof(WCHAR)-1;
506 }
507
508 *add_headers = buff;
509
510 return S_OK;
511 }
512
513 static void add_response_header(httprequest *This, const WCHAR *data, int len)
514 {
515 struct httpheader *entry;
516 const WCHAR *ptr = data;
517 BSTR header, value;
518
519 while (*ptr)
520 {
521 if (*ptr == ':')
522 {
523 header = SysAllocStringLen(data, ptr-data);
524 /* skip leading spaces for a value */
525 while (*++ptr == ' ')
526 ;
527 value = SysAllocStringLen(ptr, len-(ptr-data));
528 break;
529 }
530 ptr++;
531 }
532
533 if (!*ptr) return;
534
535 /* new header */
536 TRACE("got header %s:%s\n", debugstr_w(header), debugstr_w(value));
537
538 entry = heap_alloc(sizeof(*entry));
539 entry->header = header;
540 entry->value = value;
541 list_add_head(&This->respheaders, &entry->entry);
542 }
543
544 static HRESULT WINAPI BSCHttpNegotiate_OnResponse(IHttpNegotiate *iface, DWORD code,
545 LPCWSTR resp_headers, LPCWSTR req_headers, LPWSTR *add_reqheaders)
546 {
547 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
548
549 TRACE("(%p)->(%d %s %s %p)\n", This, code, debugstr_w(resp_headers),
550 debugstr_w(req_headers), add_reqheaders);
551
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;
557 if (resp_headers)
558 {
559 const WCHAR *ptr, *line, *status_text;
560
561 ptr = line = resp_headers;
562
563 /* skip HTTP-Version */
564 ptr = strchrW(ptr, ' ');
565 if (ptr)
566 {
567 /* skip Status-Code */
568 ptr = strchrW(++ptr, ' ');
569 if (ptr)
570 {
571 status_text = ++ptr;
572 /* now it supposed to end with CRLF */
573 while (*ptr)
574 {
575 if (*ptr == '\r' && *(ptr+1) == '\n')
576 {
577 line = ptr + 2;
578 This->request->status_text = SysAllocStringLen(status_text, ptr-status_text);
579 TRACE("status text %s\n", debugstr_w(This->request->status_text));
580 break;
581 }
582 ptr++;
583 }
584 }
585 }
586
587 /* store as unparsed string for now */
588 This->request->raw_respheaders = SysAllocString(line);
589 }
590
591 return S_OK;
592 }
593
594 static const IHttpNegotiateVtbl BSCHttpNegotiateVtbl = {
595 BSCHttpNegotiate_QueryInterface,
596 BSCHttpNegotiate_AddRef,
597 BSCHttpNegotiate_Release,
598 BSCHttpNegotiate_BeginningTransaction,
599 BSCHttpNegotiate_OnResponse
600 };
601
602 static HRESULT WINAPI Authenticate_QueryInterface(IAuthenticate *iface,
603 REFIID riid, void **ppv)
604 {
605 BindStatusCallback *This = impl_from_IAuthenticate(iface);
606 return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
607 }
608
609 static ULONG WINAPI Authenticate_AddRef(IAuthenticate *iface)
610 {
611 BindStatusCallback *This = impl_from_IAuthenticate(iface);
612 return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
613 }
614
615 static ULONG WINAPI Authenticate_Release(IAuthenticate *iface)
616 {
617 BindStatusCallback *This = impl_from_IAuthenticate(iface);
618 return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
619 }
620
621 static HRESULT WINAPI Authenticate_Authenticate(IAuthenticate *iface,
622 HWND *hwnd, LPWSTR *username, LPWSTR *password)
623 {
624 BindStatusCallback *This = impl_from_IAuthenticate(iface);
625 FIXME("(%p)->(%p %p %p)\n", This, hwnd, username, password);
626 return E_NOTIMPL;
627 }
628
629 static const IAuthenticateVtbl AuthenticateVtbl = {
630 Authenticate_QueryInterface,
631 Authenticate_AddRef,
632 Authenticate_Release,
633 Authenticate_Authenticate
634 };
635
636 static HRESULT BindStatusCallback_create(httprequest* This, BindStatusCallback **obj, const VARIANT *body)
637 {
638 BindStatusCallback *bsc;
639 IBindCtx *pbc;
640 HRESULT hr;
641 int size;
642
643 hr = CreateBindCtx(0, &pbc);
644 if (hr != S_OK) return hr;
645
646 bsc = heap_alloc(sizeof(*bsc));
647 if (!bsc)
648 {
649 IBindCtx_Release(pbc);
650 return E_OUTOFMEMORY;
651 }
652
653 bsc->IBindStatusCallback_iface.lpVtbl = &BindStatusCallbackVtbl;
654 bsc->IHttpNegotiate_iface.lpVtbl = &BSCHttpNegotiateVtbl;
655 bsc->IAuthenticate_iface.lpVtbl = &AuthenticateVtbl;
656 bsc->ref = 1;
657 bsc->request = This;
658 bsc->binding = NULL;
659 bsc->stream = NULL;
660 bsc->body = NULL;
661
662 TRACE("(%p)->(%p)\n", This, bsc);
663
664 This->use_utf8_content = FALSE;
665
666 if (This->verb != BINDVERB_GET)
667 {
668 void *send_data, *ptr;
669 SAFEARRAY *sa = NULL;
670
671 if (V_VT(body) == (VT_VARIANT|VT_BYREF))
672 body = V_VARIANTREF(body);
673
674 switch (V_VT(body))
675 {
676 case VT_BSTR:
677 {
678 int len = SysStringLen(V_BSTR(body));
679 const WCHAR *str = V_BSTR(body);
680 UINT i, cp = CP_ACP;
681
682 for (i = 0; i < len; i++)
683 {
684 if (str[i] > 127)
685 {
686 cp = CP_UTF8;
687 break;
688 }
689 }
690
691 size = WideCharToMultiByte(cp, 0, str, len, NULL, 0, NULL, NULL);
692 if (!(ptr = heap_alloc(size)))
693 {
694 heap_free(bsc);
695 return E_OUTOFMEMORY;
696 }
697 WideCharToMultiByte(cp, 0, str, len, ptr, size, NULL, NULL);
698 if (cp == CP_UTF8) This->use_utf8_content = TRUE;
699 break;
700 }
701 case VT_ARRAY|VT_UI1:
702 {
703 sa = V_ARRAY(body);
704 if ((hr = SafeArrayAccessData(sa, (void **)&ptr)) != S_OK)
705 {
706 heap_free(bsc);
707 return hr;
708 }
709 if ((hr = SafeArrayGetUBound(sa, 1, &size) != S_OK))
710 {
711 SafeArrayUnaccessData(sa);
712 heap_free(bsc);
713 return hr;
714 }
715 size++;
716 break;
717 }
718 default:
719 FIXME("unsupported body data type %d\n", V_VT(body));
720 /* fall through */
721 case VT_EMPTY:
722 case VT_ERROR:
723 ptr = NULL;
724 size = 0;
725 break;
726 }
727
728 bsc->body = GlobalAlloc(GMEM_FIXED, size);
729 if (!bsc->body)
730 {
731 if (V_VT(body) == VT_BSTR)
732 heap_free(ptr);
733 else if (V_VT(body) == (VT_ARRAY|VT_UI1))
734 SafeArrayUnaccessData(sa);
735
736 heap_free(bsc);
737 return E_OUTOFMEMORY;
738 }
739
740 send_data = GlobalLock(bsc->body);
741 memcpy(send_data, ptr, size);
742 GlobalUnlock(bsc->body);
743
744 if (V_VT(body) == VT_BSTR)
745 heap_free(ptr);
746 else if (V_VT(body) == (VT_ARRAY|VT_UI1))
747 SafeArrayUnaccessData(sa);
748 }
749
750 hr = RegisterBindStatusCallback(pbc, &bsc->IBindStatusCallback_iface, NULL, 0);
751 if (hr == S_OK)
752 {
753 IMoniker *moniker;
754
755 hr = CreateURLMonikerEx2(NULL, This->uri, &moniker, URL_MK_UNIFORM);
756 if (hr == S_OK)
757 {
758 IStream *stream;
759
760 hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (void**)&stream);
761 IMoniker_Release(moniker);
762 if (stream) IStream_Release(stream);
763 }
764 IBindCtx_Release(pbc);
765 }
766
767 if (FAILED(hr))
768 {
769 IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
770 bsc = NULL;
771 }
772
773 *obj = bsc;
774 return hr;
775 }
776
777 static HRESULT verify_uri(httprequest *This, IUri *uri)
778 {
779 DWORD scheme, base_scheme;
780 BSTR host, base_host;
781 HRESULT hr;
782
783 if(!(This->safeopt & INTERFACESAFE_FOR_UNTRUSTED_DATA))
784 return S_OK;
785
786 if(!This->base_uri)
787 return E_ACCESSDENIED;
788
789 hr = IUri_GetScheme(uri, &scheme);
790 if(FAILED(hr))
791 return hr;
792
793 hr = IUri_GetScheme(This->base_uri, &base_scheme);
794 if(FAILED(hr))
795 return hr;
796
797 if(scheme != base_scheme) {
798 WARN("Schemes don't match\n");
799 return E_ACCESSDENIED;
800 }
801
802 if(scheme == INTERNET_SCHEME_UNKNOWN) {
803 FIXME("Unknown scheme\n");
804 return E_ACCESSDENIED;
805 }
806
807 hr = IUri_GetHost(uri, &host);
808 if(FAILED(hr))
809 return hr;
810
811 hr = IUri_GetHost(This->base_uri, &base_host);
812 if(SUCCEEDED(hr)) {
813 if(strcmpiW(host, base_host)) {
814 WARN("Hosts don't match\n");
815 hr = E_ACCESSDENIED;
816 }
817 SysFreeString(base_host);
818 }
819
820 SysFreeString(host);
821 return hr;
822 }
823
824 static HRESULT httprequest_open(httprequest *This, BSTR method, BSTR url,
825 VARIANT async, VARIANT user, VARIANT password)
826 {
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;
833 IUri *uri;
834 HRESULT hr;
835
836 if (!method || !url) return E_INVALIDARG;
837
838 /* free previously set data */
839 if(This->uri) {
840 IUri_Release(This->uri);
841 This->uri = NULL;
842 }
843
844 SysFreeString(This->user);
845 SysFreeString(This->password);
846 This->user = This->password = NULL;
847
848 if (!strcmpiW(method, MethodGetW))
849 {
850 This->verb = BINDVERB_GET;
851 }
852 else if (!strcmpiW(method, MethodPutW))
853 {
854 This->verb = BINDVERB_PUT;
855 }
856 else if (!strcmpiW(method, MethodPostW))
857 {
858 This->verb = BINDVERB_POST;
859 }
860 else if (!strcmpiW(method, MethodDeleteW) ||
861 !strcmpiW(method, MethodPropFindW))
862 {
863 This->verb = BINDVERB_CUSTOM;
864 SysReAllocString(&This->custom, method);
865 }
866 else
867 {
868 FIXME("unsupported request type %s\n", debugstr_w(method));
869 This->verb = -1;
870 return E_FAIL;
871 }
872
873 if(This->base_uri)
874 hr = CoInternetCombineUrlEx(This->base_uri, url, 0, &uri, 0);
875 else
876 hr = CreateUri(url, 0, 0, &uri);
877 if(FAILED(hr)) {
878 WARN("Could not create IUri object: %08x\n", hr);
879 return hr;
880 }
881
882 hr = verify_uri(This, uri);
883 if(FAILED(hr)) {
884 IUri_Release(uri);
885 return hr;
886 }
887
888 This->uri = uri;
889
890 VariantInit(&is_async);
891 hr = VariantChangeType(&is_async, &async, 0, VT_BOOL);
892 This->async = hr == S_OK && V_BOOL(&is_async);
893
894 VariantInit(&str);
895 hr = VariantChangeType(&str, &user, 0, VT_BSTR);
896 if (hr == S_OK)
897 This->user = V_BSTR(&str);
898
899 VariantInit(&str);
900 hr = VariantChangeType(&str, &password, 0, VT_BSTR);
901 if (hr == S_OK)
902 This->password = V_BSTR(&str);
903
904 httprequest_setreadystate(This, READYSTATE_LOADING);
905
906 return S_OK;
907 }
908
909 static HRESULT httprequest_setRequestHeader(httprequest *This, BSTR header, BSTR value)
910 {
911 struct httpheader *entry;
912
913 if (!header || !*header) return E_INVALIDARG;
914 if (This->state != READYSTATE_LOADING) return E_FAIL;
915 if (!value) return E_INVALIDARG;
916
917 /* replace existing header value if already added */
918 LIST_FOR_EACH_ENTRY(entry, &This->reqheaders, struct httpheader, entry)
919 {
920 if (lstrcmpW(entry->header, header) == 0)
921 {
922 LONG length = SysStringLen(entry->value);
923 HRESULT hr;
924
925 hr = SysReAllocString(&entry->value, value) ? S_OK : E_OUTOFMEMORY;
926
927 if (hr == S_OK)
928 This->reqheader_size += (SysStringLen(entry->value) - length);
929
930 return hr;
931 }
932 }
933
934 entry = heap_alloc(sizeof(*entry));
935 if (!entry) return E_OUTOFMEMORY;
936
937 /* new header */
938 entry->header = SysAllocString(header);
939 entry->value = SysAllocString(value);
940
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;
944
945 list_add_head(&This->reqheaders, &entry->entry);
946
947 return S_OK;
948 }
949
950 static HRESULT httprequest_getResponseHeader(httprequest *This, BSTR header, BSTR *value)
951 {
952 struct httpheader *entry;
953
954 if (!header) return E_INVALIDARG;
955 if (!value) return E_POINTER;
956
957 if (This->raw_respheaders && list_empty(&This->respheaders))
958 {
959 WCHAR *ptr, *line;
960
961 ptr = line = This->raw_respheaders;
962 while (*ptr)
963 {
964 if (*ptr == '\r' && *(ptr+1) == '\n')
965 {
966 add_response_header(This, line, ptr-line);
967 ptr++; line = ++ptr;
968 continue;
969 }
970 ptr++;
971 }
972 }
973
974 LIST_FOR_EACH_ENTRY(entry, &This->respheaders, struct httpheader, entry)
975 {
976 if (!strcmpiW(entry->header, header))
977 {
978 *value = SysAllocString(entry->value);
979 TRACE("header value %s\n", debugstr_w(*value));
980 return S_OK;
981 }
982 }
983
984 return S_FALSE;
985 }
986
987 static HRESULT httprequest_getAllResponseHeaders(httprequest *This, BSTR *respheaders)
988 {
989 if (!respheaders) return E_POINTER;
990
991 *respheaders = SysAllocString(This->raw_respheaders);
992
993 return S_OK;
994 }
995
996 static HRESULT httprequest_send(httprequest *This, VARIANT body)
997 {
998 BindStatusCallback *bsc = NULL;
999 HRESULT hr;
1000
1001 if (This->state != READYSTATE_LOADING) return E_FAIL;
1002
1003 hr = BindStatusCallback_create(This, &bsc, &body);
1004 if (FAILED(hr))
1005 /* success path to detach it is OnStopBinding call */
1006 BindStatusCallback_Detach(bsc);
1007
1008 return hr;
1009 }
1010
1011 static HRESULT httprequest_abort(httprequest *This)
1012 {
1013 BindStatusCallback_Detach(This->bsc);
1014
1015 httprequest_setreadystate(This, READYSTATE_UNINITIALIZED);
1016
1017 return S_OK;
1018 }
1019
1020 static HRESULT httprequest_get_status(httprequest *This, LONG *status)
1021 {
1022 if (!status) return E_POINTER;
1023
1024 *status = This->status;
1025
1026 return This->state == READYSTATE_COMPLETE ? S_OK : E_FAIL;
1027 }
1028
1029 static HRESULT httprequest_get_statusText(httprequest *This, BSTR *status)
1030 {
1031 if (!status) return E_POINTER;
1032 if (This->state != READYSTATE_COMPLETE) return E_FAIL;
1033
1034 *status = SysAllocString(This->status_text);
1035
1036 return S_OK;
1037 }
1038
1039 static HRESULT httprequest_get_responseText(httprequest *This, BSTR *body)
1040 {
1041 HGLOBAL hglobal;
1042 HRESULT hr;
1043
1044 if (!body) return E_POINTER;
1045 if (This->state != READYSTATE_COMPLETE) return E_FAIL;
1046
1047 hr = GetHGlobalFromStream(This->bsc->stream, &hglobal);
1048 if (hr == S_OK)
1049 {
1050 xmlChar *ptr = GlobalLock(hglobal);
1051 DWORD size = GlobalSize(hglobal);
1052 xmlCharEncoding encoding = XML_CHAR_ENCODING_UTF8;
1053
1054 /* try to determine data encoding */
1055 if (size >= 4)
1056 {
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 )
1062 {
1063 FIXME("unsupported encoding: %s\n", debugstr_a(xmlGetCharEncodingName(encoding)));
1064 GlobalUnlock(hglobal);
1065 return E_FAIL;
1066 }
1067 }
1068
1069 /* without BOM assume UTF-8 */
1070 if (encoding == XML_CHAR_ENCODING_UTF8 ||
1071 encoding == XML_CHAR_ENCODING_NONE )
1072 {
1073 DWORD length = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)ptr, size, NULL, 0);
1074
1075 *body = SysAllocStringLen(NULL, length);
1076 if (*body)
1077 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)ptr, size, *body, length);
1078 }
1079 else
1080 *body = SysAllocStringByteLen((LPCSTR)ptr, size);
1081
1082 if (!*body) hr = E_OUTOFMEMORY;
1083 GlobalUnlock(hglobal);
1084 }
1085
1086 return hr;
1087 }
1088
1089 static HRESULT httprequest_get_responseXML(httprequest *This, IDispatch **body)
1090 {
1091 IXMLDOMDocument3 *doc;
1092 HRESULT hr;
1093 BSTR str;
1094
1095 if (!body) return E_INVALIDARG;
1096 if (This->state != READYSTATE_COMPLETE) return E_FAIL;
1097
1098 hr = DOMDocument_create(MSXML_DEFAULT, NULL, (void**)&doc);
1099 if (hr != S_OK) return hr;
1100
1101 hr = httprequest_get_responseText(This, &str);
1102 if (hr == S_OK)
1103 {
1104 VARIANT_BOOL ok;
1105
1106 hr = IXMLDOMDocument3_loadXML(doc, str, &ok);
1107 SysFreeString(str);
1108 }
1109
1110 IXMLDOMDocument3_QueryInterface(doc, &IID_IDispatch, (void**)body);
1111 IXMLDOMDocument3_Release(doc);
1112
1113 return hr;
1114 }
1115
1116 static HRESULT httprequest_get_responseBody(httprequest *This, VARIANT *body)
1117 {
1118 HGLOBAL hglobal;
1119 HRESULT hr;
1120
1121 if (!body) return E_INVALIDARG;
1122 V_VT(body) = VT_EMPTY;
1123
1124 if (This->state != READYSTATE_COMPLETE) return E_PENDING;
1125
1126 hr = GetHGlobalFromStream(This->bsc->stream, &hglobal);
1127 if (hr == S_OK)
1128 {
1129 void *ptr = GlobalLock(hglobal);
1130 DWORD size = GlobalSize(hglobal);
1131
1132 SAFEARRAYBOUND bound;
1133 SAFEARRAY *array;
1134
1135 bound.lLbound = 0;
1136 bound.cElements = size;
1137 array = SafeArrayCreate(VT_UI1, 1, &bound);
1138
1139 if (array)
1140 {
1141 void *dest;
1142
1143 V_VT(body) = VT_ARRAY | VT_UI1;
1144 V_ARRAY(body) = array;
1145
1146 hr = SafeArrayAccessData(array, &dest);
1147 if (hr == S_OK)
1148 {
1149 memcpy(dest, ptr, size);
1150 SafeArrayUnaccessData(array);
1151 }
1152 else
1153 {
1154 VariantClear(body);
1155 }
1156 }
1157 else
1158 hr = E_FAIL;
1159
1160 GlobalUnlock(hglobal);
1161 }
1162
1163 return hr;
1164 }
1165
1166 static HRESULT httprequest_get_responseStream(httprequest *This, VARIANT *body)
1167 {
1168 LARGE_INTEGER move;
1169 IStream *stream;
1170 HRESULT hr;
1171
1172 if (!body) return E_INVALIDARG;
1173 V_VT(body) = VT_EMPTY;
1174
1175 if (This->state != READYSTATE_COMPLETE) return E_PENDING;
1176
1177 hr = IStream_Clone(This->bsc->stream, &stream);
1178
1179 move.QuadPart = 0;
1180 IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
1181
1182 V_VT(body) = VT_UNKNOWN;
1183 V_UNKNOWN(body) = (IUnknown*)stream;
1184
1185 return hr;
1186 }
1187
1188 static HRESULT httprequest_get_readyState(httprequest *This, LONG *state)
1189 {
1190 if (!state) return E_POINTER;
1191
1192 *state = This->state;
1193 return S_OK;
1194 }
1195
1196 static HRESULT httprequest_put_onreadystatechange(httprequest *This, IDispatch *sink)
1197 {
1198 if (This->sink) IDispatch_Release(This->sink);
1199 if ((This->sink = sink)) IDispatch_AddRef(This->sink);
1200
1201 return S_OK;
1202 }
1203
1204 static void httprequest_release(httprequest *This)
1205 {
1206 struct httpheader *header, *header2;
1207
1208 if (This->site)
1209 IUnknown_Release( This->site );
1210 if (This->uri)
1211 IUri_Release(This->uri);
1212 if (This->base_uri)
1213 IUri_Release(This->base_uri);
1214
1215 SysFreeString(This->custom);
1216 SysFreeString(This->user);
1217 SysFreeString(This->password);
1218
1219 /* request headers */
1220 LIST_FOR_EACH_ENTRY_SAFE(header, header2, &This->reqheaders, struct httpheader, entry)
1221 {
1222 list_remove(&header->entry);
1223 SysFreeString(header->header);
1224 SysFreeString(header->value);
1225 heap_free(header);
1226 }
1227 /* response headers */
1228 free_response_headers(This);
1229 SysFreeString(This->status_text);
1230
1231 /* detach callback object */
1232 BindStatusCallback_Detach(This->bsc);
1233
1234 if (This->sink) IDispatch_Release(This->sink);
1235 }
1236
1237 static HRESULT WINAPI XMLHTTPRequest_QueryInterface(IXMLHTTPRequest *iface, REFIID riid, void **ppvObject)
1238 {
1239 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1240 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
1241
1242 if ( IsEqualGUID( riid, &IID_IXMLHTTPRequest) ||
1243 IsEqualGUID( riid, &IID_IDispatch) ||
1244 IsEqualGUID( riid, &IID_IUnknown) )
1245 {
1246 *ppvObject = iface;
1247 }
1248 else if (IsEqualGUID(&IID_IObjectWithSite, riid))
1249 {
1250 *ppvObject = &This->IObjectWithSite_iface;
1251 }
1252 else if (IsEqualGUID(&IID_IObjectSafety, riid))
1253 {
1254 *ppvObject = &This->IObjectSafety_iface;
1255 }
1256 else
1257 {
1258 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
1259 *ppvObject = NULL;
1260 return E_NOINTERFACE;
1261 }
1262
1263 IXMLHTTPRequest_AddRef( iface );
1264
1265 return S_OK;
1266 }
1267
1268 static ULONG WINAPI XMLHTTPRequest_AddRef(IXMLHTTPRequest *iface)
1269 {
1270 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1271 ULONG ref = InterlockedIncrement( &This->ref );
1272 TRACE("(%p)->(%u)\n", This, ref );
1273 return ref;
1274 }
1275
1276 static ULONG WINAPI XMLHTTPRequest_Release(IXMLHTTPRequest *iface)
1277 {
1278 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1279 ULONG ref = InterlockedDecrement( &This->ref );
1280
1281 TRACE("(%p)->(%u)\n", This, ref );
1282
1283 if ( ref == 0 )
1284 {
1285 httprequest_release( This );
1286 heap_free( This );
1287 }
1288
1289 return ref;
1290 }
1291
1292 static HRESULT WINAPI XMLHTTPRequest_GetTypeInfoCount(IXMLHTTPRequest *iface, UINT *pctinfo)
1293 {
1294 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1295
1296 TRACE("(%p)->(%p)\n", This, pctinfo);
1297
1298 *pctinfo = 1;
1299
1300 return S_OK;
1301 }
1302
1303 static HRESULT WINAPI XMLHTTPRequest_GetTypeInfo(IXMLHTTPRequest *iface, UINT iTInfo,
1304 LCID lcid, ITypeInfo **ppTInfo)
1305 {
1306 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1307
1308 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1309
1310 return get_typeinfo(IXMLHTTPRequest_tid, ppTInfo);
1311 }
1312
1313 static HRESULT WINAPI XMLHTTPRequest_GetIDsOfNames(IXMLHTTPRequest *iface, REFIID riid,
1314 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1315 {
1316 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1317 ITypeInfo *typeinfo;
1318 HRESULT hr;
1319
1320 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1321 lcid, rgDispId);
1322
1323 if(!rgszNames || cNames == 0 || !rgDispId)
1324 return E_INVALIDARG;
1325
1326 hr = get_typeinfo(IXMLHTTPRequest_tid, &typeinfo);
1327 if(SUCCEEDED(hr))
1328 {
1329 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1330 ITypeInfo_Release(typeinfo);
1331 }
1332
1333 return hr;
1334 }
1335
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)
1339 {
1340 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1341 ITypeInfo *typeinfo;
1342 HRESULT hr;
1343
1344 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1345 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1346
1347 hr = get_typeinfo(IXMLHTTPRequest_tid, &typeinfo);
1348 if(SUCCEEDED(hr))
1349 {
1350 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLHTTPRequest_iface, dispIdMember, wFlags,
1351 pDispParams, pVarResult, pExcepInfo, puArgErr);
1352 ITypeInfo_Release(typeinfo);
1353 }
1354
1355 return hr;
1356 }
1357
1358 static HRESULT WINAPI XMLHTTPRequest_open(IXMLHTTPRequest *iface, BSTR method, BSTR url,
1359 VARIANT async, VARIANT user, VARIANT password)
1360 {
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);
1365 }
1366
1367 static HRESULT WINAPI XMLHTTPRequest_setRequestHeader(IXMLHTTPRequest *iface, BSTR header, BSTR value)
1368 {
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);
1372 }
1373
1374 static HRESULT WINAPI XMLHTTPRequest_getResponseHeader(IXMLHTTPRequest *iface, BSTR header, BSTR *value)
1375 {
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);
1379 }
1380
1381 static HRESULT WINAPI XMLHTTPRequest_getAllResponseHeaders(IXMLHTTPRequest *iface, BSTR *respheaders)
1382 {
1383 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1384 TRACE("(%p)->(%p)\n", This, respheaders);
1385 return httprequest_getAllResponseHeaders(This, respheaders);
1386 }
1387
1388 static HRESULT WINAPI XMLHTTPRequest_send(IXMLHTTPRequest *iface, VARIANT body)
1389 {
1390 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1391 TRACE("(%p)->(%s)\n", This, debugstr_variant(&body));
1392 return httprequest_send(This, body);
1393 }
1394
1395 static HRESULT WINAPI XMLHTTPRequest_abort(IXMLHTTPRequest *iface)
1396 {
1397 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1398 TRACE("(%p)\n", This);
1399 return httprequest_abort(This);
1400 }
1401
1402 static HRESULT WINAPI XMLHTTPRequest_get_status(IXMLHTTPRequest *iface, LONG *status)
1403 {
1404 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1405 TRACE("(%p)->(%p)\n", This, status);
1406 return httprequest_get_status(This, status);
1407 }
1408
1409 static HRESULT WINAPI XMLHTTPRequest_get_statusText(IXMLHTTPRequest *iface, BSTR *status)
1410 {
1411 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1412 TRACE("(%p)->(%p)\n", This, status);
1413 return httprequest_get_statusText(This, status);
1414 }
1415
1416 static HRESULT WINAPI XMLHTTPRequest_get_responseXML(IXMLHTTPRequest *iface, IDispatch **body)
1417 {
1418 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1419 TRACE("(%p)->(%p)\n", This, body);
1420 return httprequest_get_responseXML(This, body);
1421 }
1422
1423 static HRESULT WINAPI XMLHTTPRequest_get_responseText(IXMLHTTPRequest *iface, BSTR *body)
1424 {
1425 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1426 TRACE("(%p)->(%p)\n", This, body);
1427 return httprequest_get_responseText(This, body);
1428 }
1429
1430 static HRESULT WINAPI XMLHTTPRequest_get_responseBody(IXMLHTTPRequest *iface, VARIANT *body)
1431 {
1432 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1433 TRACE("(%p)->(%p)\n", This, body);
1434 return httprequest_get_responseBody(This, body);
1435 }
1436
1437 static HRESULT WINAPI XMLHTTPRequest_get_responseStream(IXMLHTTPRequest *iface, VARIANT *body)
1438 {
1439 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1440 TRACE("(%p)->(%p)\n", This, body);
1441 return httprequest_get_responseStream(This, body);
1442 }
1443
1444 static HRESULT WINAPI XMLHTTPRequest_get_readyState(IXMLHTTPRequest *iface, LONG *state)
1445 {
1446 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1447 TRACE("(%p)->(%p)\n", This, state);
1448 return httprequest_get_readyState(This, state);
1449 }
1450
1451 static HRESULT WINAPI XMLHTTPRequest_put_onreadystatechange(IXMLHTTPRequest *iface, IDispatch *sink)
1452 {
1453 httprequest *This = impl_from_IXMLHTTPRequest( iface );
1454 TRACE("(%p)->(%p)\n", This, sink);
1455 return httprequest_put_onreadystatechange(This, sink);
1456 }
1457
1458 static const struct IXMLHTTPRequestVtbl XMLHTTPRequestVtbl =
1459 {
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
1481 };
1482
1483 /* IObjectWithSite */
1484 static HRESULT WINAPI
1485 httprequest_ObjectWithSite_QueryInterface( IObjectWithSite* iface, REFIID riid, void** ppvObject )
1486 {
1487 httprequest *This = impl_from_IObjectWithSite(iface);
1488 return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest *)This, riid, ppvObject );
1489 }
1490
1491 static ULONG WINAPI httprequest_ObjectWithSite_AddRef( IObjectWithSite* iface )
1492 {
1493 httprequest *This = impl_from_IObjectWithSite(iface);
1494 return IXMLHTTPRequest_AddRef((IXMLHTTPRequest *)This);
1495 }
1496
1497 static ULONG WINAPI httprequest_ObjectWithSite_Release( IObjectWithSite* iface )
1498 {
1499 httprequest *This = impl_from_IObjectWithSite(iface);
1500 return IXMLHTTPRequest_Release((IXMLHTTPRequest *)This);
1501 }
1502
1503 static HRESULT WINAPI httprequest_ObjectWithSite_GetSite( IObjectWithSite *iface, REFIID iid, void **ppvSite )
1504 {
1505 httprequest *This = impl_from_IObjectWithSite(iface);
1506
1507 TRACE("(%p)->(%s %p)\n", This, debugstr_guid( iid ), ppvSite );
1508
1509 if ( !This->site )
1510 return E_FAIL;
1511
1512 return IUnknown_QueryInterface( This->site, iid, ppvSite );
1513 }
1514
1515 static void get_base_uri(httprequest *This)
1516 {
1517 IServiceProvider *provider;
1518 IHTMLDocument2 *doc;
1519 IUri *uri;
1520 BSTR url;
1521 HRESULT hr;
1522
1523 hr = IUnknown_QueryInterface(This->site, &IID_IServiceProvider, (void**)&provider);
1524 if(FAILED(hr))
1525 return;
1526
1527 hr = IServiceProvider_QueryService(provider, &SID_SContainerDispatch, &IID_IHTMLDocument2, (void**)&doc);
1528 IServiceProvider_Release(provider);
1529 if(FAILED(hr))
1530 return;
1531
1532 hr = IHTMLDocument2_get_URL(doc, &url);
1533 IHTMLDocument2_Release(doc);
1534 if(FAILED(hr) || !url || !*url)
1535 return;
1536
1537 TRACE("host url %s\n", debugstr_w(url));
1538
1539 hr = CreateUri(url, 0, 0, &uri);
1540 SysFreeString(url);
1541 if(FAILED(hr))
1542 return;
1543
1544 This->base_uri = uri;
1545 }
1546
1547 static HRESULT WINAPI httprequest_ObjectWithSite_SetSite( IObjectWithSite *iface, IUnknown *punk )
1548 {
1549 httprequest *This = impl_from_IObjectWithSite(iface);
1550
1551 TRACE("(%p)->(%p)\n", This, punk);
1552
1553 if(This->site)
1554 IUnknown_Release( This->site );
1555 if(This->base_uri)
1556 IUri_Release(This->base_uri);
1557
1558 This->site = punk;
1559
1560 if (punk)
1561 {
1562 IUnknown_AddRef( punk );
1563 get_base_uri(This);
1564 }
1565
1566 return S_OK;
1567 }
1568
1569 static const IObjectWithSiteVtbl ObjectWithSiteVtbl =
1570 {
1571 httprequest_ObjectWithSite_QueryInterface,
1572 httprequest_ObjectWithSite_AddRef,
1573 httprequest_ObjectWithSite_Release,
1574 httprequest_ObjectWithSite_SetSite,
1575 httprequest_ObjectWithSite_GetSite
1576 };
1577
1578 /* IObjectSafety */
1579 static HRESULT WINAPI httprequest_Safety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1580 {
1581 httprequest *This = impl_from_IObjectSafety(iface);
1582 return IXMLHTTPRequest_QueryInterface( (IXMLHTTPRequest *)This, riid, ppv );
1583 }
1584
1585 static ULONG WINAPI httprequest_Safety_AddRef(IObjectSafety *iface)
1586 {
1587 httprequest *This = impl_from_IObjectSafety(iface);
1588 return IXMLHTTPRequest_AddRef((IXMLHTTPRequest *)This);
1589 }
1590
1591 static ULONG WINAPI httprequest_Safety_Release(IObjectSafety *iface)
1592 {
1593 httprequest *This = impl_from_IObjectSafety(iface);
1594 return IXMLHTTPRequest_Release((IXMLHTTPRequest *)This);
1595 }
1596
1597 static HRESULT WINAPI httprequest_Safety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1598 DWORD *supported, DWORD *enabled)
1599 {
1600 httprequest *This = impl_from_IObjectSafety(iface);
1601
1602 TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), supported, enabled);
1603
1604 if(!supported || !enabled) return E_POINTER;
1605
1606 *supported = safety_supported_options;
1607 *enabled = This->safeopt;
1608
1609 return S_OK;
1610 }
1611
1612 static HRESULT WINAPI httprequest_Safety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1613 DWORD mask, DWORD enabled)
1614 {
1615 httprequest *This = impl_from_IObjectSafety(iface);
1616 TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), mask, enabled);
1617
1618 if ((mask & ~safety_supported_options))
1619 return E_FAIL;
1620
1621 This->safeopt = (This->safeopt & ~mask) | (mask & enabled);
1622
1623 return S_OK;
1624 }
1625
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
1632 };
1633
1634 /* IServerXMLHTTPRequest */
1635 static HRESULT WINAPI ServerXMLHTTPRequest_QueryInterface(IServerXMLHTTPRequest *iface, REFIID riid, void **obj)
1636 {
1637 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1638
1639 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
1640
1641 if ( IsEqualGUID( riid, &IID_IServerXMLHTTPRequest) ||
1642 IsEqualGUID( riid, &IID_IXMLHTTPRequest) ||
1643 IsEqualGUID( riid, &IID_IDispatch) ||
1644 IsEqualGUID( riid, &IID_IUnknown) )
1645 {
1646 *obj = iface;
1647 }
1648 else
1649 {
1650 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
1651 *obj = NULL;
1652 return E_NOINTERFACE;
1653 }
1654
1655 IServerXMLHTTPRequest_AddRef( iface );
1656
1657 return S_OK;
1658 }
1659
1660 static ULONG WINAPI ServerXMLHTTPRequest_AddRef(IServerXMLHTTPRequest *iface)
1661 {
1662 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1663 ULONG ref = InterlockedIncrement( &This->ref );
1664 TRACE("(%p)->(%u)\n", This, ref );
1665 return ref;
1666 }
1667
1668 static ULONG WINAPI ServerXMLHTTPRequest_Release(IServerXMLHTTPRequest *iface)
1669 {
1670 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1671 ULONG ref = InterlockedDecrement( &This->ref );
1672
1673 TRACE("(%p)->(%u)\n", This, ref );
1674
1675 if ( ref == 0 )
1676 {
1677 httprequest_release( &This->req );
1678 heap_free( This );
1679 }
1680
1681 return ref;
1682 }
1683
1684 static HRESULT WINAPI ServerXMLHTTPRequest_GetTypeInfoCount(IServerXMLHTTPRequest *iface, UINT *pctinfo)
1685 {
1686 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1687
1688 TRACE("(%p)->(%p)\n", This, pctinfo);
1689 *pctinfo = 1;
1690
1691 return S_OK;
1692 }
1693
1694 static HRESULT WINAPI ServerXMLHTTPRequest_GetTypeInfo(IServerXMLHTTPRequest *iface, UINT iTInfo,
1695 LCID lcid, ITypeInfo **ppTInfo)
1696 {
1697 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1698
1699 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1700
1701 return get_typeinfo(IServerXMLHTTPRequest_tid, ppTInfo);
1702 }
1703
1704 static HRESULT WINAPI ServerXMLHTTPRequest_GetIDsOfNames(IServerXMLHTTPRequest *iface, REFIID riid,
1705 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1706 {
1707 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1708 ITypeInfo *typeinfo;
1709 HRESULT hr;
1710
1711 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1712 lcid, rgDispId);
1713
1714 if(!rgszNames || cNames == 0 || !rgDispId)
1715 return E_INVALIDARG;
1716
1717 hr = get_typeinfo(IServerXMLHTTPRequest_tid, &typeinfo);
1718 if(SUCCEEDED(hr))
1719 {
1720 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1721 ITypeInfo_Release(typeinfo);
1722 }
1723
1724 return hr;
1725 }
1726
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)
1730 {
1731 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1732 ITypeInfo *typeinfo;
1733 HRESULT hr;
1734
1735 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1736 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1737
1738 hr = get_typeinfo(IServerXMLHTTPRequest_tid, &typeinfo);
1739 if(SUCCEEDED(hr))
1740 {
1741 hr = ITypeInfo_Invoke(typeinfo, &This->IServerXMLHTTPRequest_iface, dispIdMember, wFlags,
1742 pDispParams, pVarResult, pExcepInfo, puArgErr);
1743 ITypeInfo_Release(typeinfo);
1744 }
1745
1746 return hr;
1747 }
1748
1749 static HRESULT WINAPI ServerXMLHTTPRequest_open(IServerXMLHTTPRequest *iface, BSTR method, BSTR url,
1750 VARIANT async, VARIANT user, VARIANT password)
1751 {
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);
1756 }
1757
1758 static HRESULT WINAPI ServerXMLHTTPRequest_setRequestHeader(IServerXMLHTTPRequest *iface, BSTR header, BSTR value)
1759 {
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);
1763 }
1764
1765 static HRESULT WINAPI ServerXMLHTTPRequest_getResponseHeader(IServerXMLHTTPRequest *iface, BSTR header, BSTR *value)
1766 {
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);
1770 }
1771
1772 static HRESULT WINAPI ServerXMLHTTPRequest_getAllResponseHeaders(IServerXMLHTTPRequest *iface, BSTR *respheaders)
1773 {
1774 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1775 TRACE("(%p)->(%p)\n", This, respheaders);
1776 return httprequest_getAllResponseHeaders(&This->req, respheaders);
1777 }
1778
1779 static HRESULT WINAPI ServerXMLHTTPRequest_send(IServerXMLHTTPRequest *iface, VARIANT body)
1780 {
1781 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1782 TRACE("(%p)->(%s)\n", This, debugstr_variant(&body));
1783 return httprequest_send(&This->req, body);
1784 }
1785
1786 static HRESULT WINAPI ServerXMLHTTPRequest_abort(IServerXMLHTTPRequest *iface)
1787 {
1788 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1789 TRACE("(%p)\n", This);
1790 return httprequest_abort(&This->req);
1791 }
1792
1793 static HRESULT WINAPI ServerXMLHTTPRequest_get_status(IServerXMLHTTPRequest *iface, LONG *status)
1794 {
1795 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1796 TRACE("(%p)->(%p)\n", This, status);
1797 return httprequest_get_status(&This->req, status);
1798 }
1799
1800 static HRESULT WINAPI ServerXMLHTTPRequest_get_statusText(IServerXMLHTTPRequest *iface, BSTR *status)
1801 {
1802 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1803 TRACE("(%p)->(%p)\n", This, status);
1804 return httprequest_get_statusText(&This->req, status);
1805 }
1806
1807 static HRESULT WINAPI ServerXMLHTTPRequest_get_responseXML(IServerXMLHTTPRequest *iface, IDispatch **body)
1808 {
1809 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1810 TRACE("(%p)->(%p)\n", This, body);
1811 return httprequest_get_responseXML(&This->req, body);
1812 }
1813
1814 static HRESULT WINAPI ServerXMLHTTPRequest_get_responseText(IServerXMLHTTPRequest *iface, BSTR *body)
1815 {
1816 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1817 TRACE("(%p)->(%p)\n", This, body);
1818 return httprequest_get_responseText(&This->req, body);
1819 }
1820
1821 static HRESULT WINAPI ServerXMLHTTPRequest_get_responseBody(IServerXMLHTTPRequest *iface, VARIANT *body)
1822 {
1823 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1824 TRACE("(%p)->(%p)\n", This, body);
1825 return httprequest_get_responseBody(&This->req, body);
1826 }
1827
1828 static HRESULT WINAPI ServerXMLHTTPRequest_get_responseStream(IServerXMLHTTPRequest *iface, VARIANT *body)
1829 {
1830 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1831 TRACE("(%p)->(%p)\n", This, body);
1832 return httprequest_get_responseStream(&This->req, body);
1833 }
1834
1835 static HRESULT WINAPI ServerXMLHTTPRequest_get_readyState(IServerXMLHTTPRequest *iface, LONG *state)
1836 {
1837 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1838 TRACE("(%p)->(%p)\n", This, state);
1839 return httprequest_get_readyState(&This->req, state);
1840 }
1841
1842 static HRESULT WINAPI ServerXMLHTTPRequest_put_onreadystatechange(IServerXMLHTTPRequest *iface, IDispatch *sink)
1843 {
1844 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1845 TRACE("(%p)->(%p)\n", This, sink);
1846 return httprequest_put_onreadystatechange(&This->req, sink);
1847 }
1848
1849 static HRESULT WINAPI ServerXMLHTTPRequest_setTimeouts(IServerXMLHTTPRequest *iface, LONG resolveTimeout, LONG connectTimeout,
1850 LONG sendTimeout, LONG receiveTimeout)
1851 {
1852 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1853 FIXME("(%p)->(%d %d %d %d): stub\n", This, resolveTimeout, connectTimeout, sendTimeout, receiveTimeout);
1854 return E_NOTIMPL;
1855 }
1856
1857 static HRESULT WINAPI ServerXMLHTTPRequest_waitForResponse(IServerXMLHTTPRequest *iface, VARIANT timeout, VARIANT_BOOL *isSuccessful)
1858 {
1859 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1860 FIXME("(%p)->(%s %p): stub\n", This, debugstr_variant(&timeout), isSuccessful);
1861 return E_NOTIMPL;
1862 }
1863
1864 static HRESULT WINAPI ServerXMLHTTPRequest_getOption(IServerXMLHTTPRequest *iface, SERVERXMLHTTP_OPTION option, VARIANT *value)
1865 {
1866 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1867 FIXME("(%p)->(%d %p): stub\n", This, option, value);
1868 return E_NOTIMPL;
1869 }
1870
1871 static HRESULT WINAPI ServerXMLHTTPRequest_setOption(IServerXMLHTTPRequest *iface, SERVERXMLHTTP_OPTION option, VARIANT value)
1872 {
1873 serverhttp *This = impl_from_IServerXMLHTTPRequest( iface );
1874 FIXME("(%p)->(%d %s): stub\n", This, option, debugstr_variant(&value));
1875 return E_NOTIMPL;
1876 }
1877
1878 static const struct IServerXMLHTTPRequestVtbl ServerXMLHTTPRequestVtbl =
1879 {
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
1905 };
1906
1907 static void init_httprequest(httprequest *req)
1908 {
1909 req->IXMLHTTPRequest_iface.lpVtbl = &XMLHTTPRequestVtbl;
1910 req->IObjectWithSite_iface.lpVtbl = &ObjectWithSiteVtbl;
1911 req->IObjectSafety_iface.lpVtbl = &ObjectSafetyVtbl;
1912 req->ref = 1;
1913
1914 req->async = FALSE;
1915 req->verb = -1;
1916 req->custom = NULL;
1917 req->uri = req->base_uri = NULL;
1918 req->user = req->password = NULL;
1919
1920 req->state = READYSTATE_UNINITIALIZED;
1921 req->sink = NULL;
1922
1923 req->bsc = NULL;
1924 req->status = 0;
1925 req->status_text = NULL;
1926 req->reqheader_size = 0;
1927 req->raw_respheaders = NULL;
1928 req->use_utf8_content = FALSE;
1929
1930 list_init(&req->reqheaders);
1931 list_init(&req->respheaders);
1932
1933 req->site = NULL;
1934 req->safeopt = 0;
1935 }
1936
1937 HRESULT XMLHTTPRequest_create(IUnknown *outer, void **obj)
1938 {
1939 httprequest *req;
1940
1941 TRACE("(%p, %p)\n", outer, obj);
1942
1943 req = heap_alloc( sizeof (*req) );
1944 if( !req )
1945 return E_OUTOFMEMORY;
1946
1947 init_httprequest(req);
1948 *obj = &req->IXMLHTTPRequest_iface;
1949
1950 TRACE("returning iface %p\n", *obj);
1951
1952 return S_OK;
1953 }
1954
1955 HRESULT ServerXMLHTTP_create(IUnknown *outer, void **obj)
1956 {
1957 serverhttp *req;
1958
1959 TRACE("(%p, %p)\n", outer, obj);
1960
1961 req = heap_alloc( sizeof (*req) );
1962 if( !req )
1963 return E_OUTOFMEMORY;
1964
1965 init_httprequest(&req->req);
1966 req->IServerXMLHTTPRequest_iface.lpVtbl = &ServerXMLHTTPRequestVtbl;
1967 req->ref = 1;
1968
1969 *obj = &req->IServerXMLHTTPRequest_iface;
1970
1971 TRACE("returning iface %p\n", *obj);
1972
1973 return S_OK;
1974 }
1975
1976 #else
1977
1978 HRESULT XMLHTTPRequest_create(IUnknown *pUnkOuter, void **ppObj)
1979 {
1980 MESSAGE("This program tried to use a XMLHTTPRequest object, but\n"
1981 "libxml2 support was not present at compile time.\n");
1982 return E_NOTIMPL;
1983 }
1984
1985 HRESULT ServerXMLHTTP_create(IUnknown *outer, void **obj)
1986 {
1987 MESSAGE("This program tried to use a ServerXMLHTTP object, but\n"
1988 "libxml2 support was not present at compile time.\n");
1989 return E_NOTIMPL;
1990 }
1991
1992 #endif