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