Merge branch 'feature/expat_to_component_manager' into 'master'
Push out `expat` to idf-extra-components repository Closes IDF-4546 See merge request espressif/esp-idf!16785
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
idf_component_register(SRCS "expat/expat/lib/xmlparse.c"
|
||||
"expat/expat/lib/xmlrole.c"
|
||||
"expat/expat/lib/xmltok.c"
|
||||
"expat/expat/lib/xmltok_impl.c"
|
||||
"expat/expat/lib/xmltok_ns.c"
|
||||
INCLUDE_DIRS expat/expat/lib port/include)
|
||||
|
||||
target_compile_definitions(${COMPONENT_LIB} PRIVATE HAVE_EXPAT_CONFIG_H)
|
||||
target_compile_definitions(${COMPONENT_LIB} PRIVATE HAVE_GETRANDOM)
|
||||
|
||||
# Temporary suppress "fallthrough" warnings until they are fixed in expat repo
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-implicit-fallthrough)
|
||||
Submodule components/expat/expat deleted from a28238bdee
@@ -1,22 +0,0 @@
|
||||
The Expat XML Parse Instruction
|
||||
=============================
|
||||
|
||||
Expat is an XML parser library written in C which be used for parse XML documents.
|
||||
|
||||
It is a stream-oriented parser in which an application registers handlers for things the parser might find in the XML document.
|
||||
|
||||
It can parse some larger files.
|
||||
|
||||
- Expat XML Parser support many different processor, but for the most part function you only need the following functions:
|
||||
|
||||
**XML_ParserCreate**: Create a new parser object
|
||||
|
||||
**XML_SetElementHandler**: Set handlers for start and end tags
|
||||
|
||||
**XML_SetCharacterDataHandler**: Set handler for text
|
||||
|
||||
**XML_Parse**: Pass a buffer full of document to the parser
|
||||
|
||||
More information about Expat library can be found on http://expat.sourceforge.net
|
||||
|
||||
An introductory article on using Expat is available on http://xml.com
|
||||
@@ -1,103 +0,0 @@
|
||||
/* expat_config.h. Generated from expat_config.h.in by configure. */
|
||||
/* expat_config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* 1234 = LIL_ENDIAN, 4321 = BIGENDIAN */
|
||||
#define BYTEORDER 1234
|
||||
/* Define to 1 if you have the `bcopy' function. */
|
||||
#define HAVE_BCOPY 1
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the `getpagesize' function. */
|
||||
#define HAVE_GETPAGESIZE 1
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `memmove' function. */
|
||||
#define HAVE_MEMMOVE 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have a working `mmap' system call. */
|
||||
#define HAVE_MMAP 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to the sub-directory where libtool stores uninstalled libraries. */
|
||||
#define LT_OBJDIR ".libs/"
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "expat"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "expat-bugs@libexpat.org"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "expat"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "expat 2.2.5"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "expat"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "2.2.5"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "2.2.5"
|
||||
|
||||
/* whether byteorder is bigendian */
|
||||
/* #undef WORDS_BIGENDIAN */
|
||||
|
||||
/* Define to specify how much context to retain around the current parse
|
||||
point. */
|
||||
#define XML_CONTEXT_BYTES 1024
|
||||
|
||||
/* Define to make parameter entity parsing functionality available. */
|
||||
#define XML_DTD 1
|
||||
|
||||
/* Define to make XML Namespaces functionality available. */
|
||||
#define XML_NS 1
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to `long int' if <sys/types.h> does not define. */
|
||||
/* #undef off_t */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
@@ -1,3 +0,0 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES cmock expat)
|
||||
@@ -1,127 +0,0 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <expat.h>
|
||||
#include <string.h>
|
||||
#include "unity.h"
|
||||
|
||||
typedef struct {
|
||||
int depth;
|
||||
char output[512];
|
||||
int output_off;
|
||||
} user_data_t;
|
||||
|
||||
static void insert_space(user_data_t *user_data)
|
||||
{
|
||||
const char align_str[] = " ";
|
||||
|
||||
TEST_ASSERT(sizeof(user_data->output) >= user_data->output_off);
|
||||
user_data->output[user_data->output_off++] = '\n';
|
||||
|
||||
for (int i = 0; i < user_data->depth; i++) {
|
||||
for (int j = 0; j < strlen(align_str); ++j) {
|
||||
TEST_ASSERT(sizeof(user_data->output) >= user_data->output_off);
|
||||
user_data->output[user_data->output_off++] = align_str[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void XMLCALL start_element(void *userData, const XML_Char *name, const XML_Char **atts)
|
||||
{
|
||||
user_data_t *user_data = (user_data_t *) userData;
|
||||
|
||||
insert_space(user_data);
|
||||
|
||||
const int ret = snprintf(user_data->output + user_data->output_off,
|
||||
sizeof(user_data->output) - user_data->output_off,
|
||||
"<%s>", name);
|
||||
TEST_ASSERT_EQUAL(strlen(name) + 2, ret); // 2 are the tag characters: "<>"
|
||||
user_data->output_off += ret;
|
||||
++user_data->depth;
|
||||
}
|
||||
|
||||
static void XMLCALL end_element(void *userData, const XML_Char *name)
|
||||
{
|
||||
user_data_t *user_data = (user_data_t *) userData;
|
||||
|
||||
--user_data->depth;
|
||||
insert_space(user_data);
|
||||
|
||||
int ret = snprintf(user_data->output + user_data->output_off, sizeof(user_data->output) - user_data->output_off,
|
||||
"</%s>", name);
|
||||
TEST_ASSERT_EQUAL(strlen(name) + 3, ret); // 3 are the tag characters: "</>"
|
||||
user_data->output_off += ret;
|
||||
}
|
||||
|
||||
static void data_handler(void *userData, const XML_Char *s, int len)
|
||||
{
|
||||
user_data_t *user_data = (user_data_t *) userData;
|
||||
|
||||
insert_space(user_data);
|
||||
|
||||
// s is not zero-terminated
|
||||
char tmp_str[len+1];
|
||||
strlcpy(tmp_str, s, len+1);
|
||||
|
||||
int ret = snprintf(user_data->output + user_data->output_off, sizeof(user_data->output) - user_data->output_off,
|
||||
"%s", tmp_str);
|
||||
TEST_ASSERT_EQUAL(strlen(tmp_str), ret);
|
||||
user_data->output_off += ret;
|
||||
}
|
||||
|
||||
TEST_CASE("Expat parses XML", "[expat]")
|
||||
{
|
||||
const char test_in[] = "<html><title>Page title</title><body><h>header</h><ol><li>A</li>"\
|
||||
"<li>B</li><li>C</li></ol></body></html>";
|
||||
const char test_expected[] = "\n"\
|
||||
"<html>\n"\
|
||||
" <title>\n"\
|
||||
" Page title\n"\
|
||||
" </title>\n"\
|
||||
" <body>\n"\
|
||||
" <h>\n"\
|
||||
" header\n"\
|
||||
" </h>\n"\
|
||||
" <ol>\n"\
|
||||
" <li>\n"\
|
||||
" A\n"\
|
||||
" </li>\n"\
|
||||
" <li>\n"\
|
||||
" B\n"\
|
||||
" </li>\n"\
|
||||
" <li>\n"\
|
||||
" C\n"\
|
||||
" </li>\n"\
|
||||
" </ol>\n"\
|
||||
" </body>\n"\
|
||||
"</html>";
|
||||
user_data_t user_data = {
|
||||
.depth = 0,
|
||||
.output = { '\0' },
|
||||
.output_off = 0
|
||||
};
|
||||
|
||||
XML_Parser parser = XML_ParserCreate(NULL);
|
||||
XML_SetUserData(parser, &user_data);
|
||||
XML_SetElementHandler(parser, start_element, end_element);
|
||||
XML_SetCharacterDataHandler(parser, data_handler);
|
||||
|
||||
TEST_ASSERT_NOT_EQUAL(XML_STATUS_ERROR, XML_Parse(parser, test_in, strlen(test_in), 1));
|
||||
XML_ParserFree(parser);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, user_data.depth); // all closing tags have been found
|
||||
|
||||
TEST_ASSERT_EQUAL(strlen(test_expected), strlen(user_data.output));
|
||||
TEST_ASSERT_EQUAL_STRING(test_expected, user_data.output);
|
||||
}
|
||||
Reference in New Issue
Block a user