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