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; |
| 44 | }; |
| 45 | |
Radek Krejci | 8974f45 | 2017-01-13 12:34:19 +0100 | [diff] [blame] | 46 | struct ext_substmt_info_s { |
| 47 | const char *name; |
| 48 | const char *arg; |
| 49 | int flags; |
| 50 | #define SUBST_FLAG_YIN 0x1 /**< has YIN element */ |
| 51 | #define SUBST_FLAG_ID 0x2 /**< the value is identifier -> no quotes */ |
| 52 | }; |
| 53 | |
| 54 | /* filled in printer.c */ |
| 55 | extern struct ext_substmt_info_s ext_substmt_info[]; |
| 56 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 57 | /** |
| 58 | * @brief Generic printer, replacement for printf() / write() / etc |
| 59 | */ |
| 60 | int ly_print(struct lyout *out, const char *format, ...); |
Michal Vasko | 95068c4 | 2016-03-24 14:58:11 +0100 | [diff] [blame] | 61 | void ly_print_flush(struct lyout *out); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 62 | int ly_write(struct lyout *out, const char *buf, size_t count); |
Michal Vasko | 77e8a95 | 2017-02-03 15:10:08 +0100 | [diff] [blame] | 63 | /* module_name_or_prefix: 1 - print module names for foreign if-features, 0 - print import prefixes */ |
| 64 | int ly_print_iffeature(struct lyout *out, const struct lys_module *module, struct lys_iffeature *expr, int module_name_or_prefix); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 65 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 66 | int yang_print_model(struct lyout *out, const struct lys_module *module); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 67 | int yin_print_model(struct lyout *out, const struct lys_module *module); |
Radek Krejci | d5bf08e | 2017-01-25 11:35:04 +0100 | [diff] [blame] | 68 | int tree_print_model(struct lyout *out, const struct lys_module *module, int groupings); |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 69 | int info_print_model(struct lyout *out, const struct lys_module *module, const char *target_node); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 70 | |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame] | 71 | 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] | 72 | 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^] | 73 | int xml_print_node(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 74 | |
Radek Krejci | 572f122 | 2016-09-01 09:52:47 +0200 | [diff] [blame] | 75 | /** |
| 76 | * get know if the node is supposed to be printed according to the specified with-default mode |
| 77 | * return 1 - print, 0 - do not print |
| 78 | */ |
| 79 | int lyd_wd_toprint(const struct lyd_node *node, int options); |
| 80 | |
Radek Krejci | 998a750 | 2015-10-26 15:54:33 +0100 | [diff] [blame] | 81 | /* 0 - same, 1 - different */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 82 | int nscmp(const struct lyd_node *node1, const struct lyd_node *node2); |
Radek Krejci | 998a750 | 2015-10-26 15:54:33 +0100 | [diff] [blame] | 83 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 84 | #endif /* LY_PRINTER_H_ */ |