Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file printer.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief Printers for libyang |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Michal Vasko | 8de098c | 2016-02-26 10:00:25 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef LY_PRINTER_H_ |
| 16 | #define LY_PRINTER_H_ |
| 17 | |
| 18 | #include "libyang.h" |
| 19 | #include "tree_schema.h" |
| 20 | #include "tree_internal.h" |
| 21 | |
| 22 | typedef enum LYOUT_TYPE { |
| 23 | LYOUT_FD, /**< file descriptor */ |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 24 | LYOUT_STREAM, /**< FILE stream */ |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 25 | LYOUT_MEMORY, /**< memory */ |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 26 | LYOUT_CALLBACK /**< print via provided callback */ |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 27 | } LYOUT_TYPE; |
| 28 | |
| 29 | struct lyout { |
| 30 | LYOUT_TYPE type; |
| 31 | union { |
| 32 | int fd; |
| 33 | FILE *f; |
Radek Krejci | 50929eb | 2015-10-09 18:14:15 +0200 | [diff] [blame] | 34 | struct { |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 35 | char *buf; |
| 36 | size_t len; |
| 37 | size_t size; |
| 38 | } mem; |
| 39 | struct { |
Radek Krejci | 50929eb | 2015-10-09 18:14:15 +0200 | [diff] [blame] | 40 | ssize_t (*f)(void *arg, const void *buf, size_t count); |
| 41 | void *arg; |
| 42 | } clb; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 43 | } method; |
Michal Vasko | 1e82a3b | 2018-07-03 12:16:58 +0200 | [diff] [blame] | 44 | |
| 45 | /* buffer for holes */ |
| 46 | char *buffered; |
| 47 | size_t buf_len; |
| 48 | size_t buf_size; |
| 49 | |
| 50 | /* hole counter */ |
| 51 | size_t hole_count; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
Radek Krejci | 8974f45 | 2017-01-13 12:34:19 +0100 | [diff] [blame] | 54 | struct ext_substmt_info_s { |
| 55 | const char *name; |
| 56 | const char *arg; |
| 57 | int flags; |
| 58 | #define SUBST_FLAG_YIN 0x1 /**< has YIN element */ |
| 59 | #define SUBST_FLAG_ID 0x2 /**< the value is identifier -> no quotes */ |
| 60 | }; |
| 61 | |
| 62 | /* filled in printer.c */ |
| 63 | extern struct ext_substmt_info_s ext_substmt_info[]; |
| 64 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 65 | /** |
| 66 | * @brief Generic printer, replacement for printf() / write() / etc |
| 67 | */ |
| 68 | int ly_print(struct lyout *out, const char *format, ...); |
Michal Vasko | 95068c4 | 2016-03-24 14:58:11 +0100 | [diff] [blame] | 69 | void ly_print_flush(struct lyout *out); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 70 | int ly_write(struct lyout *out, const char *buf, size_t count); |
Michal Vasko | 1e82a3b | 2018-07-03 12:16:58 +0200 | [diff] [blame] | 71 | int ly_write_skip(struct lyout *out, size_t count, size_t *position); |
| 72 | int ly_write_skipped(struct lyout *out, size_t position, const char *buf, size_t count); |
| 73 | |
Radek Krejci | 8aa90c9 | 2018-08-13 15:00:54 +0200 | [diff] [blame] | 74 | /* prefix_kind: 0 - print import prefixes for foreign features, 1 - print module names, 2 - print prefixes (tree printer), 3 - print module names including revisions (JSONS printer) */ |
Michal Vasko | 568b195 | 2018-01-30 15:53:30 +0100 | [diff] [blame] | 75 | int ly_print_iffeature(struct lyout *out, const struct lys_module *module, struct lys_iffeature *expr, int prefix_kind); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 76 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 77 | int yang_print_model(struct lyout *out, const struct lys_module *module); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 78 | int yin_print_model(struct lyout *out, const struct lys_module *module); |
Michal Vasko | 568b195 | 2018-01-30 15:53:30 +0100 | [diff] [blame] | 79 | int tree_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path, int line_length, int options); |
| 80 | int info_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path); |
Radek Krejci | 0e67ac4 | 2018-07-25 15:46:37 +0200 | [diff] [blame] | 81 | int jsons_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 82 | |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame] | 83 | int json_print_data(struct lyout *out, const struct lyd_node *root, int options); |
Michal Vasko | 95068c4 | 2016-03-24 14:58:11 +0100 | [diff] [blame] | 84 | int xml_print_data(struct lyout *out, const struct lyd_node *root, int options); |
Michal Vasko | b3c31bd | 2017-07-17 10:01:48 +0200 | [diff] [blame] | 85 | int xml_print_node(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options); |
Michal Vasko | 1e82a3b | 2018-07-03 12:16:58 +0200 | [diff] [blame] | 86 | int lyb_print_data(struct lyout *out, const struct lyd_node *root, int options); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 87 | |
Radek Krejci | 0e67ac4 | 2018-07-25 15:46:37 +0200 | [diff] [blame] | 88 | int lys_print_target(struct lyout *out, const struct lys_module *module, const char *target_schema_path, |
| 89 | void (*clb_print_typedef)(struct lyout*, const struct lys_tpdf*, int*), |
| 90 | void (*clb_print_identity)(struct lyout*, const struct lys_ident*, int*), |
| 91 | void (*clb_print_feature)(struct lyout*, const struct lys_feature*, int*), |
| 92 | void (*clb_print_type)(struct lyout*, const struct lys_type*, int*), |
| 93 | void (*clb_print_grouping)(struct lyout*, const struct lys_node*, int*), |
| 94 | void (*clb_print_container)(struct lyout*, const struct lys_node*, int*), |
| 95 | void (*clb_print_choice)(struct lyout*, const struct lys_node*, int*), |
| 96 | void (*clb_print_leaf)(struct lyout*, const struct lys_node*, int*), |
| 97 | void (*clb_print_leaflist)(struct lyout*, const struct lys_node*, int*), |
| 98 | void (*clb_print_list)(struct lyout*, const struct lys_node*, int*), |
| 99 | void (*clb_print_anydata)(struct lyout*, const struct lys_node*, int*), |
| 100 | void (*clb_print_case)(struct lyout*, const struct lys_node*, int*), |
| 101 | void (*clb_print_notif)(struct lyout*, const struct lys_node*, int*), |
| 102 | void (*clb_print_rpc)(struct lyout*, const struct lys_node*, int*), |
| 103 | void (*clb_print_action)(struct lyout*, const struct lys_node*, int*), |
| 104 | void (*clb_print_input)(struct lyout*, const struct lys_node*, int*), |
| 105 | void (*clb_print_output)(struct lyout*, const struct lys_node*, int*)); |
| 106 | |
Radek Krejci | 572f122 | 2016-09-01 09:52:47 +0200 | [diff] [blame] | 107 | /** |
| 108 | * get know if the node is supposed to be printed according to the specified with-default mode |
| 109 | * return 1 - print, 0 - do not print |
| 110 | */ |
| 111 | int lyd_wd_toprint(const struct lyd_node *node, int options); |
| 112 | |
Radek Krejci | 998a750 | 2015-10-26 15:54:33 +0100 | [diff] [blame] | 113 | /* 0 - same, 1 - different */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 114 | int nscmp(const struct lyd_node *node1, const struct lyd_node *node2); |
Radek Krejci | 998a750 | 2015-10-26 15:54:33 +0100 | [diff] [blame] | 115 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 116 | #endif /* LY_PRINTER_H_ */ |