S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
sopc_helper_expat.h
Go to the documentation of this file.
1/*
2 * Licensed to Systerel under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work
4 * for additional information regarding copyright ownership.
5 * Systerel licenses this file to you under the Apache
6 * License, Version 2.0 (the "License"); you may not use this
7 * file except in compliance with the License. You may obtain
8 * a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef SOPC_HELPER_EXPAT_H_
21#define SOPC_HELPER_EXPAT_H_
22
23#include <stdarg.h>
24#include <stdbool.h>
25#include <stddef.h>
26
27#include "expat.h"
28
29#define SKIP_TAG_LEN 256
30
31typedef struct SOPC_HelperExpatCtx
32{
33 XML_Parser parser;
34
35 char skip_tag[SKIP_TAG_LEN]; // If set, start_tag events are ignored until this tag is closed
36
37 // 0 terminated buffer for the char data handler (a single piece of char
38 // data in the XML can be broken across many callbacks).
40
41 // strlen of the text in char_data_buffer
43
44 // allocated size of char_data_buffer, at least char_data_len + 1 (for the
45 // NULL terminator).
48
49#ifdef UANODESET_LOADER_LOG
50#define LOG(str) fprintf(stderr, "UANODESET_LOADER: %s:%d: %s\n", __FILE__, __LINE__, (str))
51#define LOG_XML_ERROR(parser, str) \
52 fprintf(stderr, "UANODESET_LOADER: %s:%d: at line %lu, column %lu: %s\n", __FILE__, __LINE__, \
53 XML_GetCurrentLineNumber(parser), XML_GetCurrentColumnNumber(parser), (str))
54
55#define LOGF(format, ...) fprintf(stderr, "UANODESET_LOADER: %s:%d: " format "\n", __FILE__, __LINE__, __VA_ARGS__)
56#define LOG_XML_ERRORF(parser, format, ...) \
57 fprintf(stderr, "UANODESET_LOADER: %s:%d: at line %lu, column %lu: " format "\n", __FILE__, __LINE__, \
58 XML_GetCurrentLineNumber(parser), XML_GetCurrentColumnNumber(parser), __VA_ARGS__)
59#else
60#define LOG(str)
61#define LOG_XML_ERROR(parser, str)
62#define LOGF(format, ...)
63#define LOG_XML_ERRORF(parser, format, ...)
64#endif
65
66#define LOG_MEMORY_ALLOCATION_FAILURE LOG("Memory allocation failure")
67
69
70bool SOPC_HelperExpat_CharDataAppend(SOPC_HelperExpatCtx* ctx, const char* data, size_t len);
71
73
74/*
75 * \brief Push a tag for which all events shall be skipped until tag is closed
76 * Note: assertion failure is raised if a tag is already pushed
77 */
79
80/*
81 * \brief Check if the skip tag is still active
82 * \return true if skip tag is active, false otherwise
83 */
85
86/*
87 * \brief Pop skip tag if it is the one pushed previously
88 * \return true if skip tag is popped, false otherwise
89 */
91
92/*
93 * \brief Retrieve the attribute name in the given attribute list
94 */
95const char* SOPC_HelperExpat_GetAttr(SOPC_HelperExpatCtx* ctx, const char* attrName, const XML_Char** attrs);
96
97#endif /* SOPC_HELPER_EXPAT_H_ */
#define SKIP_TAG_LEN
Definition sopc_helper_expat.h:29
const char * SOPC_HelperExpat_GetAttr(SOPC_HelperExpatCtx *ctx, const char *attrName, const XML_Char **attrs)
void SOPC_HelperExpat_PushSkipTag(SOPC_HelperExpatCtx *ctx, const char *name)
const char * SOPC_HelperExpat_CharDataStripped(SOPC_HelperExpatCtx *ctx)
bool SOPC_HelperExpat_PopSkipTag(SOPC_HelperExpatCtx *ctx, const char *name)
void SOPC_HelperExpat_CharDataReset(SOPC_HelperExpatCtx *ctx)
bool SOPC_HelperExpat_CharDataAppend(SOPC_HelperExpatCtx *ctx, const char *data, size_t len)
bool SOPC_HelperExpat_IsSkipTagActive(SOPC_HelperExpatCtx *ctx)
struct SOPC_HelperExpatCtx SOPC_HelperExpatCtx
Definition sopc_helper_expat.h:32
char skip_tag[SKIP_TAG_LEN]
Definition sopc_helper_expat.h:35
size_t char_data_cap
Definition sopc_helper_expat.h:46
size_t char_data_len
Definition sopc_helper_expat.h:42
char * char_data_buffer
Definition sopc_helper_expat.h:39
XML_Parser parser
Definition sopc_helper_expat.h:33