JSONOptions.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. #ifndef JSON_OPTIONS_H
  2. #define JSON_OPTIONS_H
  3. /**
  4. * This file holds all of the compiling options for easy access and so
  5. * that you don't have to remember them, or look them up all the time
  6. */
  7. /*
  8. * JSON_LIBRARY must be declared if libjson is compiled as a static or dynamic
  9. * library. This exposes a C-style interface, but none of the inner workings of libjson
  10. */
  11. #define JSON_LIBRARY
  12. /*
  13. * JSON_STRICT removes all of libjson's extensions. Meaning no comments, no special numbers
  14. */
  15. //#define JSON_STRICT
  16. /*
  17. * JSON_DEBUG is used to perform extra error checking. Because libjson usually
  18. * does on the fly parsing, validation is impossible, so this option will allow
  19. * you to register an error callback so that you can record what is going wrong
  20. * before the library crashes. This option does not protect from these errors,
  21. * it simply tells you about them, which is nice for debugging, but not preferable
  22. * for release candidates
  23. */
  24. //#define JSON_DEBUG
  25. /*
  26. * JSON_ISO_STRICT turns off all code that uses non-standard C++. This removes all
  27. * references to long long and long double as well as a few others
  28. */
  29. //#define JSON_ISO_STRICT
  30. /*
  31. * JSON_SAFE performs similarly to JSON_DEBUG, except this option does protect
  32. * from the errors that it encounters. This option is recommended for those who
  33. * feel it's possible for their program to encounter invalid json.
  34. */
  35. #define JSON_SAFE
  36. /*
  37. * JSON_STDERROR routes error messages to cerr instead of a callback, this
  38. * option hides the callback registering function. This will usually display
  39. * messages in the console
  40. */
  41. //#define JSON_STDERROR
  42. /*
  43. * JSON_PREPARSE causes all parsing to be done immediately. By default, libjson
  44. * parses nodes on the fly as they are needed, this makes parsing much faster if
  45. * your program gets a lot of information that it doesn't need. An example of
  46. * this would be a client application communicating with a server if the server
  47. * returns things like last modified date and other things that you don't use.
  48. */
  49. //#define JSON_PREPARSE
  50. /*
  51. * JSON_LESS_MEMORY will force libjson to let go of memory as quickly as it can
  52. * this is recommended for software that has to run on less than optimal machines.
  53. * It will cut libjson's memory usage by about 20%, but also run slightly slower.
  54. * It's recommended that you also compile using the -Os option, as this will also
  55. * reduce the size of the library
  56. */
  57. //#define JSON_LESS_MEMORY
  58. /*
  59. * JSON_UNICODE tells libjson to use wstrings instead of regular strings, this
  60. * means that libjson supports the full array of unicode characters, but also takes
  61. * much more memory and processing power.
  62. */
  63. //#define JSON_UNICODE
  64. /*
  65. * JSON_REF_COUNT causes libjson to reference count JSONNodes, which makes copying
  66. * and passing them around much faster. It is recommended that this stay on for
  67. * most uses
  68. */
  69. #define JSON_REF_COUNT
  70. /*
  71. * JSON_BINARY is used to support binary, which is base64 encoded and decoded by libjson,
  72. * if this option is not turned off, no base64 support is included
  73. */
  74. #define JSON_BINARY
  75. /*
  76. * JSON_EXPOSE_BASE64 is used to turn on the functionality of libjson's base64 encoding
  77. * and decoding. This may be useful if you want to obfuscate your json, or send binary data over
  78. * a network
  79. */
  80. #define JSON_EXPOSE_BASE64
  81. /*
  82. * JSON_ITERATORS turns on all of libjson's iterating functionality. This would usually
  83. * only be turned off while compiling for use with C
  84. */
  85. #define JSON_ITERATORS
  86. /*
  87. * JSON_STREAM turns on libjson's streaming functionality. This allows you to give parts of
  88. * your json into a stream, which will automatically hit a callback when full nodes are
  89. * completed
  90. */
  91. #define JSON_STREAM
  92. /*
  93. * JSON_MEMORY_CALLBACKS exposes functions to register callbacks for allocating, resizing,
  94. * and freeing memory. Because libjson is designed for customizability, it is feasible
  95. * that some users would like to further add speed by having the library utilize a memory
  96. * pool. With this option turned on, the default behavior is still done internally unless
  97. * a callback is registered. So you can have this option on and not use it.
  98. */
  99. //#define JSON_MEMORY_CALLBACKS
  100. /*
  101. * JSON_MEMORY_MANAGE is used to create functionality to automatically track and clean
  102. * up memory that has been allocated by the user. This includes strings, binary data, and
  103. * nodes. It also exposes bulk delete functions.
  104. */
  105. //#define JSON_MEMORY_MANAGE
  106. /*
  107. * JSON_MEMORY_POOL Turns on libjson's iteraction with mempool++. It is more efficient that simply
  108. * connecting mempool++ to the callbacks because it integrates things internally and uses a number
  109. * of memory pools. This value tells libjson how large of a memory pool to start out with. 500KB
  110. * should suffice for most cases. libjson will distribute that within the pool for the best
  111. * performance depending on other settings.
  112. */
  113. //#define JSON_MEMORY_POOL 524288
  114. /*
  115. * JSON_MUTEX_CALLBACKS exposes functions to register callbacks to lock and unlock
  116. * mutexs and functions to lock and unlock JSONNodes and all of it's children. This
  117. * does not prevent other threads from accessing the node, but will prevent them from
  118. * locking it. It is much easier for the end programmer to allow libjson to manage
  119. * your mutexs because of reference counting and manipulating trees, libjson automatically
  120. * tracks mutex controls for you, so you only ever lock what you need to
  121. */
  122. //#define JSON_MUTEX_CALLBACKS
  123. /*
  124. * JSON_MUTEX_MANAGE lets you set mutexes and forget them, libjson will not only keep
  125. * track of the mutex, but also keep a count of how many nodes are using it, and delete
  126. * it when there are no more references
  127. */
  128. //#define JSON_MUTEX_MANAGE
  129. /*
  130. * JSON_NO_C_CONSTS removes consts from the C interface. It still acts the same way, but
  131. * this may be useful for using the header with languages or variants that don't have const
  132. */
  133. //#define JSON_NO_C_CONSTS
  134. /*
  135. * JSON_OCTAL allows libjson to use octal values in numbers.
  136. */
  137. //#define JSON_OCTAL
  138. /*
  139. * JSON_WRITE_PRIORITY turns on libjson's writing capabilties. Without this libjson can only
  140. * read and parse json, this allows it to write back out. Changing the value of the writer
  141. * changes how libjson compiles, and how fast it will go when writing
  142. */
  143. #define JSON_WRITE_PRIORITY MED
  144. /*
  145. * JSON_READ_PRIORITY turns on libjson's reading capabilties. Changing the value of the reader
  146. * changes how libjson compiles, and how fast it will go when writing
  147. */
  148. #define JSON_READ_PRIORITY HIGH
  149. /*
  150. * JSON_NEWLINE affects how libjson writes. If this option is turned on, libjson
  151. * will use whatever it's defined as for the newline signifier, otherwise, it will use
  152. * standard unix \n.
  153. */
  154. //#define JSON_NEWLINE "\r\n" //\r\n is standard for most windows and dos programs
  155. /*
  156. * JSON_INDENT affects how libjson writes. If this option is turned on, libjson
  157. * will use \t to indent formatted json, otherwise it will use the number of characters
  158. * that you specify. If this is not turned on, then it will use the tab (\t) character
  159. */
  160. #define JSON_INDENT " "
  161. /*
  162. * JSON_ESCAPE_WRITES tells the libjson engine to escape special characters when it writes
  163. * out. If this option is turned off, the json it outputs may not adhere to JSON standards
  164. */
  165. //#define JSON_ESCAPE_WRITES
  166. /*
  167. * JSON_COMMENTS tells libjson to store and write comments. libjson always supports
  168. * parsing json that has comments in it as it simply ignores them, but with this option
  169. * it keeps the comments and allows you to insert further comments
  170. */
  171. #define JSON_COMMENTS
  172. /*
  173. * JSON_WRITE_BASH_COMMENTS will cause libjson to write all comments in bash (#) style
  174. * if this option is not turned on, then it will use C-style comments. Bash comments are
  175. * all single line
  176. */
  177. //#define JSON_WRITE_BASH_COMMENTS
  178. /*
  179. * JSON_WRITE_SINGLE_LINE_COMMENTS will cause libjson to write all comments in using //
  180. * notation, or (#) if that option is on. Some parsers do not support multiline C comments
  181. * although, this option is not needed for bash comments, as they are all single line anyway
  182. */
  183. //#define JSON_WRITE_SINGLE_LINE_COMMENTS
  184. /*
  185. * JSON_ARRAY_SIZE_ON_ON_LINE allows you to put small arrays of primitives all on one line
  186. * in a write_formatted. This is common for tuples, like coordinates. If must be defined
  187. * as an integer
  188. */
  189. #define JSON_ARRAY_SIZE_ON_ONE_LINE 16
  190. /*
  191. * JSON_VALIDATE turns on validation features of libjson.
  192. */
  193. #define JSON_VALIDATE
  194. /*
  195. * JSON_CASE_INSENSITIVE_FUNCTIONS turns on funtions for finding child nodes in a case-
  196. * insenititve way
  197. */
  198. #define JSON_CASE_INSENSITIVE_FUNCTIONS
  199. /*
  200. * JSON_INDEX_TYPE allows you th change the size type for the children functions. If this
  201. * option is not used then unsigned int is used. This option is useful for cutting down
  202. * on memory, or using huge numbers of child nodes (over 4 billion)
  203. */
  204. //#define JSON_INDEX_TYPE unsigned int
  205. /*
  206. * JSON_BOOL_TYPE lets you change the bool type for the C interface. Because before C99 there
  207. * was no bool, and even then it's just a typedef, you may want to use something else. If this
  208. * is not defined, it will revert to int
  209. */
  210. //#define JSON_BOOL_TYPE char
  211. /*
  212. * JSON_INT_TYPE lets you change the int type for as_int. If you ommit this option, the default
  213. * long will be used
  214. */
  215. //#define JSON_INT_TYPE long
  216. /*
  217. * JSON_NUMBER_TYPE lets you change the number type for as_float as well as the internal storage for the
  218. * number. If you omit this option, the default double will be used for most cases and float for JSON_LESS_MEMORY
  219. */
  220. //#define JSON_NUMBER_TYPE double
  221. /*
  222. * JSON_STRING_HEADER allows you to change the type of string that libjson uses both for the
  223. * interface and internally. It must implement most of the STL string interface, but not all
  224. * of it. Things like wxString or QString should wourk without much trouble
  225. */
  226. //#define JSON_STRING_HEADER "../TestSuite/StringTest.h"
  227. /*
  228. * JSON_UNIT_TEST is used to maintain and debug the libjson. It makes all private
  229. * members and functions public so that tests can do checks of the inner workings
  230. * of libjson. This should not be turned on by end users.
  231. */
  232. //#define JSON_UNIT_TEST
  233. /*
  234. * JSON_NO_EXCEPTIONS turns off any exception throwing by the library. It may still use exceptions
  235. * internally, but the interface will never throw anything.
  236. */
  237. //#define JSON_NO_EXCEPTIONS
  238. /*
  239. * JSON_DEPRECATED_FUNCTIONS turns on functions that have been deprecated, this is for backwards
  240. * compatibility between major releases. It is highly recommended that you move your functions
  241. * over to the new equivalents
  242. */
  243. //#define JSON_DEPRECATED_FUNCTIONS
  244. /*
  245. * JSON_CASTABLE allows you to call as_bool on a number and have it do the 0 or not 0 check,
  246. * it also allows you to ask for a string from a number, or boolean, and have it return the right thing.
  247. * Without this option, those types of requests are undefined. It also exposes the as_array, as_node, and cast
  248. * functions
  249. */
  250. #define JSON_CASTABLE
  251. /*
  252. * JSON_SECURITY_MAX_NEST_LEVEL is a security measure added to make prevent against DoS attacks
  253. * This only affects validation, as if you are worried about security attacks, then you are
  254. * most certainly validating json before sending it to be parsed. This option allows you to limitl how many
  255. * levels deep a JSON Node can go. 128 is a good depth to start with
  256. */
  257. #define JSON_SECURITY_MAX_NEST_LEVEL 128
  258. /*
  259. * JSON_SECURITY_MAX_STRING_LENGTH is another security measure, preventing DoS attacks with very long
  260. * strings of JSON. 32MB is the default value for this, this allows large images to be embedded
  261. */
  262. #define JSON_SECURITY_MAX_STRING_LENGTH 33554432
  263. /*
  264. * JSON_SECURITY_MAX_STREAM_OBJECTS is a security measure for streams. It prevents DoS attacks with
  265. * large number of objects hitting the stream all at once. 128 is a lot of objects, but not out of
  266. * the question for high speed systems.
  267. */
  268. #define JSON_SECURITY_MAX_STREAM_OBJECTS 128
  269. #endif