blob: 58d3aa5f14e520df162d0b10dbb046a9e75bff27 [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
46/**
47 * @brief Generic printer, replacement for printf() / write() / etc
48 */
49int ly_print(struct lyout *out, const char *format, ...);
50int ly_write(struct lyout *out, const char *buf, size_t count);
51
Michal Vasko1e62a092015-12-01 12:27:20 +010052int yang_print_model(struct lyout *out, const struct lys_module *module);
Michal Vaskoa63ca342016-02-05 14:29:19 +010053int yin_print_model(struct lyout *out, const struct lys_module *module);
Michal Vasko1e62a092015-12-01 12:27:20 +010054int tree_print_model(struct lyout *out, const struct lys_module *module);
55int info_print_model(struct lyout *out, const struct lys_module *module, const char *target_node);
Radek Krejci76b07902015-10-09 09:11:25 +020056
Radek Krejci5044be32016-01-18 17:05:51 +010057int json_print_data(struct lyout *out, const struct lyd_node *root, int options);
58int xml_print_data(struct lyout *out, const struct lyd_node *root, int format, int options);
Radek Krejci76b07902015-10-09 09:11:25 +020059
Radek Krejci998a7502015-10-26 15:54:33 +010060/* 0 - same, 1 - different */
Michal Vasko1e62a092015-12-01 12:27:20 +010061int nscmp(const struct lyd_node *node1, const struct lyd_node *node2);
Radek Krejci998a7502015-10-26 15:54:33 +010062
Radek Krejci76b07902015-10-09 09:11:25 +020063#endif /* LY_PRINTER_H_ */