Nyx Node
Toggle main menu visibility
Loading...
Searching...
No Matches
xml_stream.c
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
#if !defined(ARDUINO)
8
/*--------------------------------------------------------------------------------------------------------------------*/
9
10
#include <string.h>
11
12
#include "nyx_node_internal.h"
13
14
/*--------------------------------------------------------------------------------------------------------------------*/
15
16
#define TAG(s_tag, e_tag) { \
17
.s_tag_size = sizeof(s_tag) - 1, \
18
.s_tag_buff = (s_tag), \
19
.e_tag_size = sizeof(e_tag) - 1, \
20
.e_tag_buff = (e_tag), \
21
}
22
23
/*--------------------------------------------------------------------------------------------------------------------*/
24
25
static
struct
tag_s
26
{
27
size_t
s_tag_size;
28
STR_t
s_tag_buff;
29
size_t
e_tag_size;
30
STR_t
e_tag_buff;
31
32
}
/* NOSONAR */
TAGS[] = {
33
TAG(
"<getProperties"
,
"/>"
),
34
TAG(
"<delProperty"
,
"/>"
),
35
TAG(
"<message"
,
"/>"
),
36
/**/
37
TAG(
"<enableBLOB"
,
"</enableBLOB>"
),
38
/**/
39
TAG(
"<newTextVector"
,
"</newTextVector>"
),
40
TAG(
"<newNumberVector"
,
"</newNumberVector>"
),
41
TAG(
"<newSwitchVector"
,
"</newSwitchVector>"
),
42
TAG(
"<newLightVector"
,
"</newLightVector>"
),
43
TAG(
"<newBLOBVector"
,
"</newBLOBVector>"
),
44
};
45
46
/*--------------------------------------------------------------------------------------------------------------------*/
47
48
#define TAG_DEF_NB (sizeof(TAGS) / sizeof(struct tag_s))
49
50
/*--------------------------------------------------------------------------------------------------------------------*/
51
52
bool
nyx_xml_stream_detect_opening_tag(nyx_xml_stream_t *xml_stream,
size_t
size,
BUFF_t
buff)
53
{
54
for
(
size_t
i = 0; i < TAG_DEF_NB; i++)
55
{
56
STR_t
p = memmem(buff, size, TAGS[i].s_tag_buff, TAGS[i].s_tag_size);
57
58
if
(p != NULL)
59
{
60
xml_stream->s_ptr = p + 0x000000000000000000000;
61
62
xml_stream->pos = (
63
(size_t) xml_stream->s_ptr
64
-
65
(size_t)
/*--*/
buff
/*--*/
66
);
67
68
xml_stream->tag = &TAGS[i];
69
70
return
true
;
71
}
72
}
73
74
return
false
;
75
}
76
77
/*--------------------------------------------------------------------------------------------------------------------*/
78
79
bool
nyx_xml_stream_detect_closing_tag(nyx_xml_stream_t *xml_stream,
size_t
size, __NYX_UNUSED__
BUFF_t
buff)
80
{
81
STR_t
p = memmem(xml_stream->s_ptr, size - xml_stream->pos, xml_stream->tag->e_tag_buff, xml_stream->tag->e_tag_size);
82
83
if
(p != NULL)
84
{
85
xml_stream->e_ptr = p + xml_stream->tag->e_tag_size;
86
87
xml_stream->len = (
88
(size_t) xml_stream->e_ptr
89
-
90
(size_t) xml_stream->s_ptr
91
);
92
93
xml_stream->tag = NULL;
94
95
return
true
;
96
}
97
98
return
false
;
99
}
100
101
/*--------------------------------------------------------------------------------------------------------------------*/
102
#endif
103
/*--------------------------------------------------------------------------------------------------------------------*/
STR_t
#define STR_t
Alias for const char *.
Definition
nyx_node.h:71
BUFF_t
#define BUFF_t
Alias for const void *.
Definition
nyx_node.h:68
Author:
Jérôme ODIER
License:
LGPL-3.0-or-later
Copyright:
LPSC / CNRS