Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Opt.h
Go to the documentation of this file.
1 /*
2  * Dibbler - a portable DHCPv6
3  *
4  * authors: Tomasz Mrugalski <thomson@klub.com.pl>
5  * Marek Senderski <msend@o2.pl>
6  *
7  * released under GNU GPL v2 only licence
8  *
9  */
10 
11 #ifndef OPT_H
12 #define OPT_H
13 
14 #include <stdint.h>
15 #include <list>
16 #include "SmartPtr.h"
17 #include "Container.h"
18 #include "DUID.h"
19 
20 class TMsg;
21 class TOpt;
22 
23 typedef SPtr<TOpt> TOptPtr;
24 typedef std::list< TOptPtr > TOptList;
25 typedef TContainer< TOptPtr > TOptContainer;
26 
27 class TOpt
28 {
29  public:
30 
32  const static size_t OPTION6_HDR_LEN = 4;
33 
34  /* this is required to specify, what is the format of expected options.
35  This cannot be class field or method, because there is no object
36  to hold that information. Option object is created when requested
37  option is received. */
38  typedef enum {
45  } EOptionLayout;
46 
47  TOpt(int optType, TMsg* parent);
48  virtual ~TOpt();
49 
58  virtual size_t getSize() = 0;
59 
67  virtual char * storeSelf(char* buf) = 0;
68  virtual bool doDuties() = 0;
69 
75  virtual bool isValid() const;
76 
77  virtual std::string getPlain();
78 
79  int getOptType();
80 
81  TOptPtr getOption(int type);
82 
83  // suboptions management
84  void firstOption();
86  void addOption(TOptPtr opt);
87  bool delOption(uint16_t type);
88  int countOption();
89  void delAllOptions();
90  void setParent(TMsg* Parent);
91 
92  static bool parseOptions(TOptContainer& options,
93  const char* buf,
94  size_t len,
95  TMsg* parent,
96  uint16_t placeId = 0, // 5 (option 5) or (message 5)
97  std::string place = "option" // "option" or "message"
98  );
99 
100  static TOptPtr getOption(const TOptList& list, uint16_t opt_type);
101 
102  protected:
103  char* storeHeader(char* buf);
104  char* storeSubOpt(char* buf);
105  int getSubOptSize();
106 
108  int OptType;
110  bool Valid;
111 };
112 
113 #endif
114