blob: 660b32bcac4bf2cbd968acf01b69cbcb16fbe4b8 [file] [log] [blame]
Radek Krejci76b07902015-10-09 09:11:25 +02001/**
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 Krejci54f6fb32016-02-24 12:56:39 +01008 * 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 Vasko8de098c2016-02-26 10:00:25 +010011 *
Radek Krejci54f6fb32016-02-24 12:56:39 +010012 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejci76b07902015-10-09 09:11:25 +020013 */
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
22typedef enum LYOUT_TYPE {
23 LYOUT_FD, /**< file descriptor */
Radek Krejci6140e4e2015-10-09 15:50:55 +020024 LYOUT_STREAM, /**< FILE stream */
Radek Krejci2fa0fc12015-10-14 18:14:29 +020025 LYOUT_MEMORY, /**< memory */
Radek Krejci6140e4e2015-10-09 15:50:55 +020026 LYOUT_CALLBACK /**< print via provided callback */
Radek Krejci76b07902015-10-09 09:11:25 +020027} LYOUT_TYPE;
28
29struct lyout {
30 LYOUT_TYPE type;
31 union {
32 int fd;
33 FILE *f;
Radek Krejci50929eb2015-10-09 18:14:15 +020034 struct {
Radek Krejci2fa0fc12015-10-14 18:14:29 +020035 char *buf;
36 size_t len;
37 size_t size;
38 } mem;
39 struct {
Radek Krejci50929eb2015-10-09 18:14:15 +020040 ssize_t (*f)(void *arg, const void *buf, size_t count);
41 void *arg;
42 } clb;
Radek Krejci76b07902015-10-09 09:11:25 +020043 } method;
Michal Vasko1e82a3b2018-07-03 12:16:58 +020044
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 Krejci76b07902015-10-09 09:11:25 +020052};
53
Radek Krejci8974f452017-01-13 12:34:19 +010054struct 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 */
63extern struct ext_substmt_info_s ext_substmt_info[];
64
Radek Krejci76b07902015-10-09 09:11:25 +020065/**
66 * @brief Generic printer, replacement for printf() / write() / etc
67 */
68int ly_print(struct lyout *out, const char *format, ...);
Michal Vasko95068c42016-03-24 14:58:11 +010069void ly_print_flush(struct lyout *out);
Radek Krejci76b07902015-10-09 09:11:25 +020070int ly_write(struct lyout *out, const char *buf, size_t count);
Michal Vasko1e82a3b2018-07-03 12:16:58 +020071int ly_write_skip(struct lyout *out, size_t count, size_t *position);
72int ly_write_skipped(struct lyout *out, size_t position, const char *buf, size_t count);
73
Radek Krejci8aa90c92018-08-13 15:00:54 +020074/* 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 Vasko568b1952018-01-30 15:53:30 +010075int ly_print_iffeature(struct lyout *out, const struct lys_module *module, struct lys_iffeature *expr, int prefix_kind);
Radek Krejci76b07902015-10-09 09:11:25 +020076
Michal Vasko1e62a092015-12-01 12:27:20 +010077int yang_print_model(struct lyout *out, const struct lys_module *module);
Michal Vaskoa63ca342016-02-05 14:29:19 +010078int yin_print_model(struct lyout *out, const struct lys_module *module);
Michal Vasko568b1952018-01-30 15:53:30 +010079int tree_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path, int line_length, int options);
80int info_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path);
Radek Krejci0e67ac42018-07-25 15:46:37 +020081int jsons_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path);
Radek Krejci76b07902015-10-09 09:11:25 +020082
Radek Krejci5044be32016-01-18 17:05:51 +010083int json_print_data(struct lyout *out, const struct lyd_node *root, int options);
Michal Vasko95068c42016-03-24 14:58:11 +010084int xml_print_data(struct lyout *out, const struct lyd_node *root, int options);
Michal Vaskob3c31bd2017-07-17 10:01:48 +020085int xml_print_node(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options);
Michal Vasko1e82a3b2018-07-03 12:16:58 +020086int lyb_print_data(struct lyout *out, const struct lyd_node *root, int options);
Radek Krejci76b07902015-10-09 09:11:25 +020087
Radek Krejci0e67ac42018-07-25 15:46:37 +020088int 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 Krejci572f1222016-09-01 09:52:47 +0200107/**
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 */
111int lyd_wd_toprint(const struct lyd_node *node, int options);
112
Radek Krejci998a7502015-10-26 15:54:33 +0100113/* 0 - same, 1 - different */
Michal Vasko1e62a092015-12-01 12:27:20 +0100114int nscmp(const struct lyd_node *node1, const struct lyd_node *node2);
Radek Krejci998a7502015-10-26 15:54:33 +0100115
Radek Krejci76b07902015-10-09 09:11:25 +0200116#endif /* LY_PRINTER_H_ */