classify.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #ifndef CLASSIFY_H
  7. #define CLASSIFY_H
  8. #include <set>
  9. #include <string>
  10. /// @file classify.h
  11. ///
  12. /// @brief Defines elements for storing the names of client classes
  13. ///
  14. /// This file defines common elements used to track the client classes
  15. /// that may be associated with a given packet. In order to minimize the
  16. /// exposure of the DHCP library to server side concepts such as client
  17. /// classification the classes herein provide a mechanism to maintain lists
  18. /// of class names, rather than the classes they represent. It is the
  19. /// upper layers' perogative to use these names as they see fit.
  20. ///
  21. /// @todo This file should be moved to dhcpsrv eventually as the classification
  22. /// is server side concept. Client has no notion of classifying incoming server
  23. /// messages as it usually talks to only one server. That move is not possible
  24. /// yet, as the Pkt4 and Pkt6 classes have server-side implementation, even
  25. /// though they reside in the dhcp directory.
  26. namespace isc {
  27. namespace dhcp {
  28. /// @brief Defines a single class name.
  29. typedef std::string ClientClass;
  30. /// @brief Container for storing client class names
  31. ///
  32. /// Depending on how you look at it, this is either a little more than just
  33. /// a set of strings or a client classifier that performs access control.
  34. /// For now, it is a simple access list that may contain zero or more
  35. /// class names. It is expected to grow in complexity once support for
  36. /// client classes becomes more feature rich.
  37. ///
  38. /// Note: This class is derived from std::set which may not have Doxygen
  39. /// documentation. See http://www.cplusplus.com/reference/set/set/.
  40. class ClientClasses : public std::set<ClientClass> {
  41. public:
  42. /// @brief Default constructor.
  43. ClientClasses() : std::set<ClientClass>() {
  44. }
  45. /// @brief Constructor from comma separated values.
  46. ///
  47. /// @param class_names A string containing a client classes separated
  48. /// with commas. The class names are trimmed before insertion to the set.
  49. ClientClasses(const std::string& class_names);
  50. /// @brief returns if class x belongs to the defined classes
  51. ///
  52. /// @param x client class to be checked
  53. /// @return true if x belongs to the classes
  54. bool
  55. contains(const ClientClass& x) const {
  56. return (find(x) != end());
  57. }
  58. /// @brief Returns all class names as text
  59. ///
  60. /// @param separator Separator to be used between class names. The
  61. /// default separator comprises comma sign followed by space
  62. /// character.
  63. std::string toText(const std::string& separator = ", ") const;
  64. };
  65. };
  66. };
  67. #endif /* CLASSIFY_H */