blob: 331d0afe28a45e31e660dd2c3e7567d2e3ccbefd [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;
44};
45
Radek Krejci8974f452017-01-13 12:34:19 +010046struct 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 */
55extern struct ext_substmt_info_s ext_substmt_info[];
56
Radek Krejci76b07902015-10-09 09:11:25 +020057/**
58 * @brief Generic printer, replacement for printf() / write() / etc
59 */
60int ly_print(struct lyout *out, const char *format, ...);
Michal Vasko95068c42016-03-24 14:58:11 +010061void ly_print_flush(struct lyout *out);
Radek Krejci76b07902015-10-09 09:11:25 +020062int ly_write(struct lyout *out, const char *buf, size_t count);
Michal Vasko77e8a952017-02-03 15:10:08 +010063/* module_name_or_prefix: 1 - print module names for foreign if-features, 0 - print import prefixes */
64int ly_print_iffeature(struct lyout *out, const struct lys_module *module, struct lys_iffeature *expr, int module_name_or_prefix);
Radek Krejci76b07902015-10-09 09:11:25 +020065
Michal Vasko1e62a092015-12-01 12:27:20 +010066int yang_print_model(struct lyout *out, const struct lys_module *module);
Michal Vaskoa63ca342016-02-05 14:29:19 +010067int yin_print_model(struct lyout *out, const struct lys_module *module);
Radek Krejcid5bf08e2017-01-25 11:35:04 +010068int tree_print_model(struct lyout *out, const struct lys_module *module, int groupings);
Michal Vasko1e62a092015-12-01 12:27:20 +010069int info_print_model(struct lyout *out, const struct lys_module *module, const char *target_node);
Radek Krejci76b07902015-10-09 09:11:25 +020070
Radek Krejci5044be32016-01-18 17:05:51 +010071int json_print_data(struct lyout *out, const struct lyd_node *root, int options);
Michal Vasko95068c42016-03-24 14:58:11 +010072int xml_print_data(struct lyout *out, const struct lyd_node *root, int options);
Michal Vaskob3c31bd2017-07-17 10:01:48 +020073int xml_print_node(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options);
Radek Krejci76b07902015-10-09 09:11:25 +020074
Radek Krejci572f1222016-09-01 09:52:47 +020075/**
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 */
79int lyd_wd_toprint(const struct lyd_node *node, int options);
80
Radek Krejci998a7502015-10-26 15:54:33 +010081/* 0 - same, 1 - different */
Michal Vasko1e62a092015-12-01 12:27:20 +010082int nscmp(const struct lyd_node *node1, const struct lyd_node *node2);
Radek Krejci998a7502015-10-26 15:54:33 +010083
Radek Krejci76b07902015-10-09 09:11:25 +020084#endif /* LY_PRINTER_H_ */