BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
AbstractHTTPScanner.h
1 #pragma once
2 
3 #include <set>
4 
5 #include <Poco/Net/HTTPRequest.h>
6 #include <Poco/Net/IPAddress.h>
7 #include <Poco/Net/NetworkInterface.h>
8 #include <Poco/Net/SocketAddress.h>
9 #include <Poco/Timespan.h>
10 
11 #include "loop/StopControl.h"
12 #include "net/HTTPEntireResponse.h"
13 #include "net/IPAddressRange.h"
14 #include "util/Loggable.h"
15 
16 namespace BeeeOn {
17 
24 class AbstractHTTPScanner : protected Loggable {
25 public:
32  AbstractHTTPScanner(const std::string& path, uint16_t port, const Poco::Net::IPAddress& minNetMask);
34 
41  std::vector<Poco::Net::SocketAddress> scan(const uint32_t maxResponseLength);
42 
43  void cancel();
44 
45  void setPath(const std::string& path);
46  void setPort(Poco::UInt16 port);
47  void setMinNetMask(const Poco::Net::IPAddress& minNetMask);
48  void setPingTimeout(const Poco::Timespan& pingTimeout);
49  void setHTTPTimeout(const Poco::Timespan& httpTimeout);
50  void setBlackList(const std::set<std::string>& set);
51 
52  std::string path();
53  Poco::UInt16 port();
54 
55 protected:
56  virtual void prepareRequest(Poco::Net::HTTPRequest& request) = 0;
62  virtual bool isValidResponse(const std::string& response) = 0;
63 
71  void probeInterface(
72  StopControl::Run &run,
73  const Poco::Net::NetworkInterface& interface,
74  std::vector<Poco::Net::SocketAddress>& devices,
75  const Poco::Int64 maxResponseLength);
76 
84  void probeAddressRange(
85  StopControl::Run &run,
86  const IPAddressRange& range,
87  std::vector<Poco::Net::SocketAddress>& devices,
88  const Poco::Int64 maxResponseLength);
89 
97  HTTPEntireResponse sendRequest(const Poco::Net::SocketAddress& socketAddress,
98  const Poco::Int64 maxResponseLength);
99 
100  bool addressIncompatible(const Poco::Net::NetworkInterface::AddressTuple& addressTuple) const;
101 
105  std::vector<Poco::Net::NetworkInterface> listNetworkInterfaces();
106 
107 private:
108  std::string m_path;
109  uint16_t m_port;
110  Poco::Net::IPAddress m_minNetMask;
111  Poco::Timespan m_pingTimeout;
112  Poco::Timespan m_httpTimeout;
113  std::set<std::string> m_blackList;
114  StopControl m_stopControl;
115 };
116 
117 }
HTTPEntireResponse sendRequest(const Poco::Net::SocketAddress &socketAddress, const Poco::Int64 maxResponseLength)
It sends HTTP request.
Definition: AbstractHTTPScanner.cpp:177
Helper class for managing a common stoppable loop situation:
Definition: StopControl.h:35
Definition: IPAddressRange.h:19
std::vector< Poco::Net::SocketAddress > scan(const uint32_t maxResponseLength)
It executes the scan of proper network interfaces.
Definition: AbstractHTTPScanner.cpp:74
Definition: HTTPEntireResponse.h:13
std::vector< Poco::Net::NetworkInterface > listNetworkInterfaces()
Definition: AbstractHTTPScanner.cpp:207
void probeAddressRange(StopControl::Run &run, const IPAddressRange &range, std::vector< Poco::Net::SocketAddress > &devices, const Poco::Int64 maxResponseLength)
It explores IP address range.
Definition: AbstractHTTPScanner.cpp:125
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
virtual bool isValidResponse(const std::string &response)=0
It defines if the response is valid or not.
void probeInterface(StopControl::Run &run, const Poco::Net::NetworkInterface &interface, std::vector< Poco::Net::SocketAddress > &devices, const Poco::Int64 maxResponseLength)
It explores network interface.
Definition: AbstractHTTPScanner.cpp:95
Definition: Loggable.h:19
The abstract class contains core of HTTP scanning of network. Derivated classes will have to implemen...
Definition: AbstractHTTPScanner.h:24