ZeroconfAuthenticator.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef ZEROCONFAUTHENTICATOR_H
  2. #define ZEROCONFAUTHENTICATOR_H
  3. #include <vector>
  4. #include <unistd.h>
  5. #include <string>
  6. #include <BaseHTTPServer.h>
  7. #include <cstdlib>
  8. #include "Utils.h"
  9. #include "LoginBlob.h"
  10. #include "Crypto.h"
  11. #include "Task.h"
  12. #include "ConstantParameters.h"
  13. #ifdef ESP_PLATFORM
  14. #include "mdns.h"
  15. #else
  16. #include "dns_sd.h"
  17. #include <unistd.h>
  18. #endif
  19. #ifndef SOCK_NONBLOCK
  20. #define SOCK_NONBLOCK O_NONBLOCK
  21. #endif
  22. #define SERVER_PORT_MAX 65535 // Max usable tcp port
  23. #define SERVER_PORT_MIN 1024 // 0-1024 services ports
  24. typedef std::function<void(std::shared_ptr<LoginBlob>)> authCallback;
  25. class ZeroconfAuthenticator {
  26. private:
  27. int serverPort;
  28. bool authorized = false;
  29. std::unique_ptr<Crypto> crypto;
  30. std::shared_ptr<bell::BaseHTTPServer> server;
  31. authCallback gotBlobCallback;
  32. void startServer();
  33. std::string buildJsonInfo();
  34. void handleAddUser(std::map<std::string, std::string>& queryMap);
  35. void registerZeroconf();
  36. std::string getParameterFromUrlEncoded(std::string data, std::string param);
  37. public:
  38. ZeroconfAuthenticator(authCallback callback, std::shared_ptr<bell::BaseHTTPServer> httpServer);
  39. void registerHandlers();
  40. };
  41. #endif