Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 1 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 2 | * @file libyang.h |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 4 | * @brief The main libyang public header. |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
| 20 | */ |
| 21 | |
| 22 | #ifndef LY_LIBYANG_H_ |
| 23 | #define LY_LIBYANG_H_ |
| 24 | |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 27 | #include "tree.h" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 28 | |
| 29 | int ly_model_print(FILE *f, struct ly_module *module, LY_MFORMAT format); |
| 30 | |
| 31 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 32 | * @defgroup libyang libyang |
| 33 | * @{ |
| 34 | * |
| 35 | * General libyang functions and structures. |
| 36 | */ |
| 37 | |
| 38 | /** |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 39 | * @brief libyang context handler. |
| 40 | */ |
| 41 | struct ly_ctx; |
| 42 | |
| 43 | /** |
| 44 | * @brief Create libyang context |
| 45 | * |
| 46 | * Context is used to hold all information about data models. Usually, the |
| 47 | * application is supposed to work with a single context in which libyang is |
| 48 | * holding all data models and other internal information according to which |
| 49 | * the instance data will be processed and validated. Therefore, also each |
| 50 | * instance data are connected |
| 51 | * |
| 52 | * @param[in] search_dir Directory where libyang will search for the imported |
| 53 | * or included modules and submodules. If no such directory is available, NULL |
| 54 | * is accepted. |
| 55 | * |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 56 | * @return Pointer to the created libyang context, NULL in case of error. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 57 | */ |
| 58 | struct ly_ctx *ly_ctx_new(const char *search_dir); |
| 59 | |
| 60 | /** |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 61 | * @brief Get pointer to the data model structure of the specified name. |
| 62 | * |
| 63 | * If the module is not yet loaded in the context, libyang tries to find it in |
| 64 | * the search directory specified when the context was created by ly_ctx_new(). |
| 65 | * |
| 66 | * @param[in] ctx Context to work in. |
| 67 | * @param[in] name Name of the YANG module to get. |
| 68 | * @param[in] revision Optional revision date of the YANG module to get. If not |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 69 | * specified, the newest revision is returned (TODO). |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame^] | 70 | * @param[in] read Flag for reading the module from a file. If set to 0, libyang |
| 71 | * searches for the module only in the modules already loaded to the context. |
| 72 | * @return Pointer to the data model structure. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 73 | */ |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 74 | struct ly_module *ly_ctx_get_module(struct ly_ctx *ctx, const char *name, |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame^] | 75 | const char *revision, int read); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 76 | |
| 77 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 78 | * @brief Free all internal structures of the specified context. |
| 79 | * |
| 80 | * The function should be used before terminating the application to destroy |
| 81 | * and free all structures internally used by libyang. If the caller uses |
| 82 | * multiple contexts, the function should be called for each used context. |
| 83 | * |
| 84 | * All instance data are supposed to be freed before destroying the context. |
| 85 | * Data models are destroyed automatically as part of ly_ctx_destroy() call. |
| 86 | * |
| 87 | * @param[in] ctx libyang context to destroy |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 88 | */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 89 | void ly_ctx_destroy(struct ly_ctx *ctx); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * @brief Load a data model into the specified context. |
| 93 | * |
| 94 | * @param[in] ctx libyang context where to process the data model. |
| 95 | * @param[in] data The string containing the dumped data model in the specified |
| 96 | * format |
| 97 | * @param[in] format Format of the input data (YANG or YIN). |
| 98 | * @return Pointer to the data model structure or NULL on error. |
| 99 | */ |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 100 | struct ly_module *ly_module_read(struct ly_ctx *ctx, const char *data, |
| 101 | LY_MFORMAT format); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 102 | |
| 103 | |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 104 | struct ly_module *ly_module_read_fd(struct ly_ctx *ctx, int fd, |
| 105 | LY_MFORMAT format); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * @brief Free data model |
| 109 | * |
| 110 | * It is up to the caller that there is no instance data using the module |
| 111 | * being freed. |
| 112 | * |
| 113 | * @param[in] module Data model to free. |
| 114 | */ |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 115 | void ly_module_free(struct ly_module *module); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 116 | |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 117 | /**@} libyang */ |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 118 | |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 119 | /** |
| 120 | * @page howto How To ... |
| 121 | * |
| 122 | * - @subpage howtologger |
| 123 | */ |
| 124 | |
| 125 | /** |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 126 | * |
| 127 | * @page howtologger Logger |
| 128 | * |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 129 | * There are 4 verbosity levels defined as ::LY_LOG_LEVEL. The level can be |
| 130 | * changed by the ly_verb() function. By default, the verbosity level is |
| 131 | * set to #LY_LLERR value. |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 132 | * |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 133 | * In case the logger has an error message (LY_LLERR) to print, also an error |
| 134 | * code is recorded in extern ly_errno variable. Possible values are of type |
| 135 | * ::LY_ERR. |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 136 | */ |
| 137 | |
| 138 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 139 | * @defgroup logger Logger |
| 140 | * @{ |
| 141 | * |
| 142 | * Publicly visible functions and values of the libyang logger. For more |
| 143 | * information, see \ref howtologger. |
| 144 | */ |
| 145 | |
| 146 | /** |
| 147 | * @typedef LY_LOG_LEVEL |
| 148 | * @brief Verbosity levels of the libyang logger. |
| 149 | */ |
| 150 | typedef enum { |
| 151 | LY_LLERR, /**< Print only error messages. */ |
| 152 | LY_LLWRN, /**< Print error and warning messages. */ |
| 153 | LY_LLVRB, /**< Besides errors and warnings, print some other verbose messages. */ |
| 154 | LY_LLDBG /**< Print all messages including some development debug messages. */ |
| 155 | } LY_LOG_LEVEL; |
| 156 | |
| 157 | /** |
| 158 | * @brief Set logger verbosity level. |
| 159 | * @param[in] level Verbosity level. |
| 160 | */ |
| 161 | void ly_verb(LY_LOG_LEVEL level); |
| 162 | |
| 163 | /** |
| 164 | * @typedef LY_ERR |
| 165 | * @brief libyang's error codes available via ly_errno extern variable |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 166 | * @ingroup logger |
| 167 | */ |
| 168 | typedef enum { |
Radek Krejci | 812b10a | 2015-05-28 16:48:25 +0200 | [diff] [blame] | 169 | LY_EMEM, /**< Memory allocation failure */ |
| 170 | LY_ESYS, /**< System call failure */ |
| 171 | LY_EINVAL, /**< Invalid value */ |
| 172 | LY_EINT, /**< Internal error */ |
| 173 | LY_EVALID /**< Validation failure */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 174 | } LY_ERR; |
| 175 | extern LY_ERR ly_errno; |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 176 | |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 177 | /**@} logger */ |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 178 | |
| 179 | #endif /* LY_LIBYANG_H_ */ |