Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file libyang.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | b475096 | 2022-10-06 15:33:35 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 5 | * @brief The main libyang public header. |
| 6 | * |
Michal Vasko | b131989 | 2024-02-26 16:15:40 +0100 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2024 CESNET, z.s.p.o. |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
| 15 | |
| 16 | #ifndef LY_LIBYANG_H_ |
| 17 | #define LY_LIBYANG_H_ |
| 18 | |
Radek Krejci | 0af5f5d | 2018-09-07 15:00:30 +0200 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 25 | #include "context.h" |
| 26 | #include "dict.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 27 | #include "in.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 28 | #include "log.h" |
Michal Vasko | 5c00c07 | 2022-11-08 12:22:19 +0100 | [diff] [blame] | 29 | #include "metadata.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 30 | #include "out.h" |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 31 | #include "parser_data.h" |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 32 | #include "parser_schema.h" |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 33 | #include "printer_data.h" |
| 34 | #include "printer_schema.h" |
Radek Krejci | 6caa6ab | 2018-10-24 10:04:48 +0200 | [diff] [blame] | 35 | #include "set.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 36 | #include "tree.h" |
| 37 | #include "tree_data.h" |
Radek Krejci | 6caa6ab | 2018-10-24 10:04:48 +0200 | [diff] [blame] | 38 | #include "tree_schema.h" |
| 39 | |
Michal Vasko | ed27758 | 2024-03-28 09:55:31 +0100 | [diff] [blame] | 40 | /** |
| 41 | * @brief libyang v3 compatibility macros with v2. |
| 42 | */ |
| 43 | #define ly_strerrcode ly_strerr |
| 44 | #define ly_last_errmsg ly_last_logmsg |
| 45 | #define ly_errcode(ctx) (ly_err_last(ctx) ? ly_err_last(ctx)->err : 0) |
| 46 | #define ly_errmsg(ctx) (ly_err_last(ctx) ? ly_err_last(ctx)->msg : NULL) |
| 47 | #define ly_errpath(ctx) (ly_err_last(ctx) ? (ly_err_last(ctx)->data_path ? ly_err_last(ctx)->data_path : ly_err_last(ctx)->schema_path) : NULL) |
| 48 | #define ly_vecode(ctx) (ly_err_last(ctx) ? ly_err_last(ctx)->vecode : 0) |
| 49 | |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 50 | /* |
| 51 | * The following headers are supposed to be included explicitly: |
Michal Vasko | ae130f5 | 2023-04-20 14:25:16 +0200 | [diff] [blame] | 52 | * - hash_table.h |
Michal Vasko | b475096 | 2022-10-06 15:33:35 +0200 | [diff] [blame] | 53 | * - metadata.h |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 54 | * - plugins_types.h |
| 55 | * - plugins_exts.h |
| 56 | */ |
| 57 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 58 | /** |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 59 | * @mainpage About |
| 60 | * |
| 61 | * libyang is a library implementing processing of the YANG schemas and data modeled by the YANG language. The |
| 62 | * library is implemented in C for GNU/Linux and provides C API. |
| 63 | * |
| 64 | * @section about-features Main Features |
| 65 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 66 | * - [Parsing (and validating) schemas](@ref howtoSchema) in YANG format. |
| 67 | * - [Parsing (and validating) schemas](@ref howtoSchema) in YIN format. |
| 68 | * - [Parsing, validating and printing instance data](@ref howtoData) in XML format. |
| 69 | * - [Parsing, validating and printing instance data](@ref howtoData) in JSON format |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 70 | * ([RFC 7951](https://tools.ietf.org/html/rfc7951)). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 71 | * - [Manipulation with the instance data](@ref howtoDataManipulation). |
| 72 | * - Support for [default values in the instance data](@ref howtoDataWD) ([RFC 6243](https://tools.ietf.org/html/rfc6243)). |
| 73 | * - Support for [YANG extensions and user types](@ref howtoPlugins). |
Radek Krejci | 7510412 | 2021-04-01 15:37:45 +0200 | [diff] [blame] | 74 | * - Support for [YANG Metadata](@ref howtoDataMetadata) ([RFC 7952](https://tools.ietf.org/html/rfc6243)). |
Michal Vasko | 1fd2741 | 2022-02-11 10:04:50 +0100 | [diff] [blame] | 75 | * - Support for [YANG Schema Mount](@ref howtoDataMountpoint) ([RFC 8528](https://tools.ietf.org/html/rfc8528)). |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 76 | * |
| 77 | * The current implementation covers YANG 1.0 ([RFC 6020](https://tools.ietf.org/html/rfc6020)) as well as |
| 78 | * YANG 1.1 ([RFC 7950](https://tools.ietf.org/html/rfc7950)). |
| 79 | * |
| 80 | * @section about-license License |
| 81 | * |
Michal Vasko | b131989 | 2024-02-26 16:15:40 +0100 | [diff] [blame] | 82 | * Copyright (c) 2015-2024 CESNET, z.s.p.o. |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 83 | * |
| 84 | * (The BSD 3-Clause License) |
| 85 | * |
| 86 | * Redistribution and use in source and binary forms, with or without |
| 87 | * modification, are permitted provided that the following conditions |
| 88 | * are met: |
| 89 | * 1. Redistributions of source code must retain the above copyright |
| 90 | * notice, this list of conditions and the following disclaimer. |
| 91 | * 2. Redistributions in binary form must reproduce the above copyright |
| 92 | * notice, this list of conditions and the following disclaimer in |
| 93 | * the documentation and/or other materials provided with the |
| 94 | * distribution. |
| 95 | * 3. Neither the name of the Company nor the names of its contributors |
| 96 | * may be used to endorse or promote products derived from this |
| 97 | * software without specific prior written permission. |
| 98 | */ |
| 99 | |
| 100 | /** |
Radek Krejci | 52785a2 | 2019-09-11 12:57:26 +0200 | [diff] [blame] | 101 | * @page howto libyang API Overview |
Radek Krejci | e53a8dc | 2018-10-17 12:52:40 +0200 | [diff] [blame] | 102 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 103 | * @section howtoGeneral General notes |
| 104 | * |
| 105 | * libyang is primarily intended for handling data modeled by YANG modeling language, so the library is supposed to be optimized |
| 106 | * for this purpose. However, as a side effect, the library has to be able precisely process YANG modules. Thus, it is usable by |
| 107 | * YANG module authors to validate their modules and schemas in the development process. |
| 108 | * |
| 109 | * - @subpage howtoStructures |
| 110 | * - @subpage howtoErrors |
| 111 | * - @subpage howtoLogger |
| 112 | * - @subpage howtoThreads |
| 113 | * - @subpage howtoContext |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 114 | * - @subpage howtoInput |
| 115 | * - @subpage howtoOutput |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 116 | * - @subpage howtoSchema |
| 117 | * - @subpage howtoData |
| 118 | * - @subpage howtoXPath |
| 119 | * - @subpage howtoPlugins |
| 120 | */ |
| 121 | |
| 122 | /** |
| 123 | * @page howtoStructures Data Structures |
| 124 | * |
| 125 | * @section sizedarrays Sized Arrays |
| 126 | * |
| 127 | * The structure starts with 32bit number storing size of the array - the number of the items inside. The size is part of the |
| 128 | * array to have it allocated together with the array itself only when it is needed. However, the pointers to the array always |
| 129 | * points after the 32b number, so items can be accessed directly as for standard C arrays. Because of a known size (available |
| 130 | * via ::LY_ARRAY_COUNT macro), it is not terminated by any special byte (sequence), so there is also no limitation for specific |
| 131 | * content of the stored records (e.g. that first byte must not be NULL). |
| 132 | * |
| 133 | * The sized arrays must be carefully freed (which should be done anyway only internally), since pointers to the sized arrays used |
| 134 | * in libyang structures, does not point to the beginning of the allocated space. |
| 135 | * |
| 136 | * - ::LY_ARRAY_COUNT |
| 137 | * - ::LY_ARRAY_FOR |
| 138 | * |
| 139 | * @section struct_lists Lists |
| 140 | * |
| 141 | * The lists are structures connected via a `next` and `prev` pointers. Iterating over the siblings can be simply done by |
| 142 | * ::LY_LIST_FOR macro. Examples of such structures are ::lyd_node or ::lysc_node. |
| 143 | * |
| 144 | * The `prev` pointer is always filled. In case there is just a single item in the list, the `prev` pointer points to the |
| 145 | * item itself. Otherwise, the `prev` pointer of the first item points to the last item of the list. In contrast, the |
| 146 | * `next` pointer of the last item in the list is always NULL. |
| 147 | */ |
| 148 | |
| 149 | /** |
Michal Vasko | 5a5e7f8 | 2021-04-15 11:11:03 +0200 | [diff] [blame] | 150 | * @page howtoThreads Threading Limitations |
| 151 | * |
| 152 | * @section context Context |
| 153 | * |
| 154 | * It is safe to read from ::ly_ctx structure concurrently and use its dictionary, which is protected by a lock. |
| 155 | * Thread-safe functions include any ones working with data trees (only context dictionary is accessed) and all |
| 156 | * the `ly_ctx_get_*()` functions. Generally, they are the functions with `const` context parameter. |
| 157 | * |
| 158 | * @section data Data Trees |
| 159 | * |
| 160 | * Data trees are not internally synchronized so the general safe practice of a single writer **or** several concurrent |
| 161 | * readers should be followed. Specifically, only the functions with non-const ::lyd_node parameters modify the node(s) |
| 162 | * and no concurrent execution of such functions should be allowed on a single data tree or subtrees of one. |
| 163 | */ |
| 164 | |
| 165 | /** |
Radek Krejci | 290a6a5 | 2019-09-12 17:13:17 +0200 | [diff] [blame] | 166 | * @internal |
| 167 | * @page internals Developers' Notes |
| 168 | * @tableofcontents |
| 169 | * |
| 170 | * Following texts describes various internal subsystems and mechanism in libyang which are hidden from external users, but important |
| 171 | * for libyang developers. The texts should explain various decisions made and internal processes utilized in libyang. |
| 172 | */ |
| 173 | |
Radek Krejci | 0af5f5d | 2018-09-07 15:00:30 +0200 | [diff] [blame] | 174 | #ifdef __cplusplus |
| 175 | } |
| 176 | #endif |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 177 | |
| 178 | #endif /* LY_LIBYANG_H_ */ |