upnp.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**************************************************************************/
  2. /* upnp.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "upnp.h"
  31. UPNP *(*UPNP::_create)(bool p_notify_postinitialize) = nullptr;
  32. void UPNP::_bind_methods() {
  33. ClassDB::bind_method(D_METHOD("get_device_count"), &UPNP::get_device_count);
  34. ClassDB::bind_method(D_METHOD("get_device", "index"), &UPNP::get_device);
  35. ClassDB::bind_method(D_METHOD("add_device", "device"), &UPNP::add_device);
  36. ClassDB::bind_method(D_METHOD("set_device", "index", "device"), &UPNP::set_device);
  37. ClassDB::bind_method(D_METHOD("remove_device", "index"), &UPNP::remove_device);
  38. ClassDB::bind_method(D_METHOD("clear_devices"), &UPNP::clear_devices);
  39. ClassDB::bind_method(D_METHOD("get_gateway"), &UPNP::get_gateway);
  40. ClassDB::bind_method(D_METHOD("discover", "timeout", "ttl", "device_filter"), &UPNP::discover, DEFVAL(2000), DEFVAL(2), DEFVAL("InternetGatewayDevice"));
  41. ClassDB::bind_method(D_METHOD("query_external_address"), &UPNP::query_external_address);
  42. ClassDB::bind_method(D_METHOD("add_port_mapping", "port", "port_internal", "desc", "proto", "duration"), &UPNP::add_port_mapping, DEFVAL(0), DEFVAL(""), DEFVAL("UDP"), DEFVAL(0));
  43. ClassDB::bind_method(D_METHOD("delete_port_mapping", "port", "proto"), &UPNP::delete_port_mapping, DEFVAL("UDP"));
  44. ClassDB::bind_method(D_METHOD("set_discover_multicast_if", "m_if"), &UPNP::set_discover_multicast_if);
  45. ClassDB::bind_method(D_METHOD("get_discover_multicast_if"), &UPNP::get_discover_multicast_if);
  46. ADD_PROPERTY(PropertyInfo(Variant::STRING, "discover_multicast_if"), "set_discover_multicast_if", "get_discover_multicast_if");
  47. ClassDB::bind_method(D_METHOD("set_discover_local_port", "port"), &UPNP::set_discover_local_port);
  48. ClassDB::bind_method(D_METHOD("get_discover_local_port"), &UPNP::get_discover_local_port);
  49. ADD_PROPERTY(PropertyInfo(Variant::INT, "discover_local_port", PROPERTY_HINT_RANGE, "0,65535"), "set_discover_local_port", "get_discover_local_port");
  50. ClassDB::bind_method(D_METHOD("set_discover_ipv6", "ipv6"), &UPNP::set_discover_ipv6);
  51. ClassDB::bind_method(D_METHOD("is_discover_ipv6"), &UPNP::is_discover_ipv6);
  52. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "discover_ipv6"), "set_discover_ipv6", "is_discover_ipv6");
  53. BIND_ENUM_CONSTANT(UPNP_RESULT_SUCCESS);
  54. BIND_ENUM_CONSTANT(UPNP_RESULT_NOT_AUTHORIZED);
  55. BIND_ENUM_CONSTANT(UPNP_RESULT_PORT_MAPPING_NOT_FOUND);
  56. BIND_ENUM_CONSTANT(UPNP_RESULT_INCONSISTENT_PARAMETERS);
  57. BIND_ENUM_CONSTANT(UPNP_RESULT_NO_SUCH_ENTRY_IN_ARRAY);
  58. BIND_ENUM_CONSTANT(UPNP_RESULT_ACTION_FAILED);
  59. BIND_ENUM_CONSTANT(UPNP_RESULT_SRC_IP_WILDCARD_NOT_PERMITTED);
  60. BIND_ENUM_CONSTANT(UPNP_RESULT_EXT_PORT_WILDCARD_NOT_PERMITTED);
  61. BIND_ENUM_CONSTANT(UPNP_RESULT_INT_PORT_WILDCARD_NOT_PERMITTED);
  62. BIND_ENUM_CONSTANT(UPNP_RESULT_REMOTE_HOST_MUST_BE_WILDCARD);
  63. BIND_ENUM_CONSTANT(UPNP_RESULT_EXT_PORT_MUST_BE_WILDCARD);
  64. BIND_ENUM_CONSTANT(UPNP_RESULT_NO_PORT_MAPS_AVAILABLE);
  65. BIND_ENUM_CONSTANT(UPNP_RESULT_CONFLICT_WITH_OTHER_MECHANISM);
  66. BIND_ENUM_CONSTANT(UPNP_RESULT_CONFLICT_WITH_OTHER_MAPPING);
  67. BIND_ENUM_CONSTANT(UPNP_RESULT_SAME_PORT_VALUES_REQUIRED);
  68. BIND_ENUM_CONSTANT(UPNP_RESULT_ONLY_PERMANENT_LEASE_SUPPORTED);
  69. BIND_ENUM_CONSTANT(UPNP_RESULT_INVALID_GATEWAY);
  70. BIND_ENUM_CONSTANT(UPNP_RESULT_INVALID_PORT);
  71. BIND_ENUM_CONSTANT(UPNP_RESULT_INVALID_PROTOCOL);
  72. BIND_ENUM_CONSTANT(UPNP_RESULT_INVALID_DURATION);
  73. BIND_ENUM_CONSTANT(UPNP_RESULT_INVALID_ARGS);
  74. BIND_ENUM_CONSTANT(UPNP_RESULT_INVALID_RESPONSE);
  75. BIND_ENUM_CONSTANT(UPNP_RESULT_INVALID_PARAM);
  76. BIND_ENUM_CONSTANT(UPNP_RESULT_HTTP_ERROR);
  77. BIND_ENUM_CONSTANT(UPNP_RESULT_SOCKET_ERROR);
  78. BIND_ENUM_CONSTANT(UPNP_RESULT_MEM_ALLOC_ERROR);
  79. BIND_ENUM_CONSTANT(UPNP_RESULT_NO_GATEWAY);
  80. BIND_ENUM_CONSTANT(UPNP_RESULT_NO_DEVICES);
  81. BIND_ENUM_CONSTANT(UPNP_RESULT_UNKNOWN_ERROR);
  82. }