NetBurner 3.5.6
PDF Version
config_obj.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
47#ifndef CONFIG_OBJ_H
48#define CONFIG_OBJ_H
49
50#include <buffers.h>
51#include <nbstring.h>
52#include <string.h>
53#include <utils.h>
54#include <limits.h>
55#include <float.h>
56
57void ShowTree();
58
59enum ConfigTestResult
60{
61 eUnchanged,
62 eOk,
63 eBad
64};
65
66
67
75const uint32_t fConfigValueLeaf = 0x01;
76const uint32_t fConfigReadOnly = 0x02;
77const uint32_t fConfigModified = 0x04;
78const uint32_t fConfigHidden = 0x08;
79const uint32_t fConfigNoSave = 0x10;
80const uint32_t fConfigNoObscure = 0x20;
81const uint32_t fConfigNeedReboot = 0x40;
82const uint32_t fConfigNoReload = 0x80;
83const uint32_t fConfigDetached = 0x100;
84const uint32_t fConfigIsDefault= 0x200;
85const uint32_t fMaskDoingSave = 0x40000000;
88/* Config Mask Values */
89const uint32_t PermitFlashFromStorage = (0x80000000);
90
91class config_leaf;
92class config_obj;
94class RootParseStateInfo;
95class ConfigNotificationObject;
96
97
98class notify_list
99{
100 volatile uint32_t bits;
101 public:
102 // The following functions are all guaranteed to be atomic
103 void set(const notify_list & nl) volatile;
104 void set(int set_num) volatile;
105 void clr(int clr_num) volatile;
106 notify_list() {bits=0;}
107 notify_list(const notify_list &l) {bits=l.bits;}
108 // The following functions return 0 if no bits are set.
109 uint32_t gethigh() volatile;
110 inline uint32_t get_high_and_clear() volatile {uint32_t h = gethigh(); clr(h); return h;}
111 inline bool AnySet() volatile const { return (bits!=0);};
112 inline uint32_t getmask()volatile {return bits; };
113};
114
115
116
117
118typedef void(LeafCallBack)(config_leaf *p, void *pextra);
119
120/*
121 * Configuration leaf class.
122 * Used to manage the configuration tree, internal use only.
123 */
124class config_leaf
125{
126 // We explicitly *do not allow* copy construction, as the only likely usage
127 // would be passing to variadic functions *which will not know this is non-POD*
128 config_leaf(config_leaf &rhs) = delete;
129 protected:
130 config_leaf *FindChild(const char *&cp);
131 void RootParse(RootParseStateInfo &rpsi);
132 static void FixTree(config_leaf* root);
133
134
135 virtual void RemoveFromRootList();
136 public:
137 virtual void RawFdPrintTree(int fd, int n, bool pretty, uint32_t mask, bool braw_values,bool valonly) = 0;
138
139 inline void FdPrintValTree(int fd, int n, bool pretty, uint32_t inhibit_mask = fConfigHidden, bool bRawValue = false)
140 {
141 RawFdPrintTree(fd,n,pretty,inhibit_mask,bRawValue,true);
142 }
143 inline void FdPrintTree(int fd, int n, bool pretty, uint32_t inhibit_mask = fConfigHidden, bool bRawValue = false)
144 {
145 RawFdPrintTree(fd,n,pretty,inhibit_mask,bRawValue,false);
146 }
147
148 virtual void FdPrintSchema(int fd, config_leaf *pl, int n, bool pretty, uint32_t inhibit_mask = fConfigHidden);
149 void SchemaOptions(int fd, int indent, bool pretty);
150 void ForEachLeaf(LeafCallBack *pc, void *pextra, bool siblings = false);
151 bool FlatParseBuffer(fifo_buffer_storage &rxbuf, uint32_t permissions, const char *where);
152 bool ParseBuffer(fifo_buffer_storage &rxbuf, uint32_t permissions, const char *where);
153 bool ParseBlob(uint8_t *pdata, int len, uint32_t permissions);
154 bool FlatParseBlob(uint8_t *pdata, int len, uint32_t permissions);
155 bool ParseFd(int fd, uint32_t permissions, config_leaf * pParseRoot = NULL);
156 config_obj *FindParent() { return pParent; };
157 static config_leaf *FindConfigLeaf(const unsigned char *name, config_leaf *pBranch = NULL);
158
159 void AddNotification(ConfigNotificationObject & noteobj);
160
161
162 //Call if a config object is not static
163 void FixNonStaticObject();
164
165 void RemoveFromConfigTree();
166
167 const char *pName;
168 const char *pDescription;
169 config_leaf *pNextSibling;
170 config_obj *pParent;
171 config_leaf *pChildren;
172 config_leaf *pGList;
173 notify_list NotifyListMask;
174
175
176 static config_leaf *pRootList;
177 static config_leaf *pDetachList;
178
179 uint32_t m_Flags;
180 void DoSchemaLine(int fd, const char *name, const char *value, int indent, bool pretty, bool quoted = true);
181 void DoSchemaLine(int fd, const char *name, int value, int indent, bool pretty, bool quoted = true);
182 void DoSchemaLine(int fd, const char *name, double value, int indent, bool pretty, bool quoted = true);
183
184 public:
185 bool NameMatch(const char *cp);
186 virtual const char *GetSortNameValue() { return pName; };
187 virtual void GetDescriptionValue(NBString &s) { s = pDescription; };
188 virtual void GetNameValue(NBString &s) { s = pName; };
189 virtual void GetTextValue(NBString &s) { s = pName; };
190 virtual void GetRawValue(NBString &s) { return GetTextValue(s); };
191 virtual void GetTypeValue(NBString &s) { s = "unknown"; };
192 virtual void ExtendedSchema(int fd, int indent, bool pretty){};
193 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) { return eOk; };
194 // This is named so error messages make sense to user
195 // Old name was GetExtent
196 virtual int Missing_ConfigEndMarker(void *&startp) = 0;
197
198 void ClearModified();
199
200 bool MatchId(ParsedJsonDataSet &pjs);
201
202 virtual void CommitTestedValue(uint32_t permission_mask){};
203
204 virtual ~config_leaf();
205
206 config_leaf(bool bDetached=false)
207 {
208 pNextSibling = NULL;
209 pChildren = NULL;
210 m_Flags = fConfigIsDefault;
211 pParent = NULL;
212 if (bDetached)
213 {
214 pGList=pDetachList;
215 pDetachList=this;
216 m_Flags|=fConfigDetached;
217 }
218 else
219 {
220 pGList = pRootList;
221 pRootList = this;
222 }
223 }
224 config_leaf(config_leaf &&l);
225
226 static void DiagShow();
227 static void FixTree();
228 void FindUnknownParent();
229
230 void ShowOne();
231
232 int compare(config_leaf *pl)
233 {
234 if (pl == NULL) return -1;
235 return strcmp(GetSortNameValue(), pl->GetSortNameValue());
236 };
237
238 void GetFullName(NBString &s);
239 void GetBranchName(NBString &s, config_leaf *branchRoot);
240 void RenderToFd(int fd, bool pretty = false, uint32_t mask = fConfigHidden, bool bRawValue = false);
241 void RenderSchemaToFd(int fd, bool pretty = false, uint32_t mask = fConfigHidden);
242 uint32_t GetFlags() { return m_Flags; }
243 uint32_t GetFlags(uint32_t mask) { return m_Flags & mask; }
244 void SetFlag(uint32_t flag) { m_Flags |= flag; };
245 void SetBranchFlag(uint32_t flag, bool upNotDown = false);
246 void ClrFlag(uint32_t flag) { m_Flags &= (~flag); };
247 void ClrBranchFlag(uint32_t flag, bool upNotDown = false);
248 void ReloadFromFlash();
249 void AssignmentNotify();
250
251 void LogParseError(NBString & err);
252 inline void LogParseError(const char * err) {NBString s(err); LogParseError(s); };
253
254
255 friend void HtmlLeafRender(int fd, config_leaf *pl, int eMode, int len, const char *extra);
256 friend ConfigNotificationObject;
257};
258
319class config_obj : public config_leaf
320{
321 protected:
322 config_obj(bool bDetached=false):config_leaf(bDetached){}
323 config_obj *pMasterObjectLink;
324 static config_obj *pObjList;
325
326 virtual void RemoveFromRootList();
327 public:
328 virtual void RawFdPrintTree(int fd, int n, bool pretty, uint32_t mask, bool braw_values,bool valonly) override;
329 void InstallUnderMe(config_leaf &ltoadd);
330 void RemoveFromChildren(config_leaf &ltoremove);
331
344 config_obj(config_obj &owner, const char *name, const char *desc)
345 {
346 pName = name;
347 pDescription = desc;
348 pChildren = NULL;
349 pMasterObjectLink = pObjList;
350 pObjList = this;
351 pParent = &owner;
352 }
354
367 config_obj(const char *name, const char *desc)
368 {
369 pName = name;
370 pDescription = desc;
371 pChildren = NULL;
372 pParent = NULL;
373 pMasterObjectLink = pObjList;
374 pObjList = this;
375 }
376
377
378
379 bool DoIContain(config_leaf *pl);
380
381 /*
382 * These two functions, along with GetTextValue(), can be used to create a custom object
383 * class, including the responsibility for the JSON serialization.
384 *
385 * GetTextValue(): Must return a string with the object encoded in it in JSON format
386 *
387 * TestNewValue(): Takes a parsed JSON object and extracts the values from that tree.
388 * This is where parameters can be tested for validity, and if not valid,
389 * the entire set is marked as invalid.
390 *
391 * CommitTestedValue(): Commit the values extracted by TestNewValue()
392 *
393 * This enables functionality such as parsing a set of values to determine if the SET is
394 * valid, rather than just an individual value.
395 */
396 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
397 virtual void CommitTestedValue(uint32_t permission_mask) override;
398
399 // This is named so error messages make sense to user, old name was GetExtent
400 virtual int Missing_ConfigEndMarker(void *&startp) override
401 {
402 startp = this;
403 return sizeof(*this);
404 };
405
413 virtual void GetTextValue(NBString &s) override;
414
422 virtual void GetTypeValue(NBString &s) override { s = "object"; };
423
424 friend class config_leaf;
425};
426
427/*
428 * Configuration Root object class
429 */
430class root_obj : public config_obj
431{
432 public:
433 root_obj()
434 { pName = "Config";
435 pDescription = "Root of config tree";
436 }
437
438 // This is named so error messages make sense to user, old name was GetExtent
439 virtual int Missing_ConfigEndMarker(void *&startp) override
440 {
441 startp = this;
442 return sizeof(*this);
443 };
444};
445
446class detached_root_obj : public config_obj
447{
448 public:
449 detached_root_obj():config_obj(true)
450 { pName = "detached";
451 pDescription = "Root of detached tree";
452 }
453
454 // This is named so error messages make sense to user, old name was GetExtent
455 virtual int Missing_ConfigEndMarker(void *&startp) override
456 {
457 startp = this;
458 return sizeof(*this);
459 };
460};
461
462
463
464
465extern root_obj root;
466extern detached_root_obj detached;
467
489class config_value : public config_leaf
490{
491 public:
492 virtual void GetTextValue(NBString &s) override = 0;
493
494 protected:
507 config_value(config_obj &owner, const char *name, const char *desc)
508 {
509 pName = name;
510 pDescription = desc;
511 owner.InstallUnderMe(*this);
512 pChildren = NULL;
513 m_Flags |= fConfigValueLeaf;
514 }
515
528 config_value(const char *name, const char *desc)
529 {
530 pName = name;
531 pDescription = desc;
532 pParent = NULL;
533 pChildren = NULL;
534 m_Flags |= fConfigValueLeaf;
535 }
536
538 virtual int FdPrintValue(int fd, bool raw);
539
540public:
541 virtual void RawFdPrintTree(int fd, int n, bool pretty, uint32_t mask, bool braw_values,bool valonly) override;
542};
543
552{
553 protected:
554 uint32_t val;
555 uint32_t pend_val;
556
557 virtual int FdPrintValue(int fd, bool raw) override;
558 public:
566 virtual void GetTextValue(NBString &s) override { s.siprintf("%u", val); };
567
576 config_uint(config_obj &owner, uint32_t def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
577 {
578 val = def_val;
579 pend_val = val;
580 }
581
589 config_uint(uint32_t def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
590 {
591 val = def_val;
592 pend_val = val;
593 }
594
596
597 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
598 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
599
600 // Assignment operators
601
613 operator uint32_t() const { return val; };
614
620 config_uint &operator=(const uint32_t i)
621 {
622 pend_val = val = i;
623 if (GetFlags(fConfigIsDefault))
624 ClrBranchFlag(fConfigIsDefault, true);
625 return *this;
626 };
627
634 {
635 pend_val = val = ci.val;
636 if (GetFlags(fConfigIsDefault))
637 ClrBranchFlag(fConfigIsDefault, true);
638 return *this;
639 };
640
641 // This is named so error messages make sense to user. Old name was GetExtent
642 virtual int Missing_ConfigEndMarker(void *&startp) override
643 {
644 startp = this;
645 return sizeof(*this);
646 };
647
655 virtual void GetTypeValue(NBString &s) override { s = "integer"; };
656};
657
658class config_hex_uint : public config_uint
659{
660
661 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs);
662
663protected:
664 virtual int FdPrintValue(int fd, bool raw) override;
665public:
674 config_hex_uint(config_obj &owner, uint32_t def_val, const char *name, const char *desc = NULL) : config_uint(owner,def_val, name, desc){}
675
683 config_hex_uint(uint32_t def_val, const char *name, const char *desc = NULL) : config_uint(def_val,name, desc){}
684
685 virtual void GetTextValue(NBString &s) override { s.siprintf("\"0x%X\"", val); };
686 virtual void GetTypeValue(NBString &s) override { s = "string"; };
687
688};
689
690
691
700{
701 protected:
702 int val;
703 int pend_val;
704
705 virtual int FdPrintValue(int fd, bool raw) override;
706 public:
714 virtual void GetTextValue(NBString &s) override { s.siprintf("%d", val); };
715
724 config_int(config_obj &owner, int def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
725 {
726 val = def_val;
727 pend_val = val;
728 }
729
737 config_int(int def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
738 {
739 val = def_val;
740 pend_val = val;
741 }
742
744
745 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
746
747 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
748
749 // Assignment operators
750
762 operator int() const { return val; };
763
769 config_int &operator=(const int i)
770 {
771 pend_val = val = i;
772 if (GetFlags(fConfigIsDefault))
773 ClrBranchFlag(fConfigIsDefault, true);
774 return *this;
775 };
776
784 {
785 pend_val = val = ci.val;
786 if (GetFlags(fConfigIsDefault))
787 ClrBranchFlag(fConfigIsDefault, true);
788 return *this;
789 };
790
791 // This is named so error messages make sense to user, old name was GetExtent
792 virtual int Missing_ConfigEndMarker(void *&startp) override
793 {
794 startp = this;
795 return sizeof(*this);
796 };
797
805 virtual void GetTypeValue(NBString &s) override { s = "integer"; };
806};
807
816{
817 protected:
818 double val;
819 double pend_val;
820
821 virtual int FdPrintValue(int fd, bool raw) override;
822 public:
830 virtual void GetTextValue(NBString &s) override { s.sprintf("%g", val); };
831
840 config_double(config_obj &owner, double def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
841 {
842 val = def_val;
843 pend_val = val;
844 }
845
853 config_double(double def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
854 {
855 val = def_val;
856 pend_val = val;
857 }
858
860
861 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
862 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
863
864 // Assignment operators
865
877 operator int() const { return val; };
878
890 operator float() const { return val; };
891
903 operator double() const { return val; };
904
910 config_double &operator=(const double d)
911 {
912 pend_val = val = d;
913 if (GetFlags(fConfigIsDefault))
914 ClrBranchFlag(fConfigIsDefault, true);
915 return *this;
916 };
917
924 {
925 pend_val = val = ci.val;
926 if (GetFlags(fConfigIsDefault))
927 ClrBranchFlag(fConfigIsDefault, true);
928 return *this;
929 };
930
931 // This is named so error messages make sense to user. old name was GetExtent
932 virtual int Missing_ConfigEndMarker(void *&startp) override
933 {
934 startp = this;
935 return sizeof(*this);
936 };
937
947 virtual void GetTypeValue(NBString &s) override { s = "string"; };
948};
949
950/*
951 * Class used for system status reports, for internal use only
952 */
953class config_report : public config_value
954{
955 protected:
956 const char *m_value;
957
958 virtual int FdPrintValue(int fd, bool raw) override;
959 public:
960 config_report(config_obj &owner, const char *value, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
961 {
962 m_Flags = fConfigReadOnly | fConfigNoSave;
963 m_value = value;
964 }
965 config_report(const char *value, const char *name, const char *desc = NULL) : config_value(name, desc)
966 {
967 m_Flags = fConfigReadOnly | fConfigNoSave;
968 m_value = value;
969 }
970
971 config_report(config_report &&r);
972
973 virtual void GetTextValue(NBString &s) override;
974 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
975 virtual void CommitTestedValue(uint32_t permission_mask) override;
976 // This is named so error messages make sense to user
977 // Old name was GetExtent
978 virtual int Missing_ConfigEndMarker(void *&startp) override
979 {
980 startp = this;
981 return sizeof(*this);
982 };
983 virtual void GetTypeValue(NBString &s) override { s = "string"; };
984
985 const char *c_str() { return m_value; };
986 void ModifyValue(const char *nv) { m_value = nv; };
987};
988
997{
998 protected:
999 bool val;
1000 bool pend_val;
1001
1002 virtual int FdPrintValue(int fd, bool raw) override;
1003 public:
1011 virtual void GetTextValue(NBString &s) override
1012 {
1013 if (val)
1014 s = "true";
1015 else
1016 s = "false";
1017 };
1018
1027 config_bool(config_obj &owner, bool def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1028 {
1029 val = def_val;
1030 pend_val = val;
1031 }
1032
1040 config_bool(bool def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1041 {
1042 val = def_val;
1043 pend_val = val;
1044 }
1046
1047 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1048 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1049
1050 // Assignemt operators
1051
1063 operator bool() const { return val; };
1064
1070 config_bool &operator=(const bool v)
1071 {
1072 pend_val = val = v;
1073 if (GetFlags(fConfigIsDefault))
1074 ClrBranchFlag(fConfigIsDefault, true);
1075 return *this;
1076 };
1077
1084 {
1085 pend_val = val = cb.val;
1086 if (GetFlags(fConfigIsDefault))
1087 ClrBranchFlag(fConfigIsDefault, true);
1088 return *this;
1089 };
1090
1097 {
1098 pend_val = val = (i != 0);
1099 if (GetFlags(fConfigIsDefault))
1100 ClrBranchFlag(fConfigIsDefault, true);
1101 return *this;
1102 };
1103
1104 // This is named so error messages make sense to user, old name was GetExtent
1105 virtual int Missing_ConfigEndMarker(void *&startp)
1106 {
1107 startp = this;
1108 return sizeof(*this);
1109 };
1110
1116 virtual void GetTypeValue(NBString &s) override { s = "boolean"; };
1117};
1118
1127{
1128 protected:
1129 NBString val;
1130 NBString pend_val;
1131 NBString enum_list;
1132
1133 virtual int FdPrintValue(int fd, bool raw) override;
1134 public:
1142 virtual void GetTextValue(NBString &s) override;
1143// {
1144// s = "\"";
1145// s += val;
1146// s += "\"";
1147// };
1148
1150
1161 config_string(config_obj &owner, NBString def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1162 {
1163 val = def_val;
1164 pend_val = val;
1165 }
1166
1176 config_string(NBString def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1177 {
1178 pName = name;
1179 val = def_val;
1180 pend_val = val;
1181 }
1182
1193 config_string(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1194 {
1195 val = def_val;
1196 pend_val = val;
1197 }
1198
1208 config_string(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1209 {
1210 val = def_val;
1211 pend_val = val;
1212 }
1213
1214 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1215 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1216
1223 void SetEnumList(NBString s) { enum_list = s; };
1224
1225 // Assignment Operators
1226
1232 operator NBString() const { return val; };
1233
1239 config_string &operator=(const char *p)
1240 {
1241 pend_val = val = p;
1242 if (GetFlags(fConfigIsDefault))
1243 ClrBranchFlag(fConfigIsDefault, true);
1244 return *this;
1245 };
1246
1253 {
1254 pend_val = val = s;
1255 if (GetFlags(fConfigIsDefault))
1256 ClrBranchFlag(fConfigIsDefault, true);
1257 return *this;
1258 };
1259
1266 {
1267 pend_val = val = ci.val;
1268 if (GetFlags(fConfigIsDefault))
1269 ClrBranchFlag(fConfigIsDefault, true);
1270 return *this;
1271 };
1272
1273 // This is named so error messages make sense to user, old name was GetExtent
1274 virtual int Missing_ConfigEndMarker(void *&startp) override
1275 {
1276 startp = this;
1277 return sizeof(*this);
1278 };
1279
1285 inline const char *c_str() const { return val.c_str(); };
1286
1292 inline size_t length() const { return val.length(); };
1293
1301 inline const char &operator[](size_t pos) const { return val[pos]; };
1302
1310 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1311
1312 virtual void ExtendedSchema(int fd, int indent, bool pretty);
1313
1314 /* *
1315 * @brief Perform a string interpolation and place the finished interpolation
1316 * in the Destination string
1317 *
1318 * @param dest Destination string
1319 *
1320 * @returns Whether the interpolation was successful
1321 */
1322 bool Interpolate(NBString &dest)
1323 {
1324 return val.Interpolate(dest);
1325 }
1326
1327 friend class config_pass;
1328 friend class config_localname;
1329 friend class config_chooser;
1330 friend class config_localname;
1331};
1332
1343{
1344 protected:
1345 virtual int FdPrintValue(int fd, bool raw) override;
1346 public:
1357 config_pass(config_obj &owner, NBString def_val, const char *name, const char *desc = NULL)
1358 : config_string(owner, def_val, name, desc){};
1359
1369 config_pass(NBString def_val, const char *name, const char *desc = NULL) : config_string(def_val, name, desc){};
1370
1381 config_pass(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL)
1382 : config_string(owner, def_val, name, desc){};
1383
1393 config_pass(const char *def_val, const char *name, const char *desc = NULL) : config_string(def_val, name, desc){};
1394
1396
1404 virtual void GetTextValue(NBString &s) override;
1405
1413 virtual void GetRawValue(NBString &s) override;
1414
1415 virtual void CommitTestedValue(uint32_t permission_mask) override;
1416
1417 // Add help pop-ups for web page display
1418 virtual void ExtendedSchema(int fd, int indent, bool pretty)
1419 {
1420 config_string::ExtendedSchema(fd, indent, pretty);
1421 DoSchemaLine(fd, "format", "password", indent, pretty);
1422 };
1423
1429 operator NBString() const { return val; };
1430
1436 config_pass &operator=(const char *p)
1437 {
1438 pend_val = val = p;
1439 if (GetFlags(fConfigIsDefault))
1440 ClrBranchFlag(fConfigIsDefault, true);
1441 return *this;
1442 };
1443
1450 {
1451 pend_val = val = s;
1452 if (GetFlags(fConfigIsDefault))
1453 ClrBranchFlag(fConfigIsDefault, true);
1454 return *this;
1455 };
1456
1463 {
1464 pend_val = val = ci.val;
1465 if (GetFlags(fConfigIsDefault))
1466 ClrBranchFlag(fConfigIsDefault, true);
1467 return *this;
1468 };
1469
1476 {
1477 pend_val = val = ci.val;
1478 if (GetFlags(fConfigIsDefault))
1479 ClrBranchFlag(fConfigIsDefault, true);
1480 return *this;
1481 };
1482};
1483
1493{
1494 IPADDR4 val;
1495 IPADDR4 pend_val;
1496
1497 protected:
1498 virtual int FdPrintValue(int fd, bool raw) override;
1499 public:
1508 virtual void GetTextValue(NBString &s) override { s.siprintf("\"%hI\"", val); };
1509
1520 config_IPADDR4(config_obj &owner, IPADDR4 def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1521 {
1522 val = def_val;
1523 pend_val = val;
1524 }
1525
1535 config_IPADDR4(IPADDR4 def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1536 {
1537 val = def_val;
1538 pend_val = val;
1539 }
1540
1542
1553 config_IPADDR4(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1554 {
1555 IPADDR4 i4;
1556 i4.SetFromAscii(def_val);
1557 val = i4;
1558 pend_val = val;
1559 }
1560
1570 config_IPADDR4(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1571 {
1572 IPADDR4 i4;
1573 i4.SetFromAscii(def_val);
1574 val = i4;
1575 pend_val = val;
1576 }
1577
1578 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1579 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1580
1581 // Assignment operators
1582
1588 operator IPADDR4() const { return val; };
1589
1597 inline bool IsNull() const { return val.IsNull(); };
1598
1606 inline bool NotNull() const { return !(val.IsNull()); };
1607
1613 inline void SetNull()
1614 {
1615 val.SetNull();
1616 pend_val = val;
1617 };
1618
1625 {
1626 pend_val = val = i4;
1627 if (GetFlags(fConfigIsDefault))
1628 ClrBranchFlag(fConfigIsDefault, true);
1629 return *this;
1630 };
1631
1638 {
1639 pend_val = val = ci.val;
1640 if (GetFlags(fConfigIsDefault))
1641 ClrBranchFlag(fConfigIsDefault, true);
1642 return *this;
1643 };
1644
1645 // This is named so error messages make sense to user, old name was GetExtent
1646 virtual int Missing_ConfigEndMarker(void *&startp)
1647 {
1648 startp = this;
1649 return sizeof(*this);
1650 };
1651
1659 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1660
1661 // Add web page help
1662 virtual void ExtendedSchema(int fd, int indent, bool pretty) { DoSchemaLine(fd, "format", "ipv4", indent, pretty); };
1663};
1664
1665#ifdef IPV6
1675{
1676 IPADDR val;
1677 IPADDR pend_val;
1678
1679 protected:
1680 virtual int FdPrintValue(int fd, bool raw) override;
1681 public:
1689 virtual void GetTextValue(NBString &s) override { s.siprintf("\"%I\"", val); };
1690
1701 config_IPADDR(config_obj &owner, IPADDR def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1702 {
1703 val = def_val;
1704 pend_val = val;
1705 }
1706
1708
1718 config_IPADDR(IPADDR def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1719 {
1720 val = def_val;
1721 pend_val = val;
1722 }
1723
1734 config_IPADDR(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1735 {
1736 IPADDR i6;
1737 i6.SetFromAscii(def_val);
1738 val = i6;
1739 pend_val = val;
1740 }
1741
1751 config_IPADDR(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1752 {
1753 IPADDR i6;
1754 i6.SetFromAscii(def_val);
1755 val = i6;
1756 pend_val = val;
1757 }
1758
1759 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1760 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1761
1767 operator IPADDR() const { return val; };
1768
1776 bool IsNull() const { return val.IsNull(); }
1777
1785 bool NotNull() const { return !(val.IsNull()); }
1786
1790 void SetNull()
1791 {
1792 val.SetNull();
1793 pend_val = val;
1794 }
1795
1802 {
1803 pend_val = val = i6;
1804 if (GetFlags(fConfigIsDefault))
1805 ClrBranchFlag(fConfigIsDefault, true);
1806 return *this;
1807 };
1808
1815 {
1816 pend_val = val = ci.val;
1817 if (GetFlags(fConfigIsDefault))
1818 ClrBranchFlag(fConfigIsDefault, true);
1819 return *this;
1820 };
1821
1822 // This is named so error messages make sense to user, old name was GetExtent
1823 virtual int Missing_ConfigEndMarker(void *&startp)
1824 {
1825 startp = this;
1826 return sizeof(*this);
1827 };
1828
1836 virtual void GetTypeValue(NBString &s) override { s = "string"; };
1837
1838 // Add web page help
1839 virtual void ExtendedSchema(int fd, int indent, bool pretty) { DoSchemaLine(fd, "format", "ipv6", indent, pretty); };
1840};
1841#else
1842#define config_IPADDR config_IPADDR4
1843#endif
1844
1853{
1854 MACADR val;
1855 MACADR pend_val;
1856
1857 protected:
1858 virtual int FdPrintValue(int fd, bool raw) override;
1859 public:
1868 virtual void GetTextValue(NBString &s) override
1869 {
1870 s.siprintf("\"%02X:%02X:%02X:%02X:%02X:%02X\"", val.phywadr[0] >> 8, val.phywadr[0] & 0xFF, val.phywadr[1] >> 8,
1871 val.phywadr[1] & 0xFF, val.phywadr[2] >> 8, val.phywadr[2] & 0xFF);
1872 };
1873
1884 config_MACADR(config_obj &owner, MACADR def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1885 {
1886 val = def_val;
1887 pend_val = val;
1888 }
1889
1891
1901 config_MACADR(MACADR def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1902 {
1903 val = def_val;
1904 pend_val = val;
1905 }
1906
1918 config_MACADR(config_obj &owner, const char *def_val, const char *name, const char *desc = NULL) : config_value(owner, name, desc)
1919 {
1920 MACADR ma;
1921 ma = AsciiToMac(def_val);
1922
1923 val = ma;
1924 pend_val = val;
1925 }
1926
1937 config_MACADR(const char *def_val, const char *name, const char *desc = NULL) : config_value(name, desc)
1938 {
1939 MACADR ma;
1940 ma = AsciiToMac(def_val);
1941 val = ma;
1942 pend_val = val;
1943 }
1944
1945 // Assignment Operators
1946
1952 operator MACADR() const { return val; };
1953
1960 {
1961 pend_val = val = ci.val;
1962 if (GetFlags(fConfigIsDefault))
1963 ClrBranchFlag(fConfigIsDefault, true);
1964 return *this;
1965 };
1966
1973 {
1974 pend_val = val = ci;
1975 if (GetFlags(fConfigIsDefault))
1976 ClrBranchFlag(fConfigIsDefault, true);
1977 return *this;
1978 };
1979
1980 MACADR operator+(uint32_t rhs)
1981 { return val + rhs; }
1982
1983 MACADR operator-(uint32_t rhs)
1984 { return val - rhs; }
1985
1986 // This is named so error messages make sense to user, old name was GetExtent
1987 virtual int Missing_ConfigEndMarker(void *&startp)
1988 {
1989 startp = this;
1990 return sizeof(*this);
1991 };
1992
1993 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
1994 virtual void CommitTestedValue(uint32_t permission_mask) override { val = pend_val; }
1995
2003 virtual void GetTypeValue(NBString &s) override { s = "string"; };
2004};
2005
2006// This is named so error messages make sense to user, old name was GetExtent
2007#define ConfigEndMarker \
2008 virtual int Missing_ConfigEndMarker(void *&startp) override \
2009 { \
2010 startp = this; \
2011 return sizeof(*this); \
2012 };
2013
2027{
2028 config_string value{"", "Value"};
2029 config_string choices{"", "Choices"};
2030 ConfigEndMarker;
2031
2032 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2033
2034 public:
2044 config_chooser(config_obj &owner, const char *name, const char *in_value, const char *in_choices, const char *desc = NULL)
2045 : config_obj(owner, name, desc)
2046 {
2047 value = in_value; // Current choice
2048 choices = in_choices; // List of choices
2049 choices.m_Flags |= fConfigReadOnly | fConfigNoSave; // Confiuration flags
2050 value.SetEnumList(choices); // Create enum list from string containing all choices
2051 };
2052
2054
2063 config_chooser(const char *name, const char *in_value, const char *in_choices, const char *desc = NULL) : config_obj(name, desc)
2064 {
2065 value = in_value;
2066 choices = in_choices;
2067 choices.m_Flags |= fConfigReadOnly | fConfigNoSave;
2068 value.SetEnumList(choices);
2069 };
2070
2079 bool IsSelected(const char *choice) { return (choice == value); };
2080
2089 bool IsSelected(const NBString &s) { return (s == value); };
2090
2104 bool IsInChoices(const char *str, size_t strLen)
2105 {
2106 const char *sChoices = choices.c_str();
2107 size_t listLen = choices.length();
2108 size_t index = 0;
2109
2110 if (str == nullptr) { return false; }
2111 if (listLen == 0) { return false; }
2112
2113 while (index < listLen)
2114 {
2115 size_t curVarStart = index;
2116 size_t curVarLength;
2117
2118 // determine the length of the current element in the list of choices
2119 while (sChoices[index] != 0 && sChoices[index] != ',')
2120 {
2121 // index until the end of the current element in the list of choices
2122 index++;
2123 }
2124 curVarLength = index - curVarStart;
2125
2126 if (strncmp(str, &sChoices[curVarStart], (curVarLength > strLen) ? curVarLength : strLen) == 0)
2127 {
2128 return true; // found a match
2129 }
2130 index++; // increment past ','
2131 }
2132
2133 return false;
2134 }
2135
2149 bool IsInChoices(const NBString &str, size_t strLen)
2150 {
2151 const char *sStr = str.c_str();
2152 const char *sChoices = choices.c_str();
2153 size_t length = choices.length();
2154 size_t index = 0;
2155
2156 if (sStr == nullptr) { return false; }
2157 if (length == 0) { return false; }
2158
2159 while (index < length)
2160 {
2161 size_t curVarStart = index;
2162 size_t curVarLength;
2163
2164 // determine the length of the current element in the list of choices
2165 while (sChoices[index] != 0 && sChoices[index] != ',')
2166 {
2167 // index until the end of the current element in the list of choices
2168 index++;
2169 }
2170 curVarLength = index - curVarStart;
2171
2172 if (strncmp(sStr, &sChoices[curVarStart], curVarLength > strLen ? curVarLength : strLen) == 0)
2173 {
2174 return true; // found a match
2175 }
2176 index++; // increment past ','
2177 }
2178
2179 return false;
2180 }
2181
2187 const config_string &GetChoices() { return choices; }
2188
2196 const config_string &SetChoices(const char *in_choices)
2197 {
2198 choices = in_choices;
2199 value.SetEnumList(choices);
2200
2201 return choices;
2202 }
2203
2204 /* @brief Set the list of choices
2205 *
2206 * @param in_choices The list of option choices
2207 *
2208 * @returns A config_string object containing the list of choices
2209 */
2210 const config_string &SetChoices(const NBString &in_choices)
2211 {
2212 choices = in_choices;
2213 value.SetEnumList(choices);
2214
2215 return choices;
2216 }
2217
2218
2224 operator NBString() const { return (NBString)value; };
2225
2232 {
2233 value = p;
2234 if (GetFlags(fConfigIsDefault))
2235 ClrBranchFlag(fConfigIsDefault, true);
2236 return *this;
2237 };
2238
2245 {
2246 value = s;
2247 if (GetFlags(fConfigIsDefault))
2248 ClrBranchFlag(fConfigIsDefault, true);
2249 return *this;
2250 };
2251
2258 {
2259 value = ci.value;
2260 if (GetFlags(fConfigIsDefault))
2261 ClrBranchFlag(fConfigIsDefault, true);
2262 return *this;
2263 };
2264
2265 virtual void GetTypeValue(NBString &s) override { s = "object"; };
2266};
2267
2274{
2275 protected:
2276 int min_val; // should be INT_MIN by default
2277 int max_val; // should be INT_MAX by default
2278
2279 public:
2290 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)
2291 {
2292 min_val=minv;
2293 max_val=maxv;
2294 }
2295
2305 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)
2306 {
2307 min_val=minv;
2308 max_val=maxv;
2309 }
2310
2311 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2312 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2313
2314 config_int_limit &operator=(const int i)
2315 {
2316 if(i>=min_val && max_val<=i)
2317 {
2318 pend_val = val = i;
2319 if (GetFlags(fConfigIsDefault))
2320 ClrBranchFlag(fConfigIsDefault, true);
2321 }
2322 return *this;
2323 };
2324
2332 {
2333 int test_v=ci;
2334 if((test_v>=min_val) && (test_v<=max_val))
2335 {
2336 pend_val = val = test_v;
2337 if (GetFlags(fConfigIsDefault))
2338 ClrBranchFlag(fConfigIsDefault, true);
2339 }
2340 return *this;
2341 };
2342
2350 {
2351 int test_v=cil;
2352 if((test_v>=min_val) && (test_v<=max_val))
2353 {
2354 pend_val = val = test_v;
2355 if (GetFlags(fConfigIsDefault))
2356 ClrBranchFlag(fConfigIsDefault, true);
2357 }
2358 return *this;
2359 };
2360
2361};
2362
2369{
2370 protected:
2371 uint32_t min_val; // should be 0 by default
2372 uint32_t max_val; // should be UINT_MAX by default
2373
2374 public:
2385 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)
2386 {
2387 min_val=minv;
2388 max_val=maxv;
2389 }
2390
2400 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)
2401 {
2402 min_val=minv;
2403 max_val=maxv;
2404 }
2405
2406 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2407 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2408
2409 config_uint_limit &operator=(const uint32_t i)
2410 {
2411 if(i>=min_val && max_val<=i)
2412 {
2413 pend_val = val = i;
2414 if (GetFlags(fConfigIsDefault))
2415 ClrBranchFlag(fConfigIsDefault, true);
2416 }
2417 return *this;
2418 };
2419
2427 {
2428 uint32_t test_v=ci;
2429 if((test_v>=min_val) && (test_v<=max_val))
2430 {
2431 pend_val = val = test_v;
2432 if (GetFlags(fConfigIsDefault))
2433 ClrBranchFlag(fConfigIsDefault, true);
2434 }
2435 return *this;
2436 };
2437
2445 {
2446 uint32_t test_v=cil;
2447 if((test_v>=min_val) && (test_v<=max_val))
2448 {
2449 pend_val = val = test_v;
2450 if (GetFlags(fConfigIsDefault))
2451 ClrBranchFlag(fConfigIsDefault, true);
2452 }
2453 return *this;
2454 };
2455
2456};
2457
2458
2459
2466{
2467 protected:
2468 double min_val; // should be -DBL_MAX by default
2469 double max_val; // should be DBL_MAX by default
2470 double step; // allowable increments in the HTML GUI (precision to round to, not strictly enforced)
2471
2472 public:
2484 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)
2485 {
2486 min_val=minv;
2487 max_val=maxv;
2488 step=stepv;
2489 }
2490
2501 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)
2502 {
2503 min_val=minv;
2504 max_val=maxv;
2505 step=stepv;
2506 }
2507
2508 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2509 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2510
2511 config_double_limit &operator=(const double i)
2512 {
2513 if(i>=min_val && max_val<=i)
2514 {
2515 pend_val = val = i;
2516 if (GetFlags(fConfigIsDefault))
2517 ClrBranchFlag(fConfigIsDefault, true);
2518 }
2519 return *this;
2520 };
2521
2529 {
2530 double test_v=ci;
2531 if((test_v>=min_val) && (test_v<=max_val))
2532 {
2533 pend_val = val = test_v;
2534 if (GetFlags(fConfigIsDefault))
2535 ClrBranchFlag(fConfigIsDefault, true);
2536 }
2537 return *this;
2538 };
2539
2547 {
2548 double test_v=cil;
2549 if((test_v>=min_val) && (test_v<=max_val))
2550 {
2551 pend_val = val = test_v;
2552 if (GetFlags(fConfigIsDefault))
2553 ClrBranchFlag(fConfigIsDefault, true);
2554 }
2555 return *this;
2556 };
2557
2558
2566 virtual void GetTypeValue(NBString &s) override { s = "number"; };
2567};
2568
2575{
2576 protected:
2577 size_t min_len; // should be 0 by default
2578 size_t max_len; // should be 0 by default
2579
2580 public:
2591 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)
2592 {
2593 min_len=minl;
2594 max_len=maxl;
2595 }
2596
2606 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)
2607 {
2608 min_len=minl;
2609 max_len=maxl;
2610 }
2611
2612 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2613 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2614
2615 config_string_limit &operator=(const NBString i)
2616 {
2617 if(i.length()>=min_len && max_len<=i.length())
2618 {
2619 pend_val = val = i;
2620 if (GetFlags(fConfigIsDefault))
2621 ClrBranchFlag(fConfigIsDefault, true);
2622 }
2623 return *this;
2624 };
2625
2633 {
2634 NBString test_v=ci;
2635 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2636 {
2637 pend_val = val = test_v;
2638 if (GetFlags(fConfigIsDefault))
2639 ClrBranchFlag(fConfigIsDefault, true);
2640 }
2641 return *this;
2642 };
2643
2651 {
2652 NBString test_v=cil;
2653 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2654 {
2655 pend_val = val = test_v;
2656 if (GetFlags(fConfigIsDefault))
2657 ClrBranchFlag(fConfigIsDefault, true);
2658 }
2659 return *this;
2660 };
2661
2662};
2663
2670{
2671 protected:
2672 size_t min_len; // should be 0 by default
2673 size_t max_len; // should be 0 by default
2674
2675 public:
2686 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)
2687 {
2688 min_len=minl;
2689 max_len=maxl;
2690 }
2691
2701 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)
2702 {
2703 min_len=minl;
2704 max_len=maxl;
2705 }
2706
2707 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2708 virtual void ExtendedSchema(int fd, int indent, bool pretty) override;
2709
2710 config_pass_limit &operator=(const NBString i)
2711 {
2712 if(i.length()>=min_len && max_len<=i.length())
2713 {
2714 pend_val = val = i;
2715 if (GetFlags(fConfigIsDefault))
2716 ClrBranchFlag(fConfigIsDefault, true);
2717 }
2718 return *this;
2719 };
2720
2728 {
2729 NBString test_v=ci;
2730 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2731 {
2732 pend_val = val = test_v;
2733 if (GetFlags(fConfigIsDefault))
2734 ClrBranchFlag(fConfigIsDefault, true);
2735 }
2736 return *this;
2737 };
2738
2746 {
2747 NBString test_v=cil;
2748 if((test_v.length()>=min_len) && (test_v.length()<=max_len))
2749 {
2750 pend_val = val = test_v;
2751 if (GetFlags(fConfigIsDefault))
2752 ClrBranchFlag(fConfigIsDefault, true);
2753 }
2754 return *this;
2755 };
2756
2757};
2758
2759class reboot_obj : public config_bool
2760{
2761 virtual const char *GetSortNameValue() { return "ZZZc"; };
2762
2763 public:
2764 reboot_obj() : config_bool(root, false, "Reboot", "Cause system reboot on save"){};
2765 void clear()
2766 {
2767 val = false;
2768 pend_val = false;
2769 };
2770
2771 // This is named so error messages make sense to user, old name was GetExtent
2772 virtual int Missing_ConfigEndMarker(void *&startp)
2773 {
2774 startp = this;
2775 return sizeof(*this);
2776 };
2777};
2778
2779class version_obj : public config_int
2780{
2781 bool bNeverSet;
2782 virtual const char *GetSortNameValue() { return "ZZZb"; };
2783
2784 public:
2785 version_obj() : config_int(root, 0, "Version", "Version serial number") { bNeverSet = true; };
2786
2787 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs);
2788 void inc()
2789 {
2790 val++;
2791 pend_val = val;
2792 };
2793 // This is named so error messages make sense to user
2794 // Old name was GetExtent
2795 virtual int Missing_ConfigEndMarker(void *&startp)
2796 {
2797 startp = this;
2798 return sizeof(*this);
2799 };
2800};
2801
2802class empty_config_obj : public config_obj
2803{
2804 ConfigEndMarker;
2805
2806 public:
2807 empty_config_obj(const char *name, const char *desc = NULL) : config_obj(name, desc){};
2808 empty_config_obj(config_obj &owner, const char *name, const char *desc = NULL) : config_obj(owner, name, desc){};
2809 empty_config_obj(empty_config_obj &&e);
2810};
2811
2812
2813
2814// This class is intended for recovery applications or for devices supporting multiple
2815// application profiles to preserve unused config tree branches across configuration
2816// updates
2817// Ex:
2818// Application A has a config object at 'AppData.AppA', and Application B
2819// has a config object at 'AppData.AppB'. Normally, if Application A were
2820// to update any configuration (whether Application or System related), this
2821// would wipe out any AppB configuration as it is not known of by Application A.
2822// Using a config_preserver_obj, any configuration tree data below it's registration
2823// will be persisted across updates unless explicitly wiped.
2824class config_preserver_obj : public config_obj
2825{
2826 ConfigEndMarker;
2827 ParsedJsonDataSet &pendingTreeData;
2828 ParsedJsonDataSet &treeData;
2829
2830 public:
2831 config_preserver_obj(const char *name, const char *desc = NULL);
2832 config_preserver_obj(config_obj &owner, const char *name, const char *desc = NULL);
2833 config_preserver_obj(config_preserver_obj &&po);
2834
2835
2836 virtual ConfigTestResult TestNewValue(ParsedJsonDataSet &pjs) override;
2837 virtual void CommitTestedValue(uint32_t permission_mask) override;
2838 virtual void GetTextValue(NBString &s) override;
2839 virtual void GetRawValue(NBString &s) override;
2840};
2841
2842extern const char *AppName;
2843extern const char PlatformName[];
2844
2845class SysRecord : public config_obj
2846{
2847 public:
2848 config_report system_platform{PlatformName, "Platform", "Hardware Platform"};
2849 config_report system_app{AppName, "Application", "Application name"};
2850 ConfigEndMarker;
2851
2852 SysRecord(const char *name, const char *desc = NULL) : config_obj(name, desc){};
2853 SysRecord(config_obj &owner, const char *name, const char *desc = NULL) : config_obj(owner, name, desc){};
2854 SysRecord(SysRecord &&sr);
2855};
2856
2857extern SysRecord sys;
2858extern empty_config_obj netif;
2859
2860extern reboot_obj rebooter;
2861extern version_obj config_cur_version;
2862
2863extern const int plat_def_baud;
2864extern const int plat_def_delay;
2865extern const int plat_def_quiet;
2866extern const int plat_def_watchdog_enabled;
2867
2868#include <plat_cfg_types.h>
2869#ifdef PRESERVE_APP_DATA
2870extern config_preserver_obj appdata;
2871#else
2872extern empty_config_obj appdata;
2873#endif
2874
2880
2881class MonitorRecord : public config_obj
2882{
2883 public:
2884 config_int Baud{plat_def_baud, "BootBaud"};
2885 config_uart Uart{plat_def_com, "BootUart"};
2886 config_int BootDelay{plat_def_delay, "BootDelay"};
2887 config_bool Quiet{plat_def_quiet, "BootQuiet"};
2888 config_chooser sercfg_action{"SerialConfig", "DuringBoot", "DuringBoot,AlwaysEnabled,PauseAfterBoot,Disabled"};
2889 config_string abortbootcmd{"A", "Abort"};
2890 config_pass system_user{"", "User"};
2891 config_pass system_pass{"", "Password"};
2892 ConfigEndMarker;
2893
2894 MonitorRecord(const char *name) : config_obj(name, "Boot monitor record")
2895 {
2896 sercfg_action.SetFlag(fConfigNeedReboot);
2897 Baud.SetFlag(fConfigNeedReboot);
2898 Uart.SetFlag(fConfigNeedReboot);
2899 };
2900 MonitorRecord(config_obj &owner, const char *name) : config_obj(owner, name, "Boot Monitor Record")
2901 {
2902 sercfg_action.SetFlag(fConfigNeedReboot);
2903 Baud.SetFlag(fConfigNeedReboot);
2904 Uart.SetFlag(fConfigNeedReboot);
2905 };
2906 MonitorRecord(MonitorRecord &&mr);
2907};
2908extern MonitorRecord monitor_config;
2909
2920
2921
2922
2923
2924#endif
2925
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:1493
bool NotNull() const
Check if the IP address is not null.
Definition config_obj.h:1606
config_IPADDR4(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1570
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1659
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:1553
config_IPADDR4(IPADDR4 def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1535
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:1508
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:1520
config_IPADDR4 & operator=(const config_IPADDR4 &ci)
Copy one config_IPADDR4 object to another.
Definition config_obj.h:1637
bool IsNull() const
Check if the IP address is null.
Definition config_obj.h:1597
void SetNull()
Set the IP address to null.
Definition config_obj.h:1613
config_IPADDR4 & operator=(const IPADDR4 &i4)
Copy an IPADDR4 object value to a config_IPADDR4 object.
Definition config_obj.h:1624
Configuration Variable for IPADDR (IPv6) object type.
Definition config_obj.h:1675
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1836
config_IPADDR & operator=(const config_IPADDR &ci)
Copy one config_IPADDR object to another.
Definition config_obj.h:1814
config_IPADDR & operator=(const IPADDR &i6)
Copy an IPADDR object value to a config_IPADDR object.
Definition config_obj.h:1801
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:1734
config_IPADDR(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1751
void SetNull()
Set the IP address value of an config_IPADDR object to null.
Definition config_obj.h:1790
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:1701
bool NotNull() const
Check if the IP address is not null.
Definition config_obj.h:1785
config_IPADDR(IPADDR def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1718
bool IsNull() const
Check if the IP address is null.
Definition config_obj.h:1776
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:1689
Configuration Variable for MACADR object type.
Definition config_obj.h:1853
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:1884
config_MACADR & operator=(const MACADR &ci)
Copy a MACADR object value to a MACADR object.
Definition config_obj.h:1972
config_MACADR(MACADR def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1901
config_MACADR & operator=(const config_MACADR &ci)
Copy one config_MACADR object to another.
Definition config_obj.h:1959
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:1918
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:1868
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:2003
config_MACADR(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1937
Boolean Configuration Variable.
Definition config_obj.h:997
config_bool(bool def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1040
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1116
config_bool & operator=(const config_bool &cb)
Copy one config_bool object to another.
Definition config_obj.h:1083
config_bool & operator=(const int i)
Assign a config_bool object value to the specified integer value.
Definition config_obj.h:1096
config_bool & operator=(const bool v)
Assign the config_bool object value to the specified bool value.
Definition config_obj.h:1070
virtual void GetTextValue(NBString &s) override
Copy the object value as a text string to the specified NBString object.
Definition config_obj.h:1011
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:1027
Chooser Configuration Variable - Select From a List of Items.
Definition config_obj.h:2027
virtual void GetTypeValue(NBString &s) override
Assigns the object type value to the specified NBString object.
Definition config_obj.h:2265
const config_string & GetChoices()
Get the list of choices.
Definition config_obj.h:2187
const config_string & SetChoices(const char *in_choices)
Set the list of choices.
Definition config_obj.h:2196
bool IsSelected(const char *choice)
Check if a particular choice option is selected.
Definition config_obj.h:2079
config_chooser & operator=(const char *p)
Assign the selected list item from a const char* value.
Definition config_obj.h:2231
bool IsSelected(const NBString &s)
Check if a particular choice option is selected.
Definition config_obj.h:2089
config_chooser & operator=(const config_chooser &ci)
Copy one config_chooser object to another.
Definition config_obj.h:2257
config_chooser(const char *name, const char *in_value, const char *in_choices, const char *desc=NULL)
Object constructor.
Definition config_obj.h:2063
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:2104
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:2044
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:2149
config_chooser & operator=(const NBString &s)
Assign the config_string object value from a NBString object.
Definition config_obj.h:2244
A config_double with minimum and/or maximum values Attempting to set a value lower than the minimum o...
Definition config_obj.h:2466
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:2566
config_double_limit & operator=(const config_double_limit &cil)
Copy one config_double_limit object to another.
Definition config_obj.h:2546
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:2501
config_double_limit & operator=(const config_double &ci)
Copy a config_double object into the config_double_limit.
Definition config_obj.h:2528
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:2484
Double Float Configuration Variable.
Definition config_obj.h:816
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:947
virtual void GetTextValue(NBString &s) override
Copy the object value as a text string to the specified NBString object.
Definition config_obj.h:830
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:840
config_double(double def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:853
config_double & operator=(const double d)
Assign the config_double object value from a double value.
Definition config_obj.h:910
config_double & operator=(const config_double &ci)
Copy one config_double object to another.
Definition config_obj.h:923
A config_int with minimum and/or maximum values Attempting to set a value lower than the minimum or g...
Definition config_obj.h:2274
config_int_limit & operator=(const config_int &ci)
Copy a config_int object into the config_int_limit.
Definition config_obj.h:2331
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:2305
config_int_limit & operator=(const config_int_limit &cil)
Copy one config_int_limit object to another.
Definition config_obj.h:2349
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:2290
Signed 32-bit Integer Configuration Variable.
Definition config_obj.h:700
config_int & operator=(const int i)
Assign the config_int object value to the specified int value.
Definition config_obj.h:769
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:724
virtual void GetTypeValue(NBString &s) override
Copy the object type value in the specified NBString object.
Definition config_obj.h:805
virtual void GetTextValue(NBString &s) override
Copy the object value to the specified NBString object.
Definition config_obj.h:714
config_int(int def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:737
config_int & operator=(const config_int &ci)
Copy one config_int object to another.
Definition config_obj.h:783
Configure device network name.
Definition config_netobj.h:26
Base class used to create configuration objects.
Definition config_obj.h:320
virtual void GetTypeValue(NBString &s) override
Assigns the object type value to the specified NBString object.
Definition config_obj.h:422
config_obj(const char *name, const char *desc)
Object constructor.
Definition config_obj.h:367
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:344
A config_pass with minimum and/or maximum lengths Attempting to set a value shorter than the minimum ...
Definition config_obj.h:2670
config_pass_limit & operator=(const config_pass_limit &cil)
Copy one config_pass_limit object to another.
Definition config_obj.h:2745
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:2686
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:2701
config_pass_limit & operator=(const config_pass &ci)
Copy a config_pass object into the config_pass_limit.
Definition config_obj.h:2727
Password string Configuration Variable.
Definition config_obj.h:1343
config_pass(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1393
config_pass & operator=(const config_string &ci)
Copy a config_string object to a config_pass object.
Definition config_obj.h:1462
config_pass & operator=(const char *p)
Assign the config_pass object value from a const char* value.
Definition config_obj.h:1436
config_pass & operator=(const NBString &s)
Assign the config_pass object value from a NBString object.
Definition config_obj.h:1449
config_pass(NBString def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1369
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:1381
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:1475
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:1357
A config_string with minimum and/or maximum lengths Attempting to set a value shorter than the minimu...
Definition config_obj.h:2575
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:2606
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:2591
config_string_limit & operator=(const config_string &ci)
Copy a config_string object into the config_string_limit.
Definition config_obj.h:2632
config_string_limit & operator=(const config_string_limit &cil)
Copy one config_string_limit object to another.
Definition config_obj.h:2650
String Configuration Variable.
Definition config_obj.h:1127
const char * c_str() const
Returns the object value as a string.
Definition config_obj.h:1285
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:1161
const char & operator[](size_t pos) const
Return the value of a character in the string.
Definition config_obj.h:1301
config_string & operator=(const char *p)
Assign the config_string object value from a const char* string.
Definition config_obj.h:1239
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:1193
config_string & operator=(const NBString &s)
Assign the config_string object value from a NBString object.
Definition config_obj.h:1252
void SetEnumList(NBString s)
Renders the data used to explain the schema/descriptions for the list of choices.
Definition config_obj.h:1223
config_string(NBString def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1176
config_string & operator=(const config_string &ci)
Copy one config_string object to another.
Definition config_obj.h:1265
config_string(const char *def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:1208
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:1310
size_t length() const
Returns the string length in bytes.
Definition config_obj.h:1292
A config_uint with minimum and/or maximum values Attempting to set a value lower than the minimum or ...
Definition config_obj.h:2369
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:2400
config_uint_limit & operator=(const config_uint_limit &cil)
Copy one config_uint_limit object to another.
Definition config_obj.h:2444
config_uint_limit & operator=(const config_uint &ci)
Copy a config_uint object into the config_uint_limit.
Definition config_obj.h:2426
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:2385
Unsigned 32-bit Integer Configuration Variable.
Definition config_obj.h:552
config_uint(uint32_t def_val, const char *name, const char *desc=NULL)
Object constructor.
Definition config_obj.h:589
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:576
config_uint & operator=(const uint32_t i)
Assign the config_uint object value from a uint32_t value.
Definition config_obj.h:620
virtual void GetTextValue(NBString &s) override
Copy the object value to the specified NBString object.
Definition config_obj.h:566
config_uint & operator=(const config_uint &ci)
Copy one config_uint object to another.
Definition config_obj.h:633
virtual void GetTypeValue(NBString &s) override
Copy the object type value to the specified NBString object.
Definition config_obj.h:655
Base class used to create a configuration value.
Definition config_obj.h:490
config_value(config_obj &owner, const char *name, const char *desc)
Object constructor with the parent/owner leaf parameter.
Definition config_obj.h:507
config_value(const char *name, const char *desc)
Object constructor.
Definition config_obj.h:528
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.
IPADDR6 IPADDR
IPADDR Object Type (either v4 or v6)
Definition nettypes.h:568
class MACADR MACADR
Used to store and manipulate MAC addresses.