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_obj *FindRoot();
131 config_leaf *FindChild(const char *&cp);
132 void RootParse(RootParseStateInfo &rpsi);
133 static void FixTree(config_leaf* root);
134 static void ClearNonParentRelations(config_leaf* root);
135
136
137 virtual void RemoveFromRootList();
138 public:
139 virtual void RawFdPrintTree(int fd, int n, bool pretty, uint32_t mask, bool braw_values,bool valonly) = 0;
140
141 inline void FdPrintValTree(int fd, int n, bool pretty, uint32_t inhibit_mask = fConfigHidden, bool bRawValue = false)
142 {
143 RawFdPrintTree(fd,n,pretty,inhibit_mask,bRawValue,true);
144 }
145 inline void FdPrintTree(int fd, int n, bool pretty, uint32_t inhibit_mask = fConfigHidden, bool bRawValue = false)
146 {
147 RawFdPrintTree(fd,n,pretty,inhibit_mask,bRawValue,false);
148 }
149
150 virtual void FdPrintSchema(int fd, config_leaf *pl, int n, bool pretty, uint32_t inhibit_mask = fConfigHidden);
151 void SchemaOptions(int fd, int indent, bool pretty);
152 void ForEachLeaf(LeafCallBack *pc, void *pextra, bool siblings = false);
153 bool FlatParseBuffer(fifo_buffer_storage &rxbuf, uint32_t permissions, const char *where);
154 bool ParseBuffer(fifo_buffer_storage &rxbuf, uint32_t permissions, const char *where);
155 bool ParseBlob(uint8_t *pdata, int len, uint32_t permissions);
156 bool FlatParseBlob(uint8_t *pdata, int len, uint32_t permissions);
157 bool ParseFd(int fd, uint32_t permissions, config_leaf * pParseRoot = NULL);
158 config_obj *FindParent() { return pParent; };
159 static config_leaf *FindConfigLeaf(const unsigned char *name, config_leaf *pBranch = NULL);
160
161 void AddNotification(ConfigNotificationObject & noteobj);
162
163
164 //Call if a config object is not static
165 void FixNonStaticObject();
166
167 void RemoveFromConfigTree();
168
169 const char *pName;
170 const char *pDescription;
171 config_leaf *pNextSibling;
172 config_obj *pParent;
173 config_leaf *pChildren;
174 config_leaf *pGList;
175 notify_list NotifyListMask;
176
177
178 static config_leaf *pRootList;
179 static config_leaf *pDetachList;
180
181 uint32_t m_Flags;
182 void DoSchemaLine(int fd, const char *name, const char *value, int indent, bool pretty, bool quoted = true);
183 void DoSchemaLine(int fd, const char *name, int value, int indent, bool pretty, bool quoted = true);
184 void DoSchemaLine(int fd, const char *name, double value, int indent, bool pretty, bool quoted = true);
185
186 public:
187 bool NameMatch(const char *cp);
188 virtual const char *GetSortNameValue() { return pName; };
189 virtual void GetDescriptionValue(NBString &s) { s = pDescription; };
190 virtual void GetNameValue(NBString &s) { s = pName; };
191 virtual void GetTextValue(NBString &s) { s = pName; };
192 virtual void GetRawValue(NBString &s) { return GetTextValue(s); };
193 virtual void GetTypeValue(NBString &s) { s = "unknown"; };
194 virtual void ExtendedSchema(int fd, int indent, bool pretty){};
195 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) { return eOk; };
196 // This is named so error messages make sense to user
197 // Old name was GetExtent
198 virtual int Missing_ConfigEndMarker(void *&startp) = 0;
199
200 void ClearModified();
201
202 bool MatchId(ParsedJsonDataSet &pjs);
203
204 virtual bool CheckGroupValues() {return true;}
205 virtual void CommitTestedValue(uint32_t permission_mask){};
206
207 virtual ~config_leaf();
208
209 config_leaf(bool bDetached=false)
210 {
211 pNextSibling = NULL;
212 pChildren = NULL;
213 m_Flags = fConfigIsDefault;
214 pParent = NULL;
215 if (bDetached)
216 {
217 pGList=pDetachList;
218 pDetachList=this;
219 m_Flags = (m_Flags & ~fConfigIsDefault) | fConfigDetached;
220 }
221 else
222 {
223 pGList = pRootList;
224 pRootList = this;
225 }
226 }
227 config_leaf(config_leaf &&l);
228
229 static void DiagShow();
230 static void FixTree();
231 void FindUnknownParent();
232
233 void ShowOne();
234
235 int compare(config_leaf *pl)
236 {
237 if (pl == NULL) return -1;
238 return strcmp(GetSortNameValue(), pl->GetSortNameValue());
239 };
240
241 void GetFullName(NBString &s);
242 void GetBranchName(NBString &s, config_leaf *branchRoot);
243 void RenderToFd(int fd, bool pretty = false, uint32_t mask = fConfigHidden, bool bRawValue = false);
244 void RenderSchemaToFd(int fd, bool pretty = false, uint32_t mask = fConfigHidden);
245 uint32_t GetFlags() { return m_Flags; }
246 uint32_t GetFlags(uint32_t mask) { return m_Flags & mask; }
247 void SetFlag(uint32_t flag) { m_Flags |= flag; };
248 void SetBranchFlag(uint32_t flag, bool upNotDown = false);
249 void ClrFlag(uint32_t flag) { m_Flags &= (~flag); };
250 void ClrBranchFlag(uint32_t flag, bool upNotDown = false);
251 void ReloadFromFlash();
252 void AssignmentNotify();
253
254 void LogParseError(NBString & err);
255 inline void LogParseError(const char * err) {NBString s(err); LogParseError(s); };
256
257
258 friend void HtmlLeafRender(int fd, config_leaf *pl, int eMode, int len, const char *extra);
259 friend ConfigNotificationObject;
260};
261
322class config_obj : public config_leaf
323{
324 protected:
325 config_obj(bool bDetached=false):config_leaf(bDetached){}
326 config_obj *pMasterObjectLink;
327 static config_obj *pObjList;
328
329 virtual void RemoveFromRootList();
330 public:
331 virtual void RawFdPrintTree(int fd, int n, bool pretty, uint32_t mask, bool braw_values,bool valonly) override;
332 void InstallUnderMe(config_leaf &ltoadd);
333 void RemoveFromChildren(config_leaf &ltoremove);
334
347 config_obj(config_obj &owner, const char *name, const char *desc)
348 {
349 pName = name;
350 pDescription = desc;
351 pChildren = NULL;
352 pMasterObjectLink = pObjList;
353 pObjList = this;
354 pParent = &owner;
355 }
357
370 config_obj(const char *name, const char *desc)
371 {
372 pName = name;
373 pDescription = desc;
374 pChildren = NULL;
375 pParent = NULL;
376 pMasterObjectLink = pObjList;
377 pObjList = this;
378 }
379
380
381
382 bool DoIContain(config_leaf *pl);
383
384 /*
385 * These two functions, along with GetTextValue(), can be used to create a custom object
386 * class, including the responsibility for the JSON serialization.
387 *
388 * GetTextValue(): Must return a string with the object encoded in it in JSON format
389 *
390 * TestNewValue(): Takes a parsed JSON object and extracts the values from that tree.
391 * This is where parameters can be tested for validity, and if not valid,
392 * the entire set is marked as invalid.
393 *
394 * CommitTestedValue(): Commit the values extracted by TestNewValue()
395 *
396 * This enables functionality such as parsing a set of values to determine if the SET is
397 * valid, rather than just an individual value.
398 */
399 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
400 virtual void CommitTestedValue(uint32_t permission_mask) override;
401
402 // This is named so error messages make sense to user, old name was GetExtent
403 virtual int Missing_ConfigEndMarker(void *&startp) override
404 {
405 startp = this;
406 return sizeof(*this);
407 };
408
416 virtual void GetTextValue(NBString &s) override;
417
425 virtual void GetTypeValue(NBString &s) override { s = "object"; };
426
427 friend class config_leaf;
428};
429
430/*
431 * Configuration Root object class
432 */
433class root_obj : public config_obj
434{
435 public:
436 root_obj()
437 { pName = "Config";
438 pDescription = "Root of config tree";
439 }
440
441 // This is named so error messages make sense to user, old name was GetExtent
442 virtual int Missing_ConfigEndMarker(void *&startp) override
443 {
444 startp = this;
445 return sizeof(*this);
446 };
447};
448
449class detached_root_obj : public config_obj
450{
451 public:
452 detached_root_obj():config_obj(true)
453 { pName = "detached";
454 pDescription = "Root of detached tree";
455 }
456
457 // This is named so error messages make sense to user, old name was GetExtent
458 virtual int Missing_ConfigEndMarker(void *&startp) override
459 {
460 startp = this;
461 return sizeof(*this);
462 };
463};
464
465
466
467
468extern root_obj root;
469extern detached_root_obj detached;
470
492class config_value : public config_leaf
493{
494 public:
495 virtual void GetTextValue(NBString &s) override = 0;
496
497 protected:
510 config_value(config_obj &owner, const char *name, const char *desc)
511 {
512 pName = name;
513 pDescription = desc;
514 owner.InstallUnderMe(*this);
515 pChildren = NULL;
516 m_Flags |= fConfigValueLeaf;
517 }
518
531 config_value(const char *name, const char *desc)
532 {
533 pName = name;
534 pDescription = desc;
535 pParent = NULL;
536 pChildren = NULL;
537 m_Flags |= fConfigValueLeaf;
538 }
539
541 virtual int FdPrintValue(int fd, bool raw);
542
543public:
544 virtual void RawFdPrintTree(int fd, int n, bool pretty, uint32_t mask, bool braw_values,bool valonly) override;
545};
546
555{
556 protected:
557 uint32_t val;
558 uint32_t pend_val;
559
560 virtual int FdPrintValue(int fd, bool raw) override;
561 public:
569 virtual void GetTextValue(NBString &s) override { s.siprintf("%u", val); };
570
579 config_uint(config_obj &owner, uint32_t def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
580 {
581 val = def_val;
582 pend_val = val;
583 }
584
592 config_uint(uint32_t def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
593 {
594 val = def_val;
595 pend_val = val;
596 }
597
599
600 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
601 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
602
603 // Assignment operators
604
616 operator uint32_t() const { return val; };
617
623 config_uint &operator=(const uint32_t i)
624 {
625 pend_val = val = i;
626 if (GetFlags(fConfigIsDefault))
627 ClrBranchFlag(fConfigIsDefault, true);
628 return *this;
629 };
630
637 {
638 pend_val = val = ci.val;
639 if (GetFlags(fConfigIsDefault))
640 ClrBranchFlag(fConfigIsDefault, true);
641 return *this;
642 };
643
644 // This is named so error messages make sense to user. Old name was GetExtent
645 virtual int Missing_ConfigEndMarker(void *&startp) override
646 {
647 startp = this;
648 return sizeof(*this);
649 };
650
658 virtual void GetTypeValue(NBString &s) override { s = "integer"; };
659};
660
661class config_hex_uint : public config_uint
662{
663
664 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs);
665
666protected:
667 virtual int FdPrintValue(int fd, bool raw) override;
668public:
677 config_hex_uint(config_obj &owner, uint32_t def_val, const char *name, const char *desc = NULL) : config_uint(owner,def_val, name, desc){}
678
686 config_hex_uint(uint32_t def_val, const char *name, const char *desc = NULL) : config_uint(def_val,name, desc){}
687
688 virtual void GetTextValue(NBString &s) override { s.siprintf("\"0x%X\"", val); };
689 virtual void GetTypeValue(NBString &s) override { s = "string"; };
690
691};
692
693
694
703{
704 protected:
705 int val;
706 int pend_val;
707
708 virtual int FdPrintValue(int fd, bool raw) override;
709 public:
717 virtual void GetTextValue(NBString &s) override { s.siprintf("%d", val); };
718
727 config_int(config_obj &owner, int def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
728 {
729 val = def_val;
730 pend_val = val;
731 }
732
740 config_int(int def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
741 {
742 val = def_val;
743 pend_val = val;
744 }
745
747
748 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
749
750 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
751
752 // Assignment operators
753
765 operator int() const { return val; };
766
772 config_int &operator=(const int i)
773 {
774 pend_val = val = i;
775 if (GetFlags(fConfigIsDefault))
776 ClrBranchFlag(fConfigIsDefault, true);
777 return *this;
778 };
779
787 {
788 pend_val = val = ci.val;
789 if (GetFlags(fConfigIsDefault))
790 ClrBranchFlag(fConfigIsDefault, true);
791 return *this;
792 };
793
794 // This is named so error messages make sense to user, old name was GetExtent
795 virtual int Missing_ConfigEndMarker(void *&startp) override
796 {
797 startp = this;
798 return sizeof(*this);
799 };
800
808 virtual void GetTypeValue(NBString &s) override { s = "integer"; };
809};
810
819{
820 protected:
821 double val;
822 double pend_val;
823
824 virtual int FdPrintValue(int fd, bool raw) override;
825 public:
833 virtual void GetTextValue(NBString &s) override { s.sprintf("%g", val); };
834
843 config_double(config_obj &owner, double def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
844 {
845 val = def_val;
846 pend_val = val;
847 }
848
856 config_double(double def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
857 {
858 val = def_val;
859 pend_val = val;
860 }
861
863
864 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
865 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
866
867 // Assignment operators
868
880 operator int() const { return val; };
881
893 operator float() const { return val; };
894
906 operator double() const { return val; };
907
913 config_double &operator=(const double d)
914 {
915 pend_val = val = d;
916 if (GetFlags(fConfigIsDefault))
917 ClrBranchFlag(fConfigIsDefault, true);
918 return *this;
919 };
920
927 {
928 pend_val = val = ci.val;
929 if (GetFlags(fConfigIsDefault))
930 ClrBranchFlag(fConfigIsDefault, true);
931 return *this;
932 };
933
934 // This is named so error messages make sense to user. old name was GetExtent
935 virtual int Missing_ConfigEndMarker(void *&startp) override
936 {
937 startp = this;
938 return sizeof(*this);
939 };
940
950 virtual void GetTypeValue(NBString &s) override { s = "string"; };
951};
952
953/*
954 * Class used for system status reports, for internal use only
955 */
956class config_report : public config_value
957{
958 protected:
959 const char *m_value;
960
961 virtual int FdPrintValue(int fd, bool raw) override;
962 public:
963 config_report(config_obj &owner, const char *value, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
964 {
965 m_Flags = fConfigReadOnly | fConfigNoSave;
966 m_value = value;
967 }
968 config_report(const char *value, const char *name, const char *desc = NULL) : config_value(name, desc)
969 {
970 m_Flags = fConfigReadOnly | fConfigNoSave;
971 m_value = value;
972 }
973
974 config_report(config_report &&r);
975
976 virtual void GetTextValue(NBString &s) override;
977 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
978 virtual void CommitTestedValue(uint32_t permission_mask) override;
979 // This is named so error messages make sense to user
980 // Old name was GetExtent
981 virtual int Missing_ConfigEndMarker(void *&startp) override
982 {
983 startp = this;
984 return sizeof(*this);
985 };
986 virtual void GetTypeValue(NBString &s) override { s = "string"; };
987
988 const char *c_str() { return m_value; };
989 void ModifyValue(const char *nv) { m_value = nv; };
990};
991
1000{
1001 protected:
1002 bool val;
1003 bool pend_val;
1004
1005 virtual int FdPrintValue(int fd, bool raw) override;
1006 public:
1014 virtual void GetTextValue(NBString &s) override
1015 {
1016 if (val)
1017 s = "true";
1018 else
1019 s = "false";
1020 };
1021
1030 config_bool(config_obj &owner, bool def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1031 {
1032 val = def_val;
1033 pend_val = val;
1034 }
1035
1043 config_bool(bool def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1044 {
1045 val = def_val;
1046 pend_val = val;
1047 }
1049
1050 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1051 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1052
1053 // Assignemt operators
1054
1066 operator bool() const { return val; };
1067
1073 config_bool &operator=(const bool v)
1074 {
1075 pend_val = val = v;
1076 if (GetFlags(fConfigIsDefault))
1077 ClrBranchFlag(fConfigIsDefault, true);
1078 return *this;
1079 };
1080
1087 {
1088 pend_val = val = cb.val;
1089 if (GetFlags(fConfigIsDefault))
1090 ClrBranchFlag(fConfigIsDefault, true);
1091 return *this;
1092 };
1093
1100 {
1101 pend_val = val = (i != 0);
1102 if (GetFlags(fConfigIsDefault))
1103 ClrBranchFlag(fConfigIsDefault, true);
1104 return *this;
1105 };
1106
1107 // This is named so error messages make sense to user, old name was GetExtent
1108 virtual int Missing_ConfigEndMarker(void *&startp)
1109 {
1110 startp = this;
1111 return sizeof(*this);
1112 };
1113
1119 virtual void GetTypeValue(NBString &s) override { s = "boolean"; };
1120};
1121
1130{
1131 protected:
1132 NBString val;
1133 NBString pend_val;
1134 NBString enum_list;
1135
1136 virtual int FdPrintValue(int fd, bool raw) override;
1137 public:
1145 virtual void GetTextValue(NBString &s) override;
1146// {
1147// s = "\"";
1148// s += val;
1149// s += "\"";
1150// };
1151
1153
1154 const char * GetPendValue() {return pend_val.c_str();};
1155
1166 config_string(config_obj &owner, NBString def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1167 {
1168 val = def_val;
1169 pend_val = val;
1170 }
1171
1181 config_string(NBString def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1182 {
1183 pName = name;
1184 val = def_val;
1185 pend_val = val;
1186 }
1187
1198 config_string(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1199 {
1200 val = def_val;
1201 pend_val = val;
1202 }
1203
1213 config_string(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1214 {
1215 val = def_val;
1216 pend_val = val;
1217 }
1218
1219 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1220 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1221
1228 void SetEnumList(NBString s) { enum_list = s; };
1229
1230 // Assignment Operators
1231
1237 operator NBString() const { return val; };
1238
1244 config_string &operator=(const char *p)
1245 {
1246 pend_val = val = p;
1247 if (GetFlags(fConfigIsDefault))
1248 ClrBranchFlag(fConfigIsDefault, true);
1249 return *this;
1250 };
1251
1258 {
1259 pend_val = val = s;
1260 if (GetFlags(fConfigIsDefault))
1261 ClrBranchFlag(fConfigIsDefault, true);
1262 return *this;
1263 };
1264
1271 {
1272 pend_val = val = ci.val;
1273 if (GetFlags(fConfigIsDefault))
1274 ClrBranchFlag(fConfigIsDefault, true);
1275 return *this;
1276 };
1277
1278 // This is named so error messages make sense to user, old name was GetExtent
1279 virtual int Missing_ConfigEndMarker(void *&startp) override
1280 {
1281 startp = this;
1282 return sizeof(*this);
1283 };
1284
1290 inline const char *c_str() const { return val.c_str(); };
1291
1297 inline size_t length() const { return val.length(); };
1298
1306 inline const char &operator[](size_t pos) const { return val[pos]; };
1307
1315 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1316
1317 virtual void ExtendedSchema(int fd, int indent, bool pretty);
1318
1319 /* *
1320 * @brief Perform a string interpolation and place the finished interpolation
1321 * in the Destination string
1322 *
1323 * @param dest Destination string
1324 *
1325 * @returns Whether the interpolation was successful
1326 */
1327 bool Interpolate(NBString &dest)
1328 {
1329 return val.Interpolate(dest);
1330 }
1331
1332 friend class config_pass;
1333 friend class config_localname;
1334 friend class config_chooser;
1335 friend class config_localname;
1336};
1337
1348{
1349 protected:
1350 virtual int FdPrintValue(int fd, bool raw) override;
1351 public:
1362 config_pass(config_obj &owner, NBString def_val, const char *name, const char *desc = NULL)
1363 : config_string(owner, def_val, name, desc){};
1364
1374 config_pass(NBString def_val, const char *name, const char *desc = NULL) : config_string(def_val, name, desc){};
1375
1386 config_pass(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL)
1387 : config_string(owner, def_val, name, desc){};
1388
1398 config_pass(const char *def_val, const char *name, const char *desc = NULL) : config_string(def_val, name, desc){};
1399
1401
1409 virtual void GetTextValue(NBString &s) override;
1410
1418 virtual void GetRawValue(NBString &s) override;
1419
1420 virtual void CommitTestedValue(uint32_t permission_mask) override;
1421
1422 // Add help pop-ups for web page display
1423 virtual void ExtendedSchema(int fd, int indent, bool pretty)
1424 {
1425 config_string::ExtendedSchema(fd, indent, pretty);
1426 DoSchemaLine(fd, "format", "password", indent, pretty);
1427 };
1428
1434 operator NBString() const { return val; };
1435
1441 config_pass &operator=(const char *p)
1442 {
1443 pend_val = val = p;
1444 if (GetFlags(fConfigIsDefault))
1445 ClrBranchFlag(fConfigIsDefault, true);
1446 return *this;
1447 };
1448
1455 {
1456 pend_val = val = s;
1457 if (GetFlags(fConfigIsDefault))
1458 ClrBranchFlag(fConfigIsDefault, true);
1459 return *this;
1460 };
1461
1468 {
1469 pend_val = val = ci.val;
1470 if (GetFlags(fConfigIsDefault))
1471 ClrBranchFlag(fConfigIsDefault, true);
1472 return *this;
1473 };
1474
1481 {
1482 pend_val = val = ci.val;
1483 if (GetFlags(fConfigIsDefault))
1484 ClrBranchFlag(fConfigIsDefault, true);
1485 return *this;
1486 };
1487};
1488
1489
1490class I4Record;
1500{
1501 friend class I4Record; // Allow I4Record to access pend_val for validation
1502
1503 IPADDR4 val;
1504 IPADDR4 pend_val;
1505
1506 protected:
1507 virtual int FdPrintValue(int fd, bool raw) override;
1508 public:
1517 virtual void GetTextValue(NBString &s) override { s.siprintf("\"%hI\"", val); };
1518
1529 config_IPADDR4(config_obj &owner, IPADDR4 def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1530 {
1531 val = def_val;
1532 pend_val = val;
1533 }
1534
1544 config_IPADDR4(IPADDR4 def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1545 {
1546 val = def_val;
1547 pend_val = val;
1548 }
1549
1551
1562 config_IPADDR4(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1563 {
1564 IPADDR4 i4;
1565 i4.SetFromAscii(def_val);
1566 val = i4;
1567 pend_val = val;
1568 }
1569
1579 config_IPADDR4(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1580 {
1581 IPADDR4 i4;
1582 i4.SetFromAscii(def_val);
1583 val = i4;
1584 pend_val = val;
1585 }
1586
1587 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1588 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1589
1590 // Assignment operators
1591
1597 operator IPADDR4() const { return val; };
1598
1606 inline bool IsNull() const { return val.IsNull(); };
1607
1615 inline bool NotNull() const { return !(val.IsNull()); };
1616
1622 inline void SetNull()
1623 {
1624 val.SetNull();
1625 pend_val = val;
1626 };
1627
1634 {
1635 pend_val = val = i4;
1636 if (GetFlags(fConfigIsDefault))
1637 ClrBranchFlag(fConfigIsDefault, true);
1638 return *this;
1639 };
1640
1647 {
1648 pend_val = val = ci.val;
1649 if (GetFlags(fConfigIsDefault))
1650 ClrBranchFlag(fConfigIsDefault, true);
1651 return *this;
1652 };
1653
1654 // This is named so error messages make sense to user, old name was GetExtent
1655 virtual int Missing_ConfigEndMarker(void *&startp)
1656 {
1657 startp = this;
1658 return sizeof(*this);
1659 };
1660
1668 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1669
1670 // Add web page help
1671 virtual void ExtendedSchema(int fd, int indent, bool pretty) { DoSchemaLine(fd, "format", "ipv4", indent, pretty); };
1672 friend I4Record;
1673};
1674
1675#ifdef IPV6
1685{
1686 IPADDR val;
1687 IPADDR pend_val;
1688
1689 protected:
1690 virtual int FdPrintValue(int fd, bool raw) override;
1691 public:
1699 virtual void GetTextValue(NBString &s) override { s.siprintf("\"%I\"", val); };
1700
1711 config_IPADDR(config_obj &owner, IPADDR def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1712 {
1713 val = def_val;
1714 pend_val = val;
1715 }
1716
1718
1728 config_IPADDR(IPADDR def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1729 {
1730 val = def_val;
1731 pend_val = val;
1732 }
1733
1744 config_IPADDR(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1745 {
1746 IPADDR i6;
1747 i6.SetFromAscii(def_val);
1748 val = i6;
1749 pend_val = val;
1750 }
1751
1761 config_IPADDR(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1762 {
1763 IPADDR i6;
1764 i6.SetFromAscii(def_val);
1765 val = i6;
1766 pend_val = val;
1767 }
1768
1769 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1770 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1771
1777 operator IPADDR() const { return val; };
1778
1786 bool IsNull() const { return val.IsNull(); }
1787
1795 bool NotNull() const { return !(val.IsNull()); }
1796
1800 void SetNull()
1801 {
1802 val.SetNull();
1803 pend_val = val;
1804 }
1805
1812 {
1813 pend_val = val = i6;
1814 if (GetFlags(fConfigIsDefault))
1815 ClrBranchFlag(fConfigIsDefault, true);
1816 return *this;
1817 };
1818
1825 {
1826 pend_val = val = ci.val;
1827 if (GetFlags(fConfigIsDefault))
1828 ClrBranchFlag(fConfigIsDefault, true);
1829 return *this;
1830 };
1831
1832 // This is named so error messages make sense to user, old name was GetExtent
1833 virtual int Missing_ConfigEndMarker(void *&startp)
1834 {
1835 startp = this;
1836 return sizeof(*this);
1837 };
1838
1846 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1847
1848 // Add web page help
1849 virtual void ExtendedSchema(int fd, int indent, bool pretty) { DoSchemaLine(fd, "format", "ipv6", indent, pretty); };
1850};
1851#else
1852#define config_IPADDR config_IPADDR4
1853#endif
1854
1863{
1864 MACADR val;
1865 MACADR pend_val;
1866
1867 protected:
1868 virtual int FdPrintValue(int fd, bool raw) override;
1869 public:
1878 virtual void GetTextValue(NBString &s) override
1879 {
1880 s.siprintf("\"%02X:%02X:%02X:%02X:%02X:%02X\"", val.phywadr[0] >> 8, val.phywadr[0] & 0xFF, val.phywadr[1] >> 8,
1881 val.phywadr[1] & 0xFF, val.phywadr[2] >> 8, val.phywadr[2] & 0xFF);
1882 };
1883
1894 config_MACADR(config_obj &owner, MACADR def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1895 {
1896 val = def_val;
1897 pend_val = val;
1898 }
1899
1901
1911 config_MACADR(MACADR def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1912 {
1913 val = def_val;
1914 pend_val = val;
1915 }
1916
1928 config_MACADR(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1929 {
1930 MACADR ma;
1931 ma = AsciiToMac(def_val);
1932
1933 val = ma;
1934 pend_val = val;
1935 }
1936
1947 config_MACADR(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1948 {
1949 MACADR ma;
1950 ma = AsciiToMac(def_val);
1951 val = ma;
1952 pend_val = val;
1953 }
1954
1955 // Assignment Operators
1956
1962 operator MACADR() const { return val; };
1963
1970 {
1971 pend_val = val = ci.val;
1972 if (GetFlags(fConfigIsDefault))
1973 ClrBranchFlag(fConfigIsDefault, true);
1974 return *this;
1975 };
1976
1983 {
1984 pend_val = val = ci;
1985 if (GetFlags(fConfigIsDefault))
1986 ClrBranchFlag(fConfigIsDefault, true);
1987 return *this;
1988 };
1989
1990 MACADR operator+(uint32_t rhs)
1991 { return val + rhs; }
1992
1993 MACADR operator-(uint32_t rhs)
1994 { return val - rhs; }
1995
1996 // This is named so error messages make sense to user, old name was GetExtent
1997 virtual int Missing_ConfigEndMarker(void *&startp)
1998 {
1999 startp = this;
2000 return sizeof(*this);
2001 };
2002
2003 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2004 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
2005
2013 virtual void GetTypeValue(NBString &s) override { s = "string"; };
2014};
2015
2016// This is named so error messages make sense to user, old name was GetExtent
2017#define ConfigEndMarker \
2018 virtual int Missing_ConfigEndMarker(void *&startp) override \
2019 { \
2020 startp = this; \
2021 return sizeof(*this); \
2022 };
2023
2037{
2038 config_string value{"", "Value"};
2039 config_string choices{"", "Choices"};
2040 ConfigEndMarker;
2041
2042 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2043
2044 public:
2054 config_chooser(config_obj &owner, const char *name, const char *in_value, const char *in_choices, const char *desc = NULL)
2055 : config_obj(owner, name, desc)
2056 {
2057 value = in_value; // Current choice
2058 choices = in_choices; // List of choices
2059 choices.m_Flags |= fConfigReadOnly | fConfigNoSave; // Confiuration flags
2060 value.SetEnumList(choices); // Create enum list from string containing all choices
2061 };
2062
2064
2065 const char * GetPendValue() {return value.pend_val.c_str();};
2066
2067
2076 config_chooser(const char *name, const char *in_value, const char *in_choices, const char *desc = NULL) : config_obj(name, desc)
2077 {
2078 value = in_value;
2079 choices = in_choices;
2080 choices.m_Flags |= fConfigReadOnly | fConfigNoSave;
2081 value.SetEnumList(choices);
2082 };
2083
2092 bool IsSelected(const char *choice) { return (choice == value); };
2093
2102 bool IsSelected(const NBString &s) { return (s == value); };
2103
2117 bool IsInChoices(const char *str, size_t strLen)
2118 {
2119 const char *sChoices = choices.c_str();
2120 size_t listLen = choices.length();
2121 size_t index = 0;
2122
2123 if (str == nullptr) { return false; }
2124 if (listLen == 0) { return false; }
2125
2126 while (index < listLen)
2127 {
2128 size_t curVarStart = index;
2129 size_t curVarLength;
2130
2131 // determine the length of the current element in the list of choices
2132 while (sChoices[index] != 0 && sChoices[index] != ',')
2133 {
2134 // index until the end of the current element in the list of choices
2135 index++;
2136 }
2137 curVarLength = index - curVarStart;
2138
2139 if (strncmp(str, &sChoices[curVarStart], (curVarLength > strLen) ? curVarLength : strLen) == 0)
2140 {
2141 return true; // found a match
2142 }
2143 index++; // increment past ','
2144 }
2145
2146 return false;
2147 }
2148
2162 bool IsInChoices(const NBString &str, size_t strLen)
2163 {
2164 const char *sStr = str.c_str();
2165 const char *sChoices = choices.c_str();
2166 size_t length = choices.length();
2167 size_t index = 0;
2168
2169 if (sStr == nullptr) { return false; }
2170 if (length == 0) { return false; }
2171
2172 while (index < length)
2173 {
2174 size_t curVarStart = index;
2175 size_t curVarLength;
2176
2177 // determine the length of the current element in the list of choices
2178 while (sChoices[index] != 0 && sChoices[index] != ',')
2179 {
2180 // index until the end of the current element in the list of choices
2181 index++;
2182 }
2183 curVarLength = index - curVarStart;
2184
2185 if (strncmp(sStr, &sChoices[curVarStart], curVarLength > strLen ? curVarLength : strLen) == 0)
2186 {
2187 return true; // found a match
2188 }
2189 index++; // increment past ','
2190 }
2191
2192 return false;
2193 }
2194
2200 const config_string &GetChoices() { return choices; }
2201
2209 const config_string &SetChoices(const char *in_choices)
2210 {
2211 choices = in_choices;
2212 value.SetEnumList(choices);
2213
2214 return choices;
2215 }
2216
2217 /* @brief Set the list of choices
2218 *
2219 * @param in_choices The list of option choices
2220 *
2221 * @returns A config_string object containing the list of choices
2222 */
2223 const config_string &SetChoices(const NBString &in_choices)
2224 {
2225 choices = in_choices;
2226 value.SetEnumList(choices);
2227
2228 return choices;
2229 }
2230
2231
2237 operator NBString() const { return (NBString)value; };
2238
2245 {
2246 value = p;
2247 if (GetFlags(fConfigIsDefault))
2248 ClrBranchFlag(fConfigIsDefault, true);
2249 return *this;
2250 };
2251
2258 {
2259 value = s;
2260 if (GetFlags(fConfigIsDefault))
2261 ClrBranchFlag(fConfigIsDefault, true);
2262 return *this;
2263 };
2264
2271 {
2272 value = ci.value;
2273 if (GetFlags(fConfigIsDefault))
2274 ClrBranchFlag(fConfigIsDefault, true);
2275 return *this;
2276 };
2277
2278 virtual void GetTypeValue(NBString &s) override { s = "object"; };
2279};
2280
2287{
2288 protected:
2289 int min_val; // should be INT_MIN by default
2290 int max_val; // should be INT_MAX by default
2291
2292 public:
2303 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)
2304 {
2305 min_val=minv;
2306 max_val=maxv;
2307 }
2308
2318 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)
2319 {
2320 min_val=minv;
2321 max_val=maxv;
2322 }
2323
2324 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2325 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2326
2327 config_int_limit &operator=(const int i)
2328 {
2329 if(i>=min_val && max_val<=i)
2330 {
2331 pend_val = val = i;
2332 if (GetFlags(fConfigIsDefault))
2333 ClrBranchFlag(fConfigIsDefault, true);
2334 }
2335 return *this;
2336 };
2337
2345 {
2346 int test_v=ci;
2347 if((test_v>=min_val) && (test_v<=max_val))
2348 {
2349 pend_val = val = test_v;
2350 if (GetFlags(fConfigIsDefault))
2351 ClrBranchFlag(fConfigIsDefault, true);
2352 }
2353 return *this;
2354 };
2355
2363 {
2364 int test_v=cil;
2365 if((test_v>=min_val) && (test_v<=max_val))
2366 {
2367 pend_val = val = test_v;
2368 if (GetFlags(fConfigIsDefault))
2369 ClrBranchFlag(fConfigIsDefault, true);
2370 }
2371 return *this;
2372 };
2373
2374};
2375
2382{
2383 protected:
2384 uint32_t min_val; // should be 0 by default
2385 uint32_t max_val; // should be UINT_MAX by default
2386
2387 public:
2398 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)
2399 {
2400 min_val=minv;
2401 max_val=maxv;
2402 }
2403
2413 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)
2414 {
2415 min_val=minv;
2416 max_val=maxv;
2417 }
2418
2419 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2420 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2421
2422 config_uint_limit &operator=(const uint32_t i)
2423 {
2424 if(i>=min_val && max_val<=i)
2425 {
2426 pend_val = val = i;
2427 if (GetFlags(fConfigIsDefault))
2428 ClrBranchFlag(fConfigIsDefault, true);
2429 }
2430 return *this;
2431 };
2432
2440 {
2441 uint32_t test_v=ci;
2442 if((test_v>=min_val) && (test_v<=max_val))
2443 {
2444 pend_val = val = test_v;
2445 if (GetFlags(fConfigIsDefault))
2446 ClrBranchFlag(fConfigIsDefault, true);
2447 }
2448 return *this;
2449 };
2450
2458 {
2459 uint32_t test_v=cil;
2460 if((test_v>=min_val) && (test_v<=max_val))
2461 {
2462 pend_val = val = test_v;
2463 if (GetFlags(fConfigIsDefault))
2464 ClrBranchFlag(fConfigIsDefault, true);
2465 }
2466 return *this;
2467 };
2468
2469};
2470
2471
2472
2479{
2480 protected:
2481 double min_val; // should be -DBL_MAX by default
2482 double max_val; // should be DBL_MAX by default
2483 double step; // allowable increments in the HTML GUI (precision to round to, not strictly enforced)
2484
2485 public:
2497 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)
2498 {
2499 min_val=minv;
2500 max_val=maxv;
2501 step=stepv;
2502 }
2503
2514 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)
2515 {
2516 min_val=minv;
2517 max_val=maxv;
2518 step=stepv;
2519 }
2520
2521 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2522 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2523
2524 config_double_limit &operator=(const double i)
2525 {
2526 if(i>=min_val && max_val<=i)
2527 {
2528 pend_val = val = i;
2529 if (GetFlags(fConfigIsDefault))
2530 ClrBranchFlag(fConfigIsDefault, true);
2531 }
2532 return *this;
2533 };
2534
2542 {
2543 double test_v=ci;
2544 if((test_v>=min_val) && (test_v<=max_val))
2545 {
2546 pend_val = val = test_v;
2547 if (GetFlags(fConfigIsDefault))
2548 ClrBranchFlag(fConfigIsDefault, true);
2549 }
2550 return *this;
2551 };
2552
2560 {
2561 double test_v=cil;
2562 if((test_v>=min_val) && (test_v<=max_val))
2563 {
2564 pend_val = val = test_v;
2565 if (GetFlags(fConfigIsDefault))
2566 ClrBranchFlag(fConfigIsDefault, true);
2567 }
2568 return *this;
2569 };
2570
2571
2579 virtual void GetTypeValue(NBString &s) override { s = "number"; };
2580};
2581
2588{
2589 protected:
2590 size_t min_len; // should be 0 by default
2591 size_t max_len; // should be 0 by default
2592
2593 public:
2604 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)
2605 {
2606 min_len=minl;
2607 max_len=maxl;
2608 }
2609
2619 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)
2620 {
2621 min_len=minl;
2622 max_len=maxl;
2623 }
2624
2625 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2626 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2627
2628 config_string_limit &operator=(const NBString i)
2629 {
2630 if(i.length()>=min_len && max_len<=i.length())
2631 {
2632 pend_val = val = i;
2633 if (GetFlags(fConfigIsDefault))
2634 ClrBranchFlag(fConfigIsDefault, true);
2635 }
2636 return *this;
2637 };
2638
2646 {
2647 NBString test_v=ci;
2648 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2649 {
2650 pend_val = val = test_v;
2651 if (GetFlags(fConfigIsDefault))
2652 ClrBranchFlag(fConfigIsDefault, true);
2653 }
2654 return *this;
2655 };
2656
2664 {
2665 NBString test_v=cil;
2666 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2667 {
2668 pend_val = val = test_v;
2669 if (GetFlags(fConfigIsDefault))
2670 ClrBranchFlag(fConfigIsDefault, true);
2671 }
2672 return *this;
2673 };
2674
2675};
2676
2683{
2684 protected:
2685 size_t min_len; // should be 0 by default
2686 size_t max_len; // should be 0 by default
2687
2688 public:
2699 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)
2700 {
2701 min_len=minl;
2702 max_len=maxl;
2703 }
2704
2714 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)
2715 {
2716 min_len=minl;
2717 max_len=maxl;
2718 }
2719
2720 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2721 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2722
2723 config_pass_limit &operator=(const NBString i)
2724 {
2725 if(i.length()>=min_len && max_len<=i.length())
2726 {
2727 pend_val = val = i;
2728 if (GetFlags(fConfigIsDefault))
2729 ClrBranchFlag(fConfigIsDefault, true);
2730 }
2731 return *this;
2732 };
2733
2741 {
2742 NBString test_v=ci;
2743 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2744 {
2745 pend_val = val = test_v;
2746 if (GetFlags(fConfigIsDefault))
2747 ClrBranchFlag(fConfigIsDefault, true);
2748 }
2749 return *this;
2750 };
2751
2759 {
2760 NBString test_v=cil;
2761 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2762 {
2763 pend_val = val = test_v;
2764 if (GetFlags(fConfigIsDefault))
2765 ClrBranchFlag(fConfigIsDefault, true);
2766 }
2767 return *this;
2768 };
2769
2770};
2771
2772class reboot_obj : public config_bool
2773{
2774 virtual const char *GetSortNameValue() { return "ZZZc"; };
2775
2776 public:
2777 reboot_obj() : config_bool(root, false, "Reboot", "Cause system reboot on save"){};
2778 void clear()
2779 {
2780 val = false;
2781 pend_val = false;
2782 };
2783
2784 // This is named so error messages make sense to user, old name was GetExtent
2785 virtual int Missing_ConfigEndMarker(void *&startp)
2786 {
2787 startp = this;
2788 return sizeof(*this);
2789 };
2790};
2791
2792class version_obj : public config_int
2793{
2794 bool bNeverSet;
2795 virtual const char *GetSortNameValue() { return "ZZZb"; };
2796
2797 public:
2798 version_obj() : config_int(root, 0, "Version", "Version serial number") { bNeverSet = true; };
2799
2800 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs);
2801 void inc()
2802 {
2803 val++;
2804 pend_val = val;
2805 };
2806 // This is named so error messages make sense to user
2807 // Old name was GetExtent
2808 virtual int Missing_ConfigEndMarker(void *&startp)
2809 {
2810 startp = this;
2811 return sizeof(*this);
2812 };
2813};
2814
2815class empty_config_obj : public config_obj
2816{
2817 ConfigEndMarker;
2818
2819 public:
2820 empty_config_obj(const char *name, const char *desc = NULL) : config_obj(name, desc){};
2821 empty_config_obj(config_obj &owner, const char *name, const char *desc = NULL) : config_obj(owner, name, desc){};
2822 empty_config_obj(empty_config_obj &&e);
2823};
2824
2825
2826
2827// This class is intended for recovery applications or for devices supporting multiple
2828// application profiles to preserve unused config tree branches across configuration
2829// updates
2830// Ex:
2831// Application A has a config object at 'AppData.AppA', and Application B
2832// has a config object at 'AppData.AppB'. Normally, if Application A were
2833// to update any configuration (whether Application or System related), this
2834// would wipe out any AppB configuration as it is not known of by Application A.
2835// Using a config_preserver_obj, any configuration tree data below it's registration
2836// will be persisted across updates unless explicitly wiped.
2837class config_preserver_obj : public config_obj
2838{
2839 ConfigEndMarker;
2840 ParsedJsonDataSet &pendingTreeData;
2841 ParsedJsonDataSet &treeData;
2842
2843 public:
2844 config_preserver_obj(const char *name, const char *desc = NULL);
2845 config_preserver_obj(config_obj &owner, const char *name, const char *desc = NULL);
2846 config_preserver_obj(config_preserver_obj &&po);
2847
2848
2849 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2850 virtual void CommitTestedValue(uint32_t permission_mask) override;
2851 virtual void GetTextValue(NBString &s) override;
2852 virtual void GetRawValue(NBString &s) override;
2853};
2854
2855extern const char *AppName;
2856extern const char PlatformName[];
2857
2858class SysRecord : public config_obj
2859{
2860 public:
2861 config_report system_platform{PlatformName, "Platform", "Hardware Platform"};
2862 config_report system_app{AppName, "Application", "Application name"};
2863 ConfigEndMarker;
2864
2865 SysRecord(const char *name, const char *desc = NULL) : config_obj(name, desc){};
2866 SysRecord(config_obj &owner, const char *name, const char *desc = NULL) : config_obj(owner, name, desc){};
2867 SysRecord(SysRecord &&sr);
2868};
2869
2870extern SysRecord sys;
2871extern empty_config_obj netif;
2872
2873extern reboot_obj rebooter;
2874extern version_obj config_cur_version;
2875
2876extern const int plat_def_baud;
2877extern const int plat_def_delay;
2878extern const int plat_def_quiet;
2879extern const int plat_def_watchdog_enabled;
2880
2881#include <plat_cfg_types.h>
2882#ifdef PRESERVE_APP_DATA
2883extern config_preserver_obj appdata;
2884#else
2885extern empty_config_obj appdata;
2886#endif
2887
2893
2894class MonitorRecord : public config_obj
2895{
2896 public:
2897 config_int Baud{plat_def_baud, "BootBaud"};
2898 config_uart Uart{plat_def_com, "BootUart"};
2899 config_int BootDelay{plat_def_delay, "BootDelay"};
2900 config_bool Quiet{plat_def_quiet, "BootQuiet"};
2901 config_chooser sercfg_action{"SerialConfig", "DuringBoot", "DuringBoot,AlwaysEnabled,PauseAfterBoot,Disabled"};
2902 config_string abortbootcmd{"A", "Abort"};
2903 config_pass system_user{"", "User"};
2904 config_pass system_pass{"", "Password"};
2905 ConfigEndMarker;
2906
2907 MonitorRecord(const char *name) : config_obj(name, "Boot monitor record")
2908 {
2909 sercfg_action.SetFlag(fConfigNeedReboot);
2910 Baud.SetFlag(fConfigNeedReboot);
2911 Uart.SetFlag(fConfigNeedReboot);
2912 };
2913 MonitorRecord(config_obj &owner, const char *name) : config_obj(owner, name, "Boot Monitor Record")
2914 {
2915 sercfg_action.SetFlag(fConfigNeedReboot);
2916 Baud.SetFlag(fConfigNeedReboot);
2917 Uart.SetFlag(fConfigNeedReboot);
2918 };
2919 MonitorRecord(MonitorRecord &&mr);
2920};
2921extern MonitorRecord monitor_config;
2922
2933
2934
2935
2936
2937#endif
2938
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:1500
bool NotNull() const
Check if the IP address is not null.
Definition config_obj.h:1615
config_IPADDR4(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1579
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1668
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:1562
config_IPADDR4(IPADDR4 def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1544
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:1517
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:1529
config_IPADDR4 & operator=(const config_IPADDR4 &ci)
Copy one config_IPADDR4 object to another.
Definition config_obj.h:1646
bool IsNull() const
Check if the IP address is null.
Definition config_obj.h:1606
void SetNull()
Set the IP address to null.
Definition config_obj.h:1622
config_IPADDR4 & operator=(const IPADDR4 &i4)
Copy an IPADDR4 object value to a config_IPADDR4 object.
Definition config_obj.h:1633
Configuration Variable for IPADDR (IPv6) object type.
Definition config_obj.h:1685
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1846
config_IPADDR & operator=(const config_IPADDR &ci)
Copy one config_IPADDR object to another.
Definition config_obj.h:1824
config_IPADDR & operator=(const IPADDR &i6)
Copy an IPADDR object value to a config_IPADDR object.
Definition config_obj.h:1811
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:1744
config_IPADDR(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1761
void SetNull()
Set the IP address value of an config_IPADDR object to null.
Definition config_obj.h:1800
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:1711
bool NotNull() const
Check if the IP address is not null.
Definition config_obj.h:1795
config_IPADDR(IPADDR def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1728
bool IsNull() const
Check if the IP address is null.
Definition config_obj.h:1786
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:1699
Configuration Variable for MACADR object type.
Definition config_obj.h:1863
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:1894
config_MACADR & operator=(const MACADR &ci)
Copy a MACADR object value to a MACADR object.
Definition config_obj.h:1982
config_MACADR(MACADR def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1911
config_MACADR & operator=(const config_MACADR &ci)
Copy one config_MACADR object to another.
Definition config_obj.h:1969
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:1928
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:1878
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:2013
config_MACADR(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1947
Boolean Configuration Variable.
Definition config_obj.h:1000
config_bool(bool def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1043
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1119
config_bool & operator=(const config_bool &cb)
Copy one config_bool object to another.
Definition config_obj.h:1086
config_bool & operator=(const int i)
Assign a config_bool object value to the specified integer value.
Definition config_obj.h:1099
config_bool & operator=(const bool v)
Assign the config_bool object value to the specified bool value.
Definition config_obj.h:1073
virtual void GetTextValue(NBString &s) override
Copy the object value as a text string to the specified NBString object.
Definition config_obj.h:1014
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:1030
Chooser Configuration Variable - Select From a List of Items.
Definition config_obj.h:2037
virtual void GetTypeValue(NBString &s) override
Assigns the object type value to the specified NBString object.
Definition config_obj.h:2278
const config_string & GetChoices()
Get the list of choices.
Definition config_obj.h:2200
const config_string & SetChoices(const char *in_choices)
Set the list of choices.
Definition config_obj.h:2209
bool IsSelected(const char *choice)
Check if a particular choice option is selected.
Definition config_obj.h:2092
config_chooser & operator=(const char *p)
Assign the selected list item from a const char* value.
Definition config_obj.h:2244
bool IsSelected(const NBString &s)
Check if a particular choice option is selected.
Definition config_obj.h:2102
config_chooser & operator=(const config_chooser &ci)
Copy one config_chooser object to another.
Definition config_obj.h:2270
config_chooser(const char *name, const char *in_value, const char *in_choices, const char *desc=NULL)
Object constructor.
Definition config_obj.h:2076
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:2117
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:2054
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:2162
config_chooser & operator=(const NBString &s)
Assign the config_string object value from a NBString object.
Definition config_obj.h:2257
A config_double with minimum and/or maximum values Attempting to set a value lower than the minimum o...
Definition config_obj.h:2479
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:2579
config_double_limit & operator=(const config_double_limit &cil)
Copy one config_double_limit object to another.
Definition config_obj.h:2559
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:2514
config_double_limit & operator=(const config_double &ci)
Copy a config_double object into the config_double_limit.
Definition config_obj.h:2541
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:2497
Double Float Configuration Variable.
Definition config_obj.h:819
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:950
virtual void GetTextValue(NBString &s) override
Copy the object value as a text string to the specified NBString object.
Definition config_obj.h:833
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:843
config_double(double def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:856
config_double & operator=(const double d)
Assign the config_double object value from a double value.
Definition config_obj.h:913
config_double & operator=(const config_double &ci)
Copy one config_double object to another.
Definition config_obj.h:926
A config_int with minimum and/or maximum values Attempting to set a value lower than the minimum or g...
Definition config_obj.h:2287
config_int_limit & operator=(const config_int &ci)
Copy a config_int object into the config_int_limit.
Definition config_obj.h:2344
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:2318
config_int_limit & operator=(const config_int_limit &cil)
Copy one config_int_limit object to another.
Definition config_obj.h:2362
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:2303
Signed 32-bit Integer Configuration Variable.
Definition config_obj.h:703
config_int & operator=(const int i)
Assign the config_int object value to the specified int value.
Definition config_obj.h:772
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:727
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:808
virtual void GetTextValue(NBString &s) override
Copy the object value to the specified NBString object.
Definition config_obj.h:717
config_int(int def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:740
config_int & operator=(const config_int &ci)
Copy one config_int object to another.
Definition config_obj.h:786
Configure device network name.
Definition config_netobj.h:26
Base class used to create configuration objects.
Definition config_obj.h:323
virtual void GetTypeValue(NBString &s) override
Assigns the object type value to the specified NBString object.
Definition config_obj.h:425
config_obj(const char *name, const char *desc)
Object constructor.
Definition config_obj.h:370
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:347
A config_pass with minimum and/or maximum lengths Attempting to set a value shorter than the minimum ...
Definition config_obj.h:2683
config_pass_limit & operator=(const config_pass_limit &cil)
Copy one config_pass_limit object to another.
Definition config_obj.h:2758
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:2699
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:2714
config_pass_limit & operator=(const config_pass &ci)
Copy a config_pass object into the config_pass_limit.
Definition config_obj.h:2740
Password string Configuration Variable.
Definition config_obj.h:1348
config_pass(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1398
config_pass & operator=(const config_string &ci)
Copy a config_string object to a config_pass object.
Definition config_obj.h:1467
config_pass & operator=(const char *p)
Assign the config_pass object value from a const char* value.
Definition config_obj.h:1441
config_pass & operator=(const NBString &s)
Assign the config_pass object value from a NBString object.
Definition config_obj.h:1454
config_pass(NBString def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1374
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:1386
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:1480
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:1362
A config_string with minimum and/or maximum lengths Attempting to set a value shorter than the minimu...
Definition config_obj.h:2588
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:2619
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:2604
config_string_limit & operator=(const config_string &ci)
Copy a config_string object into the config_string_limit.
Definition config_obj.h:2645
config_string_limit & operator=(const config_string_limit &cil)
Copy one config_string_limit object to another.
Definition config_obj.h:2663
String Configuration Variable.
Definition config_obj.h:1130
const char * c_str() const
Returns the object value as a string.
Definition config_obj.h:1290
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:1166
const char & operator[](size_t pos) const
Return the value of a character in the string.
Definition config_obj.h:1306
config_string & operator=(const char *p)
Assign the config_string object value from a const char* string.
Definition config_obj.h:1244
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:1198
config_string & operator=(const NBString &s)
Assign the config_string object value from a NBString object.
Definition config_obj.h:1257
void SetEnumList(NBString s)
Renders the data used to explain the schema/descriptions for the list of choices.
Definition config_obj.h:1228
config_string(NBString def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1181
config_string & operator=(const config_string &ci)
Copy one config_string object to another.
Definition config_obj.h:1270
config_string(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1213
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1315
size_t length() const
Returns the string length in bytes.
Definition config_obj.h:1297
A config_uint with minimum and/or maximum values Attempting to set a value lower than the minimum or ...
Definition config_obj.h:2382
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:2413
config_uint_limit & operator=(const config_uint_limit &cil)
Copy one config_uint_limit object to another.
Definition config_obj.h:2457
config_uint_limit & operator=(const config_uint &ci)
Copy a config_uint object into the config_uint_limit.
Definition config_obj.h:2439
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:2398
Unsigned 32-bit Integer Configuration Variable.
Definition config_obj.h:555
config_uint(uint32_t def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:592
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:579
config_uint & operator=(const uint32_t i)
Assign the config_uint object value from a uint32_t value.
Definition config_obj.h:623
virtual void GetTextValue(NBString &s) override
Copy the object value to the specified NBString object.
Definition config_obj.h:569
config_uint & operator=(const config_uint &ci)
Copy one config_uint object to another.
Definition config_obj.h:636
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:658
Base class used to create a configuration value.
Definition config_obj.h:493
config_value(config_obj &owner, const char *name, const char *desc)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:510
config_value(const char *name, const char *desc)
Object constructor.
Definition config_obj.h:531
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
EFFS Multiple Partitions Example.
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.