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