upnp.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**************************************************************************/
  2. /* upnp.h */
  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. #ifndef UPNP_H
  31. #define UPNP_H
  32. #include "upnp_device.h"
  33. #include "core/object/ref_counted.h"
  34. class UPNP : public RefCounted {
  35. GDCLASS(UPNP, RefCounted);
  36. protected:
  37. static void _bind_methods();
  38. static UPNP *(*_create)(bool p_notify_postinitialize);
  39. public:
  40. enum UPNPResult {
  41. UPNP_RESULT_SUCCESS,
  42. UPNP_RESULT_NOT_AUTHORIZED,
  43. UPNP_RESULT_PORT_MAPPING_NOT_FOUND,
  44. UPNP_RESULT_INCONSISTENT_PARAMETERS,
  45. UPNP_RESULT_NO_SUCH_ENTRY_IN_ARRAY,
  46. UPNP_RESULT_ACTION_FAILED,
  47. UPNP_RESULT_SRC_IP_WILDCARD_NOT_PERMITTED,
  48. UPNP_RESULT_EXT_PORT_WILDCARD_NOT_PERMITTED,
  49. UPNP_RESULT_INT_PORT_WILDCARD_NOT_PERMITTED,
  50. UPNP_RESULT_REMOTE_HOST_MUST_BE_WILDCARD,
  51. UPNP_RESULT_EXT_PORT_MUST_BE_WILDCARD,
  52. UPNP_RESULT_NO_PORT_MAPS_AVAILABLE,
  53. UPNP_RESULT_CONFLICT_WITH_OTHER_MECHANISM,
  54. UPNP_RESULT_CONFLICT_WITH_OTHER_MAPPING,
  55. UPNP_RESULT_SAME_PORT_VALUES_REQUIRED,
  56. UPNP_RESULT_ONLY_PERMANENT_LEASE_SUPPORTED,
  57. UPNP_RESULT_INVALID_GATEWAY,
  58. UPNP_RESULT_INVALID_PORT,
  59. UPNP_RESULT_INVALID_PROTOCOL,
  60. UPNP_RESULT_INVALID_DURATION,
  61. UPNP_RESULT_INVALID_ARGS,
  62. UPNP_RESULT_INVALID_RESPONSE,
  63. UPNP_RESULT_INVALID_PARAM,
  64. UPNP_RESULT_HTTP_ERROR,
  65. UPNP_RESULT_SOCKET_ERROR,
  66. UPNP_RESULT_MEM_ALLOC_ERROR,
  67. UPNP_RESULT_NO_GATEWAY,
  68. UPNP_RESULT_NO_DEVICES,
  69. UPNP_RESULT_UNKNOWN_ERROR,
  70. };
  71. static UPNP *create(bool p_notify_postinitialize = true) {
  72. if (!_create) {
  73. return nullptr;
  74. }
  75. return _create(p_notify_postinitialize);
  76. }
  77. virtual int get_device_count() const = 0;
  78. virtual Ref<UPNPDevice> get_device(int index) const = 0;
  79. virtual void add_device(Ref<UPNPDevice> device) = 0;
  80. virtual void set_device(int index, Ref<UPNPDevice> device) = 0;
  81. virtual void remove_device(int index) = 0;
  82. virtual void clear_devices() = 0;
  83. virtual Ref<UPNPDevice> get_gateway() const = 0;
  84. virtual int discover(int timeout = 2000, int ttl = 2, const String &device_filter = "InternetGatewayDevice") = 0;
  85. virtual String query_external_address() const = 0;
  86. virtual int add_port_mapping(int port, int port_internal = 0, String desc = "", String proto = "UDP", int duration = 0) const = 0;
  87. virtual int delete_port_mapping(int port, String proto = "UDP") const = 0;
  88. virtual void set_discover_multicast_if(const String &m_if) = 0;
  89. virtual String get_discover_multicast_if() const = 0;
  90. virtual void set_discover_local_port(int port) = 0;
  91. virtual int get_discover_local_port() const = 0;
  92. virtual void set_discover_ipv6(bool ipv6) = 0;
  93. virtual bool is_discover_ipv6() const = 0;
  94. UPNP() {}
  95. virtual ~UPNP() {}
  96. };
  97. VARIANT_ENUM_CAST(UPNP::UPNPResult)
  98. #endif // UPNP_H