Skip to content

Commit de5666b

Browse files
committed
```
feat: Add initial CBOR format support with libcbor integration (squahsed commit) - Add ENABLE_CBOR_SUPPORT CMake flag to conditionally enable CBOR functionality - Integrate libcbor dependency with CMake find_package and conditional compilation - Add basic parser_cbor.c and parser_cbor.h files with foundational structures - Implement initial CBOR parsing functions with libcbor as low-level parser - Add necessary format switch statements throughout codebase for CBOR support - Introduce lyd_parse_data_mem_len() high-level function for parsing CBOR from memory (required because CBOR binary data may contain null bytes, making strlen() unreliable) - Build complete CBOR parser that constructs libyang data trees - Link parsed CBOR data with schema trees for validation - Fix initial memory allocation errors and remove dead code This commit establishes the foundation for CBOR support in libyang, allowing the library to be built with or without CBOR capabilities based on build configuration. ```
1 parent c2ddd01 commit de5666b

File tree

10 files changed

+1454
-4
lines changed

10 files changed

+1454
-4
lines changed

CMakeLists.txt

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ set(format_sources
231231
src/*.h
232232
src/plugins_exts/*
233233
src/plugins_types/*)
234+
234235
#
235236
# options
236237
#
@@ -249,6 +250,7 @@ option(ENABLE_YANGLINT_INTERACTIVE "Enable interactive CLI yanglint" ON)
249250
option(ENABLE_TOOLS "Build binary tools 'yanglint' and 'yangre'" ON)
250251
option(ENABLE_COMMON_TARGETS "Define common custom target names such as 'doc' or 'uninstall', may cause conflicts when using add_subdirectory() to build this project" ON)
251252
option(BUILD_SHARED_LIBS "By default, shared libs are enabled. Turn off for a static build." ON)
253+
option(ENABLE_CBOR_SUPPORT "Enable CBOR support with libcbor" ON)
252254
set(YANG_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/yang/modules/libyang" CACHE STRING "Directory where to copy the YANG modules to")
253255

254256
if(ENABLE_INTERNAL_DOCS)
@@ -316,6 +318,42 @@ if(ENABLE_COVERAGE)
316318
gen_coverage_enable(${ENABLE_TESTS})
317319
endif()
318320

321+
if(ENABLE_CBOR_SUPPORT)
322+
find_package(PkgConfig)
323+
if(PKG_CONFIG_FOUND)
324+
pkg_check_modules(LIBCBOR REQUIRED libcbor)
325+
if(LIBCBOR_FOUND)
326+
message(STATUS "libcbor found, enabling CBOR support")
327+
add_definitions(-DENABLE_CBOR_SUPPORT)
328+
include_directories(${LIBCBOR_INCLUDE_DIRS})
329+
# Add CBOR parser files to the library sources
330+
list(APPEND libsrc src/parser_cbor.c)
331+
list(APPEND headers src/parser_cbor.h)
332+
# Add CBOR files to format sources
333+
list(APPEND format_sources src/parser_cbor.c src/parser_cbor.h)
334+
else()
335+
message(FATAL_ERROR "libcbor not found! Please install libcbor development package or disable CBOR support with -DENABLE_CBOR_SUPPORT=OFF")
336+
endif()
337+
else()
338+
# Fallback to find_path and find_library if pkg-config is not available
339+
find_path(LIBCBOR_INCLUDE_DIR cbor.h)
340+
find_library(LIBCBOR_LIBRARY cbor)
341+
if(LIBCBOR_INCLUDE_DIR AND LIBCBOR_LIBRARY)
342+
message(STATUS "libcbor found via find_path/find_library, enabling CBOR support")
343+
add_definitions(-DENABLE_CBOR_SUPPORT)
344+
include_directories(${LIBCBOR_INCLUDE_DIR})
345+
set(LIBCBOR_LIBRARIES ${LIBCBOR_LIBRARY})
346+
# Add CBOR parser files to the library sources
347+
list(APPEND libsrc src/parser_cbor.c)
348+
list(APPEND headers src/parser_cbor.h)
349+
# Add CBOR files to format sources
350+
list(APPEND format_sources src/parser_cbor.c src/parser_cbor.h)
351+
else()
352+
message(FATAL_ERROR "libcbor not found! Please install libcbor development package or disable CBOR support with -DENABLE_CBOR_SUPPORT=OFF")
353+
endif()
354+
endif()
355+
endif()
356+
319357
if ("${BUILD_TYPE_UPPER}" STREQUAL "DEBUG")
320358
# enable before adding tests to let them detect that format checking is available - one of the tests is format checking
321359
source_format_enable(0.77)
@@ -408,6 +446,11 @@ find_package(PCRE2 10.21 REQUIRED)
408446
include_directories(${PCRE2_INCLUDE_DIRS})
409447
target_link_libraries(yang ${PCRE2_LIBRARIES})
410448

449+
# link libcbor if CBOR support is enabled
450+
if(ENABLE_CBOR_SUPPORT)
451+
target_link_libraries(yang ${LIBCBOR_LIBRARIES})
452+
endif()
453+
411454
# XXHash include and library
412455
find_package(XXHash)
413456
if(XXHASH_FOUND)
@@ -497,4 +540,4 @@ add_custom_target(cclean
497540
COMMAND make clean
498541
COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} +
499542
COMMAND rm -rf Makefile Doxyfile
500-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
543+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

0 commit comments

Comments
 (0)