2
0

ZeroconfAuthenticator.h 1.3 KB

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