DynDNS.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file DynDNS.h
  11. /// \brief Helper to class to update DynDNS
  12. /// This can be used to determine what permissions are should be allowed to the other system
  13. ///
  14. #include "NativeFeatureIncludes.h"
  15. #if _RAKNET_SUPPORT_DynDNS==1 && _RAKNET_SUPPORT_TCPInterface==1
  16. #ifndef __DYN_DNS_H
  17. #define __DYN_DNS_H
  18. #include "RakString.h"
  19. namespace RakNet
  20. {
  21. class TCPInterface;
  22. enum DynDnsResultCode
  23. {
  24. // ----- Success -----
  25. RC_SUCCESS,
  26. RC_DNS_ALREADY_SET, // RakNet detects no action is needed
  27. // ----- Ignorable failure (treat same as success) -----
  28. RC_NO_CHANGE, // DynDNS detects no action is needed (treated as abuse though)
  29. // ----- User error -----
  30. RC_NOT_DONATOR, // You have to pay to do this
  31. RC_NO_HOST, // This host does not exist at all
  32. RC_BAD_AUTH, // You set the wrong password
  33. RC_NOT_YOURS, // This is not your host
  34. // ----- Permanent failure -----
  35. RC_ABUSE, // Your host has been blocked, too many failures disable your account
  36. RC_TCP_FAILED_TO_START, // TCP port already in use
  37. RC_TCP_DID_NOT_CONNECT, // DynDNS down?
  38. RC_UNKNOWN_RESULT, // DynDNS returned a result code that was not documented as of 12/4/2010 on http://www.dyndns.com/developers/specs/flow.pdf
  39. RC_PARSING_FAILURE, // Can't read the result returned, format change?
  40. RC_CONNECTION_LOST_WITHOUT_RESPONSE, // Lost the connection to DynDNS while communicating
  41. RC_BAD_AGENT, // ???
  42. RC_BAD_SYS, // ???
  43. RC_DNS_ERROR, // ???
  44. RC_NOT_FQDN, // ???
  45. RC_NUM_HOST, // ???
  46. RC_911, // ???
  47. RC_DYNDNS_TIMEOUT // DynDNS did not respond
  48. };
  49. // Can only process one at a time with the current implementation
  50. class RAK_DLL_EXPORT DynDNS
  51. {
  52. public:
  53. DynDNS();
  54. ~DynDNS();
  55. // Pass 0 for newIPAddress to autodetect whatever you are uploading from
  56. // usernameAndPassword should be in the format username:password
  57. void UpdateHostIPAsynch(const char *dnsHost, const char *newIPAddress, const char *usernameAndPassword );
  58. void Update(void);
  59. // Output
  60. bool IsRunning(void) const {return connectPhase!=CP_IDLE;}
  61. bool IsCompleted(void) const {return connectPhase==CP_IDLE;}
  62. RakNet::DynDnsResultCode GetCompletedResultCode(void) {return result;}
  63. const char *GetCompletedDescription(void) const {return resultDescription;}
  64. bool WasResultSuccessful(void) const {return result==RC_SUCCESS || result==RC_DNS_ALREADY_SET || result==RC_NO_CHANGE;}
  65. char *GetMyPublicIP(void) const {return (char*) myIPStr;} // We get our public IP as part of the process. This is valid once completed
  66. protected:
  67. void Stop(void);
  68. void SetCompleted(RakNet::DynDnsResultCode _result, const char *_resultDescription) {Stop(); result=_result; resultDescription=_resultDescription;}
  69. enum ConnectPhase
  70. {
  71. CP_CONNECTING_TO_CHECKIP,
  72. CP_WAITING_FOR_CHECKIP_RESPONSE,
  73. CP_CONNECTING_TO_DYNDNS,
  74. CP_WAITING_FOR_DYNDNS_RESPONSE,
  75. CP_IDLE
  76. };
  77. TCPInterface *tcp;
  78. RakNet::RakString getString;
  79. SystemAddress serverAddress;
  80. ConnectPhase connectPhase;
  81. RakNet::RakString host;
  82. RakNet::Time phaseTimeout;
  83. SystemAddress checkIpAddress;
  84. const char *resultDescription;
  85. RakNet::DynDnsResultCode result;
  86. char myIPStr[32];
  87. };
  88. } // namespace RakNet
  89. #endif // __DYN_DNS_H
  90. #endif // _RAKNET_SUPPORT_DynDNS
粤ICP备19079148号