Skip to content

Commit 7c5feab

Browse files
author
Meher C
committed
fix: address PR review and migrate parser_cbor.c to current API
- Add FindCBOR.cmake module for proper CBOR dependency detection - Rename lcbor.c/h to cbor.c/h for consistency - Remove debug code and leftover artifacts - Revert parser_json.c to upstream (undo unintended changes) - Fix CBOR struct layout in parser_internal.h, tree_data.c, printer_cbor.c - Migrate parser_cbor.c to current upstream API: - Rewrite lydcbor_get_snode to use lys_find_child_node - Add lnode parameter to all LOGVAL calls - Fix LOG_LOCSET/LOG_LOCBACK to single-arg macros - Fix lyd_parser_create_term signature (add parent, value_size_bits) - Fix lyd_parser_create_meta signature (add lnode, value_size_bits) - Fix lyd_create_any to new 7-arg signature - Remove lyplg_ext_insert (function removed upstream) - Fix lyd_node_any access (value.tree → child) - Add tree_schema_internal.h include
1 parent 93d4684 commit 7c5feab

File tree

10 files changed

+585
-717
lines changed

10 files changed

+585
-717
lines changed

CMakeLists.txt

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ option(ENABLE_YANGLINT_INTERACTIVE "Enable interactive CLI yanglint" ON)
257257
option(ENABLE_TOOLS "Build binary tools 'yanglint' and 'yangre'" ON)
258258
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)
259259
option(BUILD_SHARED_LIBS "By default, shared libs are enabled. Turn off for a static build." ON)
260-
option(ENABLE_CBOR_SUPPORT "Enable CBOR support with libcbor" ON)
261260
set(YANG_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/yang/modules/libyang" CACHE STRING "Directory where to copy the YANG modules to")
262261

263262
if(ENABLE_INTERNAL_DOCS)
@@ -325,40 +324,14 @@ if(ENABLE_COVERAGE)
325324
gen_coverage_enable(${ENABLE_TESTS})
326325
endif()
327326

328-
if(ENABLE_CBOR_SUPPORT)
329-
find_package(PkgConfig)
330-
if(PKG_CONFIG_FOUND)
331-
pkg_check_modules(LIBCBOR REQUIRED libcbor)
332-
if(LIBCBOR_FOUND)
333-
message(STATUS "libcbor found, enabling CBOR support")
334-
add_definitions(-DENABLE_CBOR_SUPPORT)
335-
include_directories(${LIBCBOR_INCLUDE_DIRS})
336-
# Add CBOR parser files to the library sources
337-
list(APPEND libsrc src/parser_cbor.c src/lcbor.c src/printer_cbor.c)
338-
list(APPEND headers src/lcbor.h)
339-
# Add CBOR files to format sources
340-
list(APPEND format_sources src/parser_cbor.c src/lcbor.h src/lcbor.c src/printer_cbor.c)
341-
else()
342-
message(FATAL_ERROR "libcbor not found! Please install libcbor development package or disable CBOR support with -DENABLE_CBOR_SUPPORT=OFF")
343-
endif()
344-
else()
345-
# Fallback to find_path and find_library if pkg-config is not available
346-
find_path(LIBCBOR_INCLUDE_DIR cbor.h)
347-
find_library(LIBCBOR_LIBRARY cbor)
348-
if(LIBCBOR_INCLUDE_DIR AND LIBCBOR_LIBRARY)
349-
message(STATUS "libcbor found via find_path/find_library, enabling CBOR support")
350-
add_definitions(-DENABLE_CBOR_SUPPORT)
351-
include_directories(${LIBCBOR_INCLUDE_DIR})
352-
set(LIBCBOR_LIBRARIES ${LIBCBOR_LIBRARY})
353-
# Add CBOR parser files to the library sources
354-
list(APPEND libsrc src/parser_cbor.c src/lcbor.c src/printer_cbor.c)
355-
list(APPEND headers src/lcbor.h)
356-
# Add CBOR files to format sources
357-
list(APPEND format_sources src/parser_cbor.c src/lcbor.h src/lcbor.c src/printer_cbor.c)
358-
else()
359-
message(FATAL_ERROR "libcbor not found! Please install libcbor development package or disable CBOR support with -DENABLE_CBOR_SUPPORT=OFF")
360-
endif()
361-
endif()
327+
find_package(CBOR)
328+
if(CBOR_FOUND)
329+
set(CBOR_SUPPORT ON)
330+
list(APPEND libsrc src/parser_cbor.c src/cbor.c src/printer_cbor.c)
331+
list(APPEND headers src/cbor.h)
332+
list(APPEND format_sources src/parser_cbor.c src/cbor.h src/cbor.c src/printer_cbor.c)
333+
else()
334+
message(STATUS "libcbor not found, CBOR support disabled")
362335
endif()
363336

364337
if ("${BUILD_TYPE_UPPER}" STREQUAL "DEBUG")
@@ -465,9 +438,15 @@ find_package(PCRE2 10.21 REQUIRED)
465438
include_directories(${PCRE2_INCLUDE_DIRS})
466439
target_link_libraries(yang ${PCRE2_LIBRARIES})
467440

468-
# link libcbor if CBOR support is enabled
469-
if(ENABLE_CBOR_SUPPORT)
470-
target_link_libraries(yang ${LIBCBOR_LIBRARIES})
441+
# link libcbor if found
442+
if(CBOR_FOUND)
443+
if(TARGET yangobj)
444+
target_compile_definitions(yangobj PRIVATE ENABLE_CBOR_SUPPORT)
445+
target_include_directories(yangobj PRIVATE ${CBOR_INCLUDE_DIR})
446+
endif()
447+
target_compile_definitions(yang PRIVATE ENABLE_CBOR_SUPPORT)
448+
target_include_directories(yang PRIVATE ${CBOR_INCLUDE_DIR})
449+
target_link_libraries(yang ${CBOR_LIBRARY})
471450
endif()
472451

473452
# XXHash include and library

CMakeModules/FindCBOR.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Try to find libcbor
2+
# Once done this will define
3+
#
4+
# Read-Only variables:
5+
# CBOR_FOUND - system has libcbor
6+
# CBOR_INCLUDE_DIR - the libcbor include directory
7+
# CBOR_LIBRARY - Link these to use libcbor
8+
9+
find_path(CBOR_INCLUDE_DIR
10+
NAMES
11+
cbor.h
12+
PATHS
13+
/usr/include
14+
/usr/local/include
15+
/opt/local/include
16+
/sw/include
17+
${CMAKE_INCLUDE_PATH}
18+
${CMAKE_INSTALL_PREFIX}/include
19+
)
20+
21+
find_library(CBOR_LIBRARY
22+
NAMES
23+
cbor
24+
libcbor
25+
PATHS
26+
/usr/lib
27+
/usr/lib64
28+
/usr/local/lib
29+
/usr/local/lib64
30+
/opt/local/lib
31+
/sw/lib
32+
${CMAKE_LIBRARY_PATH}
33+
${CMAKE_INSTALL_PREFIX}/lib
34+
)
35+
36+
include(FindPackageHandleStandardArgs)
37+
find_package_handle_standard_args(CBOR FOUND_VAR CBOR_FOUND REQUIRED_VARS CBOR_INCLUDE_DIR CBOR_LIBRARY)

src/lcbor.c renamed to src/cbor.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file lcbor.h
2+
* @file cbor.c
33
* @author MeherRushi <meherrrushi2@gmail.com>
44
* @brief CBOR data parser for libyang (abstraction over libcbor)
55
*
@@ -12,14 +12,12 @@
1212
* https://opensource.org/licenses/BSD-3-Clause
1313
*/
1414

15-
#ifdef ENABLE_CBOR_SUPPORT
16-
1715
#include <assert.h>
1816
#include <ctype.h>
1917
#include <errno.h>
2018

2119
#include "in_internal.h"
22-
#include "lcbor.h"
20+
#include "cbor.h"
2321
#include "log.h"
2422
#include "ly_common.h"
2523

@@ -55,8 +53,10 @@ lycbor_token2str(enum cbor_type cbortype)
5553
*/
5654
void lycbor_ctx_free(struct lycbor_ctx *cborctx)
5755
{
58-
if (cborctx)
59-
{
56+
if (cborctx) {
57+
if (cborctx->cbor_data) {
58+
cbor_decref(&cborctx->cbor_data);
59+
}
6060
free(cborctx);
6161
}
6262
}
@@ -126,6 +126,4 @@ lycbor_ctx_new(const struct ly_ctx *ctx, struct ly_in *in, struct lycbor_ctx **c
126126

127127
*cborctx_p = cborctx;
128128
return ret;
129-
}
130-
131-
#endif /* ENABLE_CBOR_SUPPORT */
129+
}

src/lcbor.h renamed to src/cbor.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file lcbor.h
2+
* @file cbor.h
33
* @author MeherRushi <meherrrushi2@gmail.com>
44
* @brief CBOR data parser routines for libyang (abstraction over libcbor)
55
*
@@ -12,10 +12,8 @@
1212
* https://opensource.org/licenses/BSD-3-Clause
1313
*/
1414

15-
#ifndef LY_LCBOR_H_
16-
#define LY_LCBOR_H_
17-
18-
#ifdef ENABLE_CBOR_SUPPORT
15+
#ifndef LY_CBOR_H_
16+
#define LY_CBOR_H_
1917

2018
#include <stddef.h>
2119
#include <stdint.h>
@@ -53,6 +51,14 @@ struct lycbor_ctx {
5351
} backup;
5452
};
5553

54+
/**
55+
* @brief Get a human-readable name for a CBOR type.
56+
*
57+
* @param[in] cbortype CBOR type.
58+
* @return String representation of the CBOR type.
59+
*/
60+
const char *lycbor_token2str(enum cbor_type cbortype);
61+
5662
/**
5763
* @brief Create new CBOR context for parsing.
5864
*
@@ -72,6 +78,4 @@ lycbor_ctx_new(const struct ly_ctx *ctx, struct ly_in *in, struct lycbor_ctx **c
7278
void
7379
lycbor_ctx_free(struct lycbor_ctx *cborctx);
7480

75-
#endif /* ENABLE_CBOR_SUPPORT */
76-
77-
#endif /* LY_LCBOR_H_ */
81+
#endif /* LY_CBOR_H_ */

0 commit comments

Comments
 (0)