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 friend class I4Record; // Allow I4Record to access pend_val for validation
1500
1501 IPADDR4 val;
1502 IPADDR4 pend_val;
1503
1504 protected:
1505 virtual int FdPrintValue(int fd, bool raw) override;
1506 public:
1515 virtual void GetTextValue(NBString &s) override { s.siprintf("\"%hI\"", val); };
1516
1527 config_IPADDR4(config_obj &owner, IPADDR4 def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1528 {
1529 val = def_val;
1530 pend_val = val;
1531 }
1532
1542 config_IPADDR4(IPADDR4 def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1543 {
1544 val = def_val;
1545 pend_val = val;
1546 }
1547
1549
1560 config_IPADDR4(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1561 {
1562 IPADDR4 i4;
1563 i4.SetFromAscii(def_val);
1564 val = i4;
1565 pend_val = val;
1566 }
1567
1577 config_IPADDR4(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1578 {
1579 IPADDR4 i4;
1580 i4.SetFromAscii(def_val);
1581 val = i4;
1582 pend_val = val;
1583 }
1584
1585 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1586 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1587
1588 // Assignment operators
1589
1595 operator IPADDR4() const { return val; };
1596
1604 inline bool IsNull() const { return val.IsNull(); };
1605
1613 inline bool NotNull() const { return !(val.IsNull()); };
1614
1620 inline void SetNull()
1621 {
1622 val.SetNull();
1623 pend_val = val;
1624 };
1625
1632 {
1633 pend_val = val = i4;
1634 if (GetFlags(fConfigIsDefault))
1635 ClrBranchFlag(fConfigIsDefault, true);
1636 return *this;
1637 };
1638
1645 {
1646 pend_val = val = ci.val;
1647 if (GetFlags(fConfigIsDefault))
1648 ClrBranchFlag(fConfigIsDefault, true);
1649 return *this;
1650 };
1651
1652 // This is named so error messages make sense to user, old name was GetExtent
1653 virtual int Missing_ConfigEndMarker(void *&startp)
1654 {
1655 startp = this;
1656 return sizeof(*this);
1657 };
1658
1666 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1667
1668 // Add web page help
1669 virtual void ExtendedSchema(int fd, int indent, bool pretty) { DoSchemaLine(fd, "format", "ipv4", indent, pretty); };
1670 friend I4Record;
1671};
1672
1673#ifdef IPV6
1683{
1684 IPADDR val;
1685 IPADDR pend_val;
1686
1687 protected:
1688 virtual int FdPrintValue(int fd, bool raw) override;
1689 public:
1697 virtual void GetTextValue(NBString &s) override { s.siprintf("\"%I\"", val); };
1698
1709 config_IPADDR(config_obj &owner, IPADDR def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1710 {
1711 val = def_val;
1712 pend_val = val;
1713 }
1714
1716
1726 config_IPADDR(IPADDR def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1727 {
1728 val = def_val;
1729 pend_val = val;
1730 }
1731
1742 config_IPADDR(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1743 {
1744 IPADDR i6;
1745 i6.SetFromAscii(def_val);
1746 val = i6;
1747 pend_val = val;
1748 }
1749
1759 config_IPADDR(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1760 {
1761 IPADDR i6;
1762 i6.SetFromAscii(def_val);
1763 val = i6;
1764 pend_val = val;
1765 }
1766
1767 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1768 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1769
1775 operator IPADDR() const { return val; };
1776
1784 bool IsNull() const { return val.IsNull(); }
1785
1793 bool NotNull() const { return !(val.IsNull()); }
1794
1798 void SetNull()
1799 {
1800 val.SetNull();
1801 pend_val = val;
1802 }
1803
1810 {
1811 pend_val = val = i6;
1812 if (GetFlags(fConfigIsDefault))
1813 ClrBranchFlag(fConfigIsDefault, true);
1814 return *this;
1815 };
1816
1823 {
1824 pend_val = val = ci.val;
1825 if (GetFlags(fConfigIsDefault))
1826 ClrBranchFlag(fConfigIsDefault, true);
1827 return *this;
1828 };
1829
1830 // This is named so error messages make sense to user, old name was GetExtent
1831 virtual int Missing_ConfigEndMarker(void *&startp)
1832 {
1833 startp = this;
1834 return sizeof(*this);
1835 };
1836
1844 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1845
1846 // Add web page help
1847 virtual void ExtendedSchema(int fd, int indent, bool pretty) { DoSchemaLine(fd, "format", "ipv6", indent, pretty); };
1848};
1849#else
1850#define config_IPADDR config_IPADDR4
1851#endif
1852
1861{
1862 MACADR val;
1863 MACADR pend_val;
1864
1865 protected:
1866 virtual int FdPrintValue(int fd, bool raw) override;
1867 public:
1876 virtual void GetTextValue(NBString &s) override
1877 {
1878 s.siprintf("\"%02X:%02X:%02X:%02X:%02X:%02X\"", val.phywadr[0] >> 8, val.phywadr[0] & 0xFF, val.phywadr[1] >> 8,
1879 val.phywadr[1] & 0xFF, val.phywadr[2] >> 8, val.phywadr[2] & 0xFF);
1880 };
1881
1892 config_MACADR(config_obj &owner, MACADR def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1893 {
1894 val = def_val;
1895 pend_val = val;
1896 }
1897
1899
1909 config_MACADR(MACADR def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1910 {
1911 val = def_val;
1912 pend_val = val;
1913 }
1914
1926 config_MACADR(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1927 {
1928 MACADR ma;
1929 ma = AsciiToMac(def_val);
1930
1931 val = ma;
1932 pend_val = val;
1933 }
1934
1945 config_MACADR(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1946 {
1947 MACADR ma;
1948 ma = AsciiToMac(def_val);
1949 val = ma;
1950 pend_val = val;
1951 }
1952
1953 // Assignment Operators
1954
1960 operator MACADR() const { return val; };
1961
1968 {
1969 pend_val = val = ci.val;
1970 if (GetFlags(fConfigIsDefault))
1971 ClrBranchFlag(fConfigIsDefault, true);
1972 return *this;
1973 };
1974
1981 {
1982 pend_val = val = ci;
1983 if (GetFlags(fConfigIsDefault))
1984 ClrBranchFlag(fConfigIsDefault, true);
1985 return *this;
1986 };
1987
1988 MACADR operator+(uint32_t rhs)
1989 { return val + rhs; }
1990
1991 MACADR operator-(uint32_t rhs)
1992 { return val - rhs; }
1993
1994 // This is named so error messages make sense to user, old name was GetExtent
1995 virtual int Missing_ConfigEndMarker(void *&startp)
1996 {
1997 startp = this;
1998 return sizeof(*this);
1999 };
2000
2001 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2002 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
2003
2011 virtual void GetTypeValue(NBString &s) override { s = "string"; };
2012};
2013
2014// This is named so error messages make sense to user, old name was GetExtent
2015#define ConfigEndMarker \
2016 virtual int Missing_ConfigEndMarker(void *&startp) override \
2017 { \
2018 startp = this; \
2019 return sizeof(*this); \
2020 };
2021
2035{
2036 config_string value{"", "Value"};
2037 config_string choices{"", "Choices"};
2038 ConfigEndMarker;
2039
2040 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2041
2042 public:
2052 config_chooser(config_obj &owner, const char *name, const char *in_value, const char *in_choices, const char *desc = NULL)
2053 : config_obj(owner, name, desc)
2054 {
2055 value = in_value; // Current choice
2056 choices = in_choices; // List of choices
2057 choices.m_Flags |= fConfigReadOnly | fConfigNoSave; // Confiuration flags
2058 value.SetEnumList(choices); // Create enum list from string containing all choices
2059 };
2060
2062
2063 const char * GetPendValue() {return value.pend_val.c_str();};
2064
2065
2074 config_chooser(const char *name, const char *in_value, const char *in_choices, const char *desc = NULL) : config_obj(name, desc)
2075 {
2076 value = in_value;
2077 choices = in_choices;
2078 choices.m_Flags |= fConfigReadOnly | fConfigNoSave;
2079 value.SetEnumList(choices);
2080 };
2081
2090 bool IsSelected(const char *choice) { return (choice == value); };
2091
2100 bool IsSelected(const NBString &s) { return (s == value); };
2101
2115 bool IsInChoices(const char *str, size_t strLen)
2116 {
2117 const char *sChoices = choices.c_str();
2118 size_t listLen = choices.length();
2119 size_t index = 0;
2120
2121 if (str == nullptr) { return false; }
2122 if (listLen == 0) { return false; }
2123
2124 while (index < listLen)
2125 {
2126 size_t curVarStart = index;
2127 size_t curVarLength;
2128
2129 // determine the length of the current element in the list of choices
2130 while (sChoices[index] != 0 && sChoices[index] != ',')
2131 {
2132 // index until the end of the current element in the list of choices
2133 index++;
2134 }
2135 curVarLength = index - curVarStart;
2136
2137 if (strncmp(str, &sChoices[curVarStart], (curVarLength > strLen) ? curVarLength : strLen) == 0)
2138 {
2139 return true; // found a match
2140 }
2141 index++; // increment past ','
2142 }
2143
2144 return false;
2145 }
2146
2160 bool IsInChoices(const NBString &str, size_t strLen)
2161 {
2162 const char *sStr = str.c_str();
2163 const char *sChoices = choices.c_str();
2164 size_t length = choices.length();
2165 size_t index = 0;
2166
2167 if (sStr == nullptr) { return false; }
2168 if (length == 0) { return false; }
2169
2170 while (index < length)
2171 {
2172 size_t curVarStart = index;
2173 size_t curVarLength;
2174
2175 // determine the length of the current element in the list of choices
2176 while (sChoices[index] != 0 && sChoices[index] != ',')
2177 {
2178 // index until the end of the current element in the list of choices
2179 index++;
2180 }
2181 curVarLength = index - curVarStart;
2182
2183 if (strncmp(sStr, &sChoices[curVarStart], curVarLength > strLen ? curVarLength : strLen) == 0)
2184 {
2185 return true; // found a match
2186 }
2187 index++; // increment past ','
2188 }
2189
2190 return false;
2191 }
2192
2198 const config_string &GetChoices() { return choices; }
2199
2207 const config_string &SetChoices(const char *in_choices)
2208 {
2209 choices = in_choices;
2210 value.SetEnumList(choices);
2211
2212 return choices;
2213 }
2214
2215 /* @brief Set the list of choices
2216 *
2217 * @param in_choices The list of option choices
2218 *
2219 * @returns A config_string object containing the list of choices
2220 */
2221 const config_string &SetChoices(const NBString &in_choices)
2222 {
2223 choices = in_choices;
2224 value.SetEnumList(choices);
2225
2226 return choices;
2227 }
2228
2229
2235 operator NBString() const { return (NBString)value; };
2236
2243 {
2244 value = p;
2245 if (GetFlags(fConfigIsDefault))
2246 ClrBranchFlag(fConfigIsDefault, true);
2247 return *this;
2248 };
2249
2256 {
2257 value = s;
2258 if (GetFlags(fConfigIsDefault))
2259 ClrBranchFlag(fConfigIsDefault, true);
2260 return *this;
2261 };
2262
2269 {
2270 value = ci.value;
2271 if (GetFlags(fConfigIsDefault))
2272 ClrBranchFlag(fConfigIsDefault, true);
2273 return *this;
2274 };
2275
2276 virtual void GetTypeValue(NBString &s) override { s = "object"; };
2277};
2278
2285{
2286 protected:
2287 int min_val; // should be INT_MIN by default
2288 int max_val; // should be INT_MAX by default
2289
2290 public:
2301 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)
2302 {
2303 min_val=minv;
2304 max_val=maxv;
2305 }
2306
2316 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)
2317 {
2318 min_val=minv;
2319 max_val=maxv;
2320 }
2321
2322 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2323 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2324
2325 config_int_limit &operator=(const int i)
2326 {
2327 if(i>=min_val && max_val<=i)
2328 {
2329 pend_val = val = i;
2330 if (GetFlags(fConfigIsDefault))
2331 ClrBranchFlag(fConfigIsDefault, true);
2332 }
2333 return *this;
2334 };
2335
2343 {
2344 int test_v=ci;
2345 if((test_v>=min_val) && (test_v<=max_val))
2346 {
2347 pend_val = val = test_v;
2348 if (GetFlags(fConfigIsDefault))
2349 ClrBranchFlag(fConfigIsDefault, true);
2350 }
2351 return *this;
2352 };
2353
2361 {
2362 int test_v=cil;
2363 if((test_v>=min_val) && (test_v<=max_val))
2364 {
2365 pend_val = val = test_v;
2366 if (GetFlags(fConfigIsDefault))
2367 ClrBranchFlag(fConfigIsDefault, true);
2368 }
2369 return *this;
2370 };
2371
2372};
2373
2380{
2381 protected:
2382 uint32_t min_val; // should be 0 by default
2383 uint32_t max_val; // should be UINT_MAX by default
2384
2385 public:
2396 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)
2397 {
2398 min_val=minv;
2399 max_val=maxv;
2400 }
2401
2411 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)
2412 {
2413 min_val=minv;
2414 max_val=maxv;
2415 }
2416
2417 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2418 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2419
2420 config_uint_limit &operator=(const uint32_t i)
2421 {
2422 if(i>=min_val && max_val<=i)
2423 {
2424 pend_val = val = i;
2425 if (GetFlags(fConfigIsDefault))
2426 ClrBranchFlag(fConfigIsDefault, true);
2427 }
2428 return *this;
2429 };
2430
2438 {
2439 uint32_t test_v=ci;
2440 if((test_v>=min_val) && (test_v<=max_val))
2441 {
2442 pend_val = val = test_v;
2443 if (GetFlags(fConfigIsDefault))
2444 ClrBranchFlag(fConfigIsDefault, true);
2445 }
2446 return *this;
2447 };
2448
2456 {
2457 uint32_t test_v=cil;
2458 if((test_v>=min_val) && (test_v<=max_val))
2459 {
2460 pend_val = val = test_v;
2461 if (GetFlags(fConfigIsDefault))
2462 ClrBranchFlag(fConfigIsDefault, true);
2463 }
2464 return *this;
2465 };
2466
2467};
2468
2469
2470
2477{
2478 protected:
2479 double min_val; // should be -DBL_MAX by default
2480 double max_val; // should be DBL_MAX by default
2481 double step; // allowable increments in the HTML GUI (precision to round to, not strictly enforced)
2482
2483 public:
2495 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)
2496 {
2497 min_val=minv;
2498 max_val=maxv;
2499 step=stepv;
2500 }
2501
2512 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)
2513 {
2514 min_val=minv;
2515 max_val=maxv;
2516 step=stepv;
2517 }
2518
2519 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2520 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2521
2522 config_double_limit &operator=(const double i)
2523 {
2524 if(i>=min_val && max_val<=i)
2525 {
2526 pend_val = val = i;
2527 if (GetFlags(fConfigIsDefault))
2528 ClrBranchFlag(fConfigIsDefault, true);
2529 }
2530 return *this;
2531 };
2532
2540 {
2541 double test_v=ci;
2542 if((test_v>=min_val) && (test_v<=max_val))
2543 {
2544 pend_val = val = test_v;
2545 if (GetFlags(fConfigIsDefault))
2546 ClrBranchFlag(fConfigIsDefault, true);
2547 }
2548 return *this;
2549 };
2550
2558 {
2559 double test_v=cil;
2560 if((test_v>=min_val) && (test_v<=max_val))
2561 {
2562 pend_val = val = test_v;
2563 if (GetFlags(fConfigIsDefault))
2564 ClrBranchFlag(fConfigIsDefault, true);
2565 }
2566 return *this;
2567 };
2568
2569
2577 virtual void GetTypeValue(NBString &s) override { s = "number"; };
2578};
2579
2586{
2587 protected:
2588 size_t min_len; // should be 0 by default
2589 size_t max_len; // should be 0 by default
2590
2591 public:
2602 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)
2603 {
2604 min_len=minl;
2605 max_len=maxl;
2606 }
2607
2617 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)
2618 {
2619 min_len=minl;
2620 max_len=maxl;
2621 }
2622
2623 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2624 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2625
2626 config_string_limit &operator=(const NBString i)
2627 {
2628 if(i.length()>=min_len && max_len<=i.length())
2629 {
2630 pend_val = val = i;
2631 if (GetFlags(fConfigIsDefault))
2632 ClrBranchFlag(fConfigIsDefault, true);
2633 }
2634 return *this;
2635 };
2636
2644 {
2645 NBString test_v=ci;
2646 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2647 {
2648 pend_val = val = test_v;
2649 if (GetFlags(fConfigIsDefault))
2650 ClrBranchFlag(fConfigIsDefault, true);
2651 }
2652 return *this;
2653 };
2654
2662 {
2663 NBString test_v=cil;
2664 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2665 {
2666 pend_val = val = test_v;
2667 if (GetFlags(fConfigIsDefault))
2668 ClrBranchFlag(fConfigIsDefault, true);
2669 }
2670 return *this;
2671 };
2672
2673};
2674
2681{
2682 protected:
2683 size_t min_len; // should be 0 by default
2684 size_t max_len; // should be 0 by default
2685
2686 public:
2697 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)
2698 {
2699 min_len=minl;
2700 max_len=maxl;
2701 }
2702
2712 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)
2713 {
2714 min_len=minl;
2715 max_len=maxl;
2716 }
2717
2718 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2719 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2720
2721 config_pass_limit &operator=(const NBString i)
2722 {
2723 if(i.length()>=min_len && max_len<=i.length())
2724 {
2725 pend_val = val = i;
2726 if (GetFlags(fConfigIsDefault))
2727 ClrBranchFlag(fConfigIsDefault, true);
2728 }
2729 return *this;
2730 };
2731
2739 {
2740 NBString test_v=ci;
2741 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2742 {
2743 pend_val = val = test_v;
2744 if (GetFlags(fConfigIsDefault))
2745 ClrBranchFlag(fConfigIsDefault, true);
2746 }
2747 return *this;
2748 };
2749
2757 {
2758 NBString test_v=cil;
2759 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2760 {
2761 pend_val = val = test_v;
2762 if (GetFlags(fConfigIsDefault))
2763 ClrBranchFlag(fConfigIsDefault, true);
2764 }
2765 return *this;
2766 };
2767
2768};
2769
2770class reboot_obj : public config_bool
2771{
2772 virtual const char *GetSortNameValue() { return "ZZZc"; };
2773
2774 public:
2775 reboot_obj() : config_bool(root, false, "Reboot", "Cause system reboot on save"){};
2776 void clear()
2777 {
2778 val = false;
2779 pend_val = false;
2780 };
2781
2782 // This is named so error messages make sense to user, old name was GetExtent
2783 virtual int Missing_ConfigEndMarker(void *&startp)
2784 {
2785 startp = this;
2786 return sizeof(*this);
2787 };
2788};
2789
2790class version_obj : public config_int
2791{
2792 bool bNeverSet;
2793 virtual const char *GetSortNameValue() { return "ZZZb"; };
2794
2795 public:
2796 version_obj() : config_int(root, 0, "Version", "Version serial number") { bNeverSet = true; };
2797
2798 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs);
2799 void inc()
2800 {
2801 val++;
2802 pend_val = val;
2803 };
2804 // This is named so error messages make sense to user
2805 // Old name was GetExtent
2806 virtual int Missing_ConfigEndMarker(void *&startp)
2807 {
2808 startp = this;
2809 return sizeof(*this);
2810 };
2811};
2812
2813class empty_config_obj : public config_obj
2814{
2815 ConfigEndMarker;
2816
2817 public:
2818 empty_config_obj(const char *name, const char *desc = NULL) : config_obj(name, desc){};
2819 empty_config_obj(config_obj &owner, const char *name, const char *desc = NULL) : config_obj(owner, name, desc){};
2820 empty_config_obj(empty_config_obj &&e);
2821};
2822
2823
2824
2825// This class is intended for recovery applications or for devices supporting multiple
2826// application profiles to preserve unused config tree branches across configuration
2827// updates
2828// Ex:
2829// Application A has a config object at 'AppData.AppA', and Application B
2830// has a config object at 'AppData.AppB'. Normally, if Application A were
2831// to update any configuration (whether Application or System related), this
2832// would wipe out any AppB configuration as it is not known of by Application A.
2833// Using a config_preserver_obj, any configuration tree data below it's registration
2834// will be persisted across updates unless explicitly wiped.
2835class config_preserver_obj : public config_obj
2836{
2837 ConfigEndMarker;
2838 ParsedJsonDataSet &pendingTreeData;
2839 ParsedJsonDataSet &treeData;
2840
2841 public:
2842 config_preserver_obj(const char *name, const char *desc = NULL);
2843 config_preserver_obj(config_obj &owner, const char *name, const char *desc = NULL);
2844 config_preserver_obj(config_preserver_obj &&po);
2845
2846
2847 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2848 virtual void CommitTestedValue(uint32_t permission_mask) override;
2849 virtual void GetTextValue(NBString &s) override;
2850 virtual void GetRawValue(NBString &s) override;
2851};
2852
2853extern const char *AppName;
2854extern const char PlatformName[];
2855
2856class SysRecord : public config_obj
2857{
2858 public:
2859 config_report system_platform{PlatformName, "Platform", "Hardware Platform"};
2860 config_report system_app{AppName, "Application", "Application name"};
2861 ConfigEndMarker;
2862
2863 SysRecord(const char *name, const char *desc = NULL) : config_obj(name, desc){};
2864 SysRecord(config_obj &owner, const char *name, const char *desc = NULL) : config_obj(owner, name, desc){};
2865 SysRecord(SysRecord &&sr);
2866};
2867
2868extern SysRecord sys;
2869extern empty_config_obj netif;
2870
2871extern reboot_obj rebooter;
2872extern version_obj config_cur_version;
2873
2874extern const int plat_def_baud;
2875extern const int plat_def_delay;
2876extern const int plat_def_quiet;
2877extern const int plat_def_watchdog_enabled;
2878
2879#include <plat_cfg_types.h>
2880#ifdef PRESERVE_APP_DATA
2881extern config_preserver_obj appdata;
2882#else
2883extern empty_config_obj appdata;
2884#endif
2885
2891
2892class MonitorRecord : public config_obj
2893{
2894 public:
2895 config_int Baud{plat_def_baud, "BootBaud"};
2896 config_uart Uart{plat_def_com, "BootUart"};
2897 config_int BootDelay{plat_def_delay, "BootDelay"};
2898 config_bool Quiet{plat_def_quiet, "BootQuiet"};
2899 config_chooser sercfg_action{"SerialConfig", "DuringBoot", "DuringBoot,AlwaysEnabled,PauseAfterBoot,Disabled"};
2900 config_string abortbootcmd{"A", "Abort"};
2901 config_pass system_user{"", "User"};
2902 config_pass system_pass{"", "Password"};
2903 ConfigEndMarker;
2904
2905 MonitorRecord(const char *name) : config_obj(name, "Boot monitor record")
2906 {
2907 sercfg_action.SetFlag(fConfigNeedReboot);
2908 Baud.SetFlag(fConfigNeedReboot);
2909 Uart.SetFlag(fConfigNeedReboot);
2910 };
2911 MonitorRecord(config_obj &owner, const char *name) : config_obj(owner, name, "Boot Monitor Record")
2912 {
2913 sercfg_action.SetFlag(fConfigNeedReboot);
2914 Baud.SetFlag(fConfigNeedReboot);
2915 Uart.SetFlag(fConfigNeedReboot);
2916 };
2917 MonitorRecord(MonitorRecord &&mr);
2918};
2919extern MonitorRecord monitor_config;
2920
2931
2932
2933
2934
2935#endif
2936
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:1613
config_IPADDR4(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1577
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1666
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:1560
config_IPADDR4(IPADDR4 def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1542
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:1515
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:1527
config_IPADDR4 & operator=(const config_IPADDR4 &ci)
Copy one config_IPADDR4 object to another.
Definition config_obj.h:1644
bool IsNull() const
Check if the IP address is null.
Definition config_obj.h:1604
void SetNull()
Set the IP address to null.
Definition config_obj.h:1620
config_IPADDR4 & operator=(const IPADDR4 &i4)
Copy an IPADDR4 object value to a config_IPADDR4 object.
Definition config_obj.h:1631
Configuration Variable for IPADDR (IPv6) object type.
Definition config_obj.h:1683
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1844
config_IPADDR & operator=(const config_IPADDR &ci)
Copy one config_IPADDR object to another.
Definition config_obj.h:1822
config_IPADDR & operator=(const IPADDR &i6)
Copy an IPADDR object value to a config_IPADDR object.
Definition config_obj.h:1809
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:1742
config_IPADDR(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1759
void SetNull()
Set the IP address value of an config_IPADDR object to null.
Definition config_obj.h:1798
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:1709
bool NotNull() const
Check if the IP address is not null.
Definition config_obj.h:1793
config_IPADDR(IPADDR def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1726
bool IsNull() const
Check if the IP address is null.
Definition config_obj.h:1784
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:1697
Configuration Variable for MACADR object type.
Definition config_obj.h:1861
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:1892
config_MACADR & operator=(const MACADR &ci)
Copy a MACADR object value to a MACADR object.
Definition config_obj.h:1980
config_MACADR(MACADR def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1909
config_MACADR & operator=(const config_MACADR &ci)
Copy one config_MACADR object to another.
Definition config_obj.h:1967
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:1926
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:1876
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:2011
config_MACADR(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1945
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:2035
virtual void GetTypeValue(NBString &s) override
Assigns the object type value to the specified NBString object.
Definition config_obj.h:2276
const config_string & GetChoices()
Get the list of choices.
Definition config_obj.h:2198
const config_string & SetChoices(const char *in_choices)
Set the list of choices.
Definition config_obj.h:2207
bool IsSelected(const char *choice)
Check if a particular choice option is selected.
Definition config_obj.h:2090
config_chooser & operator=(const char *p)
Assign the selected list item from a const char* value.
Definition config_obj.h:2242
bool IsSelected(const NBString &s)
Check if a particular choice option is selected.
Definition config_obj.h:2100
config_chooser & operator=(const config_chooser &ci)
Copy one config_chooser object to another.
Definition config_obj.h:2268
config_chooser(const char *name, const char *in_value, const char *in_choices, const char *desc=NULL)
Object constructor.
Definition config_obj.h:2074
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:2115
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:2052
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:2160
config_chooser & operator=(const NBString &s)
Assign the config_string object value from a NBString object.
Definition config_obj.h:2255
A config_double with minimum and/or maximum values Attempting to set a value lower than the minimum o...
Definition config_obj.h:2477
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:2577
config_double_limit & operator=(const config_double_limit &cil)
Copy one config_double_limit object to another.
Definition config_obj.h:2557
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:2512
config_double_limit & operator=(const config_double &ci)
Copy a config_double object into the config_double_limit.
Definition config_obj.h:2539
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:2495
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:2285
config_int_limit & operator=(const config_int &ci)
Copy a config_int object into the config_int_limit.
Definition config_obj.h:2342
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:2316
config_int_limit & operator=(const config_int_limit &cil)
Copy one config_int_limit object to another.
Definition config_obj.h:2360
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:2301
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:2681
config_pass_limit & operator=(const config_pass_limit &cil)
Copy one config_pass_limit object to another.
Definition config_obj.h:2756
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:2697
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:2712
config_pass_limit & operator=(const config_pass &ci)
Copy a config_pass object into the config_pass_limit.
Definition config_obj.h:2738
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:2586
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:2617
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:2602
config_string_limit & operator=(const config_string &ci)
Copy a config_string object into the config_string_limit.
Definition config_obj.h:2643
config_string_limit & operator=(const config_string_limit &cil)
Copy one config_string_limit object to another.
Definition config_obj.h:2661
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:2380
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:2411
config_uint_limit & operator=(const config_uint_limit &cil)
Copy one config_uint_limit object to another.
Definition config_obj.h:2455
config_uint_limit & operator=(const config_uint &ci)
Copy a config_uint object into the config_uint_limit.
Definition config_obj.h:2437
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:2396
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.