ReactOS 0.4.17-dev-966-gf06eace
port.c
Go to the documentation of this file.
1/*
2 * Copyright 2009 Hans Leidekker for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include <stdarg.h>
20#include <stdio.h>
21
22#define COBJMACROS
23
24#include "windef.h"
25#include "winbase.h"
26#include "winuser.h"
27#include "string.h"
28#include "initguid.h"
29#include "assert.h"
30#include "winsock2.h"
31#include "winhttp.h"
32#include "shlwapi.h"
33#include "xmllite.h"
34#include "ole2.h"
35#include "netfw.h"
36#include "natupnp.h"
37
38#include "wine/debug.h"
39#include "hnetcfg_private.h"
40
42
44{
52};
53
55{
56 const WCHAR *name;
58};
59
60static struct
61{
68 unsigned int version;
70 unsigned int mapping_count;
71}
73
74static SRWLOCK upnp_gateway_connection_lock = SRWLOCK_INIT;
75
77{
78 SysFreeString( mapping->external_ip );
79 SysFreeString( mapping->protocol );
80 SysFreeString( mapping->client );
81 SysFreeString( mapping->descr );
82}
83
84static void free_mappings(void)
85{
86 unsigned int i;
87
88 for (i = 0; i < upnp_gateway_connection.mapping_count; ++i)
90 free( upnp_gateway_connection.mappings );
92 upnp_gateway_connection.mapping_count = 0;
93}
94
95static BOOL copy_port_mapping( struct port_mapping *dst, const struct port_mapping *src )
96{
97 memset( dst, 0, sizeof(*dst) );
98
99#define COPY_BSTR_CHECK(name) if (src->name && !(dst->name = SysAllocString( src->name ))) \
100 { \
101 free_port_mapping( dst ); \
102 return FALSE; \
103 }
104
109#undef COPY_BSTR_CHECK
110
111 dst->external = src->external;
112 dst->internal = src->internal;
113 dst->enabled = src->enabled;
114 return TRUE;
115}
116
117static BOOL parse_search_response( char *response, WCHAR *locationW, unsigned int location_size )
118{
119 char *saveptr = NULL, *tok, *tok2;
120 unsigned int status;
121
122 tok = strtok_s( response, "\n", &saveptr );
123 if (!tok) return FALSE;
124
125 /* HTTP/1.1 200 OK */
126 tok2 = strtok( tok, " " );
127 if (!tok2) return FALSE;
128 tok2 = strtok( NULL, " " );
129 if (!tok2) return FALSE;
130 status = atoi( tok2 );
131 if (status != HTTP_STATUS_OK)
132 {
133 WARN( "status %u.\n", status );
134 return FALSE;
135 }
136 while ((tok = strtok_s( NULL, "\n", &saveptr )))
137 {
138 tok2 = strtok( tok, " " );
139 if (!tok2) continue;
140 if (!stricmp( tok2, "LOCATION:" ))
141 {
142 tok2 = strtok( NULL, " \r" );
143 if (!tok2)
144 {
145 WARN( "Error parsing location.\n" );
146 return FALSE;
147 }
148 return !!MultiByteToWideChar( CP_UTF8, 0, tok2, -1, locationW, location_size / 2 );
149 }
150 }
151 return FALSE;
152}
153
154static BOOL parse_desc_xml( const char *desc_xml )
155{
156 static const WCHAR urn_wanipconnection[] = L"urn:schemas-upnp-org:service:WANIPConnection:";
158 BOOL service_type_matches, control_url_found, found = FALSE;
159 unsigned int version = 0;
160 XmlNodeType node_type;
162 const WCHAR *value;
163 BOOL ret = FALSE;
165 HRESULT hr;
166
167 if (!(stream = SHCreateMemStream( (BYTE *)desc_xml, strlen( desc_xml ) + 1 ))) return FALSE;
168 if (FAILED(hr = CreateXmlReader( &IID_IXmlReader, (void **)&reader, NULL )))
169 {
170 IStream_Release( stream );
171 return FALSE;
172 }
173 if (FAILED(hr = IXmlReader_SetInput( reader, (IUnknown*)stream ))) goto done;
174
175 while (SUCCEEDED(IXmlReader_Read( reader, &node_type )) && node_type != XmlNodeType_None)
176 {
177 if (node_type != XmlNodeType_Element) continue;
178
179 if (FAILED(IXmlReader_GetLocalName( reader, &value, NULL ))) goto done;
180 if (wcsicmp( value, L"service" )) continue;
181 control_url_found = service_type_matches = FALSE;
182 while (SUCCEEDED(IXmlReader_Read( reader, &node_type )))
183 {
184 if (node_type != XmlNodeType_Element && node_type != XmlNodeType_EndElement) continue;
185 if (FAILED(IXmlReader_GetLocalName( reader, &value, NULL )))
186 {
187 WARN( "IXmlReader_GetLocalName failed.\n" );
188 goto done;
189 }
190 if (node_type == XmlNodeType_EndElement)
191 {
192 if (!wcsicmp( value, L"service" )) break;
193 continue;
194 }
195 if (!wcsicmp( value, L"serviceType" ))
196 {
197 if (FAILED(IXmlReader_Read(reader, &node_type ))) goto done;
198 if (node_type != XmlNodeType_Text) goto done;
199 if (FAILED(IXmlReader_GetValue( reader, &value, NULL ))) goto done;
200 if (wcsnicmp( value, urn_wanipconnection, ARRAY_SIZE(urn_wanipconnection) - 1 )) break;
201 version = _wtoi( value + ARRAY_SIZE(urn_wanipconnection) - 1 );
202 service_type_matches = version >= 1;
203 }
204 else if (!wcsicmp( value, L"controlURL" ))
205 {
206 if (FAILED(IXmlReader_Read(reader, &node_type ))) goto done;
207 if (node_type != XmlNodeType_Text) goto done;
208 if (FAILED(IXmlReader_GetValue( reader, &value, NULL ))) goto done;
209 if (wcslen( value ) + 1 > ARRAY_SIZE(control_url)) goto done;
211 control_url_found = TRUE;
212 }
213 }
214 if (service_type_matches && control_url_found)
215 {
216 if (found)
217 {
218 FIXME( "Found another WANIPConnection service, ignoring.\n" );
219 continue;
220 }
221 found = TRUE;
224 }
225 }
226
227 ret = found;
228done:
229 IXmlReader_Release( reader );
230 IStream_Release( stream );
231 return ret;
232}
233
234static BOOL get_xml_elements( const char *desc_xml, struct xml_value_desc *values, unsigned int value_count )
235{
236 XmlNodeType node_type;
238 const WCHAR *value;
239 BOOL ret = FALSE;
241 unsigned int i;
242 HRESULT hr;
243
244 for (i = 0; i < value_count; ++i) assert( !values[i].value );
245
246 if (!(stream = SHCreateMemStream( (BYTE *)desc_xml, strlen( desc_xml ) + 1 ))) return FALSE;
247 if (FAILED(hr = CreateXmlReader( &IID_IXmlReader, (void **)&reader, NULL )))
248 {
249 IStream_Release( stream );
250 return FALSE;
251 }
252 if (FAILED(hr = IXmlReader_SetInput( reader, (IUnknown*)stream ))) goto done;
253
254 while (SUCCEEDED(IXmlReader_Read( reader, &node_type )) && node_type != XmlNodeType_None)
255 {
256 if (node_type != XmlNodeType_Element) continue;
257
258 if (FAILED(IXmlReader_GetQualifiedName( reader, &value, NULL ))) goto done;
259 for (i = 0; i < value_count; ++i)
260 if (!wcsicmp( value, values[i].name )) break;
261 if (i == value_count) continue;
262 if (FAILED(IXmlReader_Read(reader, &node_type ))) goto done;
263 if (node_type != XmlNodeType_Text)
264 {
265 if (node_type == XmlNodeType_EndElement) value = L"";
266 else goto done;
267 }
268 else
269 {
270 if (FAILED(IXmlReader_GetValue( reader, &value, NULL ))) goto done;
271 }
272 if (values[i].value)
273 {
274 WARN( "Duplicate value %s.\n", debugstr_w(values[i].name) );
275 goto done;
276 }
277 if (!(values[i].value = SysAllocString( value ))) goto done;
278 }
279 ret = TRUE;
280
281done:
282 if (!ret)
283 {
284 for (i = 0; i < value_count; ++i)
285 {
287 values[i].value = NULL;
288 }
289 }
290 IXmlReader_Release( reader );
291 IStream_Release( stream );
292 return ret;
293}
294
296{
297 static const int timeout = 3000;
298
299 WCHAR hostname[64];
301
302 memset( &url, 0, sizeof(url) );
303 url.dwStructSize = sizeof(url);
304 url.lpszHostName = hostname;
305 url.dwHostNameLength = ARRAY_SIZE(hostname);
306 url.lpszUrlPath = upnp_gateway_connection.desc_urlpath;
307 url.dwUrlPathLength = ARRAY_SIZE(upnp_gateway_connection.desc_urlpath);
308
309 if (!WinHttpCrackUrl( upnp_gateway_connection.locationW, 0, 0, &url )) return FALSE;
310
313 if (!upnp_gateway_connection.session) return FALSE;
315 return FALSE;
316
317 TRACE( "hostname %s, urlpath %s, port %u.\n",
320 if (!upnp_gateway_connection.connection)
321 {
322 WARN( "WinHttpConnect error %lu.\n", GetLastError() );
323 return FALSE;
324 }
325 return TRUE;
326}
327
329{
330 static const WCHAR *accept_types[] =
331 {
332 L"text/xml",
333 NULL
334 };
335 unsigned int desc_xml_size, offset;
336 DWORD size, status = 0;
338 char *desc_xml;
339 BOOL ret;
340
342 WINHTTP_NO_REFERER, accept_types, 0 );
343 if (!request) return FALSE;
344
346 {
347 WARN( "Error sending request %lu.\n", GetLastError() );
349 return FALSE;
350 }
352 {
353 WARN( "Error receiving response %lu.\n", GetLastError() );
355 return FALSE;
356 }
357 size = sizeof(status);
360 {
361 WARN( "Error response from server, error %lu, http status %lu.\n", GetLastError(), status );
363 return FALSE;
364 }
365 desc_xml_size = 1024;
366 desc_xml = malloc( desc_xml_size );
367 offset = 0;
368 while (WinHttpReadData( request, desc_xml + offset, desc_xml_size - offset - 1, &size ) && size)
369 {
370 offset += size;
371 if (offset + 1 == desc_xml_size)
372 {
373 char *new;
374
375 desc_xml_size *= 2;
376 if (!(new = realloc( desc_xml, desc_xml_size )))
377 {
378 ERR( "No memory.\n" );
379 break;
380 }
381 desc_xml = new;
382 }
383 }
384 desc_xml[offset] = 0;
386 ret = parse_desc_xml( desc_xml );
387 free( desc_xml );
388 return ret;
389}
390
392{
393 TRACE( ".\n" );
397 if (upnp_gateway_connection.winsock_initialized) WSACleanup();
399}
400
401static BOOL request_service( const WCHAR *function, const struct xml_value_desc *request_param,
402 unsigned int request_param_count, struct xml_value_desc *result,
403 unsigned int result_count, DWORD *http_status, BSTR *server_error_code_str )
404{
405 static const char request_template_header[] =
406 "<?xml version=\"1.0\"?>\r\n"
407 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "
408 "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n"
409 " <SOAP-ENV:Body>\r\n"
410 " <m:%S xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:%u\">\r\n";
411 static const char request_template_footer[] =
412 " </m:%S>\r\n"
413 " </SOAP-ENV:Body>\r\n"
414 "</SOAP-ENV:Envelope>\r\n";
415
416 unsigned int request_data_size, request_len, offset, i, reply_buffer_size;
417 char *request_data, *reply_buffer = NULL, *ptr;
418 struct xml_value_desc error_value_desc;
419 WCHAR request_headers[1024];
421 BOOL ret = FALSE;
422 DWORD size;
423
424 *server_error_code_str = NULL;
425 request_data_size = strlen(request_template_header) + strlen(request_template_footer) + 2 * wcslen( function )
426 + 9 /* version + zero terminator */;
427 for (i = 0; i < request_param_count; ++i)
428 {
429 request_data_size += 13 + 2 * wcslen( request_param[i].name ) + wcslen( request_param[i].value );
430 }
431 if (!(request_data = malloc( request_data_size ))) return FALSE;
432
435 if (!request) goto done;
436
437 ptr = request_data;
438 snprintf( ptr, request_data_size, request_template_header, function, upnp_gateway_connection.version );
439 offset = strlen( ptr );
440 ptr += offset;
441 request_data_size -= offset;
442 for (i = 0; i < request_param_count; ++i)
443 {
444 snprintf( ptr, request_data_size, " <%S>%S</%S>\r\n",
445 request_param[i].name, request_param[i].value, request_param[i].name);
446 offset = strlen( ptr );
447 ptr += offset;
448 request_data_size -= offset;
449 }
450 snprintf( ptr, request_data_size, request_template_footer, function );
451
452 request_len = strlen( request_data );
453 swprintf( request_headers, ARRAY_SIZE(request_headers),
454 L"SOAPAction: \"urn:schemas-upnp-org:service:WANIPConnection:%u#%s\"\r\n"
455 L"Content-Type: text/xml",
456 upnp_gateway_connection.version, function );
457 if (!WinHttpSendRequest( request, request_headers, -1, request_data, request_len, request_len, 0 ))
458 {
459 WARN( "Error sending request %lu.\n", GetLastError() );
460 goto done;
461 }
463 {
464 WARN( "Error receiving response %lu.\n", GetLastError() );
465 goto done;
466 }
467 size = sizeof(*http_status);
469 NULL, http_status, &size, NULL) || *http_status != HTTP_STATUS_OK )
470 {
471 if (*http_status != HTTP_STATUS_SERVER_ERROR)
472 {
473 ret = TRUE;
474 goto done;
475 }
476 }
477
478 offset = 0;
479 reply_buffer_size = 1024;
480 if (!(reply_buffer = malloc( reply_buffer_size ))) goto done;
481 while ((ret = WinHttpReadData( request, reply_buffer + offset, reply_buffer_size - offset - 1, &size )) && size)
482 {
483 offset += size;
484 if (offset + 1 == reply_buffer_size)
485 {
486 char *new;
487
488 reply_buffer_size *= 2;
489 if (!(new = realloc( reply_buffer, reply_buffer_size ))) goto done;
490 reply_buffer = new;
491 }
492 }
493 reply_buffer[offset] = 0;
494
495 if (*http_status == HTTP_STATUS_OK) ret = get_xml_elements( reply_buffer, result, result_count );
496 else
497 {
498 error_value_desc.name = L"errorCode";
499 error_value_desc.value = NULL;
500 if ((ret = get_xml_elements( reply_buffer, &error_value_desc, 1 )))
501 *server_error_code_str = error_value_desc.value;
502 }
503
504done:
505 free( reply_buffer );
506 free( request_data );
508 return ret;
509}
510
512{
523};
524
526{
527 { L"NewRemoteHost" },
528 { L"NewExternalPort" },
529 { L"NewProtocol" },
530 { L"NewInternalPort" },
531 { L"NewInternalClient" },
532 { L"NewEnabled" },
533 { L"NewPortMappingDescription" },
534 { L"NewLeaseDuration" },
535};
536
538{
539 if (!s) return 0;
540 return _wtoi( s );
541}
542
544{
545 BSTR ret;
546
547 if (*s)
548 {
549 ret = *s;
550 *s = NULL;
551 }
552 else if (!(ret = SysAllocString( L"" )))
553 {
554 ERR( "No memory.\n" );
555 }
556 return ret;
557}
558
559static void update_mapping_list(void)
560{
561 struct xml_value_desc mapping_desc[ARRAY_SIZE(port_mapping_template)];
562 struct xml_value_desc index_param;
563 struct port_mapping *new_mappings;
564 unsigned int i, index;
565 WCHAR index_str[9];
566 BSTR error_str;
568 BOOL ret;
569
571
572 index_param.name = L"NewPortMappingIndex";
573
574 index = 0;
575 while (1)
576 {
577 new_mappings = realloc( upnp_gateway_connection.mappings, (index + 1) * sizeof(*new_mappings) );
578 if (!new_mappings) break;
579 upnp_gateway_connection.mappings = new_mappings;
580
581 memcpy( mapping_desc, port_mapping_template, sizeof(mapping_desc) );
582 swprintf( index_str, ARRAY_SIZE(index_str), L"%u", index );
583 index_param.value = SysAllocString( index_str );
584 ret = request_service( L"GetGenericPortMappingEntry", &index_param, 1,
585 mapping_desc, ARRAY_SIZE(mapping_desc), &status, &error_str );
586 SysFreeString( index_param.value );
587 if (!ret) break;
588 if (status != HTTP_STATUS_OK)
589 {
590 if (error_str)
591 {
592 if (long_from_bstr( error_str ) != 713)
593 WARN( "Server returned error %s.\n", debugstr_w(error_str) );
594 SysFreeString( error_str );
595 }
596 break;
597 }
598 new_mappings[index].external_ip = mapping_move_bstr( &mapping_desc[PM_EXTERNAL_IP].value );
599 new_mappings[index].external = long_from_bstr( mapping_desc[PM_EXTERNAL].value );
600 new_mappings[index].protocol = mapping_move_bstr( &mapping_desc[PM_PROTOCOL].value );
601 new_mappings[index].internal = long_from_bstr( mapping_desc[PM_INTERNAL].value );
602 new_mappings[index].client = mapping_move_bstr( &mapping_desc[PM_CLIENT].value );
603 if (mapping_desc[PM_ENABLED].value && (!wcsicmp( mapping_desc[PM_ENABLED].value, L"true" )
604 || long_from_bstr( mapping_desc[PM_ENABLED].value )))
605 new_mappings[index].enabled = VARIANT_TRUE;
606 else
607 new_mappings[index].enabled = VARIANT_FALSE;
608 new_mappings[index].descr = mapping_move_bstr( &mapping_desc[PM_DESC].value );
609
610 TRACE( "%s %s %s:%lu -> %s:%lu, enabled %d.\n", debugstr_w(new_mappings[index].descr),
611 debugstr_w(new_mappings[index].protocol), debugstr_w(new_mappings[index].external_ip),
612 new_mappings[index].external, debugstr_w(new_mappings[index].client),
613 new_mappings[index].internal, new_mappings[index].enabled );
614
615 for (i = 0; i < ARRAY_SIZE(mapping_desc); ++i)
616 SysFreeString( mapping_desc[i].value );
617 upnp_gateway_connection.mappings = new_mappings;
618 upnp_gateway_connection.mapping_count = ++index;
619 }
620}
621
623{
624 struct xml_value_desc mapping_desc[PM_REMOVE_PORT_LAST];
625 DWORD status = 0;
626 BSTR error_str;
627 WCHAR portW[6];
628 BOOL ret;
629
631 memcpy( mapping_desc, port_mapping_template, sizeof(mapping_desc) );
632 swprintf( portW, ARRAY_SIZE(portW), L"%u", port );
633 mapping_desc[PM_EXTERNAL_IP].value = SysAllocString( L"" );
634 mapping_desc[PM_EXTERNAL].value = SysAllocString( portW );
635 mapping_desc[PM_PROTOCOL].value = protocol;
636
637 ret = request_service( L"DeletePortMapping", mapping_desc, PM_REMOVE_PORT_LAST,
638 NULL, 0, &status, &error_str );
639 if (ret && status != HTTP_STATUS_OK)
640 {
641 WARN( "status %lu, server returned error %s.\n", status, debugstr_w(error_str) );
642 SysFreeString( error_str );
643 ret = FALSE;
644 }
645 else if (!ret)
646 {
647 WARN( "Request failed.\n" );
648 }
651
652 SysFreeString( mapping_desc[PM_EXTERNAL_IP].value );
653 SysFreeString( mapping_desc[PM_EXTERNAL].value );
654 return ret;
655}
656
659{
660 struct xml_value_desc mapping_desc[PM_LAST];
661 WCHAR externalW[6], internalW[6];
662 DWORD status = 0;
663 BSTR error_str;
664 BOOL ret;
665
667 memcpy( mapping_desc, port_mapping_template, sizeof(mapping_desc) );
668 swprintf( externalW, ARRAY_SIZE(externalW), L"%u", external );
669 swprintf( internalW, ARRAY_SIZE(internalW), L"%u", internal );
670 mapping_desc[PM_EXTERNAL_IP].value = SysAllocString( L"" );
671 mapping_desc[PM_EXTERNAL].value = SysAllocString( externalW );
672 mapping_desc[PM_PROTOCOL].value = protocol;
673 mapping_desc[PM_INTERNAL].value = SysAllocString( internalW );
674 mapping_desc[PM_CLIENT].value = client;
675 mapping_desc[PM_ENABLED].value = SysAllocString( enabled ? L"1" : L"0" );
676 mapping_desc[PM_DESC].value = description;
677 mapping_desc[PM_LEASE_DURATION].value = SysAllocString( L"0" );
678
679 ret = request_service( L"AddPortMapping", mapping_desc, PM_LAST,
680 NULL, 0, &status, &error_str );
681 if (ret && status != HTTP_STATUS_OK)
682 {
683 WARN( "status %lu, server returned error %s.\n", status, debugstr_w(error_str) );
684 SysFreeString( error_str );
685 ret = FALSE;
686 }
687 else if (!ret)
688 {
689 WARN( "Request failed.\n" );
690 }
693
694 SysFreeString( mapping_desc[PM_EXTERNAL_IP].value );
695 SysFreeString( mapping_desc[PM_EXTERNAL].value );
696 SysFreeString( mapping_desc[PM_INTERNAL].value );
697 SysFreeString( mapping_desc[PM_ENABLED].value );
698 SysFreeString( mapping_desc[PM_LEASE_DURATION].value );
699 return ret;
700}
701
703{
704 static const char upnp_search_request[] =
705 "M-SEARCH * HTTP/1.1\r\n"
706 "HOST:239.255.255.250:1900\r\n"
707 "ST:upnp:rootdevice\r\n"
708 "MX:2\r\n"
709 "MAN:\"ssdp:discover\"\r\n"
710 "\r\n";
711
712 const DWORD timeout = 1000;
713 int len, address_len;
714 char buffer[2048];
716 WSADATA wsa_data;
717 unsigned int i;
718 SOCKET s;
719
720 upnp_gateway_connection.winsock_initialized = WSAStartup( MAKEWORD( 2, 2 ), &wsa_data );
721 if ((s = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP )) == -1)
722 {
723 ERR( "Failed to create socket, error %u.\n", WSAGetLastError() );
724 return FALSE;
725 }
726 if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)) == SOCKET_ERROR)
727 {
728 ERR( "setsockopt(SO_RCVTIME0) failed, error %u.\n", WSAGetLastError() );
729 closesocket( s );
730 return FALSE;
731 }
732 addr.sin_family = AF_INET;
733 addr.sin_port = htons( 1900 );
734 addr.sin_addr.S_un.S_addr = inet_addr( "239.255.255.250" );
735 if (sendto( s, upnp_search_request, strlen( upnp_search_request ), 0, (SOCKADDR *)&addr, sizeof(addr) )
736 == SOCKET_ERROR)
737 {
738 ERR( "sendto failed, error %u\n", WSAGetLastError() );
739 closesocket( s );
740 return FALSE;
741 }
742 /* Windows has a dedicated SSDP discovery service which maintains gateway device info and does
743 * not usually delay in get_StaticPortMappingCollection(). Although it may still delay depending
744 * on network connection state and always delays in IUPnPNAT_get_NATEventManager(). */
745 FIXME( "Waiting for reply from router.\n" );
746 for (i = 0; i < 2; ++i)
747 {
748 address_len = sizeof(addr);
749 len = recvfrom( s, buffer, sizeof(buffer) - 1, 0, (SOCKADDR *)&addr, &address_len );
750 if (len == -1)
751 {
753 {
754 WARN( "recvfrom error %u.\n", WSAGetLastError() );
755 closesocket( s );
756 return FALSE;
757 }
758 }
759 else break;
760 }
761 closesocket( s );
762 if (i == 2)
763 {
764 TRACE( "No reply from router.\n" );
765 return FALSE;
766 }
767 TRACE( "Received reply from gateway, len %d.\n", len );
768 buffer[len] = 0;
770 {
771 WARN( "Error parsing response.\n" );
772 return FALSE;
773 }
774 TRACE( "Gateway description location %s.\n", debugstr_w(upnp_gateway_connection.locationW) );
776 {
777 WARN( "Error opening gateway connection.\n" );
778 return FALSE;
779 }
780 TRACE( "Opened gateway connection.\n" );
781 if (!get_control_url())
782 {
783 WARN( "Could not get_control URL.\n" );
785 return FALSE;
786 }
787 TRACE( "control_url %s, version %u.\n", debugstr_w(upnp_gateway_connection.control_url),
788 upnp_gateway_connection.version );
789
791 return TRUE;
792}
793
795{
798 {
801 return FALSE;
802 }
805 return TRUE;
806}
807
809{
812 if (!--upnp_gateway_connection.refs)
815}
816
818{
819 unsigned int i;
820 BOOL found;
821
823 for (i = 0; i < upnp_gateway_connection.mapping_count; ++i)
824 {
825 if (upnp_gateway_connection.mappings[i].external == port
826 && !wcscmp( upnp_gateway_connection.mappings[i].protocol, protocol ))
827 break;
828 }
829 found = i < upnp_gateway_connection.mapping_count;
830 if (found) copy_port_mapping( ret, &upnp_gateway_connection.mappings[i] );
832 return found;
833}
834
835static unsigned int get_port_mapping_range( unsigned int index, unsigned int count, struct port_mapping *ret )
836{
837 unsigned int i;
838
840 for (i = 0; i < count && index + i < upnp_gateway_connection.mapping_count; ++i)
841 if (!copy_port_mapping( &ret[i], &upnp_gateway_connection.mappings[index + i] ))
842 {
843 ERR( "No memory.\n" );
844 break;
845 }
847
848 return i;
849}
850
851static unsigned int get_port_mapping_count(void)
852{
853 unsigned int ret;
854
856 ret = upnp_gateway_connection.mapping_count;
858 return ret;
859}
860
862{
863 if (!protocol) return FALSE;
864 return !wcscmp( protocol, L"UDP" ) || !wcscmp( protocol, L"TCP" );
865}
866
868{
872};
873
875{
877}
878
880 IStaticPortMapping *iface )
881{
883 return InterlockedIncrement( &mapping->refs );
884}
885
887 IStaticPortMapping *iface )
888{
891 if (!refs)
892 {
893 TRACE("destroying %p\n", mapping);
894 free_port_mapping( &mapping->data );
895 free( mapping );
896 }
897 return refs;
898}
899
901 IStaticPortMapping *iface,
902 REFIID riid,
903 void **ppvObject )
904{
906
907 TRACE("%p %s %p\n", mapping, debugstr_guid( riid ), ppvObject );
908
909 if ( IsEqualGUID( riid, &IID_IStaticPortMapping ) ||
912 {
913 *ppvObject = iface;
914 }
915 else
916 {
917 FIXME("interface %s not implemented\n", debugstr_guid(riid));
918 return E_NOINTERFACE;
919 }
920 IStaticPortMapping_AddRef( iface );
921 return S_OK;
922}
923
925 IStaticPortMapping *iface,
926 UINT *pctinfo )
927{
929
930 TRACE("%p %p\n", mapping, pctinfo);
931 *pctinfo = 1;
932 return S_OK;
933}
934
936 IStaticPortMapping *iface,
937 UINT iTInfo,
938 LCID lcid,
939 ITypeInfo **ppTInfo )
940{
942
943 TRACE("%p %u %lu %p\n", mapping, iTInfo, lcid, ppTInfo);
944 return get_typeinfo( IStaticPortMapping_tid, ppTInfo );
945}
946
948 IStaticPortMapping *iface,
949 REFIID riid,
950 LPOLESTR *rgszNames,
951 UINT cNames,
952 LCID lcid,
953 DISPID *rgDispId )
954{
957 HRESULT hr;
958
959 TRACE("%p %s %p %u %lu %p\n", mapping, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
960
962 if (SUCCEEDED(hr))
963 {
964 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
965 ITypeInfo_Release( typeinfo );
966 }
967 return hr;
968}
969
971 IStaticPortMapping *iface,
972 DISPID dispIdMember,
973 REFIID riid,
974 LCID lcid,
975 WORD wFlags,
976 DISPPARAMS *pDispParams,
977 VARIANT *pVarResult,
978 EXCEPINFO *pExcepInfo,
979 UINT *puArgErr )
980{
983 HRESULT hr;
984
985 TRACE("%p %ld %s %ld %d %p %p %p %p\n", mapping, dispIdMember, debugstr_guid(riid),
986 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
987
989 if (SUCCEEDED(hr))
990 {
991 hr = ITypeInfo_Invoke( typeinfo, &mapping->IStaticPortMapping_iface, dispIdMember,
992 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
993 ITypeInfo_Release( typeinfo );
994 }
995 return hr;
996}
997
999 IStaticPortMapping *iface,
1000 BSTR *value )
1001{
1003
1004 TRACE( "iface %p, value %p.\n", iface, value );
1005
1006 if (!value) return E_POINTER;
1007 *value = SysAllocString( mapping->data.external_ip );
1008 if (mapping->data.external_ip && !*value) return E_OUTOFMEMORY;
1009 return S_OK;
1010}
1011
1013 IStaticPortMapping *iface,
1014 LONG *value )
1015{
1017
1018 TRACE( "iface %p, value %p.\n", iface, value );
1019
1020 if (!value) return E_POINTER;
1021 *value = mapping->data.external;
1022 return S_OK;
1023}
1024
1026 IStaticPortMapping *iface,
1027 LONG *value )
1028{
1030
1031 TRACE( "iface %p, value %p.\n", iface, value );
1032
1033 if (!value) return E_POINTER;
1034 *value = mapping->data.internal;
1035 return S_OK;
1036}
1037
1039 IStaticPortMapping *iface,
1040 BSTR *value )
1041{
1043
1044 TRACE( "iface %p, value %p.\n", iface, value );
1045
1046 if (!value) return E_POINTER;
1047 *value = SysAllocString( mapping->data.protocol );
1048 if (mapping->data.protocol && !*value) return E_OUTOFMEMORY;
1049 return S_OK;
1050}
1051
1053 IStaticPortMapping *iface,
1054 BSTR *value )
1055{
1057
1058 TRACE( "iface %p, value %p.\n", iface, value );
1059
1060 if (!value) return E_POINTER;
1061 *value = SysAllocString( mapping->data.client );
1062 if (mapping->data.client && !*value) return E_OUTOFMEMORY;
1063 return S_OK;
1064}
1065
1067 IStaticPortMapping *iface,
1069{
1071
1072 TRACE( "iface %p, value %p.\n", iface, value );
1073
1074 if (!value) return E_POINTER;
1075 *value = mapping->data.enabled;
1076 return S_OK;
1077}
1078
1080 IStaticPortMapping *iface,
1081 BSTR *value )
1082{
1084
1085 TRACE( "iface %p, value %p.\n", iface, value );
1086
1087 if (!value) return E_POINTER;
1088 *value = SysAllocString( mapping->data.descr );
1089 if (mapping->data.descr && !*value) return E_OUTOFMEMORY;
1090 return S_OK;
1091}
1092
1094 IStaticPortMapping *iface,
1095 BSTR value )
1096{
1097 FIXME( "iface %p, value %s stub.\n", iface, debugstr_w(value) );
1098
1099 return E_NOTIMPL;
1100}
1101
1103 IStaticPortMapping *iface,
1105{
1106 FIXME( "iface %p, value %d stub.\n", iface, value );
1107
1108 return E_NOTIMPL;
1109}
1110
1112 IStaticPortMapping *iface,
1113 BSTR value )
1114{
1115 FIXME( "iface %p, value %s stub.\n", iface, debugstr_w(value) );
1116
1117 return E_NOTIMPL;
1118}
1119
1121 IStaticPortMapping *iface,
1122 LONG value )
1123{
1124 FIXME( "iface %p, value %ld stub.\n", iface, value );
1125
1126 return E_NOTIMPL;
1127}
1128
1129static const IStaticPortMappingVtbl static_port_mapping_vtbl =
1130{
1149};
1150
1152{
1154
1155 if (!(mapping = calloc( 1, sizeof(*mapping) ))) return E_OUTOFMEMORY;
1156
1157 mapping->refs = 1;
1158 mapping->IStaticPortMapping_iface.lpVtbl = &static_port_mapping_vtbl;
1159 mapping->data = *mapping_data;
1160 *ret = &mapping->IStaticPortMapping_iface;
1161 return S_OK;
1162}
1163
1165{
1168 unsigned int index;
1169};
1170
1172{
1174}
1175
1177 IEnumVARIANT *iface )
1178{
1179 struct port_mapping_enum *mapping_enum = impl_from_IEnumVARIANT( iface );
1180 return InterlockedIncrement( &mapping_enum->refs );
1181}
1182
1184 IEnumVARIANT *iface )
1185{
1186 struct port_mapping_enum *mapping_enum = impl_from_IEnumVARIANT( iface );
1187 LONG refs = InterlockedDecrement( &mapping_enum->refs );
1188 if (!refs)
1189 {
1190 TRACE("destroying %p\n", mapping_enum);
1191 free( mapping_enum );
1193 }
1194 return refs;
1195}
1196
1198 IEnumVARIANT *iface,
1199 REFIID riid,
1200 void **ppvObject )
1201{
1202 struct port_mapping_enum *mapping_enum = impl_from_IEnumVARIANT( iface );
1203
1204 TRACE("%p %s %p\n", mapping_enum, debugstr_guid( riid ), ppvObject );
1205
1206 if ( IsEqualGUID( riid, &IID_IEnumVARIANT ) ||
1208 {
1209 *ppvObject = iface;
1210 }
1211 else
1212 {
1213 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1214 return E_NOINTERFACE;
1215 }
1216 IEnumVARIANT_AddRef( iface );
1217 return S_OK;
1218}
1219
1221{
1222 struct port_mapping_enum *mapping_enum = impl_from_IEnumVARIANT( iface );
1223 struct port_mapping *data;
1225 unsigned int i, count;
1226 HRESULT ret;
1227
1228 TRACE( "iface %p, celt %lu, var %p, fetched %p.\n", iface, celt, var, fetched );
1229
1230 if (fetched) *fetched = 0;
1231 if (!celt) return S_OK;
1232 if (!var) return E_POINTER;
1233
1234 if (!(data = calloc( 1, celt * sizeof(*data) ))) return E_OUTOFMEMORY;
1235 count = get_port_mapping_range( mapping_enum->index, celt, data );
1236 TRACE( "count %u.\n", count );
1237 for (i = 0; i < count; ++i)
1238 {
1239 if (FAILED(static_port_mapping_create( &data[i], &pm ))) break;
1240
1241 V_VT(&var[i]) = VT_DISPATCH;
1242 V_DISPATCH(&var[i]) = (IDispatch *)pm;
1243 }
1244 mapping_enum->index += i;
1245 if (fetched) *fetched = i;
1246 ret = (i < celt) ? S_FALSE : S_OK;
1247 for ( ; i < count; ++i)
1248 {
1250 VariantInit( &var[i] );
1251 }
1252 for ( ; i < celt; ++i)
1253 VariantInit( &var[i] );
1254
1255 free( data );
1256 return ret;
1257}
1258
1260{
1261 struct port_mapping_enum *mapping_enum = impl_from_IEnumVARIANT( iface );
1262 unsigned int count = get_port_mapping_count();
1263
1264 TRACE( "iface %p, celt %lu.\n", iface, celt );
1265
1266 mapping_enum->index += celt;
1267 return mapping_enum->index <= count ? S_OK : S_FALSE;
1268}
1269
1271{
1272 struct port_mapping_enum *mapping_enum = impl_from_IEnumVARIANT( iface );
1273
1274 TRACE( "iface %p.\n", iface );
1275
1276 mapping_enum->index = 0;
1277 return S_OK;
1278}
1279
1281
1283{
1284 struct port_mapping_enum *mapping_enum = impl_from_IEnumVARIANT( iface );
1285 HRESULT hr;
1286
1287 TRACE( "iface %p, ret %p.\n", iface, ret );
1288
1289 if (!ret) return E_POINTER;
1290 *ret = NULL;
1291 if (FAILED(hr = create_port_mapping_enum( (IUnknown **)ret ))) return hr;
1292 impl_from_IEnumVARIANT( *ret )->index = mapping_enum->index;
1293 return S_OK;
1294}
1295
1296static const IEnumVARIANTVtbl port_mapping_enum_vtbl =
1297{
1305};
1306
1308{
1309 struct port_mapping_enum *mapping_enum;
1310
1311 if (!(mapping_enum = calloc( 1, sizeof(*mapping_enum) ))) return E_OUTOFMEMORY;
1312
1314
1315 mapping_enum->refs = 1;
1316 mapping_enum->IEnumVARIANT_iface.lpVtbl = &port_mapping_enum_vtbl;
1317 mapping_enum->index = 0;
1318 *ret = (IUnknown *)&mapping_enum->IEnumVARIANT_iface;
1319 return S_OK;
1320}
1321
1323{
1326};
1327
1330{
1332}
1333
1336{
1338 return InterlockedIncrement( &ports->refs );
1339}
1340
1343{
1345 LONG refs = InterlockedDecrement( &ports->refs );
1346 if (!refs)
1347 {
1348 TRACE("destroying %p\n", ports);
1350 free( ports );
1351 }
1352 return refs;
1353}
1354
1357 REFIID riid,
1358 void **ppvObject )
1359{
1361
1362 TRACE("%p %s %p\n", ports, debugstr_guid( riid ), ppvObject );
1363
1364 if ( IsEqualGUID( riid, &IID_IStaticPortMappingCollection ) ||
1367 {
1368 *ppvObject = iface;
1369 }
1370 else
1371 {
1372 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1373 return E_NOINTERFACE;
1374 }
1375 IStaticPortMappingCollection_AddRef( iface );
1376 return S_OK;
1377}
1378
1381 UINT *pctinfo )
1382{
1384
1385 TRACE("%p %p\n", ports, pctinfo);
1386 *pctinfo = 1;
1387 return S_OK;
1388}
1389
1392 UINT iTInfo,
1393 LCID lcid,
1394 ITypeInfo **ppTInfo )
1395{
1397
1398 TRACE("%p %u %lu %p\n", ports, iTInfo, lcid, ppTInfo);
1400}
1401
1404 REFIID riid,
1405 LPOLESTR *rgszNames,
1406 UINT cNames,
1407 LCID lcid,
1408 DISPID *rgDispId )
1409{
1412 HRESULT hr;
1413
1414 TRACE("%p %s %p %u %lu %p\n", ports, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
1415
1417 if (SUCCEEDED(hr))
1418 {
1419 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
1420 ITypeInfo_Release( typeinfo );
1421 }
1422 return hr;
1423}
1424
1427 DISPID dispIdMember,
1428 REFIID riid,
1429 LCID lcid,
1430 WORD wFlags,
1431 DISPPARAMS *pDispParams,
1432 VARIANT *pVarResult,
1433 EXCEPINFO *pExcepInfo,
1434 UINT *puArgErr )
1435{
1438 HRESULT hr;
1439
1440 TRACE("%p %ld %s %ld %d %p %p %p %p\n", ports, dispIdMember, debugstr_guid(riid),
1441 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1442
1444 if (SUCCEEDED(hr))
1445 {
1446 hr = ITypeInfo_Invoke( typeinfo, &ports->IStaticPortMappingCollection_iface, dispIdMember,
1447 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
1448 ITypeInfo_Release( typeinfo );
1449 }
1450 return hr;
1451}
1452
1455 IUnknown **ret )
1456{
1457 TRACE( "iface %p, ret %p.\n", iface, ret );
1458
1459 if (!ret) return E_POINTER;
1460
1461 *ret = NULL;
1462 return create_port_mapping_enum( ret );
1463}
1464
1467 LONG port,
1468 BSTR protocol,
1470{
1471 struct port_mapping mapping_data;
1472 HRESULT ret;
1473
1474 TRACE( "iface %p, port %ld, protocol %s.\n", iface, port, debugstr_w(protocol) );
1475
1476 if (!mapping) return E_POINTER;
1477 *mapping = NULL;
1478 if (!is_valid_protocol( protocol )) return E_INVALIDARG;
1479 if (port < 0 || port > 65535) return E_INVALIDARG;
1480
1482 if (FAILED(ret = static_port_mapping_create( &mapping_data, mapping ))) free_port_mapping( &mapping_data );
1483 return ret;
1484}
1485
1488 LONG *count )
1489{
1490 TRACE( "iface %p, count %p.\n", iface, count );
1491
1492 if (!count) return E_POINTER;
1494 return S_OK;
1495}
1496
1499 LONG port,
1500 BSTR protocol )
1501{
1502 TRACE( "iface %p, port %ld, protocol %s.\n", iface, port, debugstr_w(protocol) );
1503
1504 if (!is_valid_protocol( protocol )) return E_INVALIDARG;
1505 if (port < 0 || port > 65535) return E_INVALIDARG;
1506
1507 if (!remove_port_mapping( port, protocol )) return E_FAIL;
1508
1509 return S_OK;
1510}
1511
1514 LONG external,
1515 BSTR protocol,
1516 LONG internal,
1517 BSTR client,
1521{
1522 struct port_mapping mapping_data;
1523 HRESULT ret;
1524
1525 TRACE( "iface %p, external %ld, protocol %s, internal %ld, client %s, enabled %d, description %s, mapping %p.\n",
1527 mapping );
1528
1529 if (!mapping) return E_POINTER;
1530 *mapping = NULL;
1531
1532 if (!is_valid_protocol( protocol )) return E_INVALIDARG;
1533 if (external < 0 || external > 65535) return E_INVALIDARG;
1534 if (internal < 0 || internal > 65535) return E_INVALIDARG;
1535 if (!client || !description) return E_INVALIDARG;
1536
1538
1539 mapping_data.external_ip = NULL;
1540 mapping_data.external = external;
1541 mapping_data.protocol = SysAllocString( protocol );
1542 mapping_data.internal = internal;
1543 mapping_data.client = SysAllocString( client );
1544 mapping_data.enabled = enabled;
1545 mapping_data.descr = SysAllocString( description );
1546 if (!mapping_data.protocol || !mapping_data.client || !mapping_data.descr)
1547 {
1548 free_port_mapping( &mapping_data );
1549 return E_OUTOFMEMORY;
1550 }
1551 if (FAILED(ret = static_port_mapping_create( &mapping_data, mapping ))) free_port_mapping( &mapping_data );
1552 return ret;
1553}
1554
1555static const IStaticPortMappingCollectionVtbl static_ports_vtbl =
1556{
1569};
1570
1572{
1573 struct static_port_mapping_collection *ports;
1574
1575 if (!object) return E_POINTER;
1577 {
1578 *object = NULL;
1579 return S_OK;
1580 }
1581 if (!(ports = calloc( 1, sizeof(*ports) )))
1582 {
1584 return E_OUTOFMEMORY;
1585 }
1586 ports->refs = 1;
1588 *object = &ports->IStaticPortMappingCollection_iface;
1589 return S_OK;
1590}
1591
1592typedef struct fw_port
1593{
1600
1602{
1603 return CONTAINING_RECORD(iface, fw_port, INetFwOpenPort_iface);
1604}
1605
1607 INetFwOpenPort *iface )
1608{
1610 return InterlockedIncrement( &fw_port->refs );
1611}
1612
1614 INetFwOpenPort *iface )
1615{
1618 if (!refs)
1619 {
1620 TRACE("destroying %p\n", fw_port);
1622 free( fw_port );
1623 }
1624 return refs;
1625}
1626
1628 INetFwOpenPort *iface,
1629 REFIID riid,
1630 void **ppvObject )
1631{
1633
1634 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1635
1636 if ( IsEqualGUID( riid, &IID_INetFwOpenPort ) ||
1639 {
1640 *ppvObject = iface;
1641 }
1642 else
1643 {
1644 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1645 return E_NOINTERFACE;
1646 }
1647 INetFwOpenPort_AddRef( iface );
1648 return S_OK;
1649}
1650
1652 INetFwOpenPort *iface,
1653 UINT *pctinfo )
1654{
1656
1657 TRACE("%p %p\n", This, pctinfo);
1658 *pctinfo = 1;
1659 return S_OK;
1660}
1661
1663 INetFwOpenPort *iface,
1664 UINT iTInfo,
1665 LCID lcid,
1666 ITypeInfo **ppTInfo )
1667{
1669
1670 TRACE("%p %u %lu %p\n", This, iTInfo, lcid, ppTInfo);
1671 return get_typeinfo( INetFwOpenPort_tid, ppTInfo );
1672}
1673
1675 INetFwOpenPort *iface,
1676 REFIID riid,
1677 LPOLESTR *rgszNames,
1678 UINT cNames,
1679 LCID lcid,
1680 DISPID *rgDispId )
1681{
1684 HRESULT hr;
1685
1686 TRACE("%p %s %p %u %lu %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
1687
1689 if (SUCCEEDED(hr))
1690 {
1691 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
1692 ITypeInfo_Release( typeinfo );
1693 }
1694 return hr;
1695}
1696
1698 INetFwOpenPort *iface,
1699 DISPID dispIdMember,
1700 REFIID riid,
1701 LCID lcid,
1702 WORD wFlags,
1703 DISPPARAMS *pDispParams,
1704 VARIANT *pVarResult,
1705 EXCEPINFO *pExcepInfo,
1706 UINT *puArgErr )
1707{
1710 HRESULT hr;
1711
1712 TRACE("%p %ld %s %ld %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
1713 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1714
1716 if (SUCCEEDED(hr))
1717 {
1718 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwOpenPort_iface, dispIdMember,
1719 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
1720 ITypeInfo_Release( typeinfo );
1721 }
1722 return hr;
1723}
1724
1726 INetFwOpenPort *iface,
1727 BSTR *name)
1728{
1730
1731 FIXME("%p %p\n", This, name);
1732 return E_NOTIMPL;
1733}
1734
1736 INetFwOpenPort *iface,
1737 BSTR name)
1738{
1740
1741 TRACE("%p %s\n", This, debugstr_w(name));
1742
1743 if (!(name = SysAllocString( name )))
1744 return E_OUTOFMEMORY;
1745
1746 SysFreeString( This->name );
1747 This->name = name;
1748 return S_OK;
1749}
1750
1752 INetFwOpenPort *iface,
1753 NET_FW_IP_VERSION *ipVersion)
1754{
1756
1757 FIXME("%p %p\n", This, ipVersion);
1758 return E_NOTIMPL;
1759}
1760
1762 INetFwOpenPort *iface,
1763 NET_FW_IP_VERSION ipVersion)
1764{
1766
1767 FIXME("%p %u\n", This, ipVersion);
1768 return E_NOTIMPL;
1769}
1770
1772 INetFwOpenPort *iface,
1773 NET_FW_IP_PROTOCOL *ipProtocol)
1774{
1776
1777 FIXME("%p %p\n", This, ipProtocol);
1778 return E_NOTIMPL;
1779}
1780
1782 INetFwOpenPort *iface,
1783 NET_FW_IP_PROTOCOL ipProtocol)
1784{
1786
1787 TRACE("%p %u\n", This, ipProtocol);
1788
1789 if (ipProtocol != NET_FW_IP_PROTOCOL_TCP && ipProtocol != NET_FW_IP_PROTOCOL_UDP)
1790 return E_INVALIDARG;
1791
1792 This->protocol = ipProtocol;
1793 return S_OK;
1794}
1795
1797 INetFwOpenPort *iface,
1798 LONG *portNumber)
1799{
1801
1802 FIXME("%p %p\n", This, portNumber);
1803 return E_NOTIMPL;
1804}
1805
1807 INetFwOpenPort *iface,
1808 LONG portNumber)
1809{
1811
1812 TRACE("%p %ld\n", This, portNumber);
1813 This->port = portNumber;
1814 return S_OK;
1815}
1816
1818 INetFwOpenPort *iface,
1819 NET_FW_SCOPE *scope)
1820{
1822
1823 FIXME("%p %p\n", This, scope);
1824 return E_NOTIMPL;
1825}
1826
1828 INetFwOpenPort *iface,
1829 NET_FW_SCOPE scope)
1830{
1832
1833 FIXME("%p %u\n", This, scope);
1834 return E_NOTIMPL;
1835}
1836
1838 INetFwOpenPort *iface,
1839 BSTR *remoteAddrs)
1840{
1842
1843 FIXME("%p %p\n", This, remoteAddrs);
1844 return E_NOTIMPL;
1845}
1846
1848 INetFwOpenPort *iface,
1849 BSTR remoteAddrs)
1850{
1852
1853 FIXME("%p %s\n", This, debugstr_w(remoteAddrs));
1854 return E_NOTIMPL;
1855}
1856
1858 INetFwOpenPort *iface,
1860{
1862
1863 FIXME("%p %p\n", This, enabled);
1864
1865 *enabled = VARIANT_TRUE;
1866 return S_OK;
1867}
1868
1870 INetFwOpenPort *iface,
1872{
1874
1875 FIXME("%p %d\n", This, enabled);
1876 return S_OK;
1877}
1878
1880 INetFwOpenPort *iface,
1881 VARIANT_BOOL *builtIn)
1882{
1884
1885 FIXME("%p %p\n", This, builtIn);
1886 return E_NOTIMPL;
1887}
1888
1889static const struct INetFwOpenPortVtbl fw_port_vtbl =
1890{
1913};
1914
1916{
1917 fw_port *fp;
1918
1919 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
1920
1921 fp = malloc( sizeof(*fp) );
1922 if (!fp) return E_OUTOFMEMORY;
1923
1924 fp->INetFwOpenPort_iface.lpVtbl = &fw_port_vtbl;
1925 fp->refs = 1;
1926 fp->name = NULL;
1928 fp->port = 0;
1929
1930 *ppObj = &fp->INetFwOpenPort_iface;
1931
1932 TRACE("returning iface %p\n", *ppObj);
1933 return S_OK;
1934}
1935
1936typedef struct fw_ports
1937{
1941
1943{
1944 return CONTAINING_RECORD(iface, fw_ports, INetFwOpenPorts_iface);
1945}
1946
1948 INetFwOpenPorts *iface )
1949{
1952}
1953
1955 INetFwOpenPorts *iface )
1956{
1959 if (!refs)
1960 {
1961 TRACE("destroying %p\n", fw_ports);
1962 free( fw_ports );
1963 }
1964 return refs;
1965}
1966
1968 INetFwOpenPorts *iface,
1969 REFIID riid,
1970 void **ppvObject )
1971{
1973
1974 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1975
1976 if ( IsEqualGUID( riid, &IID_INetFwOpenPorts ) ||
1979 {
1980 *ppvObject = iface;
1981 }
1982 else
1983 {
1984 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1985 return E_NOINTERFACE;
1986 }
1987 INetFwOpenPorts_AddRef( iface );
1988 return S_OK;
1989}
1990
1992 INetFwOpenPorts *iface,
1993 UINT *pctinfo )
1994{
1996
1997 TRACE("%p %p\n", This, pctinfo);
1998 *pctinfo = 1;
1999 return S_OK;
2000}
2001
2003 INetFwOpenPorts *iface,
2004 UINT iTInfo,
2005 LCID lcid,
2006 ITypeInfo **ppTInfo )
2007{
2009
2010 TRACE("%p %u %lu %p\n", This, iTInfo, lcid, ppTInfo);
2011 return get_typeinfo( INetFwOpenPorts_tid, ppTInfo );
2012}
2013
2015 INetFwOpenPorts *iface,
2016 REFIID riid,
2017 LPOLESTR *rgszNames,
2018 UINT cNames,
2019 LCID lcid,
2020 DISPID *rgDispId )
2021{
2024 HRESULT hr;
2025
2026 TRACE("%p %s %p %u %lu %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
2027
2029 if (SUCCEEDED(hr))
2030 {
2031 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
2032 ITypeInfo_Release( typeinfo );
2033 }
2034 return hr;
2035}
2036
2038 INetFwOpenPorts *iface,
2039 DISPID dispIdMember,
2040 REFIID riid,
2041 LCID lcid,
2042 WORD wFlags,
2043 DISPPARAMS *pDispParams,
2044 VARIANT *pVarResult,
2045 EXCEPINFO *pExcepInfo,
2046 UINT *puArgErr )
2047{
2050 HRESULT hr;
2051
2052 TRACE("%p %ld %s %ld %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
2053 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2054
2056 if (SUCCEEDED(hr))
2057 {
2058 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwOpenPorts_iface, dispIdMember,
2059 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
2060 ITypeInfo_Release( typeinfo );
2061 }
2062 return hr;
2063}
2064
2066 INetFwOpenPorts *iface,
2067 LONG *count)
2068{
2070
2071 FIXME("%p, %p\n", This, count);
2072
2073 *count = 0;
2074 return S_OK;
2075}
2076
2078 INetFwOpenPorts *iface,
2080{
2082
2083 FIXME("%p, %p\n", This, port);
2084 return S_OK;
2085}
2086
2088 INetFwOpenPorts *iface,
2089 LONG portNumber,
2090 NET_FW_IP_PROTOCOL ipProtocol)
2091{
2093
2094 FIXME("%p, %ld, %u\n", This, portNumber, ipProtocol);
2095 return E_NOTIMPL;
2096}
2097
2099 INetFwOpenPorts *iface,
2100 LONG portNumber,
2101 NET_FW_IP_PROTOCOL ipProtocol,
2102 INetFwOpenPort **openPort)
2103{
2104 HRESULT hr;
2106
2107 FIXME("%p, %ld, %u, %p\n", This, portNumber, ipProtocol, openPort);
2108
2109 hr = NetFwOpenPort_create( NULL, (void **)openPort );
2110 if (SUCCEEDED(hr))
2111 {
2112 INetFwOpenPort_put_Protocol( *openPort, ipProtocol );
2113 INetFwOpenPort_put_Port( *openPort, portNumber );
2114 }
2115 return hr;
2116}
2117
2119 INetFwOpenPorts *iface,
2120 IUnknown **newEnum)
2121{
2123
2124 FIXME("%p, %p\n", This, newEnum);
2125 return E_NOTIMPL;
2126}
2127
2128static const struct INetFwOpenPortsVtbl fw_ports_vtbl =
2129{
2142};
2143
2145{
2146 fw_ports *fp;
2147
2148 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2149
2150 fp = malloc( sizeof(*fp) );
2151 if (!fp) return E_OUTOFMEMORY;
2152
2154 fp->refs = 1;
2155
2156 *ppObj = &fp->INetFwOpenPorts_iface;
2157
2158 TRACE("returning iface %p\n", *ppObj);
2159 return S_OK;
2160}
2161
2162typedef struct _upnpnat
2163{
2167
2168static inline upnpnat *impl_from_IUPnPNAT( IUPnPNAT *iface )
2169{
2170 return CONTAINING_RECORD(iface, upnpnat, IUPnPNAT_iface);
2171}
2172
2174{
2175 upnpnat *This = impl_from_IUPnPNAT( iface );
2176
2177 TRACE("%p %s %p\n", This, debugstr_guid( riid ), object );
2178
2179 if ( IsEqualGUID( riid, &IID_IUPnPNAT ) ||
2182 {
2183 *object = iface;
2184 }
2186 {
2187 TRACE("IProvideClassInfo not supported.\n");
2188 return E_NOINTERFACE;
2189 }
2190 else
2191 {
2192 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2193 return E_NOINTERFACE;
2194 }
2195 IUPnPNAT_AddRef( iface );
2196 return S_OK;
2197}
2198
2200{
2201 upnpnat *This = impl_from_IUPnPNAT( iface );
2202 return InterlockedIncrement( &This->ref );
2203}
2204
2206{
2207 upnpnat *This = impl_from_IUPnPNAT( iface );
2209 if (!refs)
2210 {
2211 free( This );
2212 }
2213 return refs;
2214}
2215
2217{
2218 upnpnat *This = impl_from_IUPnPNAT( iface );
2219
2220 TRACE("%p %p\n", This, pctinfo);
2221 *pctinfo = 1;
2222 return S_OK;
2223}
2224
2226{
2227 upnpnat *This = impl_from_IUPnPNAT( iface );
2228
2229 TRACE("%p %u %lu %p\n", This, iTInfo, lcid, ppTInfo);
2230 return get_typeinfo( IUPnPNAT_tid, ppTInfo );
2231}
2232
2233static HRESULT WINAPI upnpnat_GetIDsOfNames(IUPnPNAT *iface, REFIID riid, LPOLESTR *rgszNames,
2234 UINT cNames, LCID lcid, DISPID *rgDispId)
2235{
2236 upnpnat *This = impl_from_IUPnPNAT( iface );
2238 HRESULT hr;
2239
2240 TRACE("%p %s %p %u %lu %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
2241
2243 if (SUCCEEDED(hr))
2244 {
2245 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
2246 ITypeInfo_Release( typeinfo );
2247 }
2248 return hr;
2249}
2250
2252 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
2253 UINT *puArgErr)
2254{
2255 upnpnat *This = impl_from_IUPnPNAT( iface );
2257 HRESULT hr;
2258
2259 TRACE("%p %ld %s %ld %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
2260 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2261
2263 if (SUCCEEDED(hr))
2264 {
2265 hr = ITypeInfo_Invoke( typeinfo, &This->IUPnPNAT_iface, dispIdMember,
2266 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
2267 ITypeInfo_Release( typeinfo );
2268 }
2269 return hr;
2270}
2271
2273{
2274 upnpnat *This = impl_from_IUPnPNAT( iface );
2275
2276 TRACE("%p, %p\n", This, collection);
2277
2279}
2280
2282{
2283 upnpnat *This = impl_from_IUPnPNAT( iface );
2284 FIXME("%p, %p\n", This, collection);
2285 if(collection)
2286 *collection = NULL;
2287 return E_NOTIMPL;
2288}
2289
2291{
2292 upnpnat *This = impl_from_IUPnPNAT( iface );
2293 FIXME("%p, %p\n", This, manager);
2294 if(manager)
2295 *manager = NULL;
2296 return E_NOTIMPL;
2297}
2298
2299const static IUPnPNATVtbl upnpnat_vtbl =
2300{
2311};
2312
2313
2315{
2316 upnpnat *nat;
2317
2318 TRACE("(%p,%p)\n", outer, object);
2319
2320 nat = malloc( sizeof(*nat) );
2321 if (!nat) return E_OUTOFMEMORY;
2322
2323 nat->IUPnPNAT_iface.lpVtbl = &upnpnat_vtbl;
2324 nat->ref = 1;
2325
2326 *object = &nat->IUPnPNAT_iface;
2327
2328 TRACE("returning iface %p\n", *object);
2329 return S_OK;
2330}
ios_base &_STLP_CALL internal(ios_base &__s)
Definition: _ios_base.h:311
HRESULT get_typeinfo(enum type_id tid, ITypeInfo **ret)
Definition: apps.c:125
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define index(s, c)
Definition: various.h:29
char * hostname
Definition: ftp.c:88
#define ARRAY_SIZE(A)
Definition: main.h:20
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
const GUID IID_IUnknown
void * description
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcsnicmp
Definition: compat.h:14
OLECHAR * BSTR
Definition: compat.h:2293
#define stricmp(_String1, _String2)
Definition: compat.h:24
short VARIANT_BOOL
Definition: compat.h:2290
#define MultiByteToWideChar
Definition: compat.h:110
@ VT_DISPATCH
Definition: compat.h:2304
#define wcsicmp
Definition: compat.h:15
static const struct INetFwOpenPortsVtbl fw_ports_vtbl
Definition: port.c:2128
static ULONG WINAPI static_port_mapping_AddRef(IStaticPortMapping *iface)
Definition: port.c:879
static HRESULT WINAPI upnpnat_GetTypeInfo(IUPnPNAT *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: port.c:2225
static unsigned int get_port_mapping_count(void)
Definition: port.c:851
static const IEnumVARIANTVtbl port_mapping_enum_vtbl
Definition: port.c:1296
static HRESULT WINAPI fw_port_put_Name(INetFwOpenPort *iface, BSTR name)
Definition: port.c:1735
static HRESULT WINAPI port_mapping_enum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *var, ULONG *fetched)
Definition: port.c:1220
static ULONG WINAPI static_ports_Release(IStaticPortMappingCollection *iface)
Definition: port.c:1341
static HRESULT WINAPI fw_port_put_Port(INetFwOpenPort *iface, LONG portNumber)
Definition: port.c:1806
static const struct INetFwOpenPortVtbl fw_port_vtbl
Definition: port.c:1889
static const IStaticPortMappingVtbl static_port_mapping_vtbl
Definition: port.c:1129
static HRESULT WINAPI static_port_mapping_GetTypeInfoCount(IStaticPortMapping *iface, UINT *pctinfo)
Definition: port.c:924
static HRESULT WINAPI static_port_mapping_Enable(IStaticPortMapping *iface, VARIANT_BOOL value)
Definition: port.c:1102
#define COPY_BSTR_CHECK(name)
unsigned int mapping_count
Definition: port.c:70
static BOOL grab_gateway_connection(void)
Definition: port.c:794
static HRESULT WINAPI static_ports_Add(IStaticPortMappingCollection *iface, LONG external, BSTR protocol, LONG internal, BSTR client, VARIANT_BOOL enabled, BSTR description, IStaticPortMapping **mapping)
Definition: port.c:1512
WCHAR locationW[256]
Definition: port.c:64
static HRESULT WINAPI static_ports_GetIDsOfNames(IStaticPortMappingCollection *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: port.c:1402
static void gateway_connection_cleanup(void)
Definition: port.c:391
static struct static_port_mapping_collection * impl_from_IStaticPortMappingCollection(IStaticPortMappingCollection *iface)
Definition: port.c:1329
static HRESULT WINAPI static_ports_Invoke(IStaticPortMappingCollection *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
Definition: port.c:1425
static HRESULT WINAPI static_port_mapping_get_ExternalPort(IStaticPortMapping *iface, LONG *value)
Definition: port.c:1012
static HRESULT WINAPI static_port_mapping_get_InternalPort(IStaticPortMapping *iface, LONG *value)
Definition: port.c:1025
WCHAR control_url[256]
Definition: port.c:67
static HRESULT WINAPI fw_port_get_BuiltIn(INetFwOpenPort *iface, VARIANT_BOOL *builtIn)
Definition: port.c:1879
static HRESULT WINAPI upnpnat_Invoke(IUPnPNAT *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
Definition: port.c:2251
static HRESULT WINAPI upnpnat_GetTypeInfoCount(IUPnPNAT *iface, UINT *pctinfo)
Definition: port.c:2216
static BOOL get_xml_elements(const char *desc_xml, struct xml_value_desc *values, unsigned int value_count)
Definition: port.c:234
static HRESULT WINAPI fw_ports_Remove(INetFwOpenPorts *iface, LONG portNumber, NET_FW_IP_PROTOCOL ipProtocol)
Definition: port.c:2087
static HRESULT WINAPI upnpnat_get_StaticPortMappingCollection(IUPnPNAT *iface, IStaticPortMappingCollection **collection)
Definition: port.c:2272
static void free_mappings(void)
Definition: port.c:84
static HRESULT WINAPI fw_port_put_IpVersion(INetFwOpenPort *iface, NET_FW_IP_VERSION ipVersion)
Definition: port.c:1761
static fw_port * impl_from_INetFwOpenPort(INetFwOpenPort *iface)
Definition: port.c:1601
static HRESULT WINAPI static_port_mapping_get_ExternalIPAddress(IStaticPortMapping *iface, BSTR *value)
Definition: port.c:998
static HRESULT WINAPI static_port_mapping_QueryInterface(IStaticPortMapping *iface, REFIID riid, void **ppvObject)
Definition: port.c:900
static BOOL open_gateway_connection(void)
Definition: port.c:295
static BSTR mapping_move_bstr(BSTR *s)
Definition: port.c:543
static HRESULT WINAPI fw_port_get_Port(INetFwOpenPort *iface, LONG *portNumber)
Definition: port.c:1796
static HRESULT WINAPI fw_ports_Add(INetFwOpenPorts *iface, INetFwOpenPort *port)
Definition: port.c:2077
static struct port_mapping_enum * impl_from_IEnumVARIANT(IEnumVARIANT *iface)
Definition: port.c:1171
static HRESULT WINAPI fw_ports_get__NewEnum(INetFwOpenPorts *iface, IUnknown **newEnum)
Definition: port.c:2118
static ULONG WINAPI upnpnat_Release(IUPnPNAT *iface)
Definition: port.c:2205
static BOOL init_gateway_connection(void)
Definition: port.c:702
static HRESULT WINAPI fw_port_get_IpVersion(INetFwOpenPort *iface, NET_FW_IP_VERSION *ipVersion)
Definition: port.c:1751
static ULONG WINAPI upnpnat_AddRef(IUPnPNAT *iface)
Definition: port.c:2199
static HRESULT WINAPI fw_ports_Item(INetFwOpenPorts *iface, LONG portNumber, NET_FW_IP_PROTOCOL ipProtocol, INetFwOpenPort **openPort)
Definition: port.c:2098
static HRESULT WINAPI fw_port_get_Name(INetFwOpenPort *iface, BSTR *name)
Definition: port.c:1725
static BOOL get_control_url(void)
Definition: port.c:328
static void release_gateway_connection(void)
Definition: port.c:808
static HRESULT WINAPI static_port_mapping_Invoke(IStaticPortMapping *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
Definition: port.c:970
static HRESULT WINAPI static_port_mapping_GetTypeInfo(IStaticPortMapping *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: port.c:935
static HRESULT WINAPI fw_port_GetTypeInfo(INetFwOpenPort *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: port.c:1662
HINTERNET connection
Definition: port.c:65
LONG refs
Definition: port.c:62
static ULONG WINAPI static_ports_AddRef(IStaticPortMappingCollection *iface)
Definition: port.c:1334
HRESULT IUPnPNAT_create(IUnknown *outer, void **object)
Definition: port.c:2314
static HRESULT WINAPI static_ports_Remove(IStaticPortMappingCollection *iface, LONG port, BSTR protocol)
Definition: port.c:1497
static HRESULT WINAPI port_mapping_enum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppvObject)
Definition: port.c:1197
static ULONG WINAPI static_port_mapping_Release(IStaticPortMapping *iface)
Definition: port.c:886
HRESULT NetFwOpenPort_create(IUnknown *pUnkOuter, LPVOID *ppObj)
Definition: port.c:1915
static HRESULT WINAPI static_port_mapping_get_Enabled(IStaticPortMapping *iface, VARIANT_BOOL *value)
Definition: port.c:1066
static HRESULT WINAPI upnpnat_GetIDsOfNames(IUPnPNAT *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: port.c:2233
static HRESULT WINAPI fw_ports_GetTypeInfo(INetFwOpenPorts *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: port.c:2002
static BOOL remove_port_mapping(LONG port, BSTR protocol)
Definition: port.c:622
static HRESULT WINAPI static_port_mapping_GetIDsOfNames(IStaticPortMapping *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: port.c:947
static HRESULT WINAPI fw_ports_get_Count(INetFwOpenPorts *iface, LONG *count)
Definition: port.c:2065
static BOOL is_valid_protocol(BSTR protocol)
Definition: port.c:861
static HRESULT WINAPI static_port_mapping_EditInternalPort(IStaticPortMapping *iface, LONG value)
Definition: port.c:1120
static HRESULT WINAPI static_ports_GetTypeInfo(IStaticPortMappingCollection *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: port.c:1390
static ULONG WINAPI port_mapping_enum_Release(IEnumVARIANT *iface)
Definition: port.c:1183
static struct xml_value_desc port_mapping_template[]
Definition: port.c:525
static HRESULT WINAPI static_port_mapping_get_InternalClient(IStaticPortMapping *iface, BSTR *value)
Definition: port.c:1052
static HRESULT WINAPI fw_port_GetIDsOfNames(INetFwOpenPort *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: port.c:1674
static HRESULT WINAPI static_port_mapping_EditDescription(IStaticPortMapping *iface, BSTR value)
Definition: port.c:1111
static HRESULT WINAPI fw_ports_GetTypeInfoCount(INetFwOpenPorts *iface, UINT *pctinfo)
Definition: port.c:1991
static HRESULT WINAPI static_ports_QueryInterface(IStaticPortMappingCollection *iface, REFIID riid, void **ppvObject)
Definition: port.c:1355
static HRESULT WINAPI upnpnat_get_NATEventManager(IUPnPNAT *iface, INATEventManager **manager)
Definition: port.c:2290
static HRESULT WINAPI fw_ports_GetIDsOfNames(INetFwOpenPorts *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: port.c:2014
static HRESULT static_port_mapping_create(const struct port_mapping *mapping_data, IStaticPortMapping **ret)
Definition: port.c:1151
static BOOL parse_desc_xml(const char *desc_xml)
Definition: port.c:154
static ULONG WINAPI port_mapping_enum_AddRef(IEnumVARIANT *iface)
Definition: port.c:1176
static HRESULT WINAPI fw_port_QueryInterface(INetFwOpenPort *iface, REFIID riid, void **ppvObject)
Definition: port.c:1627
static fw_ports * impl_from_INetFwOpenPorts(INetFwOpenPorts *iface)
Definition: port.c:1942
static HRESULT WINAPI static_port_mapping_get_Protocol(IStaticPortMapping *iface, BSTR *value)
Definition: port.c:1038
static HRESULT WINAPI fw_port_GetTypeInfoCount(INetFwOpenPort *iface, UINT *pctinfo)
Definition: port.c:1651
static HRESULT WINAPI upnpnat_get_DynamicPortMappingCollection(IUPnPNAT *iface, IDynamicPortMappingCollection **collection)
Definition: port.c:2281
HRESULT NetFwOpenPorts_create(IUnknown *pUnkOuter, LPVOID *ppObj)
Definition: port.c:2144
port_mapping_parameter
Definition: port.c:512
@ PM_LEASE_DURATION
Definition: port.c:520
@ PM_CLIENT
Definition: port.c:517
@ PM_EXTERNAL_IP
Definition: port.c:513
@ PM_INTERNAL
Definition: port.c:516
@ PM_ENABLED
Definition: port.c:518
@ PM_LAST
Definition: port.c:521
@ PM_EXTERNAL
Definition: port.c:514
@ PM_REMOVE_PORT_LAST
Definition: port.c:522
@ PM_DESC
Definition: port.c:519
@ PM_PROTOCOL
Definition: port.c:515
static HRESULT WINAPI port_mapping_enum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ret)
Definition: port.c:1282
static BOOL parse_search_response(char *response, WCHAR *locationW, unsigned int location_size)
Definition: port.c:117
static HRESULT WINAPI static_ports_get_Count(IStaticPortMappingCollection *iface, LONG *count)
Definition: port.c:1486
static const IUPnPNATVtbl upnpnat_vtbl
Definition: port.c:2299
struct _upnpnat upnpnat
unsigned int version
Definition: port.c:68
static BOOL copy_port_mapping(struct port_mapping *dst, const struct port_mapping *src)
Definition: port.c:95
static ULONG WINAPI fw_ports_AddRef(INetFwOpenPorts *iface)
Definition: port.c:1947
static ULONG WINAPI fw_port_Release(INetFwOpenPort *iface)
Definition: port.c:1613
static HRESULT WINAPI static_ports_GetTypeInfoCount(IStaticPortMappingCollection *iface, UINT *pctinfo)
Definition: port.c:1379
static HRESULT WINAPI fw_port_get_Scope(INetFwOpenPort *iface, NET_FW_SCOPE *scope)
Definition: port.c:1817
static ULONG WINAPI fw_port_AddRef(INetFwOpenPort *iface)
Definition: port.c:1606
static void free_port_mapping(struct port_mapping *mapping)
Definition: port.c:76
static BOOL add_port_mapping(LONG external, BSTR protocol, LONG internal, BSTR client, VARIANT_BOOL enabled, BSTR description)
Definition: port.c:657
static upnpnat * impl_from_IUPnPNAT(IUPnPNAT *iface)
Definition: port.c:2168
WCHAR desc_urlpath[128]
Definition: port.c:66
static const IStaticPortMappingCollectionVtbl static_ports_vtbl
Definition: port.c:1555
static HRESULT WINAPI fw_port_get_Enabled(INetFwOpenPort *iface, VARIANT_BOOL *enabled)
Definition: port.c:1857
static BOOL request_service(const WCHAR *function, const struct xml_value_desc *request_param, unsigned int request_param_count, struct xml_value_desc *result, unsigned int result_count, DWORD *http_status, BSTR *server_error_code_str)
Definition: port.c:401
HINTERNET session
Definition: port.c:65
static HRESULT WINAPI static_port_mapping_EditInternalClient(IStaticPortMapping *iface, BSTR value)
Definition: port.c:1093
static HRESULT WINAPI fw_port_put_Enabled(INetFwOpenPort *iface, VARIANT_BOOL enabled)
Definition: port.c:1869
static HRESULT static_port_mapping_collection_create(IStaticPortMappingCollection **object)
Definition: port.c:1571
static HRESULT WINAPI fw_ports_QueryInterface(INetFwOpenPorts *iface, REFIID riid, void **ppvObject)
Definition: port.c:1967
static HRESULT create_port_mapping_enum(IUnknown **ret)
Definition: port.c:1307
static HRESULT WINAPI fw_ports_Invoke(INetFwOpenPorts *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
Definition: port.c:2037
static HRESULT WINAPI static_ports__NewEnum(IStaticPortMappingCollection *iface, IUnknown **ret)
Definition: port.c:1453
static unsigned int get_port_mapping_range(unsigned int index, unsigned int count, struct port_mapping *ret)
Definition: port.c:835
static struct static_port_mapping * impl_from_IStaticPortMapping(IStaticPortMapping *iface)
Definition: port.c:874
static HRESULT WINAPI fw_port_get_RemoteAddresses(INetFwOpenPort *iface, BSTR *remoteAddrs)
Definition: port.c:1837
static HRESULT WINAPI fw_port_put_Scope(INetFwOpenPort *iface, NET_FW_SCOPE scope)
Definition: port.c:1827
static HRESULT WINAPI static_ports_get_Item(IStaticPortMappingCollection *iface, LONG port, BSTR protocol, IStaticPortMapping **mapping)
Definition: port.c:1465
static void update_mapping_list(void)
Definition: port.c:559
static BOOL find_port_mapping(LONG port, BSTR protocol, struct port_mapping *ret)
Definition: port.c:817
static ULONG WINAPI fw_ports_Release(INetFwOpenPorts *iface)
Definition: port.c:1954
static HRESULT WINAPI fw_port_Invoke(INetFwOpenPort *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
Definition: port.c:1697
static HRESULT WINAPI port_mapping_enum_Skip(IEnumVARIANT *iface, ULONG celt)
Definition: port.c:1259
BOOL winsock_initialized
Definition: port.c:63
static struct @525 upnp_gateway_connection
static HRESULT WINAPI port_mapping_enum_Reset(IEnumVARIANT *iface)
Definition: port.c:1270
static HRESULT WINAPI fw_port_put_Protocol(INetFwOpenPort *iface, NET_FW_IP_PROTOCOL ipProtocol)
Definition: port.c:1781
static SRWLOCK upnp_gateway_connection_lock
Definition: port.c:74
static HRESULT WINAPI static_port_mapping_get_Description(IStaticPortMapping *iface, BSTR *value)
Definition: port.c:1079
static HRESULT WINAPI fw_port_get_Protocol(INetFwOpenPort *iface, NET_FW_IP_PROTOCOL *ipProtocol)
Definition: port.c:1771
struct port_mapping * mappings
Definition: port.c:69
static HRESULT WINAPI upnpnat_QueryInterface(IUPnPNAT *iface, REFIID riid, void **object)
Definition: port.c:2173
static HRESULT WINAPI fw_port_put_RemoteAddresses(INetFwOpenPort *iface, BSTR remoteAddrs)
Definition: port.c:1847
static LONG long_from_bstr(BSTR s)
Definition: port.c:537
VOID WINAPI AcquireSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:8
VOID WINAPI ReleaseSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:36
LCID lcid
Definition: locale.c:5660
#define assert(_expr)
Definition: assert.h:32
_ACRTIMP int __cdecl _wtoi(const wchar_t *)
Definition: wcs.c:2778
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1977
_ACRTIMP int __cdecl atoi(const char *)
Definition: string.c:1720
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP char *__cdecl strtok_s(char *, const char *, char **)
Definition: string.c:314
_ACRTIMP char *__cdecl strtok(char *, const char *)
Definition: string.c:290
IStream *WINAPI SHCreateMemStream(const BYTE *data, UINT data_len)
Definition: main.c:873
USHORT port
Definition: uri.c:210
HINTERNET WINAPI WinHttpOpenRequest(HINTERNET hconnect, const WCHAR *verb, const WCHAR *object, const WCHAR *version, const WCHAR *referrer, const WCHAR **types, DWORD flags)
Definition: session.c:1277
HINTERNET WINAPI WinHttpOpen(LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags)
Definition: session.c:304
HINTERNET WINAPI WinHttpConnect(HINTERNET hsession, const WCHAR *server, INTERNET_PORT port, DWORD reserved)
Definition: session.c:594
BOOL WINAPI WinHttpCloseHandle(HINTERNET handle)
Definition: session.c:1358
BOOL WINAPI WinHttpSetTimeouts(HINTERNET handle, int resolve, int connect, int send, int receive)
Definition: session.c:2460
BOOL WINAPI WinHttpCrackUrl(const WCHAR *url, DWORD len, DWORD flags, URL_COMPONENTSW *uc)
Definition: url.c:173
#define swprintf
Definition: precomp.h:40
INT WSAAPI recvfrom(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags, OUT LPSOCKADDR from, IN OUT INT FAR *fromlen)
Definition: recv.c:87
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82
HRESULT WINAPI CreateXmlReader(REFIID riid, void **obj, IMalloc *imalloc)
Definition: reader.c:3616
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
#define IPPROTO_UDP
Definition: ip.h:198
#define AF_INET
Definition: tcpip.h:117
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLdouble s
Definition: gl.h:2039
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
GLenum src
Definition: glext.h:6340
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLintptr offset
Definition: glext.h:5920
GLuint index
Definition: glext.h:6031
GLenum GLenum dst
Definition: glext.h:6340
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:5666
GLenum const GLvoid * addr
Definition: glext.h:9621
GLuint64EXT * result
Definition: glext.h:11304
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: sysinfo.c:13
@ IStaticPortMapping_tid
@ INetFwOpenPort_tid
@ IStaticPortMappingCollection_tid
@ INetFwOpenPorts_tid
@ IUPnPNAT_tid
enum NET_FW_IP_PROTOCOL_ NET_FW_IP_PROTOCOL
enum NET_FW_IP_VERSION_ NET_FW_IP_VERSION
enum NET_FW_SCOPE_ NET_FW_SCOPE
@ NET_FW_IP_PROTOCOL_TCP
Definition: icftypes.idl:75
@ NET_FW_IP_PROTOCOL_UDP
Definition: icftypes.idl:76
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_w
Definition: kernel32.h:32
static LPMONITOREX pm
Definition: localmon.c:45
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define htons(x)
Definition: module.h:215
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static PVOID ptr
Definition: dispmode.c:27
static const WCHAR url[]
Definition: encode.c:1384
const char * var
Definition: shader.c:5879
static IUnknown * outer
Definition: compobj.c:82
static VARIANTARG static DISPID
Definition: ordinal.c:49
#define closesocket
Definition: ncftp.h:477
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:240
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:273
#define V_VT(A)
Definition: oleauto.h:211
#define V_DISPATCH(A)
Definition: oleauto.h:239
const GUID IID_IProvideClassInfo
const GUID IID_IDispatch
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
BOOL WINAPI WinHttpQueryHeaders(HINTERNET hrequest, DWORD level, const WCHAR *name, void *buffer, DWORD *buflen, DWORD *index)
Definition: request.c:814
BOOL WINAPI WinHttpReadData(HINTERNET hrequest, void *buffer, DWORD to_read, DWORD *read)
Definition: request.c:3252
BOOL WINAPI WinHttpSendRequest(HINTERNET hrequest, const WCHAR *headers, DWORD headers_len, void *optional, DWORD optional_len, DWORD total_len, DWORD_PTR context)
Definition: request.c:2397
BOOL WINAPI WinHttpReceiveResponse(HINTERNET hrequest, LPVOID reserved)
Definition: request.c:3068
#define calloc
Definition: rosglue.h:14
DWORD LCID
Definition: nls.h:13
#define CP_UTF8
Definition: nls.h:20
wcscpy
const char * descr
Definition: boot.c:45
#define memset(x, y, z)
Definition: compat.h:39
static FILE * client
Definition: client.c:37
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
#define TRACE(s)
Definition: solgame.cpp:4
LONG ref
Definition: port.c:2165
IUPnPNAT IUPnPNAT_iface
Definition: port.c:2164
Definition: port.c:1593
INetFwOpenPort INetFwOpenPort_iface
Definition: port.c:1594
LONG port
Definition: port.c:1598
BSTR name
Definition: port.c:1596
LONG refs
Definition: port.c:1595
NET_FW_IP_PROTOCOL protocol
Definition: port.c:1597
LONG refs
Definition: port.c:1939
INetFwOpenPorts INetFwOpenPorts_iface
Definition: port.c:1938
Definition: name.c:39
IEnumVARIANT IEnumVARIANT_iface
Definition: port.c:1166
unsigned int index
Definition: port.c:1168
LONG internal
Definition: port.c:48
BSTR descr
Definition: port.c:51
BSTR external_ip
Definition: port.c:45
LONG external
Definition: port.c:46
VARIANT_BOOL enabled
Definition: port.c:50
BSTR protocol
Definition: port.c:47
BSTR client
Definition: port.c:49
Definition: reader.h:84
Definition: tftpd.h:86
IStaticPortMappingCollection IStaticPortMappingCollection_iface
Definition: port.c:1324
IStaticPortMapping IStaticPortMapping_iface
Definition: port.c:869
Definition: ps.c:97
Definition: parse.h:23
Definition: dhcpd.h:248
const WCHAR * name
Definition: port.c:56
BSTR value
Definition: port.c:57
#define MAKEWORD(a, b)
Definition: typedefs.h:248
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
Definition: pdh_main.c:64
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:547
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
WINBASEAPI _In_ DWORD _Out_ _In_ WORD wFlags
Definition: wincon_undoc.h:337
#define WINAPI
Definition: msvc.h:6
u_long WINAPI inet_addr(const char *str)
Definition: wine.c:35
#define S_FALSE
Definition: winerror.h:3451
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define E_NOINTERFACE
Definition: winerror.h:3479
#define WSAETIMEDOUT
Definition: winerror.h:2876
#define E_POINTER
Definition: winerror.h:3480
#define HTTP_STATUS_OK
Definition: winhttp.h:301
#define WINHTTP_DEFAULT_ACCEPT_TYPES
Definition: winhttp.h:226
#define WINHTTP_NO_ADDITIONAL_HEADERS
Definition: winhttp.h:229
#define HTTP_STATUS_SERVER_ERROR
Definition: winhttp.h:334
#define WINHTTP_QUERY_STATUS_CODE
Definition: winhttp.h:379
#define WINHTTP_NO_PROXY_NAME
Definition: winhttp.h:74
#define WINHTTP_QUERY_FLAG_NUMBER
Definition: winhttp.h:439
#define WINHTTP_ACCESS_TYPE_NO_PROXY
Definition: winhttp.h:70
#define WINHTTP_NO_REFERER
Definition: winhttp.h:225
#define WINHTTP_NO_PROXY_BYPASS
Definition: winhttp.h:75
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:131
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
#define SOCK_DGRAM
Definition: winsock.h:330
UINT_PTR SOCKET
Definition: winsock.h:41
#define SOCKET_ERROR
Definition: winsock.h:327
#define SOL_SOCKET
Definition: winsock.h:392
#define SO_RCVTIMEO
Definition: winsock.h:187
#define snprintf
Definition: wintirpc.h:48
XmlNodeType
Definition: xmllite.idl:23
@ XmlNodeType_EndElement
Definition: xmllite.idl:33
@ XmlNodeType_None
Definition: xmllite.idl:24
@ XmlNodeType_Element
Definition: xmllite.idl:25
@ XmlNodeType_Text
Definition: xmllite.idl:27
unsigned char BYTE
Definition: xxhash.c:193