2
0

upnp_miniupnp.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**************************************************************************/
  2. /* upnp_miniupnp.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_MINIUPNP_H
  31. #define UPNP_MINIUPNP_H
  32. #ifndef WEB_ENABLED
  33. #include "upnp.h"
  34. #include <miniupnpc/miniupnpc.h>
  35. class UPNPMiniUPNP : public UPNP {
  36. GDCLASS(UPNPMiniUPNP, UPNP);
  37. private:
  38. static UPNP *_create(bool p_notify_postinitialize) { return static_cast<UPNP *>(ClassDB::creator<UPNPMiniUPNP>(p_notify_postinitialize)); }
  39. String discover_multicast_if = "";
  40. int discover_local_port = 0;
  41. bool discover_ipv6 = false;
  42. Vector<Ref<UPNPDevice>> devices;
  43. bool is_common_device(const String &dev) const;
  44. void add_device_to_list(UPNPDev *dev, UPNPDev *devlist);
  45. void parse_igd(Ref<UPNPDevice> dev, UPNPDev *devlist);
  46. char *load_description(const String &url, int *size, int *status_code) const;
  47. public:
  48. static void make_default();
  49. static int upnp_result(int in);
  50. virtual int get_device_count() const override;
  51. virtual Ref<UPNPDevice> get_device(int index) const override;
  52. virtual void add_device(Ref<UPNPDevice> device) override;
  53. virtual void set_device(int index, Ref<UPNPDevice> device) override;
  54. virtual void remove_device(int index) override;
  55. virtual void clear_devices() override;
  56. virtual Ref<UPNPDevice> get_gateway() const override;
  57. virtual int discover(int timeout = 2000, int ttl = 2, const String &device_filter = "InternetGatewayDevice") override;
  58. virtual String query_external_address() const override;
  59. virtual int add_port_mapping(int port, int port_internal = 0, String desc = "", String proto = "UDP", int duration = 0) const override;
  60. virtual int delete_port_mapping(int port, String proto = "UDP") const override;
  61. virtual void set_discover_multicast_if(const String &m_if) override;
  62. virtual String get_discover_multicast_if() const override;
  63. virtual void set_discover_local_port(int port) override;
  64. virtual int get_discover_local_port() const override;
  65. virtual void set_discover_ipv6(bool ipv6) override;
  66. virtual bool is_discover_ipv6() const override;
  67. UPNPMiniUPNP() {}
  68. virtual ~UPNPMiniUPNP() {}
  69. };
  70. #endif // WEB_ENABLED
  71. #endif // UPNP_MINIUPNP_H