[HTTPAPI] Sync with Wine Staging 4.18. CORE-16441
[reactos.git] / dll / win32 / httpapi / httpapi_main.c
1 /*
2 * HTTPAPI implementation
3 *
4 * Copyright 2009 Austin English
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #ifdef __REACTOS__
22 #include <stdio.h>
23 #endif
24 #include "wine/http.h"
25 #include "winsvc.h"
26 #include "wine/winternl.h"
27 #include "wine/debug.h"
28 #include "wine/heap.h"
29 #include "wine/list.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(httpapi);
32
33 static const WCHAR device_nameW[] = {'\\','D','e','v','i','c','e','\\','H','t','t','p','\\','R','e','q','Q','u','e','u','e',0};
34
35 static WCHAR *heap_strdupW(const WCHAR *str)
36 {
37 int len = wcslen(str) + 1;
38 WCHAR *ret = heap_alloc(len * sizeof(WCHAR));
39 wcscpy(ret, str);
40 return ret;
41 }
42
43 /***********************************************************************
44 * HttpInitialize (HTTPAPI.@)
45 *
46 * Initializes HTTP Server API engine
47 *
48 * PARAMS
49 * version [ I] HTTP API version which caller will use
50 * flags [ I] initialization options which specify parts of API what will be used
51 * reserved [IO] reserved, must be NULL
52 *
53 * RETURNS
54 * NO_ERROR if function succeeds, or error code if function fails
55 *
56 */
57 ULONG WINAPI HttpInitialize(HTTPAPI_VERSION version, ULONG flags, void *reserved)
58 {
59 static const WCHAR httpW[] = {'h','t','t','p',0};
60 SC_HANDLE manager, service;
61
62 TRACE("version %u.%u, flags %#x, reserved %p.\n", version.HttpApiMajorVersion,
63 version.HttpApiMinorVersion, flags, reserved);
64
65 if (flags & ~HTTP_INITIALIZE_SERVER)
66 {
67 FIXME("Unhandled flags %#x.\n", flags);
68 return ERROR_CALL_NOT_IMPLEMENTED;
69 }
70
71 if (!(manager = OpenSCManagerW(NULL, NULL, SC_MANAGER_CONNECT)))
72 return GetLastError();
73
74 if (!(service = OpenServiceW(manager, httpW, SERVICE_START)))
75 {
76 ERR("Failed to open HTTP service, error %u.\n", GetLastError());
77 CloseServiceHandle(manager);
78 return GetLastError();
79 }
80
81 if (!StartServiceW(service, 0, NULL) && GetLastError() != ERROR_SERVICE_ALREADY_RUNNING)
82 {
83 ERR("Failed to start HTTP service, error %u.\n", GetLastError());
84 CloseServiceHandle(service);
85 CloseServiceHandle(manager);
86 return GetLastError();
87 }
88
89 CloseServiceHandle(service);
90 CloseServiceHandle(manager);
91 return ERROR_SUCCESS;
92 }
93
94 /***********************************************************************
95 * HttpTerminate (HTTPAPI.@)
96 *
97 * Cleans up HTTP Server API engine resources allocated by HttpInitialize
98 *
99 * PARAMS
100 * flags [ I] options which specify parts of API what should be released
101 * reserved [IO] reserved, must be NULL
102 *
103 * RETURNS
104 * NO_ERROR if function succeeds, or error code if function fails
105 *
106 */
107 ULONG WINAPI HttpTerminate( ULONG flags, PVOID reserved )
108 {
109 FIXME( "(0x%x, %p): stub!\n", flags, reserved );
110 return NO_ERROR;
111 }
112
113 /***********************************************************************
114 * HttpDeleteServiceConfiguration (HTTPAPI.@)
115 *
116 * Remove configuration record from HTTP Server API configuration store
117 *
118 * PARAMS
119 * handle [I] reserved, must be 0
120 * type [I] configuration record type
121 * config [I] buffer which contains configuration record information
122 * length [I] length of configuration record buffer
123 * overlapped [I] reserved, must be NULL
124 *
125 * RETURNS
126 * NO_ERROR if function succeeds, or error code if function fails
127 *
128 */
129 ULONG WINAPI HttpDeleteServiceConfiguration( HANDLE handle, HTTP_SERVICE_CONFIG_ID type,
130 PVOID config, ULONG length, LPOVERLAPPED overlapped )
131 {
132 FIXME( "(%p, %d, %p, %d, %p): stub!\n", handle, type, config, length, overlapped );
133 return NO_ERROR;
134 }
135
136 /***********************************************************************
137 * HttpQueryServiceConfiguration (HTTPAPI.@)
138 *
139 * Retrieves configuration records from HTTP Server API configuration store
140 *
141 * PARAMS
142 * handle [ I] reserved, must be 0
143 * type [ I] configuration records type
144 * query [ I] buffer which contains query data used to retrieve records
145 * query_len [ I] length of query buffer
146 * buffer [IO] buffer to store query results
147 * buffer_len [ I] length of output buffer
148 * data_len [ O] optional pointer to a buffer which receives query result length
149 * overlapped [ I] reserved, must be NULL
150 *
151 * RETURNS
152 * NO_ERROR if function succeeds, or error code if function fails
153 *
154 */
155 ULONG WINAPI HttpQueryServiceConfiguration( HANDLE handle, HTTP_SERVICE_CONFIG_ID type,
156 PVOID query, ULONG query_len, PVOID buffer, ULONG buffer_len,
157 PULONG data_len, LPOVERLAPPED overlapped )
158 {
159 FIXME( "(%p, %d, %p, %d, %p, %d, %p, %p): stub!\n", handle, type, query, query_len,
160 buffer, buffer_len, data_len, overlapped );
161 return ERROR_FILE_NOT_FOUND;
162 }
163
164 /***********************************************************************
165 * HttpSetServiceConfiguration (HTTPAPI.@)
166 *
167 * Add configuration record to HTTP Server API configuration store
168 *
169 * PARAMS
170 * handle [I] reserved, must be 0
171 * type [I] configuration record type
172 * config [I] buffer which contains configuration record information
173 * length [I] length of configuration record buffer
174 * overlapped [I] reserved, must be NULL
175 *
176 * RETURNS
177 * NO_ERROR if function succeeds, or error code if function fails
178 *
179 */
180 ULONG WINAPI HttpSetServiceConfiguration( HANDLE handle, HTTP_SERVICE_CONFIG_ID type,
181 PVOID config, ULONG length, LPOVERLAPPED overlapped )
182 {
183 FIXME( "(%p, %d, %p, %d, %p): stub!\n", handle, type, config, length, overlapped );
184 return NO_ERROR;
185 }
186
187 /***********************************************************************
188 * HttpCreateHttpHandle (HTTPAPI.@)
189 *
190 * Creates a handle to the HTTP request queue
191 *
192 * PARAMS
193 * handle [O] handle to request queue
194 * reserved [I] reserved, must be NULL
195 *
196 * RETURNS
197 * NO_ERROR if function succeeds, or error code if function fails
198 *
199 */
200 ULONG WINAPI HttpCreateHttpHandle(HANDLE *handle, ULONG reserved)
201 {
202 OBJECT_ATTRIBUTES attr = {sizeof(attr)};
203 UNICODE_STRING string;
204 IO_STATUS_BLOCK iosb;
205
206 TRACE("handle %p, reserved %#x.\n", handle, reserved);
207
208 if (!handle)
209 return ERROR_INVALID_PARAMETER;
210
211 RtlInitUnicodeString(&string, device_nameW);
212 attr.ObjectName = &string;
213 return RtlNtStatusToDosError(NtCreateFile(handle, 0, &attr, &iosb, NULL,
214 FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_NON_DIRECTORY_FILE, NULL, 0));
215 }
216
217 static ULONG add_url(HANDLE queue, const WCHAR *urlW, HTTP_URL_CONTEXT context)
218 {
219 struct http_add_url_params *params;
220 ULONG ret = ERROR_SUCCESS;
221 OVERLAPPED ovl;
222 int len;
223
224 len = WideCharToMultiByte(CP_ACP, 0, urlW, -1, NULL, 0, NULL, NULL);
225 if (!(params = heap_alloc(offsetof(struct http_add_url_params, url[len]))))
226 return ERROR_OUTOFMEMORY;
227 WideCharToMultiByte(CP_ACP, 0, urlW, -1, params->url, len, NULL, NULL);
228 params->context = context;
229
230 ovl.hEvent = (HANDLE)((ULONG_PTR)CreateEventW(NULL, TRUE, FALSE, NULL) | 1);
231
232 if (!DeviceIoControl(queue, IOCTL_HTTP_ADD_URL, params,
233 offsetof(struct http_add_url_params, url[len]), NULL, 0, NULL, &ovl))
234 ret = GetLastError();
235 CloseHandle(ovl.hEvent);
236 heap_free(params);
237 return ret;
238 }
239
240 /***********************************************************************
241 * HttpAddUrl (HTTPAPI.@)
242 */
243 ULONG WINAPI HttpAddUrl(HANDLE queue, const WCHAR *url, void *reserved)
244 {
245 TRACE("queue %p, url %s, reserved %p.\n", queue, debugstr_w(url), reserved);
246
247 return add_url(queue, url, 0);
248 }
249
250 static ULONG remove_url(HANDLE queue, const WCHAR *urlW)
251 {
252 ULONG ret = ERROR_SUCCESS;
253 OVERLAPPED ovl = {0};
254 char *url;
255 int len;
256
257 len = WideCharToMultiByte(CP_ACP, 0, urlW, -1, NULL, 0, NULL, NULL);
258 if (!(url = heap_alloc(len)))
259 return ERROR_OUTOFMEMORY;
260 WideCharToMultiByte(CP_ACP, 0, urlW, -1, url, len, NULL, NULL);
261
262 ovl.hEvent = (HANDLE)((ULONG_PTR)CreateEventW(NULL, TRUE, FALSE, NULL) | 1);
263
264 if (!DeviceIoControl(queue, IOCTL_HTTP_REMOVE_URL, url, len, NULL, 0, NULL, &ovl))
265 ret = GetLastError();
266 CloseHandle(ovl.hEvent);
267 heap_free(url);
268 return ret;
269 }
270
271 /***********************************************************************
272 * HttpRemoveUrl (HTTPAPI.@)
273 */
274 ULONG WINAPI HttpRemoveUrl(HANDLE queue, const WCHAR *url)
275 {
276 TRACE("queue %p, url %s.\n", queue, debugstr_w(url));
277
278 if (!queue)
279 return ERROR_INVALID_PARAMETER;
280
281 return remove_url(queue, url);
282 }
283
284 /***********************************************************************
285 * HttpReceiveHttpRequest (HTTPAPI.@)
286 */
287 ULONG WINAPI HttpReceiveHttpRequest(HANDLE queue, HTTP_REQUEST_ID id, ULONG flags,
288 HTTP_REQUEST *request, ULONG size, ULONG *ret_size, OVERLAPPED *ovl)
289 {
290 struct http_receive_request_params params =
291 {
292 .addr = (ULONG_PTR)request,
293 .id = id,
294 .flags = flags,
295 .bits = sizeof(void *) * 8,
296 };
297 ULONG ret = ERROR_SUCCESS;
298 OVERLAPPED sync_ovl;
299
300 TRACE("queue %p, id %s, flags %#x, request %p, size %#x, ret_size %p, ovl %p.\n",
301 queue, wine_dbgstr_longlong(id), flags, request, size, ret_size, ovl);
302
303 if (flags & ~HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY)
304 FIXME("Ignoring flags %#x.\n", flags & ~HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY);
305
306 if (size < sizeof(HTTP_REQUEST_V1))
307 return ERROR_INSUFFICIENT_BUFFER;
308
309 if (!ovl)
310 {
311 sync_ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
312 ovl = &sync_ovl;
313 }
314
315 if (!DeviceIoControl(queue, IOCTL_HTTP_RECEIVE_REQUEST, &params, sizeof(params), request, size, NULL, ovl))
316 ret = GetLastError();
317
318 if (ovl == &sync_ovl)
319 {
320 ret = ERROR_SUCCESS;
321 if (!GetOverlappedResult(queue, ovl, ret_size, TRUE))
322 ret = GetLastError();
323 CloseHandle(sync_ovl.hEvent);
324 }
325
326 return ret;
327 }
328
329 static void format_date(char *buffer)
330 {
331 static const char day_names[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
332 static const char month_names[12][4] =
333 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
334 SYSTEMTIME date;
335 GetSystemTime(&date);
336 sprintf(buffer + strlen(buffer), "Date: %s, %02u %s %u %02u:%02u:%02u GMT\r\n",
337 day_names[date.wDayOfWeek], date.wDay, month_names[date.wMonth - 1],
338 date.wYear, date.wHour, date.wMinute, date.wSecond);
339 }
340
341 /***********************************************************************
342 * HttpSendHttpResponse (HTTPAPI.@)
343 */
344 ULONG WINAPI HttpSendHttpResponse(HANDLE queue, HTTP_REQUEST_ID id, ULONG flags,
345 HTTP_RESPONSE *response, HTTP_CACHE_POLICY *cache_policy, ULONG *ret_size,
346 void *reserved1, ULONG reserved2, OVERLAPPED *ovl, HTTP_LOG_DATA *log_data)
347 {
348 static const char *const header_names[] =
349 {
350 "Cache-Control",
351 "Connection",
352 "Date",
353 "Keep-Alive",
354 "Pragma",
355 "Trailer",
356 "Transfer-Encoding",
357 "Upgrade",
358 "Via",
359 "Warning",
360 "Allow",
361 "Content-Length",
362 "Content-Type",
363 "Content-Encoding",
364 "Content-Language",
365 "Content-Location",
366 "Content-MD5",
367 "Content-Range",
368 "Expires",
369 "Last-Modified",
370 "Accept-Ranges",
371 "Age",
372 "ETag",
373 "Location",
374 "Proxy-Authenticate",
375 "Retry-After",
376 "Server",
377 "Set-Cookie",
378 "Vary",
379 "WWW-Authenticate",
380 };
381
382 struct http_response *buffer;
383 OVERLAPPED dummy_ovl = {0};
384 ULONG ret = ERROR_SUCCESS;
385 int len, body_len = 0;
386 char *p, dummy[12];
387 USHORT i;
388
389 TRACE("queue %p, id %s, flags %#x, response %p, cache_policy %p, "
390 "ret_size %p, reserved1 %p, reserved2 %#x, ovl %p, log_data %p.\n",
391 queue, wine_dbgstr_longlong(id), flags, response, cache_policy,
392 ret_size, reserved1, reserved2, ovl, log_data);
393
394 if (flags)
395 FIXME("Unhandled flags %#x.\n", flags);
396 if (response->s.Flags)
397 FIXME("Unhandled response flags %#x.\n", response->s.Flags);
398 if (cache_policy)
399 WARN("Ignoring cache_policy.\n");
400 if (log_data)
401 WARN("Ignoring log_data.\n");
402
403 len = 12 + sprintf(dummy, "%hu", response->s.StatusCode) + response->s.ReasonLength;
404 for (i = 0; i < response->s.EntityChunkCount; ++i)
405 {
406 if (response->s.pEntityChunks[i].DataChunkType != HttpDataChunkFromMemory)
407 {
408 FIXME("Unhandled data chunk type %u.\n", response->s.pEntityChunks[i].DataChunkType);
409 return ERROR_CALL_NOT_IMPLEMENTED;
410 }
411 body_len += response->s.pEntityChunks[i].FromMemory.BufferLength;
412 }
413 len += body_len;
414 for (i = 0; i < HttpHeaderResponseMaximum; ++i)
415 {
416 if (i == HttpHeaderDate)
417 len += 37;
418 else if (response->s.Headers.KnownHeaders[i].RawValueLength)
419 len += strlen(header_names[i]) + 2 + response->s.Headers.KnownHeaders[i].RawValueLength + 2;
420 else if (i == HttpHeaderContentLength)
421 {
422 char dummy[12];
423 len += strlen(header_names[i]) + 2 + sprintf(dummy, "%d", body_len) + 2;
424 }
425 }
426 for (i = 0; i < response->s.Headers.UnknownHeaderCount; ++i)
427 {
428 len += response->s.Headers.pUnknownHeaders[i].NameLength + 2;
429 len += response->s.Headers.pUnknownHeaders[i].RawValueLength + 2;
430 }
431 len += 2;
432
433 if (!(buffer = heap_alloc(offsetof(struct http_response, buffer[len]))))
434 return ERROR_OUTOFMEMORY;
435 buffer->id = id;
436 buffer->len = len;
437 sprintf(buffer->buffer, "HTTP/1.1 %u %.*s\r\n", response->s.StatusCode,
438 response->s.ReasonLength, response->s.pReason);
439
440 for (i = 0; i < HttpHeaderResponseMaximum; ++i)
441 {
442 const HTTP_KNOWN_HEADER *header = &response->s.Headers.KnownHeaders[i];
443 if (i == HttpHeaderDate)
444 format_date(buffer->buffer);
445 else if (header->RawValueLength)
446 sprintf(buffer->buffer + strlen(buffer->buffer), "%s: %.*s\r\n",
447 header_names[i], header->RawValueLength, header->pRawValue);
448 else if (i == HttpHeaderContentLength)
449 sprintf(buffer->buffer + strlen(buffer->buffer), "Content-Length: %d\r\n", body_len);
450 }
451 for (i = 0; i < response->s.Headers.UnknownHeaderCount; ++i)
452 {
453 const HTTP_UNKNOWN_HEADER *header = &response->s.Headers.pUnknownHeaders[i];
454 sprintf(buffer->buffer + strlen(buffer->buffer), "%.*s: %.*s\r\n", header->NameLength,
455 header->pName, header->RawValueLength, header->pRawValue);
456 }
457 p = buffer->buffer + strlen(buffer->buffer);
458 /* Don't use strcat, because this might be the end of the buffer. */
459 memcpy(p, "\r\n", 2);
460 p += 2;
461 for (i = 0; i < response->s.EntityChunkCount; ++i)
462 {
463 const HTTP_DATA_CHUNK *chunk = &response->s.pEntityChunks[i];
464 memcpy(p, chunk->FromMemory.pBuffer, chunk->FromMemory.BufferLength);
465 p += chunk->FromMemory.BufferLength;
466 }
467
468 if (!ovl)
469 ovl = &dummy_ovl;
470
471 if (!DeviceIoControl(queue, IOCTL_HTTP_SEND_RESPONSE, buffer,
472 offsetof(struct http_response, buffer[len]), NULL, 0, NULL, ovl))
473 ret = GetLastError();
474
475 heap_free(buffer);
476 return ret;
477 }
478
479 struct url_group
480 {
481 struct list entry, session_entry;
482 HANDLE queue;
483 WCHAR *url;
484 HTTP_URL_CONTEXT context;
485 };
486
487 static struct list url_groups = LIST_INIT(url_groups);
488
489 static struct url_group *get_url_group(HTTP_URL_GROUP_ID id)
490 {
491 struct url_group *group;
492 LIST_FOR_EACH_ENTRY(group, &url_groups, struct url_group, entry)
493 {
494 if ((HTTP_URL_GROUP_ID)(ULONG_PTR)group == id)
495 return group;
496 }
497 return NULL;
498 }
499
500 struct server_session
501 {
502 struct list entry;
503 struct list groups;
504 };
505
506 static struct list server_sessions = LIST_INIT(server_sessions);
507
508 static struct server_session *get_server_session(HTTP_SERVER_SESSION_ID id)
509 {
510 struct server_session *session;
511 LIST_FOR_EACH_ENTRY(session, &server_sessions, struct server_session, entry)
512 {
513 if ((HTTP_SERVER_SESSION_ID)(ULONG_PTR)session == id)
514 return session;
515 }
516 return NULL;
517 }
518
519 /***********************************************************************
520 * HttpCreateServerSession (HTTPAPI.@)
521 */
522 ULONG WINAPI HttpCreateServerSession(HTTPAPI_VERSION version, HTTP_SERVER_SESSION_ID *id, ULONG reserved)
523 {
524 struct server_session *session;
525
526 TRACE("version %u.%u, id %p, reserved %u.\n", version.HttpApiMajorVersion,
527 version.HttpApiMinorVersion, id, reserved);
528
529 if (!id)
530 return ERROR_INVALID_PARAMETER;
531
532 if ((version.HttpApiMajorVersion != 1 && version.HttpApiMajorVersion != 2)
533 || version.HttpApiMinorVersion)
534 return ERROR_REVISION_MISMATCH;
535
536 if (!(session = heap_alloc(sizeof(*session))))
537 return ERROR_OUTOFMEMORY;
538
539 list_add_tail(&server_sessions, &session->entry);
540 list_init(&session->groups);
541
542 *id = (ULONG_PTR)session;
543 return ERROR_SUCCESS;
544 }
545
546 /***********************************************************************
547 * HttpCloseServerSession (HTTPAPI.@)
548 */
549 ULONG WINAPI HttpCloseServerSession(HTTP_SERVER_SESSION_ID id)
550 {
551 struct url_group *group, *group_next;
552 struct server_session *session;
553
554 TRACE("id %s.\n", wine_dbgstr_longlong(id));
555
556 if (!(session = get_server_session(id)))
557 return ERROR_INVALID_PARAMETER;
558
559 LIST_FOR_EACH_ENTRY_SAFE(group, group_next, &session->groups, struct url_group, session_entry)
560 {
561 HttpCloseUrlGroup((ULONG_PTR)group);
562 }
563 list_remove(&session->entry);
564 heap_free(session);
565 return ERROR_SUCCESS;
566 }
567
568 /***********************************************************************
569 * HttpCreateUrlGroup (HTTPAPI.@)
570 */
571 ULONG WINAPI HttpCreateUrlGroup(HTTP_SERVER_SESSION_ID session_id, HTTP_URL_GROUP_ID *group_id, ULONG reserved)
572 {
573 struct server_session *session;
574 struct url_group *group;
575
576 TRACE("session_id %s, group_id %p, reserved %#x.\n",
577 wine_dbgstr_longlong(session_id), group_id, reserved);
578
579 if (!(session = get_server_session(session_id)))
580 return ERROR_INVALID_PARAMETER;
581
582 if (!(group = heap_alloc_zero(sizeof(*group))))
583 return ERROR_OUTOFMEMORY;
584 list_add_tail(&url_groups, &group->entry);
585 list_add_tail(&session->groups, &group->session_entry);
586
587 *group_id = (ULONG_PTR)group;
588
589 return ERROR_SUCCESS;
590 }
591
592 /***********************************************************************
593 * HttpCloseUrlGroup (HTTPAPI.@)
594 */
595 ULONG WINAPI HttpCloseUrlGroup(HTTP_URL_GROUP_ID id)
596 {
597 struct url_group *group;
598
599 TRACE("id %s.\n", wine_dbgstr_longlong(id));
600
601 if (!(group = get_url_group(id)))
602 return ERROR_INVALID_PARAMETER;
603
604 list_remove(&group->session_entry);
605 list_remove(&group->entry);
606 heap_free(group);
607
608 return ERROR_SUCCESS;
609 }
610
611 /***********************************************************************
612 * HttpSetUrlGroupProperty (HTTPAPI.@)
613 */
614 ULONG WINAPI HttpSetUrlGroupProperty(HTTP_URL_GROUP_ID id, HTTP_SERVER_PROPERTY property, void *value, ULONG length)
615 {
616 struct url_group *group = get_url_group(id);
617 const HTTP_BINDING_INFO *info = value;
618
619 TRACE("id %s, property %u, value %p, length %u.\n",
620 wine_dbgstr_longlong(id), property, value, length);
621
622 if (property != HttpServerBindingProperty)
623 {
624 FIXME("Unhandled property %u.\n", property);
625 return ERROR_CALL_NOT_IMPLEMENTED;
626 }
627
628 TRACE("Binding to queue %p.\n", info->RequestQueueHandle);
629
630 group->queue = info->RequestQueueHandle;
631
632 if (group->url)
633 add_url(group->queue, group->url, group->context);
634
635 return ERROR_SUCCESS;
636 }
637
638 /***********************************************************************
639 * HttpAddUrlToUrlGroup (HTTPAPI.@)
640 */
641 ULONG WINAPI HttpAddUrlToUrlGroup(HTTP_URL_GROUP_ID id, const WCHAR *url,
642 HTTP_URL_CONTEXT context, ULONG reserved)
643 {
644 struct url_group *group = get_url_group(id);
645
646 TRACE("id %s, url %s, context %s, reserved %#x.\n", wine_dbgstr_longlong(id),
647 debugstr_w(url), wine_dbgstr_longlong(context), reserved);
648
649 if (group->url)
650 {
651 FIXME("Multiple URLs are not handled!\n");
652 return ERROR_CALL_NOT_IMPLEMENTED;
653 }
654
655 if (!(group->url = heap_strdupW(url)))
656 return ERROR_OUTOFMEMORY;
657 group->context = context;
658
659 if (group->queue)
660 return add_url(group->queue, url, context);
661
662 return ERROR_SUCCESS;
663 }
664
665 /***********************************************************************
666 * HttpRemoveUrlFromUrlGroup (HTTPAPI.@)
667 */
668 ULONG WINAPI HttpRemoveUrlFromUrlGroup(HTTP_URL_GROUP_ID id, const WCHAR *url, ULONG flags)
669 {
670 struct url_group *group = get_url_group(id);
671
672 TRACE("id %s, url %s, flags %#x.\n", wine_dbgstr_longlong(id), debugstr_w(url), flags);
673
674 if (!group->url)
675 return ERROR_FILE_NOT_FOUND;
676
677 if (flags)
678 FIXME("Ignoring flags %#x.\n", flags);
679
680 heap_free(group->url);
681 group->url = NULL;
682
683 if (group->queue)
684 return remove_url(group->queue, url);
685
686 return ERROR_SUCCESS;
687 }
688
689 /***********************************************************************
690 * HttpCreateRequestQueue (HTTPAPI.@)
691 */
692 ULONG WINAPI HttpCreateRequestQueue(HTTPAPI_VERSION version, const WCHAR *name,
693 SECURITY_ATTRIBUTES *sa, ULONG flags, HANDLE *handle)
694 {
695 OBJECT_ATTRIBUTES attr = {sizeof(attr)};
696 UNICODE_STRING string;
697 IO_STATUS_BLOCK iosb;
698
699 TRACE("version %u.%u, name %s, sa %p, flags %#x, handle %p.\n",
700 version.HttpApiMajorVersion, version.HttpApiMinorVersion,
701 debugstr_w(name), sa, flags, handle);
702
703 if (name)
704 FIXME("Unhandled name %s.\n", debugstr_w(name));
705 if (flags)
706 FIXME("Unhandled flags %#x.\n", flags);
707
708 RtlInitUnicodeString(&string, device_nameW);
709 attr.ObjectName = &string;
710 if (sa && sa->bInheritHandle)
711 attr.Attributes |= OBJ_INHERIT;
712 attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
713 return RtlNtStatusToDosError(NtCreateFile(handle, 0, &attr, &iosb, NULL,
714 FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_NON_DIRECTORY_FILE, NULL, 0));
715 }
716
717 /***********************************************************************
718 * HttpCloseRequestQueue (HTTPAPI.@)
719 */
720 ULONG WINAPI HttpCloseRequestQueue(HANDLE handle)
721 {
722 TRACE("handle %p.\n", handle);
723 if (!CloseHandle(handle))
724 return GetLastError();
725 return ERROR_SUCCESS;
726 }