Nyx Node
Loading...
Searching...
No Matches
nyx_node.h
1/* NyxNode
2 * Author: Jérôme ODIER <jerome.odier@lpsc.in2p3.fr>
3 * SPDX-License-Identifier: GPL-2.0-only (Mongoose backend) or GPL-3.0+
4 */
5
6/*--------------------------------------------------------------------------------------------------------------------*/
7
8#ifndef NYX_NODE_H
9#define NYX_NODE_H
10
11/*--------------------------------------------------------------------------------------------------------------------*/
12
13#include <stddef.h>
14#include <stdint.h>
15#include <stdbool.h>
16
17/*--------------------------------------------------------------------------------------------------------------------*/
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/*--------------------------------------------------------------------------------------------------------------------*/
24
25#ifndef ARDUINO
26# pragma clang diagnostic push
27# pragma ide diagnostic ignored "OCUnusedMacroInspection"
28# pragma ide diagnostic ignored "UnreachableCallsOfFunction"
29#endif
30
31/*--------------------------------------------------------------------------------------------------------------------*/
32
33double nan(const char *tag);
34
35/*--------------------------------------------------------------------------------------------------------------------*/
36
37#define __NOTNULL__ \
38 /* do nothing */
39
40#define __NULLABLE__ \
41 /* do nothing */
42
43#define __ZEROABLE__ \
44 /* do nothing */
45
46#define __UNUSED__ \
47 __attribute__((unused))
48
49#define __INLINE__ \
50 __attribute__((always_inline)) static inline
51
52/*--------------------------------------------------------------------------------------------------------------------*/
53
54typedef /*-*/ void *buff_t;
55typedef const void *BUFF_t;
56
57typedef /*-*/ char *str_t;
58typedef const char *STR_t;
59
60/*--------------------------------------------------------------------------------------------------------------------*/
61/* MEMORY */
62/*--------------------------------------------------------------------------------------------------------------------*/
67/*--------------------------------------------------------------------------------------------------------------------*/
68
72
74
75/*--------------------------------------------------------------------------------------------------------------------*/
76
80
82
83/*--------------------------------------------------------------------------------------------------------------------*/
84
88
89__ZEROABLE__ size_t nyx_memory_free(
90 __NULLABLE__ buff_t buff
91);
92
93/*--------------------------------------------------------------------------------------------------------------------*/
94
98
99__NULLABLE__ buff_t nyx_memory_alloc(
100 __ZEROABLE__ size_t size
101);
102
103/*--------------------------------------------------------------------------------------------------------------------*/
104
108
109__NULLABLE__ buff_t nyx_memory_realloc(
110 __NULLABLE__ buff_t buff,
111 __ZEROABLE__ size_t size
112);
113
114/*--------------------------------------------------------------------------------------------------------------------*/
115/* LOGGER */
116/*--------------------------------------------------------------------------------------------------------------------*/
122/*--------------------------------------------------------------------------------------------------------------------*/
123
127
128typedef enum nyx_log_level_e
129{
130 NYX_LOG_LEVEL_NONE = 0,
131 NYX_LOG_LEVEL_FATAL = 1,
132 NYX_LOG_LEVEL_ERROR = 2,
133 NYX_LOG_LEVEL_INFO = 3,
134 NYX_LOG_LEVEL_DEBUG = 4,
135 NYX_LOG_LEVEL_VERBOSE = 5,
136
138
139/*--------------------------------------------------------------------------------------------------------------------*/
140
146
148 nyx_log_level_t level
149);
150
151/*--------------------------------------------------------------------------------------------------------------------*/
152
156
157void nyx_log(
158 nyx_log_level_t level,
159 STR_t file,
160 STR_t func,
161 int line,
162 STR_t fmt,
163 ...
164);
165
166/*--------------------------------------------------------------------------------------------------------------------*/
167
174
175#define NYX_LOG_FATAL(fmt, ...) \
176 do { nyx_log(NYX_LOG_LEVEL_FATAL, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(1)
177
184
185#define NYX_LOG_ERROR(fmt, ...) \
186 do { nyx_log(NYX_LOG_LEVEL_ERROR, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
187
194
195#define NYX_LOG_INFO(fmt, ...) \
196 do { nyx_log(NYX_LOG_LEVEL_INFO, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
197
204
205#define NYX_LOG_DEBUG(fmt, ...) \
206 do { nyx_log(NYX_LOG_LEVEL_DEBUG, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
207
214
215#define NYX_LOG_VERBOSE(fmt, ...) \
216 do { nyx_log(NYX_LOG_LEVEL_VERBOSE, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
217
218/*--------------------------------------------------------------------------------------------------------------------*/
219/* UTILITIES */
220/*--------------------------------------------------------------------------------------------------------------------*/
226/*--------------------------------------------------------------------------------------------------------------------*/
227
236
237uint32_t nyx_hash32(
238 __ZEROABLE__ size_t size,
239 __NULLABLE__ BUFF_t buff,
240 uint32_t seed
241);
242
243/*--------------------------------------------------------------------------------------------------------------------*/
244
253
255 uint8_t result_mac[6],
256 uint8_t mac0,
257 uint8_t mac1,
258 STR_t node_id
259);
260
261/*--------------------------------------------------------------------------------------------------------------------*/
262
271
272__NULLABLE__ str_t nyx_base64_encode(
273 __NULLABLE__ size_t *result_len,
274 __ZEROABLE__ size_t size,
275 __NULLABLE__ BUFF_t buff
276);
277
278/*--------------------------------------------------------------------------------------------------------------------*/
279
288
289__NULLABLE__ buff_t nyx_base64_decode(
290 __NULLABLE__ size_t *result_size,
291 __ZEROABLE__ size_t len,
292 __NULLABLE__ STR_t str
293);
294
295/*--------------------------------------------------------------------------------------------------------------------*/
296
305
306__NULLABLE__ buff_t nyx_zlib_deflate(
307 __NULLABLE__ size_t *result_buff,
308 __ZEROABLE__ size_t size,
309 __NULLABLE__ BUFF_t buff
310);
311
312/*--------------------------------------------------------------------------------------------------------------------*/
313
322
323__NULLABLE__ buff_t nyx_zlib_inflate(
324 __NOTNULL__ size_t *result_size,
325 __ZEROABLE__ size_t size,
326 __NULLABLE__ BUFF_t buff
327);
328
329/*--------------------------------------------------------------------------------------------------------------------*/
330
339
340__NULLABLE__ str_t nyx_zlib_base64_deflate(
341 __NULLABLE__ size_t *result_len,
342 __ZEROABLE__ size_t size,
343 __NULLABLE__ BUFF_t buff
344);
345
346/*--------------------------------------------------------------------------------------------------------------------*/
347
356
357__NULLABLE__ buff_t nyx_zlib_base64_inflate(
358 __NOTNULL__ size_t *result_size,
359 __ZEROABLE__ size_t len,
360 __NULLABLE__ STR_t str
361);
362
363/*--------------------------------------------------------------------------------------------------------------------*/
364/* OBJECT */
365/*--------------------------------------------------------------------------------------------------------------------*/
371/*--------------------------------------------------------------------------------------------------------------------*/
372
373#define NYX_OBJECT_MAGIC 0x65656565U
374
375/*--------------------------------------------------------------------------------------------------------------------*/
376
377#define NYX_FLAGS_DISABLED ((uint64_t) 0x0000000000000001U)
378/* 0b0000000000000000000000000000000_0000000000000000000000000000000_01 */
379
380#define NYX_FLAGS_BLOB_MASK ((uint64_t) 0x00000001FFFFFFFCU)
381/* 0b0000000000000000000000000000000_1111111111111111111111111111111_00 */
382
383#define NYX_FLAGS_STREAM_MASK ((uint64_t) 0xFFFFFFFE00000000U)
384/* 0b1111111111111111111111111111111_0000000000000000000000000000000_00 */
385
386/*--------------------------------------------------------------------------------------------------------------------*/
387
391
402
403/*--------------------------------------------------------------------------------------------------------------------*/
404
408
409typedef struct nyx_object_s
410{
411 uint32_t magic;
412 uint64_t flags;
413
415
416 __NULLABLE__ struct nyx_node_s *node;
417
418 __NULLABLE__ struct nyx_object_s *parent;
419
420 __NULLABLE__ void (* in_callback)(
421 struct nyx_object_s *object,
422 bool modified
423 );
424
425 __NULLABLE__ void (* out_callback)(
426 struct nyx_object_s *object,
427 bool modified
428 );
429
430 __NULLABLE__ void *ctx;
431
433
434/*--------------------------------------------------------------------------------------------------------------------*/
435
444
446 __ZEROABLE__ size_t size,
447 __NULLABLE__ BUFF_t buff
448);
449
457
459 __NULLABLE__ STR_t text
460);
461
462/*--------------------------------------------------------------------------------------------------------------------*/
463
470
472 __NULLABLE__ nyx_object_t *object
473);
474
475/*--------------------------------------------------------------------------------------------------------------------*/
476
485
487 __NULLABLE__ const nyx_object_t *object1,
488 __NULLABLE__ const nyx_object_t *object2
489);
490
491/*--------------------------------------------------------------------------------------------------------------------*/
492
500
502 __NULLABLE__ const nyx_object_t *object
503);
504
505/*--------------------------------------------------------------------------------------------------------------------*/
506
514
516 __NULLABLE__ const nyx_object_t *object
517);
518
519/*--------------------------------------------------------------------------------------------------------------------*/
520/* NULL */
521/*--------------------------------------------------------------------------------------------------------------------*/
527/*--------------------------------------------------------------------------------------------------------------------*/
528
532
533typedef struct
534{
535 nyx_object_t base;
536
537} nyx_null_t;
538
539/*--------------------------------------------------------------------------------------------------------------------*/
540
547
549
556
558 /*-*/ nyx_null_t *object
559);
560
568
570 const nyx_null_t *object
571);
572
573/*--------------------------------------------------------------------------------------------------------------------*/
574/* NUMBER */
575/*--------------------------------------------------------------------------------------------------------------------*/
581/*--------------------------------------------------------------------------------------------------------------------*/
582
586
587typedef struct
588{
589 nyx_object_t base;
590
591 double value;
592
594
595/*--------------------------------------------------------------------------------------------------------------------*/
596
603
605
606/*--------------------------------------------------------------------------------------------------------------------*/
607
614
616 /*-*/ nyx_number_t *object
617);
618
619/*--------------------------------------------------------------------------------------------------------------------*/
620
628
630 const nyx_number_t *object
631);
632
633/*--------------------------------------------------------------------------------------------------------------------*/
634
638
639bool nyx_number_set_alt(
640 /*-*/ nyx_number_t *object,
641 double value,
642 bool notify
643);
644
653
654__INLINE__ bool nyx_number_set(nyx_number_t *object, double value)
655{
656 return nyx_number_set_alt(object, value, true);
657}
658
659/*--------------------------------------------------------------------------------------------------------------------*/
660
668
670 const nyx_number_t *object
671);
672
673/*--------------------------------------------------------------------------------------------------------------------*/
674
682
684{
685 nyx_number_t *result = nyx_number_new();
686
687 nyx_number_set(result, value);
688
689 return result;
690}
691
692/*--------------------------------------------------------------------------------------------------------------------*/
693/* BOOLEAN */
694/*--------------------------------------------------------------------------------------------------------------------*/
700/*--------------------------------------------------------------------------------------------------------------------*/
701
705
706typedef struct
707{
708 nyx_object_t base;
709
710 bool value;
711
713
714/*--------------------------------------------------------------------------------------------------------------------*/
715
722
724
725/*--------------------------------------------------------------------------------------------------------------------*/
726
733
735 /*-*/ nyx_boolean_t *object
736);
737
738/*--------------------------------------------------------------------------------------------------------------------*/
739
747
749 const nyx_boolean_t *object
750);
751
752/*--------------------------------------------------------------------------------------------------------------------*/
753
757
758bool nyx_boolean_set_alt(
759 /*-*/ nyx_boolean_t *object,
760 bool value,
761 bool notify
762);
763
772
773__INLINE__ bool nyx_boolean_set(nyx_boolean_t *object, bool value)
774{
775 return nyx_boolean_set_alt(object, value, true);
776}
777
778/*--------------------------------------------------------------------------------------------------------------------*/
779
787
789 const nyx_boolean_t *object
790);
791
792/*--------------------------------------------------------------------------------------------------------------------*/
793
801
803{
804 nyx_boolean_t *result = nyx_boolean_new();
805
806 nyx_boolean_set(result, value);
807
808 return result;
809}
810
811/*--------------------------------------------------------------------------------------------------------------------*/
812/* STRING */
813/*--------------------------------------------------------------------------------------------------------------------*/
819/*--------------------------------------------------------------------------------------------------------------------*/
820
824
825typedef struct
826{
827 nyx_object_t base;
828
829 size_t raw_size;
830 size_t length;
831 str_t value;
832
833 bool dyn;
834
836
837/*--------------------------------------------------------------------------------------------------------------------*/
838
845
847
848/*--------------------------------------------------------------------------------------------------------------------*/
849
856
858 /*-*/ nyx_string_t *object
859);
860
861/*--------------------------------------------------------------------------------------------------------------------*/
862
870
872 const nyx_string_t *object
873);
874
875/*--------------------------------------------------------------------------------------------------------------------*/
876
880
881void nyx_string_get_buff(
882 const nyx_string_t *object,
883 __NULLABLE__ size_t *result_size,
884 __NULLABLE__ buff_t *result_buff,
885 bool base64_decode,
886 bool compress
887);
888
889/*--------------------------------------------------------------------------------------------------------------------*/
890
894
895bool nyx_string_set_dup_alt(
896 /*-*/ nyx_string_t *object,
897 STR_t value,
898 bool notify
899);
900
909
910__INLINE__ bool nyx_string_set_dup(nyx_string_t *object, STR_t value)
911{
912 return nyx_string_set_dup_alt(object, value, true);
913}
914
915/*--------------------------------------------------------------------------------------------------------------------*/
916
920
921bool nyx_string_set_ref_alt(
922 /*-*/ nyx_string_t *object,
923 STR_t value,
924 bool notify
925);
926
935
936__INLINE__ bool nyx_string_set_ref(nyx_string_t *object, STR_t value)
937{
938 return nyx_string_set_ref_alt(object, value, true);
939}
940
941/*--------------------------------------------------------------------------------------------------------------------*/
942
946
947bool nyx_string_set_buff_alt(
948 /*-*/ nyx_string_t *object,
949 __ZEROABLE__ size_t size,
950 __NULLABLE__ BUFF_t buff,
951 bool base64_encode,
952 bool compress,
953 bool notify
954);
955
967
968__INLINE__ bool nyx_string_set_buff(nyx_string_t *object, size_t size, BUFF_t buff, bool base64_encode, bool compress)
969{
970 return nyx_string_set_buff_alt(object, size, buff, base64_encode, compress, true);
971}
972
973/*--------------------------------------------------------------------------------------------------------------------*/
974
982
984 const nyx_string_t *object
985);
986
987/*--------------------------------------------------------------------------------------------------------------------*/
988
996
998 const nyx_string_t *object
999);
1000
1001/*--------------------------------------------------------------------------------------------------------------------*/
1002
1010
1012 const nyx_string_t *object
1013);
1014
1015/*--------------------------------------------------------------------------------------------------------------------*/
1016
1024
1026 const nyx_string_t *object
1027);
1028
1029/*--------------------------------------------------------------------------------------------------------------------*/
1030
1038
1040{
1041 nyx_string_t *result = nyx_string_new();
1042
1043 nyx_string_set_dup(result, value);
1044
1045 return result;
1046}
1047
1048/*--------------------------------------------------------------------------------------------------------------------*/
1049
1057
1059{
1060 nyx_string_t *result = nyx_string_new();
1061
1062 nyx_string_set_ref(result, value);
1063
1064 return result;
1065}
1066
1067/*--------------------------------------------------------------------------------------------------------------------*/
1068
1079
1080__INLINE__ nyx_string_t *nyx_string_from_buff(size_t size, BUFF_t buff, bool base64_encode, bool compress)
1081{
1082 nyx_string_t *result = nyx_string_new();
1083
1084 nyx_string_set_buff(result, size, buff, base64_encode, compress);
1085
1086 return result;
1087}
1088
1089/*--------------------------------------------------------------------------------------------------------------------*/
1090
1094
1095#define nyx_string_set nyx_string_set_dup
1096
1100
1101#define nyx_string_from nyx_string_from_dup
1102
1103/*--------------------------------------------------------------------------------------------------------------------*/
1104/* DICT */
1105/*--------------------------------------------------------------------------------------------------------------------*/
1111/*--------------------------------------------------------------------------------------------------------------------*/
1112
1116
1117typedef struct
1118{
1119 nyx_object_t base;
1120
1121 struct nyx_dict_node_s *head;
1122 struct nyx_dict_node_s *tail;
1123
1124} nyx_dict_t;
1125
1126/*--------------------------------------------------------------------------------------------------------------------*/
1127
1128typedef struct
1129{
1130 int idx;
1131
1133
1134 struct nyx_dict_node_s *head;
1135
1137
1138/*--------------------------------------------------------------------------------------------------------------------*/
1139
1140#define NYX_DICT_ITER(object) \
1141 ((nyx_dict_iter_t) {.idx = 0, .type = ((nyx_dict_t *) (object))->base.type, .head = ((nyx_dict_t *) (object))->head})
1142
1143/*--------------------------------------------------------------------------------------------------------------------*/
1144
1151
1153
1154/*--------------------------------------------------------------------------------------------------------------------*/
1155
1162
1164 /*-*/ nyx_dict_t *object
1165);
1166
1167/*--------------------------------------------------------------------------------------------------------------------*/
1168
1175
1177 /*-*/ nyx_dict_t *object
1178);
1179
1180/*--------------------------------------------------------------------------------------------------------------------*/
1181
1189
1191 /*-*/ nyx_dict_t *object,
1192 STR_t key
1193);
1194
1195/*--------------------------------------------------------------------------------------------------------------------*/
1196
1206
1208 nyx_dict_iter_t *iter,
1209 STR_t *key,
1210 nyx_object_t **object
1211);
1212
1213/*--------------------------------------------------------------------------------------------------------------------*/
1214
1223
1224nyx_object_t *nyx_dict_get(
1225 const nyx_dict_t *object,
1226 STR_t key
1227);
1228
1229/*--------------------------------------------------------------------------------------------------------------------*/
1230
1234
1235bool nyx_dict_set_alt(
1236 /*-*/ nyx_dict_t *object,
1237 STR_t key,
1238 buff_t value,
1239 bool notify
1240);
1241
1251
1252__INLINE__ bool nyx_dict_set(nyx_dict_t *object, STR_t key, buff_t value)
1253{
1254 return nyx_dict_set_alt(object, key, value, true);
1255}
1256
1257/*--------------------------------------------------------------------------------------------------------------------*/
1258
1266
1268 const nyx_dict_t *object
1269);
1270
1271/*--------------------------------------------------------------------------------------------------------------------*/
1272
1280
1282 const nyx_dict_t *object
1283);
1284
1285/*--------------------------------------------------------------------------------------------------------------------*/
1286
1295
1296__INLINE__ double nyx_dict_get_number(const nyx_dict_t *object, STR_t key)
1297{
1298 nyx_object_t *number = nyx_dict_get(object, key);
1299
1300 return (number != NULL && number->type == NYX_TYPE_NUMBER) ? nyx_number_get((nyx_number_t *) number)
1301 : nan("1")
1302 ;
1303}
1304
1305/*--------------------------------------------------------------------------------------------------------------------*/
1306
1315
1316__INLINE__ STR_t nyx_dict_get_string(const nyx_dict_t *object, STR_t key)
1317{
1318 nyx_object_t *string = nyx_dict_get(object, key);
1319
1320 return (string != NULL && string->type == NYX_TYPE_STRING) ? nyx_string_get((nyx_string_t *) string)
1321 : NULL
1322 ;
1323}
1324
1325/*--------------------------------------------------------------------------------------------------------------------*/
1326/* LIST */
1327/*--------------------------------------------------------------------------------------------------------------------*/
1333/*--------------------------------------------------------------------------------------------------------------------*/
1334
1338
1339typedef struct
1340{
1341 nyx_object_t base;
1342
1343 struct nyx_list_node_s *head;
1344 struct nyx_list_node_s *tail;
1345
1346} nyx_list_t;
1347
1348/*--------------------------------------------------------------------------------------------------------------------*/
1349
1350typedef struct
1351{
1352 int idx;
1353
1355
1356 struct nyx_list_node_s *head;
1357
1359
1360/*--------------------------------------------------------------------------------------------------------------------*/
1361
1362#define NYX_LIST_ITER(object) \
1363 ((nyx_list_iter_t) {.idx = 0, .type = ((nyx_list_t *) (object))->base.type, .head = ((nyx_list_t *) (object))->head})
1364
1365/*--------------------------------------------------------------------------------------------------------------------*/
1366
1373
1375
1376/*--------------------------------------------------------------------------------------------------------------------*/
1377
1384
1386 /*-*/ nyx_list_t *object
1387);
1388
1389/*--------------------------------------------------------------------------------------------------------------------*/
1390
1397
1399 /*-*/ nyx_list_t *object
1400);
1401
1402/*--------------------------------------------------------------------------------------------------------------------*/
1403
1411
1413 /*-*/ nyx_list_t *object,
1414 int idx
1415);
1416
1417/*--------------------------------------------------------------------------------------------------------------------*/
1418
1428
1430 nyx_list_iter_t *iter,
1431 int *idx,
1432 nyx_object_t **object
1433);
1434
1435/*--------------------------------------------------------------------------------------------------------------------*/
1436
1445
1446nyx_object_t *nyx_list_get(
1447 const nyx_list_t *object,
1448 int idx
1449);
1450
1451/*--------------------------------------------------------------------------------------------------------------------*/
1452
1456
1457nyx_list_t *nyx_list_set_alt(
1458 /*-*/ nyx_list_t *object,
1459 size_t idx,
1460 buff_t value,
1461 bool notify
1462);
1463
1472
1473__INLINE__ bool nyx_list_push(nyx_list_t *object, buff_t value)
1474{
1475 return nyx_list_set_alt(object, -1, value, true);
1476}
1477
1478/*--------------------------------------------------------------------------------------------------------------------*/
1479
1487
1489 const nyx_list_t *object
1490);
1491
1492/*--------------------------------------------------------------------------------------------------------------------*/
1493
1501
1503 const nyx_list_t *object
1504);
1505
1506/*--------------------------------------------------------------------------------------------------------------------*/
1507
1516
1517__INLINE__ double nyx_list_get_number(const nyx_list_t *object, int idx)
1518{
1519 nyx_object_t *number = nyx_list_get(object, idx);
1520
1521 return (number != NULL && number->type == NYX_TYPE_NUMBER) ? nyx_number_get((nyx_number_t *) number)
1522 : nan("1")
1523 ;
1524}
1525
1526/*--------------------------------------------------------------------------------------------------------------------*/
1527
1536
1537__INLINE__ STR_t nyx_list_get_string(const nyx_list_t *object, int idx)
1538{
1539 nyx_object_t *string = nyx_list_get(object, idx);
1540
1541 return (string != NULL && string->type == NYX_TYPE_STRING) ? nyx_string_get((nyx_string_t *) string)
1542 : NULL
1543 ;
1544}
1545
1546/*--------------------------------------------------------------------------------------------------------------------*/
1547/* XMLDOC */
1548/*--------------------------------------------------------------------------------------------------------------------*/
1554/*--------------------------------------------------------------------------------------------------------------------*/
1555
1559
1569
1570/*--------------------------------------------------------------------------------------------------------------------*/
1571
1575
1576typedef struct nyx_xmldoc_s
1577{
1578 str_t name;
1579 nyx_xml_type_t type;
1580 str_t data;
1581
1582 struct nyx_xmldoc_s *next;
1583 struct nyx_xmldoc_s *parent;
1584
1585 struct nyx_xmldoc_s *children;
1586 struct nyx_xmldoc_s *attributes;
1587
1588 bool self_closing;
1589
1590} nyx_xmldoc_t;
1591
1592/*--------------------------------------------------------------------------------------------------------------------*/
1593
1602
1604 __ZEROABLE__ size_t size,
1605 __NULLABLE__ BUFF_t buff
1606);
1607
1608/*--------------------------------------------------------------------------------------------------------------------*/
1609
1617
1619 __NULLABLE__ STR_t text
1620);
1621
1622/*--------------------------------------------------------------------------------------------------------------------*/
1623
1630
1632 __NULLABLE__ nyx_xmldoc_t *xmldoc
1633);
1634
1635/*--------------------------------------------------------------------------------------------------------------------*/
1636
1644
1646 const nyx_xmldoc_t *xmldoc
1647);
1648
1649/*--------------------------------------------------------------------------------------------------------------------*/
1650/* TRANSFORM */
1651/*--------------------------------------------------------------------------------------------------------------------*/
1657/*--------------------------------------------------------------------------------------------------------------------*/
1658
1665
1667 __NULLABLE__ const nyx_xmldoc_t *xmldoc
1668);
1669
1670/*--------------------------------------------------------------------------------------------------------------------*/
1671
1678
1680 __NULLABLE__ const nyx_object_t *object
1681);
1682
1683/*--------------------------------------------------------------------------------------------------------------------*/
1684/* NYX */
1685/*--------------------------------------------------------------------------------------------------------------------*/
1691/*--------------------------------------------------------------------------------------------------------------------*/
1692
1693#define NYX_INDI_VERSION "1.7"
1694
1695/*--------------------------------------------------------------------------------------------------------------------*/
1696
1697typedef enum
1698{
1699 NYX_STATE_IDLE = 200,
1700 NYX_STATE_OK = 201,
1701 NYX_STATE_BUSY = 202,
1702 NYX_STATE_ALERT = 203,
1703
1704} nyx_state_t;
1705
1706/*--------------------------------------------------------------------------------------------------------------------*/
1707
1708STR_t nyx_state_to_str(
1709 nyx_state_t state
1710);
1711
1712/*--------------------------------------------------------------------------------------------------------------------*/
1713
1714nyx_state_t nyx_str_to_state(
1715 STR_t state
1716);
1717
1718/*--------------------------------------------------------------------------------------------------------------------*/
1719
1720typedef enum
1721{
1722 NYX_PERM_RO = 300,
1723 NYX_PERM_WO = 301,
1724 NYX_PERM_RW = 302,
1725
1726} nyx_perm_t;
1727
1728/*--------------------------------------------------------------------------------------------------------------------*/
1729
1730STR_t nyx_perm_to_str(
1731 nyx_perm_t perm
1732);
1733
1734/*--------------------------------------------------------------------------------------------------------------------*/
1735
1736nyx_perm_t nyx_str_to_perm(
1737 STR_t perm
1738);
1739
1740/*--------------------------------------------------------------------------------------------------------------------*/
1741
1742typedef enum
1743{
1744 NYX_RULE_ONE_OF_MANY = 400,
1745 NYX_RULE_AT_MOST_ONE = 401,
1746 NYX_RULE_ANY_OF_MANY = 402,
1747
1748} nyx_rule_t;
1749
1750/*--------------------------------------------------------------------------------------------------------------------*/
1751
1752STR_t nyx_rule_to_str(
1753 nyx_rule_t rule
1754);
1755
1756/*--------------------------------------------------------------------------------------------------------------------*/
1757
1758nyx_rule_t nyx_str_to_rule(
1759 STR_t rule
1760);
1761
1762/*--------------------------------------------------------------------------------------------------------------------*/
1763
1764typedef enum
1765{
1766 NYX_ONOFF_ON = 500,
1767 NYX_ONOFF_OFF = 501,
1768
1769} nyx_onoff_t;
1770
1771/*--------------------------------------------------------------------------------------------------------------------*/
1772
1773STR_t nyx_onoff_to_str(
1774 nyx_onoff_t onoff
1775);
1776
1777/*--------------------------------------------------------------------------------------------------------------------*/
1778
1779nyx_onoff_t nyx_str_to_onoff(
1780 STR_t onoff
1781);
1782
1783/*--------------------------------------------------------------------------------------------------------------------*/
1784
1785typedef enum
1786{
1787 NYX_BLOB_NEVER = 600,
1788 NYX_BLOB_ALSO = 601,
1789 NYX_BLOB_ONLY = 602,
1790
1791} nyx_blob_t;
1792
1793/*--------------------------------------------------------------------------------------------------------------------*/
1794
1795STR_t nyx_blob_to_str(
1796 nyx_blob_t blob
1797);
1798
1799/*--------------------------------------------------------------------------------------------------------------------*/
1800
1801nyx_blob_t nyx_str_to_blob(
1802 STR_t blob
1803);
1804
1805/*--------------------------------------------------------------------------------------------------------------------*/
1806
1807typedef enum
1808{
1809 NYX_STREAM_NEVER = 700,
1810 NYX_STREAM_ALSO = 701,
1811 NYX_STREAM_ONLY = 702,
1812
1813} nyx_stream_t;
1814
1815/*--------------------------------------------------------------------------------------------------------------------*/
1816
1817STR_t nyx_stream_to_str(
1818 nyx_stream_t stream
1819);
1820
1821/*--------------------------------------------------------------------------------------------------------------------*/
1822
1823nyx_stream_t nyx_str_to_stream(
1824 STR_t stream
1825);
1826
1827/*--------------------------------------------------------------------------------------------------------------------*/
1828
1829typedef struct
1830{
1831 __NULLABLE__ STR_t label;
1832 __NULLABLE__ STR_t group;
1833 __NULLABLE__ STR_t hints;
1834 __NULLABLE__ double timeout;
1835 __NULLABLE__ STR_t message;
1836
1837} nyx_opts_t;
1838
1839/*--------------------------------------------------------------------------------------------------------------------*/
1840
1844
1845nyx_string_t *nyx_format_double_to_string(
1846 STR_t format,
1847 double value
1848);
1849
1853
1854double nyx_format_string_to_double(
1855 STR_t format,
1856 nyx_string_t *value
1857);
1858
1859/*--------------------------------------------------------------------------------------------------------------------*/
1865/*--------------------------------------------------------------------------------------------------------------------*/
1866
1878
1880 STR_t name,
1881 __NULLABLE__ STR_t label,
1882 STR_t format,
1883 double min,
1884 double max,
1885 double step,
1886 double value
1887);
1888
1889/*--------------------------------------------------------------------------------------------------------------------*/
1890
1891__INLINE__ bool nyx_number_def_set(nyx_dict_t *def, double value)
1892{
1893 nyx_string_t *format = (nyx_string_t *) nyx_dict_get(def, "@format");
1894
1895 nyx_string_t *string = nyx_format_double_to_string(format->value, value);
1896
1897 return nyx_dict_set(def, "$", string);
1898}
1899
1900/*--------------------------------------------------------------------------------------------------------------------*/
1901
1902__INLINE__ double nyx_number_def_get(const nyx_dict_t *def)
1903{
1904 nyx_string_t *format = (nyx_string_t *) nyx_dict_get(def, "@format");
1905
1906 nyx_string_t *string = (nyx_string_t *) nyx_dict_get(def, "$");
1907
1908 return nyx_format_string_to_double(format->value, string);
1909}
1910
1911/*--------------------------------------------------------------------------------------------------------------------*/
1912
1923
1925 STR_t device,
1926 STR_t name,
1927 nyx_state_t state,
1928 nyx_perm_t perm,
1929 nyx_dict_t *defs[],
1930 __NULLABLE__ const nyx_opts_t *opts
1931);
1932
1933/*--------------------------------------------------------------------------------------------------------------------*/
1934
1938
1939nyx_dict_t *nyx_number_set_vector_new(
1940 const nyx_dict_t *def_vector
1941);
1942
1943/*--------------------------------------------------------------------------------------------------------------------*/
1949/*--------------------------------------------------------------------------------------------------------------------*/
1950
1958
1960 STR_t name,
1961 __NULLABLE__ STR_t label,
1962 STR_t value
1963);
1964
1965/*--------------------------------------------------------------------------------------------------------------------*/
1966
1967__INLINE__ bool nyx_text_def_set(nyx_dict_t *def, STR_t value)
1968{
1969 return nyx_dict_set(def, "$", nyx_string_from(value));
1970}
1971
1972/*--------------------------------------------------------------------------------------------------------------------*/
1973
1974__INLINE__ STR_t nyx_text_def_get(const nyx_dict_t *def)
1975{
1976 return nyx_string_get((nyx_string_t *) nyx_dict_get(def, "$"));
1977}
1978
1979/*--------------------------------------------------------------------------------------------------------------------*/
1980
1991
1993 STR_t device,
1994 STR_t name,
1995 nyx_state_t state,
1996 nyx_perm_t perm,
1997 nyx_dict_t *defs[],
1998 __NULLABLE__ const nyx_opts_t *opts
1999);
2000
2001/*--------------------------------------------------------------------------------------------------------------------*/
2002
2006
2007nyx_dict_t *nyx_text_set_vector_new(
2008 const nyx_dict_t *def_vector
2009);
2010
2011/*--------------------------------------------------------------------------------------------------------------------*/
2017/*--------------------------------------------------------------------------------------------------------------------*/
2018
2026
2028 STR_t name,
2029 __NULLABLE__ STR_t label,
2030 nyx_state_t value
2031);
2032
2033/*--------------------------------------------------------------------------------------------------------------------*/
2034
2035__INLINE__ bool nyx_light_def_set(nyx_dict_t *def, nyx_state_t value)
2036{
2037 return nyx_dict_set(def, "$", nyx_string_from(nyx_state_to_str(value)));
2038}
2039
2040/*--------------------------------------------------------------------------------------------------------------------*/
2041
2042__INLINE__ nyx_state_t nyx_light_def_get(const nyx_dict_t *def)
2043{
2044 return nyx_str_to_state(((nyx_string_t *) nyx_dict_get(def, "$"))->value);
2045}
2046
2047/*--------------------------------------------------------------------------------------------------------------------*/
2048
2058
2060 STR_t device,
2061 STR_t name,
2062 nyx_state_t state,
2063 nyx_dict_t *defs[],
2064 __NULLABLE__ const nyx_opts_t *opts
2065);
2066
2067/*--------------------------------------------------------------------------------------------------------------------*/
2068
2072
2073nyx_dict_t *nyx_light_set_vector_new(
2074 const nyx_dict_t *def_vector
2075);
2076
2077/*--------------------------------------------------------------------------------------------------------------------*/
2083/*--------------------------------------------------------------------------------------------------------------------*/
2084
2092
2094 STR_t name,
2095 __NULLABLE__ STR_t label,
2096 nyx_onoff_t value
2097);
2098
2099/*--------------------------------------------------------------------------------------------------------------------*/
2100
2101__INLINE__ bool nyx_switch_def_set(nyx_dict_t *def, nyx_onoff_t value)
2102{
2103 return nyx_dict_set(def, "$", nyx_string_from(nyx_onoff_to_str(value)));
2104}
2105
2106/*--------------------------------------------------------------------------------------------------------------------*/
2107
2108__INLINE__ nyx_onoff_t nyx_switch_def_get(const nyx_dict_t *def)
2109{
2110 return nyx_str_to_onoff(((nyx_string_t *) nyx_dict_get(def, "$"))->value);
2111}
2112
2113/*--------------------------------------------------------------------------------------------------------------------*/
2114
2126
2128 STR_t device,
2129 STR_t name,
2130 nyx_state_t state,
2131 nyx_perm_t perm,
2132 nyx_rule_t rule,
2133 nyx_dict_t *defs[],
2134 __NULLABLE__ const nyx_opts_t *opts
2135);
2136
2137/*--------------------------------------------------------------------------------------------------------------------*/
2138
2142
2143nyx_dict_t *nyx_switch_set_vector_new(
2144 const nyx_dict_t *def_vector
2145);
2146
2147/*--------------------------------------------------------------------------------------------------------------------*/
2153/*--------------------------------------------------------------------------------------------------------------------*/
2154
2163
2165 STR_t name,
2166 __NULLABLE__ STR_t label,
2167 STR_t value,
2168 STR_t format
2169);
2170
2171/*--------------------------------------------------------------------------------------------------------------------*/
2172
2176
2177bool nyx_glob_is_compressed(const nyx_dict_t *def);
2178
2179/*--------------------------------------------------------------------------------------------------------------------*/
2180
2181__INLINE__ bool nyx_blob_def_set(nyx_dict_t *def, size_t size, BUFF_t buff)
2182{
2183 return nyx_dict_set(def, "$", nyx_string_from_buff(size, buff, true, nyx_glob_is_compressed(def)));
2184}
2185
2186/*--------------------------------------------------------------------------------------------------------------------*/
2187
2188__INLINE__ void nyx_blob_def_get(const nyx_dict_t *def, size_t *size, buff_t *buff)
2189{
2190 nyx_string_get_buff((nyx_string_t *) nyx_dict_get(def, "$"), size, buff, true, nyx_glob_is_compressed(def));
2191}
2192
2193/*--------------------------------------------------------------------------------------------------------------------*/
2194
2205
2207 STR_t device,
2208 STR_t name,
2209 nyx_state_t state,
2210 nyx_perm_t perm,
2211 nyx_dict_t *defs[],
2212 __NULLABLE__ const nyx_opts_t *opts
2213);
2214
2215/*--------------------------------------------------------------------------------------------------------------------*/
2216
2220
2221nyx_dict_t *nyx_blob_set_vector_new(
2222 const nyx_dict_t *def_vector
2223);
2224
2225/*--------------------------------------------------------------------------------------------------------------------*/
2231/*--------------------------------------------------------------------------------------------------------------------*/
2232
2239
2241 STR_t name,
2242 __NULLABLE__ STR_t label
2243);
2244
2245/*--------------------------------------------------------------------------------------------------------------------*/
2246
2256
2258 STR_t device,
2259 STR_t name,
2260 nyx_state_t state,
2261 nyx_dict_t *defs[],
2262 __NULLABLE__ const nyx_opts_t *opts
2263);
2264
2265/*--------------------------------------------------------------------------------------------------------------------*/
2266
2270
2271nyx_dict_t *nyx_stream_set_vector_new(
2272 const nyx_dict_t *def_vector
2273);
2274
2275/*--------------------------------------------------------------------------------------------------------------------*/
2281/*--------------------------------------------------------------------------------------------------------------------*/
2282
2289
2291 STR_t device,
2292 STR_t message
2293);
2294
2295/*--------------------------------------------------------------------------------------------------------------------*/
2301/*--------------------------------------------------------------------------------------------------------------------*/
2302
2303nyx_dict_t *nyx_del_property_new(
2304 STR_t device,
2305 __NULLABLE__ STR_t name,
2306 __NULLABLE__ STR_t message
2307);
2308
2309/*--------------------------------------------------------------------------------------------------------------------*/
2310/* NODE */
2311/*--------------------------------------------------------------------------------------------------------------------*/
2317/*--------------------------------------------------------------------------------------------------------------------*/
2318
2323
2324typedef struct nyx_node_s nyx_node_t;
2325
2326/*--------------------------------------------------------------------------------------------------------------------*/
2327
2331
2332typedef enum
2333{
2336
2337} nyx_event_t;
2338
2339/*--------------------------------------------------------------------------------------------------------------------*/
2340
2351
2352typedef void (* nyx_mqtt_handler_t)(
2353 nyx_node_t *node,
2354 nyx_event_t event,
2355 size_t topic_size,
2356 BUFF_t topic_buff,
2357 size_t message_size,
2358 BUFF_t message_buff
2359);
2360
2361/*--------------------------------------------------------------------------------------------------------------------*/
2362
2381
2383 STR_t node_id,
2384 nyx_dict_t *vectors[],
2385 /**/
2386 __NULLABLE__ STR_t indi_url,
2387 /**/
2388 __NULLABLE__ STR_t mqtt_url,
2389 __NULLABLE__ STR_t mqtt_username,
2390 __NULLABLE__ STR_t mqtt_password,
2391 /**/
2392 __NULLABLE__ nyx_mqtt_handler_t mqtt_handler,
2393 /**/
2394 __NULLABLE__ STR_t redis_url,
2395 __NULLABLE__ STR_t redis_username,
2396 __NULLABLE__ STR_t redis_password,
2397 /**/
2398 int retry_ms,
2399 bool enable_xml
2400);
2401
2402/*--------------------------------------------------------------------------------------------------------------------*/
2403
2411
2413 nyx_node_t *node,
2414 bool free_vectors
2415);
2416
2417/*--------------------------------------------------------------------------------------------------------------------*/
2418
2426
2428 nyx_node_t *node,
2429 int timeout_ms
2430);
2431
2432/*--------------------------------------------------------------------------------------------------------------------*/
2433
2443
2445 nyx_node_t *node,
2446 /*--------*/ STR_t device,
2447 __NULLABLE__ STR_t name,
2448 __NULLABLE__ STR_t message
2449);
2450
2451/*--------------------------------------------------------------------------------------------------------------------*/
2452
2462
2464 nyx_node_t *node,
2465 /*--------*/ STR_t device,
2466 __NULLABLE__ STR_t name,
2467 __NULLABLE__ STR_t message
2468);
2469
2470/*--------------------------------------------------------------------------------------------------------------------*/
2471
2480
2482 nyx_node_t *node,
2483 STR_t device,
2484 STR_t message
2485);
2486
2487/*--------------------------------------------------------------------------------------------------------------------*/
2488
2496
2498 nyx_node_t *node,
2499 STR_t topic
2500);
2501
2502/*--------------------------------------------------------------------------------------------------------------------*/
2503
2513
2515 nyx_node_t *node,
2516 STR_t topic,
2517 __ZEROABLE__ size_t message_size,
2518 __NULLABLE__ BUFF_t message_buff
2519);
2520
2521/*--------------------------------------------------------------------------------------------------------------------*/
2522
2540
2542 nyx_node_t *node,
2543 STR_t device,
2544 STR_t stream,
2545 bool check,
2546 size_t max_len,
2547 __ZEROABLE__ size_t n_fields,
2548 const str_t field_names[],
2549 const size_t field_sizes[],
2550 const buff_t field_buffs[]
2551);
2552
2553/*--------------------------------------------------------------------------------------------------------------------*/
2555/*--------------------------------------------------------------------------------------------------------------------*/
2556
2557#ifndef ARDUINO
2558# pragma clang diagnostic pop
2559#endif
2560
2561/*--------------------------------------------------------------------------------------------------------------------*/
2562
2563#ifdef __cplusplus
2564}
2565#endif
2566
2567/*--------------------------------------------------------------------------------------------------------------------*/
2568
2569#endif /* NYX_NODE_H */
2570
2571/*--------------------------------------------------------------------------------------------------------------------*/
void nyx_boolean_free(nyx_boolean_t *object)
Frees memory of the provided JSON boolean object.
bool nyx_boolean_get(const nyx_boolean_t *object)
Get the value of the provided JSON boolean object.
nyx_boolean_t * nyx_boolean_new()
Allocates a new JSON boolean object.
__INLINE__ nyx_boolean_t * nyx_boolean_from(bool value)
Returns a JSON boolean object holding the value of the provided argument.
Definition nyx_node.h:802
__INLINE__ bool nyx_boolean_set(nyx_boolean_t *object, bool value)
Set the value of the provided JSON boolean object.
Definition nyx_node.h:773
str_t nyx_boolean_to_string(const nyx_boolean_t *object)
Returns a string representing the provided JSON boolean object.
__INLINE__ double nyx_dict_get_number(const nyx_dict_t *object, STR_t key)
Definition nyx_node.h:1296
size_t nyx_dict_size(const nyx_dict_t *object)
Gets the number of items in the provided JSON dict object.
bool nyx_dict_iterate(nyx_dict_iter_t *iter, STR_t *key, nyx_object_t **object)
str_t nyx_dict_to_string(const nyx_dict_t *object)
Returns a string representing the provided JSON dict object.
nyx_dict_t * nyx_dict_new()
Allocates a new JSON dict object.
nyx_object_t * nyx_dict_get(const nyx_dict_t *object, STR_t key)
void nyx_dict_del(nyx_dict_t *object, STR_t key)
void nyx_dict_clear(nyx_dict_t *object)
Clears the content of the provided JSON dict object.
__INLINE__ bool nyx_dict_set(nyx_dict_t *object, STR_t key, buff_t value)
Definition nyx_node.h:1252
void nyx_dict_free(nyx_dict_t *object)
Frees memory of the provided JSON dict object.
__INLINE__ STR_t nyx_dict_get_string(const nyx_dict_t *object, STR_t key)
Definition nyx_node.h:1316
__INLINE__ STR_t nyx_list_get_string(const nyx_list_t *object, int idx)
Definition nyx_node.h:1537
bool nyx_list_iterate(nyx_list_iter_t *iter, int *idx, nyx_object_t **object)
nyx_object_t * nyx_list_get(const nyx_list_t *object, int idx)
str_t nyx_list_to_string(const nyx_list_t *object)
Returns a string representing the provided JSON list object.
void nyx_list_del(nyx_list_t *object, int idx)
__INLINE__ double nyx_list_get_number(const nyx_list_t *object, int idx)
Definition nyx_node.h:1517
void nyx_list_free(nyx_list_t *object)
Frees memory of the provided JSON list object.
size_t nyx_list_size(const nyx_list_t *object)
Gets the number of items in the provided JSON list object.
__INLINE__ bool nyx_list_push(nyx_list_t *object, buff_t value)
Definition nyx_node.h:1473
nyx_list_t * nyx_list_new()
Allocates a new JSON list.
void nyx_list_clear(nyx_list_t *object)
Clears the content of the provided JSON list object.
nyx_log_level_e
Nyx log levels.
Definition nyx_node.h:129
void nyx_set_log_level(nyx_log_level_t level)
Sets the log level threshold.
enum nyx_log_level_e nyx_log_level_t
Nyx log levels.
void nyx_memory_initialize()
Initialize the memory subsystem.
bool nyx_memory_finalize()
Finalize the memory subsystem.
__NULLABLE__ buff_t nyx_memory_realloc(__NULLABLE__ buff_t buff, __ZEROABLE__ size_t size)
Similar to libc realloc except that a memory overflow causes the node to stop.
__NULLABLE__ buff_t nyx_memory_alloc(__ZEROABLE__ size_t size)
Similar to libc malloc except that a memory overflow causes the node to stop.
__ZEROABLE__ size_t nyx_memory_free(__NULLABLE__ buff_t buff)
Similar to libc free except that it returns the amount of memory freed.
void(* nyx_mqtt_handler_t)(nyx_node_t *node, nyx_event_t event, size_t topic_size, BUFF_t topic_buff, size_t message_size, BUFF_t message_buff)
MQTT event handler.
Definition nyx_node.h:2352
void nyx_node_poll(nyx_node_t *node, int timeout_ms)
Performs a single poll iteration.
void nyx_mqtt_sub(nyx_node_t *node, STR_t topic)
If MQTT is enabled, subscribes to a topic.
bool nyx_stream_pub(nyx_node_t *node, STR_t device, STR_t stream, bool check, size_t max_len, __ZEROABLE__ size_t n_fields, const str_t field_names[], const size_t field_sizes[], const buff_t field_buffs[])
If Redis is enabled, publishes an entry to a stream, see https://redis.io/commands/xadd/.
nyx_event_t
Nyx TCP or MQTT event type.
Definition nyx_node.h:2333
void nyx_node_send_message(nyx_node_t *node, STR_t device, STR_t message)
Sends a message to the clients.
nyx_node_t * nyx_node_initialize(STR_t node_id, nyx_dict_t *vectors[], __NULLABLE__ STR_t indi_url, __NULLABLE__ STR_t mqtt_url, __NULLABLE__ STR_t mqtt_username, __NULLABLE__ STR_t mqtt_password, __NULLABLE__ nyx_mqtt_handler_t mqtt_handler, __NULLABLE__ STR_t redis_url, __NULLABLE__ STR_t redis_username, __NULLABLE__ STR_t redis_password, int retry_ms, bool enable_xml)
Initializes the Nyx node.
void nyx_node_enable(nyx_node_t *node, STR_t device, __NULLABLE__ STR_t name, __NULLABLE__ STR_t message)
Enables a whole device or a definition vector.
void nyx_node_disable(nyx_node_t *node, STR_t device, __NULLABLE__ STR_t name, __NULLABLE__ STR_t message)
Disables a whole device or a definition vector.
void nyx_mqtt_pub(nyx_node_t *node, STR_t topic, __ZEROABLE__ size_t message_size, __NULLABLE__ BUFF_t message_buff)
If MQTT is enabled, publishes a message to a topic.
void nyx_node_finalize(nyx_node_t *node, bool free_vectors)
Finalizes the Nyx node.
@ NYX_EVENT_OPEN
A connection is opened.
Definition nyx_node.h:2334
@ NYX_EVENT_MSG
A message is received.
Definition nyx_node.h:2335
str_t nyx_null_to_string(const nyx_null_t *object)
Returns a string representing the provided JSON null object.
nyx_null_t * nyx_null_new()
Allocates a new JSON null object.
void nyx_null_free(nyx_null_t *object)
Frees memory of the provided JSON null object.
double nyx_number_get(const nyx_number_t *object)
Get the value of the provided JSON number object.
nyx_number_t * nyx_number_new()
Allocates a new JSON number object.
str_t nyx_number_to_string(const nyx_number_t *object)
Returns a string representing the provided JSON number object.
__INLINE__ nyx_number_t * nyx_number_from(double value)
Returns a JSON number object holding the value of the provided argument.
Definition nyx_node.h:683
void nyx_number_free(nyx_number_t *object)
Frees memory of the provided JSON number object.
__INLINE__ bool nyx_number_set(nyx_number_t *object, double value)
Set the value of the provided JSON number object.
Definition nyx_node.h:654
nyx_dict_t * nyx_blob_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx BLOB vector.
nyx_dict_t * nyx_blob_def_new(STR_t name, __NULLABLE__ STR_t label, STR_t value, STR_t format)
Allocates a new INDI / Nyx BLOB.
nyx_dict_t * nyx_light_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx light vector.
nyx_dict_t * nyx_light_def_new(STR_t name, __NULLABLE__ STR_t label, nyx_state_t value)
Allocates a new INDI / Nyx light.
nyx_dict_t * nyx_message_new(STR_t device, STR_t message)
Allocates a new INDI / Nyx message.
nyx_dict_t * nyx_number_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx number vector.
nyx_dict_t * nyx_number_def_new(STR_t name, __NULLABLE__ STR_t label, STR_t format, double min, double max, double step, double value)
Allocates a new INDI / Nyx number.
nyx_dict_t * nyx_stream_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new Nyx stream vector.
nyx_dict_t * nyx_stream_def_new(STR_t name, __NULLABLE__ STR_t label)
Allocates a new Nyx Stream.
nyx_dict_t * nyx_switch_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_rule_t rule, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx switch vector.
nyx_dict_t * nyx_switch_def_new(STR_t name, __NULLABLE__ STR_t label, nyx_onoff_t value)
Allocates a new INDI / Nyx switch.
nyx_dict_t * nyx_text_def_new(STR_t name, __NULLABLE__ STR_t label, STR_t value)
Allocates a new INDI / Nyx text.
nyx_dict_t * nyx_text_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx text vector.
str_t nyx_object_to_string(__NULLABLE__ const nyx_object_t *object)
Returns a string representing the provided object.
__NULLABLE__ nyx_object_t * nyx_object_parse(__NULLABLE__ STR_t text)
Parses a JSON object from a string.
bool nyx_object_equal(__NULLABLE__ const nyx_object_t *object1, __NULLABLE__ const nyx_object_t *object2)
Compares two JSON objects.
nyx_type_t
JSON object types.
Definition nyx_node.h:393
void nyx_object_free(__NULLABLE__ nyx_object_t *object)
Frees memory of the provided JSON object.
str_t nyx_object_to_cstring(__NULLABLE__ const nyx_object_t *object)
Returns a C/C++ string representing the provided object.
nyx_object_t * nyx_object_parse_buff(__ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff)
Parses a JSON object from a string buffer.
@ NYX_TYPE_DICT
Dict object.
Definition nyx_node.h:398
@ NYX_TYPE_LIST
List object.
Definition nyx_node.h:399
@ NYX_TYPE_BOOLEAN
Boolean object.
Definition nyx_node.h:395
@ NYX_TYPE_NUMBER
Number object.
Definition nyx_node.h:396
@ NYX_TYPE_NULL
Null object.
Definition nyx_node.h:394
@ NYX_TYPE_STRING
String object.
Definition nyx_node.h:397
__INLINE__ nyx_string_t * nyx_string_from_dup(STR_t value)
Returns a JSON string object holding the value of the provided argument (string duplication).
Definition nyx_node.h:1039
nyx_string_t * nyx_string_new()
Allocates a new JSON string object.
__INLINE__ nyx_string_t * nyx_string_from_ref(STR_t value)
Returns a JSON string object holding the value of the provided argument (string reference).
Definition nyx_node.h:1058
size_t nyx_string_length(const nyx_string_t *object)
Returns the length of the provided JSON string object.
__INLINE__ bool nyx_string_set_buff(nyx_string_t *object, size_t size, BUFF_t buff, bool base64_encode, bool compress)
Set the value of the provided JSON string object (buffer reference or base64 encoding).
Definition nyx_node.h:968
str_t nyx_string_to_string(const nyx_string_t *object)
Returns a string representing the provided JSON string object.
__INLINE__ bool nyx_string_set_ref(nyx_string_t *object, STR_t value)
Set the value of the provided JSON string object (string reference).
Definition nyx_node.h:936
str_t nyx_string_to_cstring(const nyx_string_t *object)
Returns a C/C++ string representing the provided JSON string object.
__INLINE__ bool nyx_string_set_dup(nyx_string_t *object, STR_t value)
Set the value of the provided JSON string object (string duplication).
Definition nyx_node.h:910
size_t nyx_string_raw_size(const nyx_string_t *object)
Returns the raw size (before base64-encoding or compressing) of JSON string object.
#define nyx_string_from
Alias to nyx_string_from_dup.
Definition nyx_node.h:1101
__INLINE__ nyx_string_t * nyx_string_from_buff(size_t size, BUFF_t buff, bool base64_encode, bool compress)
Returns a JSON string object holding the value of the provided argument (buffer reference or base64 e...
Definition nyx_node.h:1080
STR_t nyx_string_get(const nyx_string_t *object)
Get the value of the provided JSON string object.
void nyx_string_free(nyx_string_t *object)
Frees memory of the provided JSON string object.
__NULLABLE__ nyx_xmldoc_t * nyx_object_to_xmldoc(__NULLABLE__ const nyx_object_t *object)
Convert an JSON Nyx / INDI command to the XML one.
__NULLABLE__ nyx_object_t * nyx_xmldoc_to_object(__NULLABLE__ const nyx_xmldoc_t *xmldoc)
Convert an XML Nyx / INDI command to the JSON one.
__NULLABLE__ buff_t nyx_zlib_inflate(__NOTNULL__ size_t *result_size, __ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff)
ZLib-uncompresses a string to a buffer.
__NULLABLE__ str_t nyx_base64_encode(__NULLABLE__ size_t *result_len, __ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff)
Base64-encodes a buffer to a string.
__NULLABLE__ buff_t nyx_base64_decode(__NULLABLE__ size_t *result_size, __ZEROABLE__ size_t len, __NULLABLE__ STR_t str)
Base64-encodes a string to a buffer.
__NULLABLE__ buff_t nyx_zlib_deflate(__NULLABLE__ size_t *result_buff, __ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff)
ZLib-compresses a buffer to a string.
__NULLABLE__ buff_t nyx_zlib_base64_inflate(__NOTNULL__ size_t *result_size, __ZEROABLE__ size_t len, __NULLABLE__ STR_t str)
ZLib+base64-uncompresses a string to a buffer.
uint32_t nyx_hash32(__ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff, uint32_t seed)
Hashes a buffer using the MurmurHash2 algorithm.
__NULLABLE__ str_t nyx_zlib_base64_deflate(__NULLABLE__ size_t *result_len, __ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff)
ZLib+base64-compresses a buffer to a string.
void nyx_generate_mac_addr(uint8_t result_mac[6], uint8_t mac0, uint8_t mac1, STR_t node_id)
Generates a MAC address based on a node identifier.
nyx_xml_type_t
XML node types.
Definition nyx_node.h:1561
str_t nyx_xmldoc_to_string(const nyx_xmldoc_t *xmldoc)
Returns a string representing the provided XML document.
void nyx_xmldoc_free(__NULLABLE__ nyx_xmldoc_t *xmldoc)
Frees memory of the provided XML document.
nyx_xmldoc_t * nyx_xmldoc_parse_buff(__ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff)
Parses an XML document from a string buffer.
nyx_xmldoc_t * nyx_xmldoc_parse(__NULLABLE__ STR_t text)
Parses an XML document from a string.
@ NYX_XML_CDATA
CDATA content.
Definition nyx_node.h:1565
@ NYX_XML_ELEM
Element node.
Definition nyx_node.h:1562
@ NYX_XML_COMMENT
Comment node.
Definition nyx_node.h:1564
@ NYX_XML_TEXT
Text content.
Definition nyx_node.h:1566
@ NYX_XML_ATTR
Attribute node.
Definition nyx_node.h:1563
Struct describing a JSON boolean.
Definition nyx_node.h:707
bool value
???
Definition nyx_node.h:710
nyx_object_t base
???
Definition nyx_node.h:708
Definition nyx_node.h:1129
nyx_type_t type
???
Definition nyx_node.h:1132
struct nyx_dict_node_s * head
???
Definition nyx_node.h:1134
int idx
???
Definition nyx_node.h:1130
Struct describing a JSON dict.
Definition nyx_node.h:1118
struct nyx_dict_node_s * tail
???
Definition nyx_node.h:1122
struct nyx_dict_node_s * head
???
Definition nyx_node.h:1121
nyx_object_t base
???
Definition nyx_node.h:1119
Definition nyx_node.h:1351
int idx
???
Definition nyx_node.h:1352
struct nyx_list_node_s * head
???
Definition nyx_node.h:1356
nyx_type_t type
???
Definition nyx_node.h:1354
Struct describing a JSON list.
Definition nyx_node.h:1340
nyx_object_t base
???
Definition nyx_node.h:1341
struct nyx_list_node_s * head
???
Definition nyx_node.h:1343
struct nyx_list_node_s * tail
???
Definition nyx_node.h:1344
Opaque struct describing a Nyx node.
Struct describing a JSON null value.
Definition nyx_node.h:534
nyx_object_t base
???
Definition nyx_node.h:535
Struct describing a JSON number.
Definition nyx_node.h:588
double value
???
Definition nyx_node.h:591
nyx_object_t base
???
Definition nyx_node.h:589
Definition nyx_node.h:410
uint32_t magic
Magic number, must always be NYX_OBJECT_MAGIC.
Definition nyx_node.h:411
__NULLABLE__ void(* in_callback)(struct nyx_object_s *object, bool modified)
Callback triggered when a client modifies this object.
Definition nyx_node.h:420
__NULLABLE__ struct nyx_object_s * parent
Pointer to the parent object.
Definition nyx_node.h:418
nyx_type_t type
Type of object, see nyx_type_t.
Definition nyx_node.h:414
uint64_t flags
Mask of flags, see NYX_FLAGS_XXX definitions.
Definition nyx_node.h:412
__NULLABLE__ struct nyx_node_s * node
Pointer to the associated Nyx node.
Definition nyx_node.h:416
__NULLABLE__ void(* out_callback)(struct nyx_object_s *object, bool modified)
Callback triggered when the server modifies this object.
Definition nyx_node.h:425
__NULLABLE__ void * ctx
Custom pointer for callbacks.
Definition nyx_node.h:430
Definition nyx_node.h:1830
Struct describing a JSON string.
Definition nyx_node.h:826
bool dyn
???
Definition nyx_node.h:833
str_t value
???
Definition nyx_node.h:831
nyx_object_t base
???
Definition nyx_node.h:827
size_t raw_size
???
Definition nyx_node.h:829
size_t length
???
Definition nyx_node.h:830
Definition nyx_node.h:1577