NetBurner 3.5.6
PDF Version
json_lexer.h
Go to the documentation of this file.
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
46#ifndef _JSON_LEXER_H
47#define _JSON_LEXER_H
48
49#include <buffers.h>
50#include <math.h>
51#include <nettypes.h>
52#include <webclient/web_buffers.h>
53#include <nbstring.h>
54
79
80const char *GetTypeName(json_primitive_type t);
81
82
83typedef json_primitive_type json_primative_type; // Added for backwards compatibility
84
92typedef void(CharOutputFn)(const char *chars, int len, void *blob);
93
103
104class ParsedJsonDataSet; // forward declaration
105
113class JsonRef {
114 const ParsedJsonDataSet *parser;
115 PoolPtr m_pCurrent_Pool;
116 int m_nCurrent_Position;
117
118 JsonRef() {parser = 0; m_pCurrent_Pool = 0; m_nCurrent_Position = 0;}
119 friend class ParsedJsonDataSet;
120 // Used to print objects
121 int printhelper(CharOutputFn *pf, void *p, bool pretty);
122
123
124
125 public:
126 JsonRef(const JsonRef &pos);
127 json_primitive_type GetCurrent() const;
128 json_primitive_type GetRawCurrent() const; // Get current position element including non public types
129 json_primitive_type GetNextName();
130 json_primitive_type GetNext();
131 json_primitive_type GetFirst();
132 json_primitive_type GetNextNameInCurrentArray();
133 json_primitive_type GetNextNameInCurrentObject(); // Retrieve only name elements inside current object
134 json_primitive_type FindFullAtName(const char *name);
135 json_primitive_type SkipCurrentValue(); // Skips over the current value
136 json_primitive_type FindFullName(const char *name);
137 json_primitive_type FindElementAfterName(const char *name);
138 json_primitive_type FindElementAfterNameInCurrentObject(const char *name);
139 json_primitive_type FindGlobalElementAfterName(const char *name);
140 json_primitive_type GetIndexInCurrentArray(int i);
141 json_primitive_type FindElementAfterNameInCurrentArray(const char *name);
142
143
144 const char *CurrentName() const;
145 bool CurrentNameMatches(const char *name) const;
146 const char *CurrentString() const;
147 int CopyCurrentString(char *buf, int buflen) const;
148 int CopyCurrentString(NBString &nbs) const;
149 double CurrentNumber() const;
150 inline double CurrentIntNumber() const { double dv=CurrentNumber(); if(isnan(dv))return 0; return dv;};
151 bool CurrentBool() const;
152 bool PermissiveCurrentBool() const;
153
175
188 JsonRef object(const char *name)
189 {
190 JsonRef prf = *this;
191 if (prf.Valid())
192 {
193 if (prf.GetCurrent() == BEGIN_OBJECT)
194 prf.next();
195
196 while (1)
197 {
198 json_primitive_type t = prf.FindElementAfterNameInCurrentObject(name);
199 if ((t != NOTFOUND) && (t != UNDEFINED) && (t != EOF_EL))
200 return prf;
201
202 if (t == NOTFOUND)
203 {
204 prf.MakeInvalid();
205 return prf;
206 };
207
208 if (t == BEGIN_OBJECT)
209 {
210 prf.MakeInvalid();
211 return prf;
212 };
213 }
214 }
215 else
216 {
217 return prf;
218 }
219 };
220
221 JsonRef GetA(const char *name,json_primitive_type pt1,json_primitive_type pt2=UNDEFINED)
222 {
223 JsonRef prf = *this;
224 if (prf.Valid())
225 {
226 if (prf.GetCurrent() == BEGIN_OBJECT)
227 prf.next();
228
229 while (1)
230 {
231 json_primitive_type t = prf.FindElementAfterNameInCurrentObject(name);
232 if(t==pt1) return prf;
233 if((t==pt2) &&(t!=UNDEFINED)) return prf;
234
235 if((t == UNDEFINED) || (t == EOF_EL)||(t == NOTFOUND))
236 {
237 prf.MakeInvalid();
238 return prf;
239 };
240
241 }
242 }
243 else
244 {
245 return prf;
246 }
247 };
248
249
250inline JsonRef Number(const char * name) {return GetA(name,NUMBER); };
251inline JsonRef Bool(const char * name) {return GetA(name,FALSE_EL,TRUE_EL);};
252inline JsonRef String(const char * name) {return GetA(name,STRING,ALLOC_STRING);};
253inline JsonRef Array(const char * name) {return GetA(name,BEGIN_ARRAY);};
254
255
256
257
269 JsonRef name(const char *name);
270
282 JsonRef operator()(const char *namev) {return name(namev); };
300 operator bool () const {return PermissiveCurrentBool(); };
301
305 operator float () const {return (float)CurrentNumber(); };
306
310 operator double () const {return CurrentNumber(); };
311
315 operator uint8_t() const {return (uint8_t)CurrentIntNumber(); };
316
320 operator int() const {return (int)CurrentIntNumber(); };
321
325 operator uint16_t() const {return (uint16_t)CurrentIntNumber(); };
326
330 operator uint32_t() const {return (uint32_t)CurrentIntNumber(); };
331
335 operator int8_t() const {return (int8_t)CurrentIntNumber(); };
336
340 operator int16_t() const {return (int16_t)CurrentIntNumber(); };
341
345 operator int32_t() const {return (uint32_t)CurrentIntNumber(); };
346
350 operator time_t() const {return (time_t)CurrentIntNumber(); };
351
355 operator const char *() const {return CurrentString(); };
356
360 operator NBString() const {return (NBString)CurrentString(); };
361
371 inline bool IsNumber() {return (Valid() && GetCurrent() == NUMBER); };
372
376 inline bool IsObject() {return (Valid() && GetCurrent() == BEGIN_OBJECT); } ;
377
382 inline bool IsString() {return (Valid() && ((GetCurrent() == STRING)||(GetCurrent() == ALLOC_STRING))); } ;
383
387 inline bool IsBool() {return (Valid() && ((GetCurrent() == TRUE_EL) || (GetCurrent() == FALSE_EL))); } ;
388
392 inline bool IsNull() {return (Valid() && GetCurrent() == NULL_EL); } ;
393
397 inline bool IsArray() {return (Valid() && GetCurrent() == BEGIN_ARRAY); } ;
398
402 inline bool Valid()const {return ((m_pCurrent_Pool) && (parser));};
403
415 inline JsonRef start()
416 {
417 JsonRef prf = *this;
418 if (prf.Valid())
419 prf.ResetPosition();
420 return prf;
421 };
422
427 JsonRef next() const {JsonRef prf=*this; if(prf.Valid()) prf.IncPosition(); return prf; };
428
434
439 bool JumpPosition(int siz);
440
446
452
457 void SkipArray();
458
464
476 int PrintChildren(bool pretty = false);
477
482 int PrintChildrenToFd(int fd, bool pretty = false);
483
488 int PrintChildrenToBuffer(char *buffer, int maxlen, bool pretty = false);
489
490
495 int PrintChildrenToString(NBString & s,bool pretty = false);
496
497
505 int GetChildPrintSize(bool pretty=false);
506
511 void DiagDump(const char * lab);
512
513
518 void MakeInvalid(){m_pCurrent_Pool=0; };
519
521};
522
523
524//Standalons function to check validity.
525inline bool Valid(const JsonRef & ref) {return ref.Valid(); }
526
527
536 PoolPtr m_pStorage_List_Head;
537 JsonRef m_ref;
538 JsonAllocString * pStringList;
539 int m_nMax_Position;
540 int m_nPool_Count;
541
542 int m_currentLine;
543 int m_currentColumn;
544 NBString m_stateStack;
545 json_primitive_type m_LastEmit;
546 json_primitive_type m_PrevLastEmit;
547 NBString m_LastError;
548 bool m_syntaxValid = true;
549
550
551 unsigned char m_BoolFlags;
552 const unsigned char fEnableLargeStrings=1;
553 const unsigned char fNeedComma=2;
554 const unsigned char fFirstFind=4;
555 const unsigned char fNeedNameTerm=8;
556
557 inline bool EnableLargeStrings() {return ((m_BoolFlags & fEnableLargeStrings)!=0);};
558 inline bool NeedComma() {return ((m_BoolFlags & fNeedComma)!=0);};
559 inline bool NeedNameTerm() {return ((m_BoolFlags & fNeedNameTerm)!=0);};
560 inline void CheckLastComma() {if(m_LastEmit==VALUE_SEPERATOR){Error("Trailing comma");}};
561
562 inline void pushStack(char c) {m_stateStack+=c; };
563
564 inline bool popStack(char c)
565 {int len=m_stateStack.length();
566 if((len==0) || (m_stateStack[len-1]!=c))
567 return false;
568 m_stateStack.shrink(1);
569 return true;
570 };
571
572 inline char topStack()
573 {int len=m_stateStack.length();
574 if(len==0) return 0;
575 return m_stateStack[len-1];
576 }
577
578 inline bool OkForValue(json_primitive_type prev)
579 {
580
581 if(prev==BEGIN_ARRAY) return true;
582 if((prev==VALUE_SEPERATOR) &&(topStack()=='['))return true;
583 if(prev==NAME) return true;
584 if(prev==UNDEFINED) return true;
585 return false;
586 }
587
588 inline bool OkForName(json_primitive_type prev)
589 {
590 if((prev==BEGIN_OBJECT)) return true;
591 if((prev==VALUE_SEPERATOR) &&(topStack()=='{'))return true;
592 return false;
593 }
594
595
596
597 unsigned char m_sep; // Current string separator
598 unsigned short m_tv;
599
600
601 // Parser state vars used when receiving text data
602 int m_state; // Parser state flag
603 unsigned char *m_pPrevStringStart;
604 int m_nStrLen;
605
606 unsigned char *PutChar(unsigned char c); // Used to process incoming text
607 void CheckForAndFixBrokenString();
608 void ProcessChar(unsigned char c);
609 void ZeroNextString();
610 void ZeroNextNumber(char c);
611 void AddStringChar(char c);
612 void AddEscapedStringChar(char c);
613 void AddNumberChar(char c);
614 void EmitNumberBuffer();
615 bool CheckStringEmit(json_primitive_type t);
616 void Emit(json_primitive_type t);
617 void ChangeString(json_primitive_type t);
618 inline bool IncPosition() { return m_ref.IncPosition(); };
619 inline bool JumpPosition(int siz) {return m_ref.JumpPosition(siz); };
620 bool Built();
621
622 virtual void Error(const char *err);// Error handler
623 virtual void Error(NBString & s); // Error handler
624 virtual void Warn(const char *err); // Warn handler
625 virtual void Warn(NBString & s); // Warn handler
626
627
628
629 private:
630 ParsedJsonDataSet *InsertName(const char *name);
631 ParsedJsonDataSet *InsertString(const char *s);
632 ParsedJsonDataSet *Insert(short i);
633 ParsedJsonDataSet *Insert(int i);
634 ParsedJsonDataSet *Insert(long i);
635 ParsedJsonDataSet *Insert(unsigned short i);
636 ParsedJsonDataSet *Insert(unsigned int i);
637 ParsedJsonDataSet *Insert(unsigned long i);
638 ParsedJsonDataSet *Insert(bool b);
639 ParsedJsonDataSet *Insert(double d);
640 ParsedJsonDataSet *Insert(const IPADDR &ip);
641
642
643 public:
644 friend class JsonRef;
645
646
647 inline void DiagDump(const char * lab) {m_ref.DiagDump(lab);};
648
659 inline void EnableLargeStrings(bool b)
660 {
661 if(b) m_BoolFlags|=fEnableLargeStrings;
662 else
663 m_BoolFlags&=~fEnableLargeStrings;
664
665 };
666
667 inline void NeedComma(bool b)
668 {
669 if(b) m_BoolFlags|=fNeedComma;
670 else
671 m_BoolFlags&=~fNeedComma;
672
673 };
674
675 inline bool FirstFind() {return ((m_BoolFlags & fFirstFind)!=0);};
676 inline void FirstFind(bool b)
677 {
678 if(b) m_BoolFlags|=fFirstFind;
679 else
680 m_BoolFlags&=~fFirstFind;
681
682 };
683
684
685
686
687
696 virtual int WriteData(const unsigned char *pCopyFrom, int numBytes);
697
705 virtual int ReadFrom(int fd);
706
714
742 inline JsonRef operator [](int i){return m_ref[i]; };
743
755 inline JsonRef operator()(const char * name){return m_ref.name(name);}
756
768 inline JsonRef name(const char * name){return m_ref.name(name);}
769
779 inline JsonRef object(const char * name){return m_ref.object(name);}
780
792 inline JsonRef start(){return m_ref.start();};
793
798 inline JsonRef next(){return m_ref.next();};
799
813 inline json_primitive_type GetFirst() {return m_ref.GetFirst(); };
814
828 inline json_primitive_type GetNext() {return m_ref.GetNext();};
829
843 inline json_primitive_type GetCurrent() {return m_ref.GetCurrent();};
844
858 // Get current position element including non public types
859 inline json_primitive_type GetRawCurrent() {return m_ref.GetRawCurrent(); };
860
861 // Retrieve only name elements
862 // returns NOTFOUND if its not there
863
873 inline json_primitive_type GetNextName() {return m_ref.GetNextName(); };
874
885
896
906 inline json_primitive_type GetNextNameInCurrentObject(){return m_ref.GetNextNameInCurrentObject(); };
907
917 inline json_primitive_type GetNextNameInCurrentArray() {return m_ref.GetNextNameInCurrentArray(); };
918
928
938
949
974 inline json_primitive_type SkipCurrentValue() {return m_ref.SkipCurrentValue(); }; // Skips over the current value
975
976 // Get/Restore parser position
986 inline void ResetPosition() {m_ref.ResetPosition(); };
987
994
1003
1067 inline json_primitive_type FindFullName(const char *name){ return m_ref.FindFullName(name); };
1068
1078 inline json_primitive_type FindFullAtName(const char *name) {return m_ref.FindFullAtName(name); };
1088 inline json_primitive_type FindElementAfterName(const char *name) {return m_ref.FindElementAfterName(name); };
1089
1099 inline json_primitive_type FindGlobalElementAfterName(const char *name) {return m_ref.FindGlobalElementAfterName(name); };
1100
1109 inline json_primitive_type FindElementAfterNameInCurrentObject(const char *name) {return m_ref.FindElementAfterNameInCurrentObject(name); };
1119 {return m_ref.FindElementAfterNameInCurrentArray(name);};
1120
1127 inline bool CurrentBool() {return m_ref.CurrentBool(); };
1128
1135 inline bool PermissiveCurrentBool() {return m_ref.PermissiveCurrentBool(); };
1136
1143 inline double CurrentNumber() {return m_ref.CurrentNumber(); };
1144
1151 inline const char *CurrentString() {return m_ref.CurrentString(); };
1152
1159 inline int CopyCurrentString(char *buf, int buflen) {return m_ref.CopyCurrentString(buf, buflen); };
1160
1167 inline int CopyCurrentString(NBString &nbs) {return m_ref.CopyCurrentString(nbs); };
1168
1174 inline const char *CurrentName() {return m_ref.CurrentName(); };
1175 inline bool CurrentNameMatches(const char *name) {return m_ref.CurrentNameMatches(name); };
1176
1185 bool FindFullNameBoolean(const char *name)
1186 {
1187 if (FindFullName(name) == TRUE_EL) return true;
1188 return false;
1189 };
1190
1200 bool FindGlobalBoolean(const char *name)
1201 {
1202 if (FindGlobalElementAfterName(name) == TRUE_EL) return true;
1203 return false;
1204 };
1205
1214 bool FindBoolean(const char *name)
1215 {
1216 if (FindElementAfterName(name) == TRUE_EL) return true;
1217 return false;
1218 };
1219
1228 bool FindBooleanInCurentObject(const char *name)
1229 {
1230 if (FindElementAfterNameInCurrentObject(name) == TRUE_EL) return true;
1231 return false;
1232 };
1233
1242 bool FindFullNamePermissiveBoolean(const char *name)
1243 {
1244 if (FindFullName(name) != NOTFOUND) return PermissiveCurrentBool();
1245 return false;
1246 };
1247
1257 bool FindGlobalPermissiveBoolean(const char *name)
1258 {
1260 return false;
1261 };
1262
1271 bool FindPermissiveBoolean(const char *name)
1272 {
1274 return false;
1275 };
1276
1286 {
1288 return false;
1289 };
1290
1291 // If item not found returns null
1299 const char *FindFullNameString(const char *name)
1300 {
1301 if (FindFullName(name) == STRING) return CurrentString();
1302 return 0;
1303 };
1304
1316 int FindAndCopyFullNameString(const char *name, char *buf, int buflen)
1317 {
1318 json_primitive_type type = FindFullName(name);
1319 if (type == STRING) return CopyCurrentString(buf, buflen);
1320 if (type == STRING_CHUNK) return CopyCurrentString(buf, buflen);
1321 return 0;
1322 };
1323
1334 int FindAndCopyFullNameString(const char *name, NBString &nbs)
1335 {
1336 json_primitive_type type = FindFullName(name);
1337 if (type == STRING) return CopyCurrentString(nbs);
1338 if (type == STRING_CHUNK) return CopyCurrentString(nbs);
1339 return 0;
1340 };
1349 const char *FindGlobalString(const char *name)
1350 {
1351 if (FindGlobalElementAfterName(name) == STRING) return CurrentString();
1352 return 0;
1353 };
1354
1355
1369 int FindAndCopyGlobalString(const char *name, char *buf, int buflen)
1370 {
1372 if (type == STRING) return CopyCurrentString(buf, buflen);
1373 if (type == STRING_CHUNK) return CopyCurrentString(buf, buflen);
1374 return 0;
1375 };
1376
1389 int FindAndCopyGlobalString(const char *name, NBString &nbs)
1390 {
1392 if (type == STRING) return CopyCurrentString(nbs);
1393 if (type == STRING_CHUNK) return CopyCurrentString(nbs);
1394 return 0;
1395 };
1396
1404 const char *FindString(const char *name)
1405 {
1406 if (FindElementAfterName(name) == STRING) return CurrentString();
1407 return 0;
1408 };
1409
1421 int FindAndCopyString(const char *name, char *buf, int buflen)
1422 {
1424 if (type == STRING) return CopyCurrentString(buf, buflen);
1425 if (type == STRING_CHUNK) return CopyCurrentString(buf, buflen);
1426 return 0;
1427 };
1428
1439 int FindAndCopyString(const char *name, NBString &nbs)
1440 {
1442 if (type == STRING) return CopyCurrentString(nbs);
1443 if (type == STRING_CHUNK) return CopyCurrentString(nbs);
1444 return 0;
1445 };
1446
1454 const char *FindStringInCurentObject(const char *name)
1455 {
1457 return 0;
1458 };
1459
1460 // if item is not found returns nan
1468 double FindFullNameNumber(const char *name)
1469 {
1470 if (FindFullName(name) == NUMBER) return CurrentNumber();
1471 return nan("quiet");
1472 };
1473
1482 double FindGlobalNumber(const char *name)
1483 {
1484 if (FindGlobalElementAfterName(name) == NUMBER) return CurrentNumber();
1485 return nan("quiet");
1486 };
1487
1495 double FindNumber(const char *name)
1496 {
1497 if (FindElementAfterName(name) == NUMBER) return CurrentNumber();
1498 return nan("quiet");
1499 };
1500
1508 double FindNumberInCurentObject(const char *name)
1509 {
1511 return nan("quiet");
1512 };
1513
1514 // If item is not found returns false
1524 bool FindGlobalObject(const char *name)
1525 {
1526 if (FindGlobalElementAfterName(name) == BEGIN_OBJECT) return true;
1527 return false;
1528 };
1529
1538 bool FindObject(const char *name)
1539 {
1540 if (FindElementAfterName(name) == BEGIN_OBJECT) return true;
1541 return false;
1542 };
1543
1552 bool FindObjectInCurentObject(const char *name)
1553 {
1554 if (FindElementAfterNameInCurrentObject(name) == BEGIN_OBJECT) return true;
1555 return false;
1556 };
1560 // Constructors
1561 // Build emty
1563 ParsedJsonDataSet(const char *pData, int len = 0, bool bBigStrings=false); // 0 len mean use strlen
1564 // Destructor
1565 virtual ~ParsedJsonDataSet(); //Needs to be virtual for derived classes....
1566
1577
1583 inline int PrintObject(bool pretty = false){return m_ref.start().PrintChildren(pretty);}
1584
1594 inline int PrintObjectToBuffer(char *buffer, int maxlen, bool pretty = false) {return m_ref.start().PrintChildrenToBuffer(buffer,maxlen,pretty);}
1595
1603 inline int PrintObjectToFd(int fd, bool pretty = false){return m_ref.start().PrintChildrenToFd(fd,pretty);};
1604
1605
1613 inline int PrintObjectToString(NBString & s, bool pretty = false)
1614 {
1615 FDCounter fdc;
1616 int len=m_ref.start().PrintChildrenToFd(fdc.GetActiveFD(),pretty);
1617 s.clear();
1618 s.Reserve(len+2);
1619 return m_ref.start().PrintChildrenToString(s,pretty);
1620 }
1621
1622
1623
1628 inline int PrintChildren(bool pretty = false) {return m_ref.PrintChildren(pretty); }
1629
1634 int PrintChildrenToFd(int fd, bool pretty = false) {return m_ref.PrintChildrenToFd(fd,pretty); }
1635
1640 int PrintChildrenToBuffer(char *buffer, int maxlen, bool pretty = false){return m_ref.PrintChildrenToBuffer(buffer,maxlen,pretty); }
1641
1649 inline int GetPrintSize(bool pretty = false){return m_ref.start().GetChildPrintSize(pretty);};
1662
1669
1675 ParsedJsonDataSet *AddMyMac(const char *name);
1676
1683 ParsedJsonDataSet *Add(const char *name, int i);
1684
1691 ParsedJsonDataSet *Add(const char *name, short i);
1692
1699 ParsedJsonDataSet *Add(const char *name, long i);
1700
1707 ParsedJsonDataSet *Add(const char *name, unsigned int i);
1708
1715 ParsedJsonDataSet *Add(const char *name, unsigned short i);
1716
1723 ParsedJsonDataSet *Add(const char *name, unsigned long i);
1724
1731 ParsedJsonDataSet *Add(const char *name, double d);
1732
1739 ParsedJsonDataSet *Add(const char *name, const char *str);
1740
1747 ParsedJsonDataSet *Add(const char *name, bool b);
1748
1755 ParsedJsonDataSet *Add(const char *name, IPADDR4 i4);
1756
1763 ParsedJsonDataSet *Add(const char *name, const IPADDR &i);
1764
1771 ParsedJsonDataSet *Add(const char *name, const MACADR &ma);
1772
1778 ParsedJsonDataSet *AddNull(const char *name);
1779
1786
1792
1799
1806
1813
1820
1827
1834
1841
1848
1855
1862
1868
1874
1880
1886
1893 bool CheckLint();
1894 NBString LastError();
1895};
1896
1905#include <fd_adapter.h>
1906class JsonLexerFDAdapter :public ParsedJsonDataSet, public fd_adapter
1907{
1908 virtual int read(char *buf, int nbytes);
1909 virtual int write(const char *buf, int nbytes);
1910 virtual int close();
1911public:
1912 JsonLexerFDAdapter() {};
1913};
1914
1915
1916#endif
1917
NetBurner Buffers API.
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:225
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
Get the type name of the JSON primitive type passed in.
Definition json_lexer.h:1907
Represents a positional reference (pointer) of a location inside a ParsedJsonDataSet object.
Definition json_lexer.h:113
int GetChildPrintSize(bool pretty=false)
Return the length of the child objects' JSON text as written with the PrintChildren* functions.
JsonRef operator()(const char *namev)
Get a JsonRef representing any entity from a parent object by key name.
Definition json_lexer.h:282
bool IsNull()
Check if the current JsonRef is a valid JSON null element.
Definition json_lexer.h:392
void DiagDump(const char *lab)
Output a verbose diagnostic report of the ParsedJsonDatSet to stdout.
int PrintChildren(bool pretty=false)
Output child objects of this JsonRef as JSON text to stdout.
JsonRef operator[](int i)
Get a JsonRef from an array by numerical index.
bool IsString()
Check if the current JsonRef is a valid JSON string element.
Definition json_lexer.h:382
bool IsObject()
Check if the current JsonRef is a valid JSON object element.
Definition json_lexer.h:376
JsonRef start()
Begin traversal: check for ref validity and reset the position.
Definition json_lexer.h:415
int PrintChildrenToFd(int fd, bool pretty=false)
Output child objects of this JsonRef as JSON text to a file descriptor.
bool IsArray()
Check if the current JsonRef is a valid JSON array element.
Definition json_lexer.h:397
void SkipArray()
Increment the position index of the ParsedJsonDataSet beyond this array.
JsonRef next() const
Traverse: check for ref validity and increment the position.
Definition json_lexer.h:427
bool IsBool()
Check if the current JsonRef is a valid JSON boolean element.
Definition json_lexer.h:387
int PrintChildrenToBuffer(char *buffer, int maxlen, bool pretty=false)
Output child objects of this JsonRef as JSON text to a buffer pointer.
bool Valid() const
Check if the current JsonRef is a valid JSON position.
Definition json_lexer.h:402
void SkipElement()
Increment the position index of the ParsedJsonDataSet beyond this element.
void ResetPosition()
Reset the position index of the ParsedJsonDataSet to the beginning.
int PrintChildrenToString(NBString &s, bool pretty=false)
Output child objects of this JsonRef as JSON text to a NBString.
bool IsNumber()
Check if the current JsonRef is a valid JSON number element.
Definition json_lexer.h:371
bool JumpPosition(int siz)
Jump to a specific position index in the ParsedJsonDataSet.
bool IncPosition()
Increment the position index of the ParsedJsonDataSet.
JsonRef name(const char *name)
Get a JsonRef representing any entity from a parent object by key name.
void SkipObject()
Increment the position index of the ParsedJsonDataSet beyond this object.
JsonRef object(const char *name)
Get a JsonRef representing an object from a parent object by key name.
Definition json_lexer.h:188
void MakeInvalid()
Definition json_lexer.h:518
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
size_t length() const
Returns the length of the string.
void shrink(int n)
Reduces the length of the string by n.
A class to create, read, and modify a JSON object.
Definition json_lexer.h:535
ParsedJsonDataSet * AddMyMac(const char *name)
Add the device MAC address to the JSON data set.
ParsedJsonDataSet * Add(const char *name, unsigned long i)
Add a name/value pair to the JSON data set where the value is a unsigned long.
ParsedJsonDataSet * Add(const char *name, unsigned short i)
Add a name/value pair to the JSON data set where the value is a unsigned short.
bool FindGlobalPermissiveBoolean(const char *name)
Find the permissive boolean value of a given element. Starts at the current position and then starts ...
Definition json_lexer.h:1257
json_primitive_type GetNextArray()
Iterates the current element of the JSON data set until it finds one of type BEGIN_ARRAY.
json_primitive_type FindElementAfterNameInCurrentArray(const char *name)
Looks for elements with the current name in the current ARRAY only. Does not search sub arrays.
Definition json_lexer.h:1118
const char * CurrentName()
Get the name of the current element.
Definition json_lexer.h:1174
json_primitive_type GetNextNumberInCurrentArray()
Get the next element of type NUMBER that exists in the current ARRAY after the current position.
ParsedJsonDataSet * Add(const char *name, const MACADR &ma)
Add a name/value pair to the JSON data set where the value is a MAC address.
json_primitive_type FindGlobalElementAfterName(const char *name)
Finds name in current object points at element after name. This only supports simple,...
Definition json_lexer.h:1099
int PrintChildrenToFd(int fd, bool pretty=false)
Output child objects of this JsonRef as JSON text to a file descriptor.
Definition json_lexer.h:1634
int FindAndCopyString(const char *name, char *buf, int buflen)
Find and copy the string value of the element with the given name If not provided a buffer or the pro...
Definition json_lexer.h:1421
ParsedJsonDataSet * AddArrayElement(const char *str)
Add a string to the current array.
double FindGlobalNumber(const char *name)
Find the number value of a given element. Starts at the current position and then starts again at the...
Definition json_lexer.h:1482
JsonRef SetParsePosition(JsonRef pos)
Sets the current parse position object for the JSON data set.
int PrintObjectToBuffer(char *buffer, int maxlen, bool pretty=false)
Prints the JSON data set to a provided buffer.
Definition json_lexer.h:1594
json_primitive_type GetNextObjectInCurrentArray()
Get the next element of type BEGIN_OBJECT that exists in the current ARRAY after the current position...
int PrintChildrenToBuffer(char *buffer, int maxlen, bool pretty=false)
Output child objects of this JsonRef as JSON text to a buffer pointer.
Definition json_lexer.h:1640
ParsedJsonDataSet * Add(const char *name, unsigned int i)
Add a name/value pair to the JSON data set where the value is an unsigned int.
JsonRef object(const char *name)
Get a JsonRef representing an object from a parent object by key name.
Definition json_lexer.h:779
double FindNumberInCurentObject(const char *name)
Find the number value of the element with the given name in the current object. Does not search sub-o...
Definition json_lexer.h:1508
json_primitive_type FindFullName(const char *name)
Find the element in the data set with the given name and move the parser to the next element....
Definition json_lexer.h:1067
json_primitive_type FindElementAfterNameInCurrentObject(const char *name)
Looks for elements with the current name in the current OBJECT only. Does not search sub objects.
Definition json_lexer.h:1109
bool FindGlobalObject(const char *name)
Find the OBJECT with the given name. Starts at the current position and then starts again at the begi...
Definition json_lexer.h:1524
json_primitive_type GetNextBoolInCurrentArray()
Get the next element of type TRUE_EL that exists in the current ARRAY after the current position.
json_primitive_type FindFullAtName(const char *name)
Find the element in the data set with the given name and move the parser to that element....
Definition json_lexer.h:1078
json_primitive_type GetNextObject()
Get the next element of type name that exists in the current OBJECT after the current position.
ParsedJsonDataSet * Add(const char *name, short i)
Add a name/value pair to the JSON data set where the value is a short.
json_primitive_type GetFirst()
Get the first element of the JSON data set.
Definition json_lexer.h:813
bool FindFullNamePermissiveBoolean(const char *name)
Find the permissive boolean value of a given element.
Definition json_lexer.h:1242
JsonRef name(const char *name)
Get a JsonRef representing any entity from a parent object by key name.
Definition json_lexer.h:768
bool FindGlobalBoolean(const char *name)
Find the boolean value of a given element. Starts at the current position and then starts again at th...
Definition json_lexer.h:1200
ParsedJsonDataSet * AddArrayElement(unsigned int i)
Add an unsigned int value to the current array.
ParsedJsonDataSet * EndObject()
Add an end to the current object.
ParsedJsonDataSet * AddNullArrayElement()
Add a null element to the current array.
ParsedJsonDataSet * Add(const char *name, const char *str)
Add a name/value pair to the JSON data set where the value is a string.
int FindAndCopyFullNameString(const char *name, NBString &nbs)
Find and copy the string value of the element with the given name in the current object....
Definition json_lexer.h:1334
bool FindFullNameBoolean(const char *name)
Find the boolean value of a given element.
Definition json_lexer.h:1185
ParsedJsonDataSet * AddArrayElement(unsigned short i)
Add an unsigned short value to the current array.
bool FindBooleanInCurentObject(const char *name)
Find the boolean value of the element within the current object. Does not search sub-objects.
Definition json_lexer.h:1228
const char * CurrentString()
Get the string value of the current element.
Definition json_lexer.h:1151
bool FindPermissiveBoolean(const char *name)
Find the permissive boolean value of the element after the element with the provided name.
Definition json_lexer.h:1271
virtual int WriteData(const unsigned char *pCopyFrom, int numBytes)
Writes the passed in data to the JSON data set.
void ResetPosition()
Resets the parser position to the beginning of the JSON data set.
Definition json_lexer.h:986
json_primitive_type GetNextStringInCurrentArray()
Get the next element of type STRING that exists in the current ARRAY after the current position.
ParsedJsonDataSet * Add(const char *name, double d)
Add a name/value pair to the JSON data set where the value is a double.
json_primitive_type GetNextNameInCurrentObject()
Get the next element of type NAME that exists in the current OBJECT after the current position.
Definition json_lexer.h:906
json_primitive_type GetCurrent()
Get the element at the current position of the JSON data set.
Definition json_lexer.h:843
ParsedJsonDataSet * AddNull(const char *name)
Add a name/value pair to the JSON data set where the value is null.
json_primitive_type SkipCurrentValue()
Skips over the current value, and get the next element. If called inside an ARRAY or OBJECT,...
Definition json_lexer.h:974
json_primitive_type GetRawCurrent()
Get the element at the current position of the JSON data set, including non-public types.
Definition json_lexer.h:859
bool FindPermissiveBooleanInCurentObject(const char *name)
Find the permissive boolean value of the element with the given name in the current object....
Definition json_lexer.h:1285
ParsedJsonDataSet * AddArrayElement(bool b)
Add a bool to the current array.
ParsedJsonDataSet * AddArrayStart(const char *name)
Add an ARRAY start to the JSON data set.
bool PermissiveCurrentBool()
Returns true if the current element a TRUE_EL primitive type, is "True", "true", or is a non-zero num...
Definition json_lexer.h:1135
int FindAndCopyString(const char *name, NBString &nbs)
Find and copy the string value of the element with the given name If not provided a buffer or the pro...
Definition json_lexer.h:1439
ParsedJsonDataSet * Add(const char *name, IPADDR4 i4)
Add a name/value pair to the JSON data set where the value is an IPv4 address.
ParsedJsonDataSet * Add(const char *name, int i)
Add a name/value pair to the JSON data set where the value is an int.
JsonRef GetParsePosition()
Gets the current parse position object for the JSON data set.
virtual int ReadFrom(int fd)
Reads in data from the specified file descriptor and parses it into the JSON data set.
ParsedJsonDataSet * AddArrayObjectStart()
Add the start of an object element to the current array.
bool FindBoolean(const char *name)
Find the boolean value of the element after the element with the given name.
Definition json_lexer.h:1214
json_primitive_type FindElementAfterName(const char *name)
Finds name in current object points at element after name. This only supports simple,...
Definition json_lexer.h:1088
int GetPrintSize(bool pretty=false)
Calculates how many characters the JSON data set would take to print.
Definition json_lexer.h:1649
int PrintChildren(bool pretty=false)
Output child objects of this JsonRef as JSON text to stdout.
Definition json_lexer.h:1628
int PrintObjectToFd(int fd, bool pretty=false)
Prints the JSON data set to a specified file descriptor.
Definition json_lexer.h:1603
bool CurrentBool()
Returns true if the current element a TRUE_EL primitive type.
Definition json_lexer.h:1127
JsonRef next()
Traverse: check for ref validity and increment the position.
Definition json_lexer.h:798
json_primitive_type GetNextNameInCurrentArray()
Get the next element of type NAME that exists in the current ARRAY after the current position.
Definition json_lexer.h:917
ParsedJsonDataSet * AddArrayElement(const IPADDR &i)
Add an IP address to the current array.
ParsedJsonDataSet * AddObjectStart(const char *name)
Use to start an object in the JSON data set.
ParsedJsonDataSet * StartBuilding()
Use to start building the JSON data set.
int FindAndCopyGlobalString(const char *name, char *buf, int buflen)
Starts at the current position and then starts again at the beginning of the data set if the element ...
Definition json_lexer.h:1369
ParsedJsonDataSet * AddArrayElementArray()
Add the start of an array element to the current array.
const char * FindGlobalString(const char *name)
Find the string value of a given element. Starts at the current position and then starts again at the...
Definition json_lexer.h:1349
JsonRef start()
Begin traversal: check for ref validity and reset the position.
Definition json_lexer.h:792
json_primitive_type GetNextName()
Iterates the current element of the JSON data set until it finds one of type NAME.
Definition json_lexer.h:873
ParsedJsonDataSet * DoneBuilding()
Add an end JSON data set and finish building.
ParsedJsonDataSet * EndArray()
Add an ARRAY end to the JSON data set.
const char * FindString(const char *name)
Find the string value of the element after the element with the given name.
Definition json_lexer.h:1404
ParsedJsonDataSet * AddArrayElement(short i)
Add a short value to the current array.
double CurrentNumber()
Get the number value of the current element.
Definition json_lexer.h:1143
int CopyCurrentString(NBString &nbs)
Copy the string value of the current element.
Definition json_lexer.h:1167
ParsedJsonDataSet * Add(const char *name, long i)
Add a name/value pair to the JSON data set where the value is a long.
int FindAndCopyFullNameString(const char *name, char *buf, int buflen)
Find and copy the string value of the element with the given name in the current object....
Definition json_lexer.h:1316
ParsedJsonDataSet * AddArrayElement(unsigned long i)
Add an unsigned long value to the current array.
int PrintObject(bool pretty=false)
Prints the JSON data set to stdout.
Definition json_lexer.h:1583
JsonRef operator()(const char *name)
Get a JsonRef representing any entity from a parent object by key name.
Definition json_lexer.h:755
void DumpState()
Outputs what's in the parse tree to stdout.
void EnableLargeStrings(bool b)
Call to allow allocation of strings larger than 1500 bytes.
Definition json_lexer.h:659
bool FindObjectInCurentObject(const char *name)
Find the OBJECT of the element with the given name in the current OBJECT. Does not search sub-objects...
Definition json_lexer.h:1552
json_primitive_type GetNext()
Get the element at the next position of the JSON data set.
Definition json_lexer.h:828
int PrintObjectToString(NBString &s, bool pretty=false)
Prints the JSON data set to a NBString object.
Definition json_lexer.h:1613
ParsedJsonDataSet * Add(const char *name, bool b)
Add a name/value pair to the JSON data set where the value is a bool.
ParsedJsonDataSet * AddArrayElement(double d)
Add a double to the current array.
ParsedJsonDataSet * AddArrayElement(long i)
Add a long value to the current array.
double FindFullNameNumber(const char *name)
Find the number value of the element with the given name in the current object.
Definition json_lexer.h:1468
ParsedJsonDataSet * AddArrayElement(int i)
Add an integer value to the current array.
bool FindObject(const char *name)
Find the OBJECT of the element after the element with the given name.
Definition json_lexer.h:1538
ParsedJsonDataSet * Add(const char *name, const IPADDR &i)
Add a name/value pair to the JSON data set where the value is an IP address.
bool CopyObject(ParsedJsonDataSet &src_set)
Copies the provided JSON data set into the current one.
int CopyCurrentString(char *buf, int buflen)
Copy the string value of the current element.
Definition json_lexer.h:1159
double FindNumber(const char *name)
Find the number value of the element after the element with the given name.
Definition json_lexer.h:1495
const char * FindStringInCurentObject(const char *name)
Find the string value of the element with the given name in the current object. Does not search sub-o...
Definition json_lexer.h:1454
const char * FindFullNameString(const char *name)
Find the string value of the element with the given name in the current object.
Definition json_lexer.h:1299
void ClearObject()
Clears all data from the object and resets it to its initial state.
int FindAndCopyGlobalString(const char *name, NBString &nbs)
Starts at the current position and then starts again at the beginning of the data set if the element ...
Definition json_lexer.h:1389
JsonRef operator[](int i)
Get a JsonRef from an array by numerical index.
Definition json_lexer.h:742
Base class for web client response buffers.
Definition web_buffers.h:20
json_primitive_type
The following types define the basic building blocks that make up a JSON data set....
Definition json_lexer.h:60
void CharOutputFn(const char *chars, int len, void *blob)
Helper function typedef for print functions.
Definition json_lexer.h:92
@ BEGIN_ARRAY
[ - Signals the start of an array.
Definition json_lexer.h:62
@ NUMBER
An element with a number value.
Definition json_lexer.h:69
@ EOF_EL
Last token in the data set.
Definition json_lexer.h:77
@ TRUE_EL
An element with the value true.
Definition json_lexer.h:71
@ STRING_CHUNK
Not quiet an error, but we got a sting but it was too big to fit in the storage scheme (1500 bytes).
Definition json_lexer.h:74
@ NOTFOUND
Return value when we don't find what we are looking for.
Definition json_lexer.h:76
@ UNDEFINED
Not a defined primitive type. This indicates an error somewhere.
Definition json_lexer.h:61
@ NAME
"xxx": - Signals the name of a name/value pair.
Definition json_lexer.h:66
@ END_OBJECT
} - Signals the end of an object.
Definition json_lexer.h:65
@ NULL_EL
An element with the null value.
Definition json_lexer.h:72
@ ALLOC_STRING
We allocated a large string.
Definition json_lexer.h:75
@ BEGIN_OBJECT
{ - Signals the start of an object.
Definition json_lexer.h:63
@ END_ARRAY
] - Signals the end of an array.
Definition json_lexer.h:64
@ STRING_TOO_BIG
Error, we got a sting but it was too big to fit in the storage scheme (1500 bytes).
Definition json_lexer.h:73
@ VALUE_SEPERATOR
, - Signals the separation between to arrays, objects, or values.
Definition json_lexer.h:68
@ STRING
"xxx" - An element with a string value.
Definition json_lexer.h:67
@ FALSE_EL
An element with the value false.
Definition json_lexer.h:70
NetBurner String Class.
NetBurner IPADDR4 Class. See the IPADDR4 Class page for complete documentation.
A list of large strings that are created with malloc.
Definition json_lexer.h:99
JsonAllocString * pNext
A pointer to the next string.
Definition json_lexer.h:100
char data[]
The current string data.
Definition json_lexer.h:101
Main buffer structure for network and serial communication.
Definition buffers.h:90