libDwmRDAP-0.1.4
DwmRDAPFetcher.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $Name:$
3 // @(#) $Id: DwmRDAPFetcher.hh 9156 2017-04-19 05:36:59Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2017
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMRDAPFETCHER_HH_
43 #define _DWMRDAPFETCHER_HH_
44 
45 #include <map>
46 #include <string>
47 #include <vector>
48 
49 #include "DwmIpv4Prefix.hh"
50 #include "DwmSocket.hh"
51 #include "DwmTimeValue64.hh"
52 #include "DwmRDAPRequestMessage.hh"
54 
55 namespace Dwm {
56 
57  namespace RDAP {
58 
59  //------------------------------------------------------------------------
62  //------------------------------------------------------------------------
64  {
65  public:
66  //----------------------------------------------------------------------
68  //----------------------------------------------------------------------
69  FetchedEntry() = default;
70 
71  //----------------------------------------------------------------------
75  //----------------------------------------------------------------------
76  FetchedEntry(const Ipv4Prefix & prefix, const std::string & country,
77  const TimeValue64 & lastUpdated);
78 
79  //----------------------------------------------------------------------
81  //----------------------------------------------------------------------
82  const Ipv4Prefix & Prefix() const;
83 
84  //----------------------------------------------------------------------
86  //----------------------------------------------------------------------
87  const Ipv4Prefix & Prefix(const Ipv4Prefix & prefix);
88 
89  //----------------------------------------------------------------------
91  //----------------------------------------------------------------------
92  const std::string & Country() const;
93 
94  //----------------------------------------------------------------------
96  //----------------------------------------------------------------------
97  const std::string & Country(const std::string & country);
98 
99  //----------------------------------------------------------------------
103  //----------------------------------------------------------------------
104  const TimeValue64 & LastUpdated() const;
105 
106  //----------------------------------------------------------------------
110  //----------------------------------------------------------------------
111  const TimeValue64 & LastUpdated(const TimeValue64 & lastUpdated);
112 
113  private:
114  Ipv4Prefix _prefix;
115  std::string _country;
116  TimeValue64 _lastUpdated;
117  };
118 
119  typedef std::map<Ipv4Address,FetchedEntry> FetchedEntryMap;
120 
121  //------------------------------------------------------------------------
124  //------------------------------------------------------------------------
125  class Fetcher
126  {
127  public:
128  //----------------------------------------------------------------------
130  //----------------------------------------------------------------------
131  Fetcher();
132 
133  //----------------------------------------------------------------------
143  //----------------------------------------------------------------------
144  bool OpenSession(const std::string & server,
145  const std::string & privKeyPath,
146  const std::string & knownServicesPath);
147 
148  //----------------------------------------------------------------------
150  //----------------------------------------------------------------------
151  ~Fetcher();
152 
153  //----------------------------------------------------------------------
159  //----------------------------------------------------------------------
160  FetchedEntryMap GetEntries(const std::vector<Ipv4Address> & addrs);
161 
162  //----------------------------------------------------------------------
168  //----------------------------------------------------------------------
169  std::pair<bool,FetchedEntry> GetEntry(const Ipv4Address & addr);
170 
171  //----------------------------------------------------------------------
173  //----------------------------------------------------------------------
174  void CloseSession();
175 
176  private:
177  Socket _rdapSocket;
178  std::string _agreedKey;
179 
180  bool RequestResponse(const RequestMessage & request,
181  ResponseMessage & response);
182  static bool ResponseEntryHasData(const Json::Value & jv);
183  };
184 
185  } // namespace RDAP
186 
187 } // namespace Dwm
188 
189 #endif // _DWMRDAPFETCHER_HH_
Encapsulates the IPv4 prefix, country code and lastUpdated parts of a response from dwmrdapd...
Definition: DwmRDAPFetcher.hh:63
const std::string & Country() const
Returns the contained country code.
NOT YET DOCUMENTED.
Encapsulates interaction with dwmrdapd for fetching IPv4 prefix and country information for IPv4 host...
Definition: DwmRDAPFetcher.hh:125
const Ipv4Prefix & Prefix() const
Returns the contained IPv4 prefix.
Definition: DwmCountryCode.hh:53
FetchedEntry()=default
Default constructor.
NOT YET DOCUMENTED.
const TimeValue64 & LastUpdated() const
Returns the contained &#39;last updated&#39; field.