NetBurner 3.5.7
PDF Version
config_obj.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
47#ifndef CONFIG_OBJ_H
48#define CONFIG_OBJ_H
49
50#include <buffers.h>
51#include <nbstring.h>
52#include <string.h>
53#include <utils.h>
54#include <limits.h>
55#include <float.h>
56
57void ShowTree();
58
59enum ConfigTestResult
60{
61 eUnchanged,
62 eOk,
63 eBad
64};
65
66
67
75const uint32_t fConfigValueLeaf = 0x01;
76const uint32_t fConfigReadOnly = 0x02;
77const uint32_t fConfigModified = 0x04;
78const uint32_t fConfigHidden = 0x08;
79const uint32_t fConfigNoSave = 0x10;
80const uint32_t fConfigNoObscure = 0x20;
81const uint32_t fConfigNeedReboot = 0x40;
82const uint32_t fConfigNoReload = 0x80;
83const uint32_t fConfigDetached = 0x100;
84const uint32_t fConfigIsDefault= 0x200;
85const uint32_t fMaskDoingSave = 0x40000000;
88/* Config Mask Values */
89const uint32_t PermitFlashFromStorage = (0x80000000);
90
91class config_leaf;
92class config_obj;
94class RootParseStateInfo;
95class ConfigNotificationObject;
96
97
98class notify_list
99{
100 volatile uint32_t bits;
101 public:
102 // The following functions are all guaranteed to be atomic
103 void set(const notify_list & nl) volatile;
104 void set(int set_num) volatile;
105 void clr(int clr_num) volatile;
106 notify_list() {bits=0;}
107 notify_list(const notify_list &l) {bits=l.bits;}
108 // The following functions return 0 if no bits are set.
109 uint32_t gethigh() volatile;
110 inline uint32_t get_high_and_clear() volatile {uint32_t h = gethigh(); clr(h); return h;}
111 inline bool AnySet() volatile const { return (bits!=0);};
112 inline uint32_t getmask()volatile {return bits; };
113};
114
115
116
117
118typedef void(LeafCallBack)(config_leaf *p, void *pextra);
119
120/*
121 * Configuration leaf class.
122 * Used to manage the configuration tree, internal use only.
123 */
124class config_leaf
125{
126 // We explicitly *do not allow* copy construction, as the only likely usage
127 // would be passing to variadic functions *which will not know this is non-POD*
128 config_leaf(config_leaf &rhs) = delete;
129 protected:
130 config_leaf *FindChild(const char *&cp);
131 void RootParse(RootParseStateInfo &rpsi);
132 static void FixTree(config_leaf* root);
133
134
135 virtual void RemoveFromRootList();
136 public:
137 virtual void RawFdPrintTree(int fd, int n, bool pretty, uint32_t mask, bool braw_values,bool valonly) = 0;
138
139 inline void FdPrintValTree(int fd, int n, bool pretty, uint32_t inhibit_mask = fConfigHidden, bool bRawValue = false)
140 {
141 RawFdPrintTree(fd,n,pretty,inhibit_mask,bRawValue,true);
142 }
143 inline void FdPrintTree(int fd, int n, bool pretty, uint32_t inhibit_mask = fConfigHidden, bool bRawValue = false)
144 {
145 RawFdPrintTree(fd,n,pretty,inhibit_mask,bRawValue,false);
146 }
147
148 virtual void FdPrintSchema(int fd, config_leaf *pl, int n, bool pretty, uint32_t inhibit_mask = fConfigHidden);
149 void SchemaOptions(int fd, int indent, bool pretty);
150 void ForEachLeaf(LeafCallBack *pc, void *pextra, bool siblings = false);
151 bool FlatParseBuffer(fifo_buffer_storage &rxbuf, uint32_t permissions, const char *where);
152 bool ParseBuffer(fifo_buffer_storage &rxbuf, uint32_t permissions, const char *where);
153 bool ParseBlob(uint8_t *pdata, int len, uint32_t permissions);
154 bool FlatParseBlob(uint8_t *pdata, int len, uint32_t permissions);
155 bool ParseFd(int fd, uint32_t permissions, config_leaf * pParseRoot = NULL);
156 config_obj *FindParent() { return pParent; };
157 static config_leaf *FindConfigLeaf(const unsigned char *name, config_leaf *pBranch = NULL);
158
159 void AddNotification(ConfigNotificationObject & noteobj);
160
161
162 //Call if a config object is not static
163 void FixNonStaticObject();
164
165 void RemoveFromConfigTree();
166
167 const char *pName;
168 const char *pDescription;
169 config_leaf *pNextSibling;
170 config_obj *pParent;
171 config_leaf *pChildren;
172 config_leaf *pGList;
173 notify_list NotifyListMask;
174
175
176 static config_leaf *pRootList;
177 static config_leaf *pDetachList;
178
179 uint32_t m_Flags;
180 void DoSchemaLine(int fd, const char *name, const char *value, int indent, bool pretty, bool quoted = true);
181 void DoSchemaLine(int fd, const char *name, int value, int indent, bool pretty, bool quoted = true);
182 void DoSchemaLine(int fd, const char *name, double value, int indent, bool pretty, bool quoted = true);
183
184 public:
185 bool NameMatch(const char *cp);
186 virtual const char *GetSortNameValue() { return pName; };
187 virtual void GetDescriptionValue(NBString &s) { s = pDescription; };
188 virtual void GetNameValue(NBString &s) { s = pName; };
189 virtual void GetTextValue(NBString &s) { s = pName; };
190 virtual void GetRawValue(NBString &s) { return GetTextValue(s); };
191 virtual void GetTypeValue(NBString &s) { s = "unknown"; };
192 virtual void ExtendedSchema(int fd, int indent, bool pretty){};
193 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) { return eOk; };
194 // This is named so error messages make sense to user
195 // Old name was GetExtent
196 virtual int Missing_ConfigEndMarker(void *&startp) = 0;
197
198 void ClearModified();
199
200 bool MatchId(ParsedJsonDataSet &pjs);
201
202 virtual bool CheckGroupValues() {return true;}
203 virtual void CommitTestedValue(uint32_t permission_mask){};
204
205 virtual ~config_leaf();
206
207 config_leaf(bool bDetached=false)
208 {
209 pNextSibling = NULL;
210 pChildren = NULL;
211 m_Flags = fConfigIsDefault;
212 pParent = NULL;
213 if (bDetached)
214 {
215 pGList=pDetachList;
216 pDetachList=this;
217 m_Flags|=fConfigDetached;
218 }
219 else
220 {
221 pGList = pRootList;
222 pRootList = this;
223 }
224 }
225 config_leaf(config_leaf &&l);
226
227 static void DiagShow();
228 static void FixTree();
229 void FindUnknownParent();
230
231 void ShowOne();
232
233 int compare(config_leaf *pl)
234 {
235 if (pl == NULL) return -1;
236 return strcmp(GetSortNameValue(), pl->GetSortNameValue());
237 };
238
239 void GetFullName(NBString &s);
240 void GetBranchName(NBString &s, config_leaf *branchRoot);
241 void RenderToFd(int fd, bool pretty = false, uint32_t mask = fConfigHidden, bool bRawValue = false);
242 void RenderSchemaToFd(int fd, bool pretty = false, uint32_t mask = fConfigHidden);
243 uint32_t GetFlags() { return m_Flags; }
244 uint32_t GetFlags(uint32_t mask) { return m_Flags & mask; }
245 void SetFlag(uint32_t flag) { m_Flags |= flag; };
246 void SetBranchFlag(uint32_t flag, bool upNotDown = false);
247 void ClrFlag(uint32_t flag) { m_Flags &= (~flag); };
248 void ClrBranchFlag(uint32_t flag, bool upNotDown = false);
249 void ReloadFromFlash();
250 void AssignmentNotify();
251
252 void LogParseError(NBString & err);
253 inline void LogParseError(const char * err) {NBString s(err); LogParseError(s); };
254
255
256 friend void HtmlLeafRender(int fd, config_leaf *pl, int eMode, int len, const char *extra);
257 friend ConfigNotificationObject;
258};
259
320class config_obj : public config_leaf
321{
322 protected:
323 config_obj(bool bDetached=false):config_leaf(bDetached){}
324 config_obj *pMasterObjectLink;
325 static config_obj *pObjList;
326
327 virtual void RemoveFromRootList();
328 public:
329 virtual void RawFdPrintTree(int fd, int n, bool pretty, uint32_t mask, bool braw_values,bool valonly) override;
330 void InstallUnderMe(config_leaf &ltoadd);
331 void RemoveFromChildren(config_leaf &ltoremove);
332
345 config_obj(config_obj &owner, const char *name, const char *desc)
346 {
347 pName = name;
348 pDescription = desc;
349 pChildren = NULL;
350 pMasterObjectLink = pObjList;
351 pObjList = this;
352 pParent = &owner;
353 }
355
368 config_obj(const char *name, const char *desc)
369 {
370 pName = name;
371 pDescription = desc;
372 pChildren = NULL;
373 pParent = NULL;
374 pMasterObjectLink = pObjList;
375 pObjList = this;
376 }
377
378
379
380 bool DoIContain(config_leaf *pl);
381
382 /*
383 * These two functions, along with GetTextValue(), can be used to create a custom object
384 * class, including the responsibility for the JSON serialization.
385 *
386 * GetTextValue(): Must return a string with the object encoded in it in JSON format
387 *
388 * TestNewValue(): Takes a parsed JSON object and extracts the values from that tree.
389 * This is where parameters can be tested for validity, and if not valid,
390 * the entire set is marked as invalid.
391 *
392 * CommitTestedValue(): Commit the values extracted by TestNewValue()
393 *
394 * This enables functionality such as parsing a set of values to determine if the SET is
395 * valid, rather than just an individual value.
396 */
397 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
398 virtual void CommitTestedValue(uint32_t permission_mask) override;
399
400 // This is named so error messages make sense to user, old name was GetExtent
401 virtual int Missing_ConfigEndMarker(void *&startp) override
402 {
403 startp = this;
404 return sizeof(*this);
405 };
406
414 virtual void GetTextValue(NBString &s) override;
415
423 virtual void GetTypeValue(NBString &s) override { s = "object"; };
424
425 friend class config_leaf;
426};
427
428/*
429 * Configuration Root object class
430 */
431class root_obj : public config_obj
432{
433 public:
434 root_obj()
435 { pName = "Config";
436 pDescription = "Root of config tree";
437 }
438
439 // This is named so error messages make sense to user, old name was GetExtent
440 virtual int Missing_ConfigEndMarker(void *&startp) override
441 {
442 startp = this;
443 return sizeof(*this);
444 };
445};
446
447class detached_root_obj : public config_obj
448{
449 public:
450 detached_root_obj():config_obj(true)
451 { pName = "detached";
452 pDescription = "Root of detached tree";
453 }
454
455 // This is named so error messages make sense to user, old name was GetExtent
456 virtual int Missing_ConfigEndMarker(void *&startp) override
457 {
458 startp = this;
459 return sizeof(*this);
460 };
461};
462
463
464
465
466extern root_obj root;
467extern detached_root_obj detached;
468
490class config_value : public config_leaf
491{
492 public:
493 virtual void GetTextValue(NBString &s) override = 0;
494
495 protected:
508 config_value(config_obj &owner, const char *name, const char *desc)
509 {
510 pName = name;
511 pDescription = desc;
512 owner.InstallUnderMe(*this);
513 pChildren = NULL;
514 m_Flags |= fConfigValueLeaf;
515 }
516
529 config_value(const char *name, const char *desc)
530 {
531 pName = name;
532 pDescription = desc;
533 pParent = NULL;
534 pChildren = NULL;
535 m_Flags |= fConfigValueLeaf;
536 }
537
539 virtual int FdPrintValue(int fd, bool raw);
540
541public:
542 virtual void RawFdPrintTree(int fd, int n, bool pretty, uint32_t mask, bool braw_values,bool valonly) override;
543};
544
553{
554 protected:
555 uint32_t val;
556 uint32_t pend_val;
557
558 virtual int FdPrintValue(int fd, bool raw) override;
559 public:
567 virtual void GetTextValue(NBString &s) override { s.siprintf("%u", val); };
568
577 config_uint(config_obj &owner, uint32_t def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
578 {
579 val = def_val;
580 pend_val = val;
581 }
582
590 config_uint(uint32_t def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
591 {
592 val = def_val;
593 pend_val = val;
594 }
595
597
598 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
599 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
600
601 // Assignment operators
602
614 operator uint32_t() const { return val; };
615
621 config_uint &operator=(const uint32_t i)
622 {
623 pend_val = val = i;
624 if (GetFlags(fConfigIsDefault))
625 ClrBranchFlag(fConfigIsDefault, true);
626 return *this;
627 };
628
635 {
636 pend_val = val = ci.val;
637 if (GetFlags(fConfigIsDefault))
638 ClrBranchFlag(fConfigIsDefault, true);
639 return *this;
640 };
641
642 // This is named so error messages make sense to user. Old name was GetExtent
643 virtual int Missing_ConfigEndMarker(void *&startp) override
644 {
645 startp = this;
646 return sizeof(*this);
647 };
648
656 virtual void GetTypeValue(NBString &s) override { s = "integer"; };
657};
658
659class config_hex_uint : public config_uint
660{
661
662 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs);
663
664protected:
665 virtual int FdPrintValue(int fd, bool raw) override;
666public:
675 config_hex_uint(config_obj &owner, uint32_t def_val, const char *name, const char *desc = NULL) : config_uint(owner,def_val, name, desc){}
676
684 config_hex_uint(uint32_t def_val, const char *name, const char *desc = NULL) : config_uint(def_val,name, desc){}
685
686 virtual void GetTextValue(NBString &s) override { s.siprintf("\"0x%X\"", val); };
687 virtual void GetTypeValue(NBString &s) override { s = "string"; };
688
689};
690
691
692
701{
702 protected:
703 int val;
704 int pend_val;
705
706 virtual int FdPrintValue(int fd, bool raw) override;
707 public:
715 virtual void GetTextValue(NBString &s) override { s.siprintf("%d", val); };
716
725 config_int(config_obj &owner, int def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
726 {
727 val = def_val;
728 pend_val = val;
729 }
730
738 config_int(int def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
739 {
740 val = def_val;
741 pend_val = val;
742 }
743
745
746 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
747
748 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
749
750 // Assignment operators
751
763 operator int() const { return val; };
764
770 config_int &operator=(const int i)
771 {
772 pend_val = val = i;
773 if (GetFlags(fConfigIsDefault))
774 ClrBranchFlag(fConfigIsDefault, true);
775 return *this;
776 };
777
785 {
786 pend_val = val = ci.val;
787 if (GetFlags(fConfigIsDefault))
788 ClrBranchFlag(fConfigIsDefault, true);
789 return *this;
790 };
791
792 // This is named so error messages make sense to user, old name was GetExtent
793 virtual int Missing_ConfigEndMarker(void *&startp) override
794 {
795 startp = this;
796 return sizeof(*this);
797 };
798
806 virtual void GetTypeValue(NBString &s) override { s = "integer"; };
807};
808
817{
818 protected:
819 double val;
820 double pend_val;
821
822 virtual int FdPrintValue(int fd, bool raw) override;
823 public:
831 virtual void GetTextValue(NBString &s) override { s.sprintf("%g", val); };
832
841 config_double(config_obj &owner, double def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
842 {
843 val = def_val;
844 pend_val = val;
845 }
846
854 config_double(double def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
855 {
856 val = def_val;
857 pend_val = val;
858 }
859
861
862 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
863 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
864
865 // Assignment operators
866
878 operator int() const { return val; };
879
891 operator float() const { return val; };
892
904 operator double() const { return val; };
905
911 config_double &operator=(const double d)
912 {
913 pend_val = val = d;
914 if (GetFlags(fConfigIsDefault))
915 ClrBranchFlag(fConfigIsDefault, true);
916 return *this;
917 };
918
925 {
926 pend_val = val = ci.val;
927 if (GetFlags(fConfigIsDefault))
928 ClrBranchFlag(fConfigIsDefault, true);
929 return *this;
930 };
931
932 // This is named so error messages make sense to user. old name was GetExtent
933 virtual int Missing_ConfigEndMarker(void *&startp) override
934 {
935 startp = this;
936 return sizeof(*this);
937 };
938
948 virtual void GetTypeValue(NBString &s) override { s = "string"; };
949};
950
951/*
952 * Class used for system status reports, for internal use only
953 */
954class config_report : public config_value
955{
956 protected:
957 const char *m_value;
958
959 virtual int FdPrintValue(int fd, bool raw) override;
960 public:
961 config_report(config_obj &owner, const char *value, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
962 {
963 m_Flags = fConfigReadOnly | fConfigNoSave;
964 m_value = value;
965 }
966 config_report(const char *value, const char *name, const char *desc = NULL) : config_value(name, desc)
967 {
968 m_Flags = fConfigReadOnly | fConfigNoSave;
969 m_value = value;
970 }
971
972 config_report(config_report &&r);
973
974 virtual void GetTextValue(NBString &s) override;
975 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
976 virtual void CommitTestedValue(uint32_t permission_mask) override;
977 // This is named so error messages make sense to user
978 // Old name was GetExtent
979 virtual int Missing_ConfigEndMarker(void *&startp) override
980 {
981 startp = this;
982 return sizeof(*this);
983 };
984 virtual void GetTypeValue(NBString &s) override { s = "string"; };
985
986 const char *c_str() { return m_value; };
987 void ModifyValue(const char *nv) { m_value = nv; };
988};
989
998{
999 protected:
1000 bool val;
1001 bool pend_val;
1002
1003 virtual int FdPrintValue(int fd, bool raw) override;
1004 public:
1012 virtual void GetTextValue(NBString &s) override
1013 {
1014 if (val)
1015 s = "true";
1016 else
1017 s = "false";
1018 };
1019
1028 config_bool(config_obj &owner, bool def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1029 {
1030 val = def_val;
1031 pend_val = val;
1032 }
1033
1041 config_bool(bool def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1042 {
1043 val = def_val;
1044 pend_val = val;
1045 }
1047
1048 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1049 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1050
1051 // Assignemt operators
1052
1064 operator bool() const { return val; };
1065
1071 config_bool &operator=(const bool v)
1072 {
1073 pend_val = val = v;
1074 if (GetFlags(fConfigIsDefault))
1075 ClrBranchFlag(fConfigIsDefault, true);
1076 return *this;
1077 };
1078
1085 {
1086 pend_val = val = cb.val;
1087 if (GetFlags(fConfigIsDefault))
1088 ClrBranchFlag(fConfigIsDefault, true);
1089 return *this;
1090 };
1091
1098 {
1099 pend_val = val = (i != 0);
1100 if (GetFlags(fConfigIsDefault))
1101 ClrBranchFlag(fConfigIsDefault, true);
1102 return *this;
1103 };
1104
1105 // This is named so error messages make sense to user, old name was GetExtent
1106 virtual int Missing_ConfigEndMarker(void *&startp)
1107 {
1108 startp = this;
1109 return sizeof(*this);
1110 };
1111
1117 virtual void GetTypeValue(NBString &s) override { s = "boolean"; };
1118};
1119
1128{
1129 protected:
1130 NBString val;
1131 NBString pend_val;
1132 NBString enum_list;
1133
1134 virtual int FdPrintValue(int fd, bool raw) override;
1135 public:
1143 virtual void GetTextValue(NBString &s) override;
1144// {
1145// s = "\"";
1146// s += val;
1147// s += "\"";
1148// };
1149
1151
1152 const char * GetPendValue() {return pend_val.c_str();};
1153
1164 config_string(config_obj &owner, NBString def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1165 {
1166 val = def_val;
1167 pend_val = val;
1168 }
1169
1179 config_string(NBString def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1180 {
1181 pName = name;
1182 val = def_val;
1183 pend_val = val;
1184 }
1185
1196 config_string(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1197 {
1198 val = def_val;
1199 pend_val = val;
1200 }
1201
1211 config_string(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1212 {
1213 val = def_val;
1214 pend_val = val;
1215 }
1216
1217 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1218 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1219
1226 void SetEnumList(NBString s) { enum_list = s; };
1227
1228 // Assignment Operators
1229
1235 operator NBString() const { return val; };
1236
1242 config_string &operator=(const char *p)
1243 {
1244 pend_val = val = p;
1245 if (GetFlags(fConfigIsDefault))
1246 ClrBranchFlag(fConfigIsDefault, true);
1247 return *this;
1248 };
1249
1256 {
1257 pend_val = val = s;
1258 if (GetFlags(fConfigIsDefault))
1259 ClrBranchFlag(fConfigIsDefault, true);
1260 return *this;
1261 };
1262
1269 {
1270 pend_val = val = ci.val;
1271 if (GetFlags(fConfigIsDefault))
1272 ClrBranchFlag(fConfigIsDefault, true);
1273 return *this;
1274 };
1275
1276 // This is named so error messages make sense to user, old name was GetExtent
1277 virtual int Missing_ConfigEndMarker(void *&startp) override
1278 {
1279 startp = this;
1280 return sizeof(*this);
1281 };
1282
1288 inline const char *c_str() const { return val.c_str(); };
1289
1295 inline size_t length() const { return val.length(); };
1296
1304 inline const char &operator[](size_t pos) const { return val[pos]; };
1305
1313 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1314
1315 virtual void ExtendedSchema(int fd, int indent, bool pretty);
1316
1317 /* *
1318 * @brief Perform a string interpolation and place the finished interpolation
1319 * in the Destination string
1320 *
1321 * @param dest Destination string
1322 *
1323 * @returns Whether the interpolation was successful
1324 */
1325 bool Interpolate(NBString &dest)
1326 {
1327 return val.Interpolate(dest);
1328 }
1329
1330 friend class config_pass;
1331 friend class config_localname;
1332 friend class config_chooser;
1333 friend class config_localname;
1334};
1335
1346{
1347 protected:
1348 virtual int FdPrintValue(int fd, bool raw) override;
1349 public:
1360 config_pass(config_obj &owner, NBString def_val, const char *name, const char *desc = NULL)
1361 : config_string(owner, def_val, name, desc){};
1362
1372 config_pass(NBString def_val, const char *name, const char *desc = NULL) : config_string(def_val, name, desc){};
1373
1384 config_pass(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL)
1385 : config_string(owner, def_val, name, desc){};
1386
1396 config_pass(const char *def_val, const char *name, const char *desc = NULL) : config_string(def_val, name, desc){};
1397
1399
1407 virtual void GetTextValue(NBString &s) override;
1408
1416 virtual void GetRawValue(NBString &s) override;
1417
1418 virtual void CommitTestedValue(uint32_t permission_mask) override;
1419
1420 // Add help pop-ups for web page display
1421 virtual void ExtendedSchema(int fd, int indent, bool pretty)
1422 {
1423 config_string::ExtendedSchema(fd, indent, pretty);
1424 DoSchemaLine(fd, "format", "password", indent, pretty);
1425 };
1426
1432 operator NBString() const { return val; };
1433
1439 config_pass &operator=(const char *p)
1440 {
1441 pend_val = val = p;
1442 if (GetFlags(fConfigIsDefault))
1443 ClrBranchFlag(fConfigIsDefault, true);
1444 return *this;
1445 };
1446
1453 {
1454 pend_val = val = s;
1455 if (GetFlags(fConfigIsDefault))
1456 ClrBranchFlag(fConfigIsDefault, true);
1457 return *this;
1458 };
1459
1466 {
1467 pend_val = val = ci.val;
1468 if (GetFlags(fConfigIsDefault))
1469 ClrBranchFlag(fConfigIsDefault, true);
1470 return *this;
1471 };
1472
1479 {
1480 pend_val = val = ci.val;
1481 if (GetFlags(fConfigIsDefault))
1482 ClrBranchFlag(fConfigIsDefault, true);
1483 return *this;
1484 };
1485};
1486
1487
1488class I4Record;
1498{
1499 IPADDR4 val;
1500 IPADDR4 pend_val;
1501
1502 protected:
1503 virtual int FdPrintValue(int fd, bool raw) override;
1504 public:
1513 virtual void GetTextValue(NBString &s) override { s.siprintf("\"%hI\"", val); };
1514
1525 config_IPADDR4(config_obj &owner, IPADDR4 def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1526 {
1527 val = def_val;
1528 pend_val = val;
1529 }
1530
1540 config_IPADDR4(IPADDR4 def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1541 {
1542 val = def_val;
1543 pend_val = val;
1544 }
1545
1547
1558 config_IPADDR4(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1559 {
1560 IPADDR4 i4;
1561 i4.SetFromAscii(def_val);
1562 val = i4;
1563 pend_val = val;
1564 }
1565
1575 config_IPADDR4(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1576 {
1577 IPADDR4 i4;
1578 i4.SetFromAscii(def_val);
1579 val = i4;
1580 pend_val = val;
1581 }
1582
1583 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1584 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1585
1586 // Assignment operators
1587
1593 operator IPADDR4() const { return val; };
1594
1602 inline bool IsNull() const { return val.IsNull(); };
1603
1611 inline bool NotNull() const { return !(val.IsNull()); };
1612
1618 inline void SetNull()
1619 {
1620 val.SetNull();
1621 pend_val = val;
1622 };
1623
1630 {
1631 pend_val = val = i4;
1632 if (GetFlags(fConfigIsDefault))
1633 ClrBranchFlag(fConfigIsDefault, true);
1634 return *this;
1635 };
1636
1643 {
1644 pend_val = val = ci.val;
1645 if (GetFlags(fConfigIsDefault))
1646 ClrBranchFlag(fConfigIsDefault, true);
1647 return *this;
1648 };
1649
1650 // This is named so error messages make sense to user, old name was GetExtent
1651 virtual int Missing_ConfigEndMarker(void *&startp)
1652 {
1653 startp = this;
1654 return sizeof(*this);
1655 };
1656
1664 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1665
1666 // Add web page help
1667 virtual void ExtendedSchema(int fd, int indent, bool pretty) { DoSchemaLine(fd, "format", "ipv4", indent, pretty); };
1668 friend I4Record;
1669};
1670
1671#ifdef IPV6
1681{
1682 IPADDR val;
1683 IPADDR pend_val;
1684
1685 protected:
1686 virtual int FdPrintValue(int fd, bool raw) override;
1687 public:
1695 virtual void GetTextValue(NBString &s) override { s.siprintf("\"%I\"", val); };
1696
1707 config_IPADDR(config_obj &owner, IPADDR def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1708 {
1709 val = def_val;
1710 pend_val = val;
1711 }
1712
1714
1724 config_IPADDR(IPADDR def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1725 {
1726 val = def_val;
1727 pend_val = val;
1728 }
1729
1740 config_IPADDR(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1741 {
1742 IPADDR i6;
1743 i6.SetFromAscii(def_val);
1744 val = i6;
1745 pend_val = val;
1746 }
1747
1757 config_IPADDR(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1758 {
1759 IPADDR i6;
1760 i6.SetFromAscii(def_val);
1761 val = i6;
1762 pend_val = val;
1763 }
1764
1765 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1766 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1767
1773 operator IPADDR() const { return val; };
1774
1782 bool IsNull() const { return val.IsNull(); }
1783
1791 bool NotNull() const { return !(val.IsNull()); }
1792
1796 void SetNull()
1797 {
1798 val.SetNull();
1799 pend_val = val;
1800 }
1801
1808 {
1809 pend_val = val = i6;
1810 if (GetFlags(fConfigIsDefault))
1811 ClrBranchFlag(fConfigIsDefault, true);
1812 return *this;
1813 };
1814
1821 {
1822 pend_val = val = ci.val;
1823 if (GetFlags(fConfigIsDefault))
1824 ClrBranchFlag(fConfigIsDefault, true);
1825 return *this;
1826 };
1827
1828 // This is named so error messages make sense to user, old name was GetExtent
1829 virtual int Missing_ConfigEndMarker(void *&startp)
1830 {
1831 startp = this;
1832 return sizeof(*this);
1833 };
1834
1842 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1843
1844 // Add web page help
1845 virtual void ExtendedSchema(int fd, int indent, bool pretty) { DoSchemaLine(fd, "format", "ipv6", indent, pretty); };
1846};
1847#else
1848#define config_IPADDR config_IPADDR4
1849#endif
1850
1859{
1860 MACADR val;
1861 MACADR pend_val;
1862
1863 protected:
1864 virtual int FdPrintValue(int fd, bool raw) override;
1865 public:
1874 virtual void GetTextValue(NBString &s) override
1875 {
1876 s.siprintf("\"%02X:%02X:%02X:%02X:%02X:%02X\"", val.phywadr[0] >> 8, val.phywadr[0] & 0xFF, val.phywadr[1] >> 8,
1877 val.phywadr[1] & 0xFF, val.phywadr[2] >> 8, val.phywadr[2] & 0xFF);
1878 };
1879
1890 config_MACADR(config_obj &owner, MACADR def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1891 {
1892 val = def_val;
1893 pend_val = val;
1894 }
1895
1897
1907 config_MACADR(MACADR def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1908 {
1909 val = def_val;
1910 pend_val = val;
1911 }
1912
1924 config_MACADR(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1925 {
1926 MACADR ma;
1927 ma = AsciiToMac(def_val);
1928
1929 val = ma;
1930 pend_val = val;
1931 }
1932
1943 config_MACADR(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1944 {
1945 MACADR ma;
1946 ma = AsciiToMac(def_val);
1947 val = ma;
1948 pend_val = val;
1949 }
1950
1951 // Assignment Operators
1952
1958 operator MACADR() const { return val; };
1959
1966 {
1967 pend_val = val = ci.val;
1968 if (GetFlags(fConfigIsDefault))
1969 ClrBranchFlag(fConfigIsDefault, true);
1970 return *this;
1971 };
1972
1979 {
1980 pend_val = val = ci;
1981 if (GetFlags(fConfigIsDefault))
1982 ClrBranchFlag(fConfigIsDefault, true);
1983 return *this;
1984 };
1985
1986 MACADR operator+(uint32_t rhs)
1987 { return val + rhs; }
1988
1989 MACADR operator-(uint32_t rhs)
1990 { return val - rhs; }
1991
1992 // This is named so error messages make sense to user, old name was GetExtent
1993 virtual int Missing_ConfigEndMarker(void *&startp)
1994 {
1995 startp = this;
1996 return sizeof(*this);
1997 };
1998
1999 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2000 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
2001
2009 virtual void GetTypeValue(NBString &s) override { s = "string"; };
2010};
2011
2012// This is named so error messages make sense to user, old name was GetExtent
2013#define ConfigEndMarker \
2014 virtual int Missing_ConfigEndMarker(void *&startp) override \
2015 { \
2016 startp = this; \
2017 return sizeof(*this); \
2018 };
2019
2033{
2034 config_string value{"", "Value"};
2035 config_string choices{"", "Choices"};
2036 ConfigEndMarker;
2037
2038 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2039
2040 public:
2050 config_chooser(config_obj &owner, const char *name, const char *in_value, const char *in_choices, const char *desc = NULL)
2051 : config_obj(owner, name, desc)
2052 {
2053 value = in_value; // Current choice
2054 choices = in_choices; // List of choices
2055 choices.m_Flags |= fConfigReadOnly | fConfigNoSave; // Confiuration flags
2056 value.SetEnumList(choices); // Create enum list from string containing all choices
2057 };
2058
2060
2061 const char * GetPendValue() {return value.pend_val.c_str();};
2062
2063
2072 config_chooser(const char *name, const char *in_value, const char *in_choices, const char *desc = NULL) : config_obj(name, desc)
2073 {
2074 value = in_value;
2075 choices = in_choices;
2076 choices.m_Flags |= fConfigReadOnly | fConfigNoSave;
2077 value.SetEnumList(choices);
2078 };
2079
2088 bool IsSelected(const char *choice) { return (choice == value); };
2089
2098 bool IsSelected(const NBString &s) { return (s == value); };
2099
2113 bool IsInChoices(const char *str, size_t strLen)
2114 {
2115 const char *sChoices = choices.c_str();
2116 size_t listLen = choices.length();
2117 size_t index = 0;
2118
2119 if (str == nullptr) { return false; }
2120 if (listLen == 0) { return false; }
2121
2122 while (index < listLen)
2123 {
2124 size_t curVarStart = index;
2125 size_t curVarLength;
2126
2127 // determine the length of the current element in the list of choices
2128 while (sChoices[index] != 0 && sChoices[index] != ',')
2129 {
2130 // index until the end of the current element in the list of choices
2131 index++;
2132 }
2133 curVarLength = index - curVarStart;
2134
2135 if (strncmp(str, &sChoices[curVarStart], (curVarLength > strLen) ? curVarLength : strLen) == 0)
2136 {
2137 return true; // found a match
2138 }
2139 index++; // increment past ','
2140 }
2141
2142 return false;
2143 }
2144
2158 bool IsInChoices(const NBString &str, size_t strLen)
2159 {
2160 const char *sStr = str.c_str();
2161 const char *sChoices = choices.c_str();
2162 size_t length = choices.length();
2163 size_t index = 0;
2164
2165 if (sStr == nullptr) { return false; }
2166 if (length == 0) { return false; }
2167
2168 while (index < length)
2169 {
2170 size_t curVarStart = index;
2171 size_t curVarLength;
2172
2173 // determine the length of the current element in the list of choices
2174 while (sChoices[index] != 0 && sChoices[index] != ',')
2175 {
2176 // index until the end of the current element in the list of choices
2177 index++;
2178 }
2179 curVarLength = index - curVarStart;
2180
2181 if (strncmp(sStr, &sChoices[curVarStart], curVarLength > strLen ? curVarLength : strLen) == 0)
2182 {
2183 return true; // found a match
2184 }
2185 index++; // increment past ','
2186 }
2187
2188 return false;
2189 }
2190
2196 const config_string &GetChoices() { return choices; }
2197
2205 const config_string &SetChoices(const char *in_choices)
2206 {
2207 choices = in_choices;
2208 value.SetEnumList(choices);
2209
2210 return choices;
2211 }
2212
2213 /* @brief Set the list of choices
2214 *
2215 * @param in_choices The list of option choices
2216 *
2217 * @returns A config_string object containing the list of choices
2218 */
2219 const config_string &SetChoices(const NBString &in_choices)
2220 {
2221 choices = in_choices;
2222 value.SetEnumList(choices);
2223
2224 return choices;
2225 }
2226
2227
2233 operator NBString() const { return (NBString)value; };
2234
2241 {
2242 value = p;
2243 if (GetFlags(fConfigIsDefault))
2244 ClrBranchFlag(fConfigIsDefault, true);
2245 return *this;
2246 };
2247
2254 {
2255 value = s;
2256 if (GetFlags(fConfigIsDefault))
2257 ClrBranchFlag(fConfigIsDefault, true);
2258 return *this;
2259 };
2260
2267 {
2268 value = ci.value;
2269 if (GetFlags(fConfigIsDefault))
2270 ClrBranchFlag(fConfigIsDefault, true);
2271 return *this;
2272 };
2273
2274 virtual void GetTypeValue(NBString &s) override { s = "object"; };
2275};
2276
2283{
2284 protected:
2285 int min_val; // should be INT_MIN by default
2286 int max_val; // should be INT_MAX by default
2287
2288 public:
2299 config_int_limit(config_obj &owner, int def_val, int minv=INT_MIN,int maxv=INT_MAX,const char *name = NULL, const char *desc = NULL) : config_int(owner,def_val, name, desc)
2300 {
2301 min_val=minv;
2302 max_val=maxv;
2303 }
2304
2314 config_int_limit(int def_val, int minv=INT_MIN,int maxv=INT_MAX,const char *name = NULL, const char *desc = NULL) : config_int(def_val,name, desc)
2315 {
2316 min_val=minv;
2317 max_val=maxv;
2318 }
2319
2320 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2321 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2322
2323 config_int_limit &operator=(const int i)
2324 {
2325 if(i>=min_val && max_val<=i)
2326 {
2327 pend_val = val = i;
2328 if (GetFlags(fConfigIsDefault))
2329 ClrBranchFlag(fConfigIsDefault, true);
2330 }
2331 return *this;
2332 };
2333
2341 {
2342 int test_v=ci;
2343 if((test_v>=min_val) && (test_v<=max_val))
2344 {
2345 pend_val = val = test_v;
2346 if (GetFlags(fConfigIsDefault))
2347 ClrBranchFlag(fConfigIsDefault, true);
2348 }
2349 return *this;
2350 };
2351
2359 {
2360 int test_v=cil;
2361 if((test_v>=min_val) && (test_v<=max_val))
2362 {
2363 pend_val = val = test_v;
2364 if (GetFlags(fConfigIsDefault))
2365 ClrBranchFlag(fConfigIsDefault, true);
2366 }
2367 return *this;
2368 };
2369
2370};
2371
2378{
2379 protected:
2380 uint32_t min_val; // should be 0 by default
2381 uint32_t max_val; // should be UINT_MAX by default
2382
2383 public:
2394 config_uint_limit(config_obj &owner, uint32_t def_val, uint32_t minv=0,uint32_t maxv=UINT_MAX,const char *name = NULL, const char *desc = NULL) : config_uint(owner,def_val, name, desc)
2395 {
2396 min_val=minv;
2397 max_val=maxv;
2398 }
2399
2409 config_uint_limit(uint32_t def_val, uint32_t minv=0,uint32_t maxv=UINT_MAX,const char *name = NULL, const char *desc = NULL) : config_uint(def_val,name, desc)
2410 {
2411 min_val=minv;
2412 max_val=maxv;
2413 }
2414
2415 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2416 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2417
2418 config_uint_limit &operator=(const uint32_t i)
2419 {
2420 if(i>=min_val && max_val<=i)
2421 {
2422 pend_val = val = i;
2423 if (GetFlags(fConfigIsDefault))
2424 ClrBranchFlag(fConfigIsDefault, true);
2425 }
2426 return *this;
2427 };
2428
2436 {
2437 uint32_t test_v=ci;
2438 if((test_v>=min_val) && (test_v<=max_val))
2439 {
2440 pend_val = val = test_v;
2441 if (GetFlags(fConfigIsDefault))
2442 ClrBranchFlag(fConfigIsDefault, true);
2443 }
2444 return *this;
2445 };
2446
2454 {
2455 uint32_t test_v=cil;
2456 if((test_v>=min_val) && (test_v<=max_val))
2457 {
2458 pend_val = val = test_v;
2459 if (GetFlags(fConfigIsDefault))
2460 ClrBranchFlag(fConfigIsDefault, true);
2461 }
2462 return *this;
2463 };
2464
2465};
2466
2467
2468
2475{
2476 protected:
2477 double min_val; // should be -DBL_MAX by default
2478 double max_val; // should be DBL_MAX by default
2479 double step; // allowable increments in the HTML GUI (precision to round to, not strictly enforced)
2480
2481 public:
2493 config_double_limit(config_obj &owner, double def_val, double minv=-DBL_MAX,double maxv=DBL_MAX,double stepv=0.01, const char *name = NULL, const char *desc = NULL) : config_double(owner,def_val, name, desc)
2494 {
2495 min_val=minv;
2496 max_val=maxv;
2497 step=stepv;
2498 }
2499
2510 config_double_limit(double def_val, double minv=-DBL_MAX,double maxv=DBL_MAX,double stepv=0.01, const char *name = NULL, const char *desc = NULL) : config_double(def_val,name, desc)
2511 {
2512 min_val=minv;
2513 max_val=maxv;
2514 step=stepv;
2515 }
2516
2517 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2518 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2519
2520 config_double_limit &operator=(const double i)
2521 {
2522 if(i>=min_val && max_val<=i)
2523 {
2524 pend_val = val = i;
2525 if (GetFlags(fConfigIsDefault))
2526 ClrBranchFlag(fConfigIsDefault, true);
2527 }
2528 return *this;
2529 };
2530
2538 {
2539 double test_v=ci;
2540 if((test_v>=min_val) && (test_v<=max_val))
2541 {
2542 pend_val = val = test_v;
2543 if (GetFlags(fConfigIsDefault))
2544 ClrBranchFlag(fConfigIsDefault, true);
2545 }
2546 return *this;
2547 };
2548
2556 {
2557 double test_v=cil;
2558 if((test_v>=min_val) && (test_v<=max_val))
2559 {
2560 pend_val = val = test_v;
2561 if (GetFlags(fConfigIsDefault))
2562 ClrBranchFlag(fConfigIsDefault, true);
2563 }
2564 return *this;
2565 };
2566
2567
2575 virtual void GetTypeValue(NBString &s) override { s = "number"; };
2576};
2577
2584{
2585 protected:
2586 size_t min_len; // should be 0 by default
2587 size_t max_len; // should be 0 by default
2588
2589 public:
2600 config_string_limit(config_obj &owner, NBString def_val, size_t minl=0,size_t maxl=0,const char *name = NULL, const char *desc = NULL) : config_string(owner,def_val, name, desc)
2601 {
2602 min_len=minl;
2603 max_len=maxl;
2604 }
2605
2615 config_string_limit(NBString def_val, size_t minl=0,size_t maxl=0,const char *name = NULL, const char *desc = NULL) : config_string(def_val,name, desc)
2616 {
2617 min_len=minl;
2618 max_len=maxl;
2619 }
2620
2621 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2622 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2623
2624 config_string_limit &operator=(const NBString i)
2625 {
2626 if(i.length()>=min_len && max_len<=i.length())
2627 {
2628 pend_val = val = i;
2629 if (GetFlags(fConfigIsDefault))
2630 ClrBranchFlag(fConfigIsDefault, true);
2631 }
2632 return *this;
2633 };
2634
2642 {
2643 NBString test_v=ci;
2644 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2645 {
2646 pend_val = val = test_v;
2647 if (GetFlags(fConfigIsDefault))
2648 ClrBranchFlag(fConfigIsDefault, true);
2649 }
2650 return *this;
2651 };
2652
2660 {
2661 NBString test_v=cil;
2662 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2663 {
2664 pend_val = val = test_v;
2665 if (GetFlags(fConfigIsDefault))
2666 ClrBranchFlag(fConfigIsDefault, true);
2667 }
2668 return *this;
2669 };
2670
2671};
2672
2679{
2680 protected:
2681 size_t min_len; // should be 0 by default
2682 size_t max_len; // should be 0 by default
2683
2684 public:
2695 config_pass_limit(config_obj &owner, NBString def_val, size_t minl=0,size_t maxl=0,const char *name = NULL, const char *desc = NULL) : config_pass(owner,def_val, name, desc)
2696 {
2697 min_len=minl;
2698 max_len=maxl;
2699 }
2700
2710 config_pass_limit(NBString def_val, size_t minl=0,size_t maxl=0,const char *name = NULL, const char *desc = NULL) : config_pass(def_val,name, desc)
2711 {
2712 min_len=minl;
2713 max_len=maxl;
2714 }
2715
2716 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2717 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2718
2719 config_pass_limit &operator=(const NBString i)
2720 {
2721 if(i.length()>=min_len && max_len<=i.length())
2722 {
2723 pend_val = val = i;
2724 if (GetFlags(fConfigIsDefault))
2725 ClrBranchFlag(fConfigIsDefault, true);
2726 }
2727 return *this;
2728 };
2729
2737 {
2738 NBString test_v=ci;
2739 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2740 {
2741 pend_val = val = test_v;
2742 if (GetFlags(fConfigIsDefault))
2743 ClrBranchFlag(fConfigIsDefault, true);
2744 }
2745 return *this;
2746 };
2747
2755 {
2756 NBString test_v=cil;
2757 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2758 {
2759 pend_val = val = test_v;
2760 if (GetFlags(fConfigIsDefault))
2761 ClrBranchFlag(fConfigIsDefault, true);
2762 }
2763 return *this;
2764 };
2765
2766};
2767
2768class reboot_obj : public config_bool
2769{
2770 virtual const char *GetSortNameValue() { return "ZZZc"; };
2771
2772 public:
2773 reboot_obj() : config_bool(root, false, "Reboot", "Cause system reboot on save"){};
2774 void clear()
2775 {
2776 val = false;
2777 pend_val = false;
2778 };
2779
2780 // This is named so error messages make sense to user, old name was GetExtent
2781 virtual int Missing_ConfigEndMarker(void *&startp)
2782 {
2783 startp = this;
2784 return sizeof(*this);
2785 };
2786};
2787
2788class version_obj : public config_int
2789{
2790 bool bNeverSet;
2791 virtual const char *GetSortNameValue() { return "ZZZb"; };
2792
2793 public:
2794 version_obj() : config_int(root, 0, "Version", "Version serial number") { bNeverSet = true; };
2795
2796 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs);
2797 void inc()
2798 {
2799 val++;
2800 pend_val = val;
2801 };
2802 // This is named so error messages make sense to user
2803 // Old name was GetExtent
2804 virtual int Missing_ConfigEndMarker(void *&startp)
2805 {
2806 startp = this;
2807 return sizeof(*this);
2808 };
2809};
2810
2811class empty_config_obj : public config_obj
2812{
2813 ConfigEndMarker;
2814
2815 public:
2816 empty_config_obj(const char *name, const char *desc = NULL) : config_obj(name, desc){};
2817 empty_config_obj(config_obj &owner, const char *name, const char *desc = NULL) : config_obj(owner, name, desc){};
2818 empty_config_obj(empty_config_obj &&e);
2819};
2820
2821
2822
2823// This class is intended for recovery applications or for devices supporting multiple
2824// application profiles to preserve unused config tree branches across configuration
2825// updates
2826// Ex:
2827// Application A has a config object at 'AppData.AppA', and Application B
2828// has a config object at 'AppData.AppB'. Normally, if Application A were
2829// to update any configuration (whether Application or System related), this
2830// would wipe out any AppB configuration as it is not known of by Application A.
2831// Using a config_preserver_obj, any configuration tree data below it's registration
2832// will be persisted across updates unless explicitly wiped.
2833class config_preserver_obj : public config_obj
2834{
2835 ConfigEndMarker;
2836 ParsedJsonDataSet &pendingTreeData;
2837 ParsedJsonDataSet &treeData;
2838
2839 public:
2840 config_preserver_obj(const char *name, const char *desc = NULL);
2841 config_preserver_obj(config_obj &owner, const char *name, const char *desc = NULL);
2842 config_preserver_obj(config_preserver_obj &&po);
2843
2844
2845 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2846 virtual void CommitTestedValue(uint32_t permission_mask) override;
2847 virtual void GetTextValue(NBString &s) override;
2848 virtual void GetRawValue(NBString &s) override;
2849};
2850
2851extern const char *AppName;
2852extern const char PlatformName[];
2853
2854class SysRecord : public config_obj
2855{
2856 public:
2857 config_report system_platform{PlatformName, "Platform", "Hardware Platform"};
2858 config_report system_app{AppName, "Application", "Application name"};
2859 ConfigEndMarker;
2860
2861 SysRecord(const char *name, const char *desc = NULL) : config_obj(name, desc){};
2862 SysRecord(config_obj &owner, const char *name, const char *desc = NULL) : config_obj(owner, name, desc){};
2863 SysRecord(SysRecord &&sr);
2864};
2865
2866extern SysRecord sys;
2867extern empty_config_obj netif;
2868
2869extern reboot_obj rebooter;
2870extern version_obj config_cur_version;
2871
2872extern const int plat_def_baud;
2873extern const int plat_def_delay;
2874extern const int plat_def_quiet;
2875extern const int plat_def_watchdog_enabled;
2876
2877#include <plat_cfg_types.h>
2878#ifdef PRESERVE_APP_DATA
2879extern config_preserver_obj appdata;
2880#else
2881extern empty_config_obj appdata;
2882#endif
2883
2889
2890class MonitorRecord : public config_obj
2891{
2892 public:
2893 config_int Baud{plat_def_baud, "BootBaud"};
2894 config_uart Uart{plat_def_com, "BootUart"};
2895 config_int BootDelay{plat_def_delay, "BootDelay"};
2896 config_bool Quiet{plat_def_quiet, "BootQuiet"};
2897 config_chooser sercfg_action{"SerialConfig", "DuringBoot", "DuringBoot,AlwaysEnabled,PauseAfterBoot,Disabled"};
2898 config_string abortbootcmd{"A", "Abort"};
2899 config_pass system_user{"", "User"};
2900 config_pass system_pass{"", "Password"};
2901 ConfigEndMarker;
2902
2903 MonitorRecord(const char *name) : config_obj(name, "Boot monitor record")
2904 {
2905 sercfg_action.SetFlag(fConfigNeedReboot);
2906 Baud.SetFlag(fConfigNeedReboot);
2907 Uart.SetFlag(fConfigNeedReboot);
2908 };
2909 MonitorRecord(config_obj &owner, const char *name) : config_obj(owner, name, "Boot Monitor Record")
2910 {
2911 sercfg_action.SetFlag(fConfigNeedReboot);
2912 Baud.SetFlag(fConfigNeedReboot);
2913 Uart.SetFlag(fConfigNeedReboot);
2914 };
2915 MonitorRecord(MonitorRecord &&mr);
2916};
2917extern MonitorRecord monitor_config;
2918
2929
2930
2931
2932
2933#endif
2934
Definition config_netobj.h:302
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:225
bool IsNull() const
Check if the IP address is null.
Definition nettypes.h:279
void SetFromAscii(const char *cp)
Set the IPv4 address from a character string.
void SetNull()
Set the IP address to null.
Definition nettypes.h:295
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
void SetFromAscii(const char *cp, bool bembed_v4addresses=true)
Set the IP address value of an IPADDR6 object.
void SetNull()
Set the IP address value of an IPADDR6 object to null.
Definition ipv6_addr.h:320
bool IsNull() const
Check if the IP address is null.
Definition ipv6_addr.h:133
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
const char * c_str() const
Method to pass a NBString as a constant char *.
bool Interpolate(NBString &dest)
Perform a string interpolation and place the finished interpolation in the Destination string....
size_t length() const
Returns the length of the string.
A class to create, read, and modify a JSON object.
Definition json_lexer.h:535
Configuration Variable for IPADDR4 (IPv4) object types.
Definition config_obj.h:1498
bool NotNull() const
Check if the IP address is not null.
Definition config_obj.h:1611
config_IPADDR4(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1575
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1664
config_IPADDR4(config_obj &owner, const char *def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1558
config_IPADDR4(IPADDR4 def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1540
virtual void GetTextValue(NBString &s) override
Get the object value as a text string with quotations to the specified NBString object.
Definition config_obj.h:1513
config_IPADDR4(config_obj &owner, IPADDR4 def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1525
config_IPADDR4 & operator=(const config_IPADDR4 &ci)
Copy one config_IPADDR4 object to another.
Definition config_obj.h:1642
bool IsNull() const
Check if the IP address is null.
Definition config_obj.h:1602
void SetNull()
Set the IP address to null.
Definition config_obj.h:1618
config_IPADDR4 & operator=(const IPADDR4 &i4)
Copy an IPADDR4 object value to a config_IPADDR4 object.
Definition config_obj.h:1629
Configuration Variable for IPADDR (IPv6) object type.
Definition config_obj.h:1681
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1842
config_IPADDR & operator=(const config_IPADDR &ci)
Copy one config_IPADDR object to another.
Definition config_obj.h:1820
config_IPADDR & operator=(const IPADDR &i6)
Copy an IPADDR object value to a config_IPADDR object.
Definition config_obj.h:1807
config_IPADDR(config_obj &owner, const char *def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1740
config_IPADDR(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1757
void SetNull()
Set the IP address value of an config_IPADDR object to null.
Definition config_obj.h:1796
config_IPADDR(config_obj &owner, IPADDR def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1707
bool NotNull() const
Check if the IP address is not null.
Definition config_obj.h:1791
config_IPADDR(IPADDR def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1724
bool IsNull() const
Check if the IP address is null.
Definition config_obj.h:1782
virtual void GetTextValue(NBString &s) override
Get the object value as a text string with quotations to the specified NBString object.
Definition config_obj.h:1695
Configuration Variable for MACADR object type.
Definition config_obj.h:1859
config_MACADR(config_obj &owner, MACADR def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1890
config_MACADR & operator=(const MACADR &ci)
Copy a MACADR object value to a MACADR object.
Definition config_obj.h:1978
config_MACADR(MACADR def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1907
config_MACADR & operator=(const config_MACADR &ci)
Copy one config_MACADR object to another.
Definition config_obj.h:1965
config_MACADR(config_obj &owner, const char *def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1924
virtual void GetTextValue(NBString &s) override
Get the object value as a text string with quotations to the specified NBString object.
Definition config_obj.h:1874
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:2009
config_MACADR(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1943
Boolean Configuration Variable.
Definition config_obj.h:998
config_bool(bool def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1041
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1117
config_bool & operator=(const config_bool &cb)
Copy one config_bool object to another.
Definition config_obj.h:1084
config_bool & operator=(const int i)
Assign a config_bool object value to the specified integer value.
Definition config_obj.h:1097
config_bool & operator=(const bool v)
Assign the config_bool object value to the specified bool value.
Definition config_obj.h:1071
virtual void GetTextValue(NBString &s) override
Copy the object value as a text string to the specified NBString object.
Definition config_obj.h:1012
config_bool(config_obj &owner, bool def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1028
Chooser Configuration Variable - Select From a List of Items.
Definition config_obj.h:2033
virtual void GetTypeValue(NBString &s) override
Assigns the object type value to the specified NBString object.
Definition config_obj.h:2274
const config_string & GetChoices()
Get the list of choices.
Definition config_obj.h:2196
const config_string & SetChoices(const char *in_choices)
Set the list of choices.
Definition config_obj.h:2205
bool IsSelected(const char *choice)
Check if a particular choice option is selected.
Definition config_obj.h:2088
config_chooser & operator=(const char *p)
Assign the selected list item from a const char* value.
Definition config_obj.h:2240
bool IsSelected(const NBString &s)
Check if a particular choice option is selected.
Definition config_obj.h:2098
config_chooser & operator=(const config_chooser &ci)
Copy one config_chooser object to another.
Definition config_obj.h:2266
config_chooser(const char *name, const char *in_value, const char *in_choices, const char *desc=NULL)
Object constructor.
Definition config_obj.h:2072
bool IsInChoices(const char *str, size_t strLen)
Check if a string is in the list of possible choices. A comparison will continue until a null charact...
Definition config_obj.h:2113
config_chooser(config_obj &owner, const char *name, const char *in_value, const char *in_choices, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:2050
bool IsInChoices(const NBString &str, size_t strLen)
Check if a string is in the list of possible choices. A comparison will continue until a null charact...
Definition config_obj.h:2158
config_chooser & operator=(const NBString &s)
Assign the config_string object value from a NBString object.
Definition config_obj.h:2253
A config_double with minimum and/or maximum values Attempting to set a value lower than the minimum o...
Definition config_obj.h:2475
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:2575
config_double_limit & operator=(const config_double_limit &cil)
Copy one config_double_limit object to another.
Definition config_obj.h:2555
config_double_limit(double def_val, double minv=-DBL_MAX, double maxv=DBL_MAX, double stepv=0.01, const char *name=NULL, const char *desc=NULL)
Object constructor with limits.
Definition config_obj.h:2510
config_double_limit & operator=(const config_double &ci)
Copy a config_double object into the config_double_limit.
Definition config_obj.h:2537
config_double_limit(config_obj &owner, double def_val, double minv=-DBL_MAX, double maxv=DBL_MAX, double stepv=0.01, const char *name=NULL, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter and limits.
Definition config_obj.h:2493
Double Float Configuration Variable.
Definition config_obj.h:817
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:948
virtual void GetTextValue(NBString &s) override
Copy the object value as a text string to the specified NBString object.
Definition config_obj.h:831
config_double(config_obj &owner, double def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:841
config_double(double def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:854
config_double & operator=(const double d)
Assign the config_double object value from a double value.
Definition config_obj.h:911
config_double & operator=(const config_double &ci)
Copy one config_double object to another.
Definition config_obj.h:924
A config_int with minimum and/or maximum values Attempting to set a value lower than the minimum or g...
Definition config_obj.h:2283
config_int_limit & operator=(const config_int &ci)
Copy a config_int object into the config_int_limit.
Definition config_obj.h:2340
config_int_limit(int def_val, int minv=INT_MIN, int maxv=INT_MAX, const char *name=NULL, const char *desc=NULL)
Object constructor with limits.
Definition config_obj.h:2314
config_int_limit & operator=(const config_int_limit &cil)
Copy one config_int_limit object to another.
Definition config_obj.h:2358
config_int_limit(config_obj &owner, int def_val, int minv=INT_MIN, int maxv=INT_MAX, const char *name=NULL, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter and limits.
Definition config_obj.h:2299
Signed 32-bit Integer Configuration Variable.
Definition config_obj.h:701
config_int & operator=(const int i)
Assign the config_int object value to the specified int value.
Definition config_obj.h:770
config_int(config_obj &owner, int def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:725
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:806
virtual void GetTextValue(NBString &s) override
Copy the object value to the specified NBString object.
Definition config_obj.h:715
config_int(int def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:738
config_int & operator=(const config_int &ci)
Copy one config_int object to another.
Definition config_obj.h:784
Configure device network name.
Definition config_netobj.h:26
Base class used to create configuration objects.
Definition config_obj.h:321
virtual void GetTypeValue(NBString &s) override
Assigns the object type value to the specified NBString object.
Definition config_obj.h:423
config_obj(const char *name, const char *desc)
Object constructor.
Definition config_obj.h:368
virtual void GetTextValue(NBString &s) override
Get the object value as a text string to the specified NBString object.
config_obj(config_obj &owner, const char *name, const char *desc)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:345
A config_pass with minimum and/or maximum lengths Attempting to set a value shorter than the minimum ...
Definition config_obj.h:2679
config_pass_limit & operator=(const config_pass_limit &cil)
Copy one config_pass_limit object to another.
Definition config_obj.h:2754
config_pass_limit(config_obj &owner, NBString def_val, size_t minl=0, size_t maxl=0, const char *name=NULL, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter and limits.
Definition config_obj.h:2695
config_pass_limit(NBString def_val, size_t minl=0, size_t maxl=0, const char *name=NULL, const char *desc=NULL)
Object constructor with limits.
Definition config_obj.h:2710
config_pass_limit & operator=(const config_pass &ci)
Copy a config_pass object into the config_pass_limit.
Definition config_obj.h:2736
Password string Configuration Variable.
Definition config_obj.h:1346
config_pass(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1396
config_pass & operator=(const config_string &ci)
Copy a config_string object to a config_pass object.
Definition config_obj.h:1465
config_pass & operator=(const char *p)
Assign the config_pass object value from a const char* value.
Definition config_obj.h:1439
config_pass & operator=(const NBString &s)
Assign the config_pass object value from a NBString object.
Definition config_obj.h:1452
config_pass(NBString def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1372
virtual void GetRawValue(NBString &s) override
Copy the raw config_string object value to the NBString object.
config_pass(config_obj &owner, const char *def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1384
virtual void GetTextValue(NBString &s) override
Get the config_pass object value as a text string.
config_pass & operator=(const config_pass &ci)
Copy one config_pass object to another.
Definition config_obj.h:1478
config_pass(config_obj &owner, NBString def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1360
A config_string with minimum and/or maximum lengths Attempting to set a value shorter than the minimu...
Definition config_obj.h:2584
config_string_limit(NBString def_val, size_t minl=0, size_t maxl=0, const char *name=NULL, const char *desc=NULL)
Object constructor with limits.
Definition config_obj.h:2615
config_string_limit(config_obj &owner, NBString def_val, size_t minl=0, size_t maxl=0, const char *name=NULL, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter and limits.
Definition config_obj.h:2600
config_string_limit & operator=(const config_string &ci)
Copy a config_string object into the config_string_limit.
Definition config_obj.h:2641
config_string_limit & operator=(const config_string_limit &cil)
Copy one config_string_limit object to another.
Definition config_obj.h:2659
String Configuration Variable.
Definition config_obj.h:1128
const char * c_str() const
Returns the object value as a string.
Definition config_obj.h:1288
virtual void GetTextValue(NBString &s) override
Get the object value (as a text string with quotations) to the specified NBString object.
config_string(config_obj &owner, NBString def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1164
const char & operator[](size_t pos) const
Return the value of a character in the string.
Definition config_obj.h:1304
config_string & operator=(const char *p)
Assign the config_string object value from a const char* string.
Definition config_obj.h:1242
config_string(config_obj &owner, const char *def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:1196
config_string & operator=(const NBString &s)
Assign the config_string object value from a NBString object.
Definition config_obj.h:1255
void SetEnumList(NBString s)
Renders the data used to explain the schema/descriptions for the list of choices.
Definition config_obj.h:1226
config_string(NBString def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1179
config_string & operator=(const config_string &ci)
Copy one config_string object to another.
Definition config_obj.h:1268
config_string(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1211
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1313
size_t length() const
Returns the string length in bytes.
Definition config_obj.h:1295
A config_uint with minimum and/or maximum values Attempting to set a value lower than the minimum or ...
Definition config_obj.h:2378
config_uint_limit(uint32_t def_val, uint32_t minv=0, uint32_t maxv=UINT_MAX, const char *name=NULL, const char *desc=NULL)
Object constructor with limits.
Definition config_obj.h:2409
config_uint_limit & operator=(const config_uint_limit &cil)
Copy one config_uint_limit object to another.
Definition config_obj.h:2453
config_uint_limit & operator=(const config_uint &ci)
Copy a config_uint object into the config_uint_limit.
Definition config_obj.h:2435
config_uint_limit(config_obj &owner, uint32_t def_val, uint32_t minv=0, uint32_t maxv=UINT_MAX, const char *name=NULL, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter and limits.
Definition config_obj.h:2394
Unsigned 32-bit Integer Configuration Variable.
Definition config_obj.h:553
config_uint(uint32_t def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:590
config_uint(config_obj &owner, uint32_t def_val, const char *name, const char *desc=NULL)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:577
config_uint & operator=(const uint32_t i)
Assign the config_uint object value from a uint32_t value.
Definition config_obj.h:621
virtual void GetTextValue(NBString &s) override
Copy the object value to the specified NBString object.
Definition config_obj.h:567
config_uint & operator=(const config_uint &ci)
Copy one config_uint object to another.
Definition config_obj.h:634
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:656
Base class used to create a configuration value.
Definition config_obj.h:491
config_value(config_obj &owner, const char *name, const char *desc)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:508
config_value(const char *name, const char *desc)
Object constructor.
Definition config_obj.h:529
FIFO buffer storage using linked pool buffers.
Definition buffers.h:443
MACADR AsciiToMac(const char *p)
Convert an ASCII MAC address string to a MAC address.
const uint32_t fConfigModified
Variable has been modified, but not yet saved.
Definition config_obj.h:77
const uint32_t fConfigNeedReboot
System reboot required for changes to take effect.
Definition config_obj.h:81
const uint32_t fConfigNoObscure
Do not obscure the value.
Definition config_obj.h:80
const uint32_t fConfigValueLeaf
Value is a leaf.
Definition config_obj.h:75
const uint32_t fMaskDoingSave
We're currently executing a config save to non-volatile storage.
Definition config_obj.h:85
const uint32_t fConfigHidden
Not visible to configuration web server display.
Definition config_obj.h:78
const uint32_t fConfigNoSave
Do not save to flash memory when save functions are called.
Definition config_obj.h:79
const uint32_t fConfigNoReload
Disable reloading value from flash during a call to ReloadFromFlash.
Definition config_obj.h:82
const uint32_t fConfigDetached
Disable reloading value from flash during a call to ReloadFromFlash.
Definition config_obj.h:83
const uint32_t fConfigIsDefault
Value is unchanged from the default, i.e. wes never set.
Definition config_obj.h:84
const uint32_t fConfigReadOnly
Variable is read-only.
Definition config_obj.h:76
void OverrideConfig()
Create this function to override config settings.
void SaveConfigToStorage()
Save configuration to flash storage.
const char * AppName
Application name displayed in web interface and console output.
Definition aes/src/main.cpp:10
IPADDR6 IPADDR
IPADDR Object Type (either v4 or v6)
Definition nettypes.h:568
class MACADR MACADR
Used to store and manipulate MAC addresses.