NetBurner 3.5.8
PDF Version
config_obj.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
9
16
46
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;
87
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
1129class config_string : public config_value
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
1152 config_string(config_string &&s);
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
1257 config_string &operator=(const NBString &s)
1258 {
1259 pend_val = val = s;
1260 if (GetFlags(fConfigIsDefault))
1261 ClrBranchFlag(fConfigIsDefault, true);
1262 return *this;
1263 };
1264
1270 config_string &operator=(const config_string &ci)
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
1347class config_pass : public config_string
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
1467 config_pass &operator=(const config_string &ci)
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
2036class config_chooser : public config_obj
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
2334
2335 config_int_limit &operator=(const int i)
2336 {
2337 if(i>=min_val && i<=max_val)
2338 {
2339 pend_val = val = i;
2340 if (GetFlags(fConfigIsDefault))
2341 ClrBranchFlag(fConfigIsDefault, true);
2342 }
2343 return *this;
2344 };
2345
2353 {
2354 int test_v=ci;
2355 if((test_v>=min_val) && (test_v<=max_val))
2356 {
2357 pend_val = val = test_v;
2358 if (GetFlags(fConfigIsDefault))
2359 ClrBranchFlag(fConfigIsDefault, true);
2360 }
2361 return *this;
2362 };
2363
2371 {
2372 int test_v=cil;
2373 if((test_v>=min_val) && (test_v<=max_val))
2374 {
2375 pend_val = val = test_v;
2376 if (GetFlags(fConfigIsDefault))
2377 ClrBranchFlag(fConfigIsDefault, true);
2378 }
2379 return *this;
2380 };
2381
2382};
2383
2390{
2391 protected:
2392 uint32_t min_val; // should be 0 by default
2393 uint32_t max_val; // should be UINT_MAX by default
2394
2395 public:
2406 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)
2407 {
2408 min_val=minv;
2409 max_val=maxv;
2410 }
2411
2421 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)
2422 {
2423 min_val=minv;
2424 max_val=maxv;
2425 }
2426
2427 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2428 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2429
2437
2438 config_uint_limit &operator=(const uint32_t i)
2439 {
2440 if(i>=min_val && i<=max_val)
2441 {
2442 pend_val = val = i;
2443 if (GetFlags(fConfigIsDefault))
2444 ClrBranchFlag(fConfigIsDefault, true);
2445 }
2446 return *this;
2447 };
2448
2456 {
2457 uint32_t test_v=ci;
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
2474 {
2475 uint32_t test_v=cil;
2476 if((test_v>=min_val) && (test_v<=max_val))
2477 {
2478 pend_val = val = test_v;
2479 if (GetFlags(fConfigIsDefault))
2480 ClrBranchFlag(fConfigIsDefault, true);
2481 }
2482 return *this;
2483 };
2484
2485};
2486
2487
2488
2495{
2496 protected:
2497 double min_val; // should be -DBL_MAX by default
2498 double max_val; // should be DBL_MAX by default
2499 double step; // allowable increments in the HTML GUI (precision to round to, not strictly enforced)
2500
2501 public:
2513 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)
2514 {
2515 min_val=minv;
2516 max_val=maxv;
2517 step=stepv;
2518 }
2519
2530 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)
2531 {
2532 min_val=minv;
2533 max_val=maxv;
2534 step=stepv;
2535 }
2536
2537 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2538 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2539
2547
2548 config_double_limit &operator=(const double i)
2549 {
2550 if(i>=min_val && i<=max_val)
2551 {
2552 pend_val = val = i;
2553 if (GetFlags(fConfigIsDefault))
2554 ClrBranchFlag(fConfigIsDefault, true);
2555 }
2556 return *this;
2557 };
2558
2566 {
2567 double test_v=ci;
2568 if((test_v>=min_val) && (test_v<=max_val))
2569 {
2570 pend_val = val = test_v;
2571 if (GetFlags(fConfigIsDefault))
2572 ClrBranchFlag(fConfigIsDefault, true);
2573 }
2574 return *this;
2575 };
2576
2584 {
2585 double test_v=cil;
2586 if((test_v>=min_val) && (test_v<=max_val))
2587 {
2588 pend_val = val = test_v;
2589 if (GetFlags(fConfigIsDefault))
2590 ClrBranchFlag(fConfigIsDefault, true);
2591 }
2592 return *this;
2593 };
2594
2595
2603 virtual void GetTypeValue(NBString &s) override { s = "number"; };
2604};
2605
2611class config_string_limit : public config_string
2612{
2613 protected:
2614 size_t min_len; // should be 0 by default
2615 size_t max_len; // should be 0 by default
2616
2617 public:
2628 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)
2629 {
2630 min_len=minl;
2631 max_len=maxl;
2632 }
2633
2643 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)
2644 {
2645 min_len=minl;
2646 max_len=maxl;
2647 }
2648
2649 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2650 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2651
2659
2660 config_string_limit &operator=(const NBString i)
2661 {
2662 if(i.length()>=min_len && i.length()<=max_len)
2663 {
2664 pend_val = val = i;
2665 if (GetFlags(fConfigIsDefault))
2666 ClrBranchFlag(fConfigIsDefault, true);
2667 }
2668 return *this;
2669 };
2670
2677 config_string_limit &operator=(const config_string &ci)
2678 {
2679 NBString test_v=ci;
2680 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2681 {
2682 pend_val = val = test_v;
2683 if (GetFlags(fConfigIsDefault))
2684 ClrBranchFlag(fConfigIsDefault, true);
2685 }
2686 return *this;
2687 };
2688
2696 {
2697 NBString test_v=cil;
2698 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2699 {
2700 pend_val = val = test_v;
2701 if (GetFlags(fConfigIsDefault))
2702 ClrBranchFlag(fConfigIsDefault, true);
2703 }
2704 return *this;
2705 };
2706
2707};
2708
2715{
2716 protected:
2717 size_t min_len; // should be 0 by default
2718 size_t max_len; // should be 0 by default
2719
2720 public:
2731 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)
2732 {
2733 min_len=minl;
2734 max_len=maxl;
2735 }
2736
2746 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)
2747 {
2748 min_len=minl;
2749 max_len=maxl;
2750 }
2751
2752 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2753 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2754
2762
2763 config_pass_limit &operator=(const NBString i)
2764 {
2765 if(i.length()>=min_len && i.length()<=max_len)
2766 {
2767 pend_val = val = i;
2768 if (GetFlags(fConfigIsDefault))
2769 ClrBranchFlag(fConfigIsDefault, true);
2770 }
2771 return *this;
2772 };
2773
2781 {
2782 NBString test_v=ci;
2783 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2784 {
2785 pend_val = val = test_v;
2786 if (GetFlags(fConfigIsDefault))
2787 ClrBranchFlag(fConfigIsDefault, true);
2788 }
2789 return *this;
2790 };
2791
2799 {
2800 NBString test_v=cil;
2801 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2802 {
2803 pend_val = val = test_v;
2804 if (GetFlags(fConfigIsDefault))
2805 ClrBranchFlag(fConfigIsDefault, true);
2806 }
2807 return *this;
2808 };
2809
2810};
2811
2812class reboot_obj : public config_bool
2813{
2814 virtual const char *GetSortNameValue() { return "ZZZc"; };
2815
2816 public:
2817 reboot_obj() : config_bool(root, false, "Reboot", "Cause system reboot on save"){};
2818 void clear()
2819 {
2820 val = false;
2821 pend_val = false;
2822 };
2823
2824 // This is named so error messages make sense to user, old name was GetExtent
2825 virtual int Missing_ConfigEndMarker(void *&startp)
2826 {
2827 startp = this;
2828 return sizeof(*this);
2829 };
2830};
2831
2832class version_obj : public config_int
2833{
2834 bool bNeverSet;
2835 virtual const char *GetSortNameValue() { return "ZZZb"; };
2836
2837 public:
2838 version_obj() : config_int(root, 0, "Version", "Version serial number") { bNeverSet = true; };
2839
2840 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs);
2841 void inc()
2842 {
2843 val++;
2844 pend_val = val;
2845 };
2846 // This is named so error messages make sense to user
2847 // Old name was GetExtent
2848 virtual int Missing_ConfigEndMarker(void *&startp)
2849 {
2850 startp = this;
2851 return sizeof(*this);
2852 };
2853};
2854
2855class empty_config_obj : public config_obj
2856{
2857 ConfigEndMarker;
2858
2859 public:
2860 empty_config_obj(const char *name, const char *desc = NULL) : config_obj(name, desc){};
2861 empty_config_obj(config_obj &owner, const char *name, const char *desc = NULL) : config_obj(owner, name, desc){};
2862 empty_config_obj(empty_config_obj &&e);
2863};
2864
2865
2866
2867// This class is intended for recovery applications or for devices supporting multiple
2868// application profiles to preserve unused config tree branches across configuration
2869// updates
2870// Ex:
2871// Application A has a config object at 'AppData.AppA', and Application B
2872// has a config object at 'AppData.AppB'. Normally, if Application A were
2873// to update any configuration (whether Application or System related), this
2874// would wipe out any AppB configuration as it is not known of by Application A.
2875// Using a config_preserver_obj, any configuration tree data below it's registration
2876// will be persisted across updates unless explicitly wiped.
2877class config_preserver_obj : public config_obj
2878{
2879 ConfigEndMarker;
2880 ParsedJsonDataSet &pendingTreeData;
2881 ParsedJsonDataSet &treeData;
2882
2883 public:
2884 config_preserver_obj(const char *name, const char *desc = NULL);
2885 config_preserver_obj(config_obj &owner, const char *name, const char *desc = NULL);
2886 config_preserver_obj(config_preserver_obj &&po);
2887
2888
2889 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2890 virtual void CommitTestedValue(uint32_t permission_mask) override;
2891 virtual void GetTextValue(NBString &s) override;
2892 virtual void GetRawValue(NBString &s) override;
2893};
2894
2895extern const char *AppName;
2896extern const char PlatformName[];
2897
2898class SysRecord : public config_obj
2899{
2900 public:
2901 config_report system_platform{PlatformName, "Platform", "Hardware Platform"};
2902 config_report system_app{AppName, "Application", "Application name"};
2903 ConfigEndMarker;
2904
2905 SysRecord(const char *name, const char *desc = NULL) : config_obj(name, desc){};
2906 SysRecord(config_obj &owner, const char *name, const char *desc = NULL) : config_obj(owner, name, desc){};
2907 SysRecord(SysRecord &&sr);
2908};
2909
2910extern SysRecord sys;
2911extern empty_config_obj netif;
2912
2913extern reboot_obj rebooter;
2914extern version_obj config_cur_version;
2915
2916extern const int plat_def_baud;
2917extern const int plat_def_delay;
2918extern const int plat_def_quiet;
2919extern const int plat_def_watchdog_enabled;
2920
2921#include <plat_cfg_types.h>
2922#ifdef PRESERVE_APP_DATA
2923extern config_preserver_obj appdata;
2924#else
2925extern empty_config_obj appdata;
2926#endif
2927
2933
2934class MonitorRecord : public config_obj
2935{
2936 public:
2937 config_int Baud{plat_def_baud, "BootBaud"};
2938 config_uart Uart{plat_def_com, "BootUart"};
2939 config_int BootDelay{plat_def_delay, "BootDelay"};
2940 config_bool Quiet{plat_def_quiet, "BootQuiet"};
2941 config_chooser sercfg_action{"SerialConfig", "DuringBoot", "DuringBoot,AlwaysEnabled,PauseAfterBoot,Disabled"};
2942 config_string abortbootcmd{"A", "Abort"};
2943 config_pass system_user{"", "User"};
2944 config_pass system_pass{"", "Password"};
2945 ConfigEndMarker;
2946
2947 MonitorRecord(const char *name) : config_obj(name, "Boot monitor record")
2948 {
2949 sercfg_action.SetFlag(fConfigNeedReboot);
2950 Baud.SetFlag(fConfigNeedReboot);
2951 Uart.SetFlag(fConfigNeedReboot);
2952 };
2953 MonitorRecord(config_obj &owner, const char *name) : config_obj(owner, name, "Boot Monitor Record")
2954 {
2955 sercfg_action.SetFlag(fConfigNeedReboot);
2956 Baud.SetFlag(fConfigNeedReboot);
2957 Uart.SetFlag(fConfigNeedReboot);
2958 };
2959 MonitorRecord(MonitorRecord &&mr);
2960};
2961extern MonitorRecord monitor_config;
2962
2973
2974
2975
2976
2977#endif
2978
Definition config_netobj.h:302
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:225
void SetFromAscii(const char *cp)
Set the IPv4 address from a character string.
void SetFromAscii(const char *cp, bool bembed_v4addresses=true)
Set the IP address value of an IPADDR6 object.
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
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:2603
config_double_limit(config_double_limit &&o)=default
Move constructor (mirrors the movable base config_double).
config_double_limit & operator=(const config_double_limit &cil)
Copy one config_double_limit object to another.
Definition config_obj.h:2583
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:2530
config_double_limit & operator=(const config_double &ci)
Copy a config_double object into the config_double_limit.
Definition config_obj.h:2565
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:2513
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
config_int_limit & operator=(const config_int &ci)
Copy a config_int object into the config_int_limit.
Definition config_obj.h:2352
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(config_int_limit &&o)=default
Move constructor (mirrors the movable base config_int).
config_int_limit & operator=(const config_int_limit &cil)
Copy one config_int_limit object to another.
Definition config_obj.h:2370
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
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
config_pass_limit & operator=(const config_pass_limit &cil)
Copy one config_pass_limit object to another.
Definition config_obj.h:2798
config_pass_limit(config_pass_limit &&o)=default
Move constructor (mirrors the movable base config_pass).
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:2731
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:2746
config_pass_limit & operator=(const config_pass &ci)
Copy a config_pass object into the config_pass_limit.
Definition config_obj.h:2780
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
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:2643
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:2628
config_string_limit & operator=(const config_string &ci)
Copy a config_string object into the config_string_limit.
Definition config_obj.h:2677
config_string_limit(config_string_limit &&o)=default
Move constructor (mirrors the movable base config_string).
config_string_limit & operator=(const config_string_limit &cil)
Copy one config_string_limit object to another.
Definition config_obj.h:2695
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
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:2421
config_uint_limit(config_uint_limit &&o)=default
Move constructor (mirrors the movable base config_uint).
config_uint_limit & operator=(const config_uint_limit &cil)
Copy one config_uint_limit object to another.
Definition config_obj.h:2473
config_uint_limit & operator=(const config_uint &ci)
Copy a config_uint object into the config_uint_limit.
Definition config_obj.h:2455
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:2406
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
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 EFFS/Std/SystemFileSystem/MultiPartition/src/main.cpp:33
IPADDR6 IPADDR
IPADDR Object Type (either v4 or v6).
Definition nettypes.h:568