blob: 9ce7dd86c739a01e7d49dfcea05ae0ccb65bf757 [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 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of the Company nor the names of its contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 */
21
22#ifndef LY_PRINTER_H_
23#define LY_PRINTER_H_
24
25#include "libyang.h"
26#include "tree_schema.h"
27#include "tree_internal.h"
28
29typedef enum LYOUT_TYPE {
30 LYOUT_FD, /**< file descriptor */
Radek Krejci6140e4e2015-10-09 15:50:55 +020031 LYOUT_STREAM, /**< FILE stream */
32 LYOUT_CALLBACK /**< print via provided callback */
Radek Krejci76b07902015-10-09 09:11:25 +020033} LYOUT_TYPE;
34
35struct lyout {
36 LYOUT_TYPE type;
37 union {
38 int fd;
39 FILE *f;
Radek Krejci6140e4e2015-10-09 15:50:55 +020040 ssize_t (*writeclb)(const void *buf, size_t count);
Radek Krejci76b07902015-10-09 09:11:25 +020041 } method;
42};
43
44/**
45 * @brief Generic printer, replacement for printf() / write() / etc
46 */
47int ly_print(struct lyout *out, const char *format, ...);
48int ly_write(struct lyout *out, const char *buf, size_t count);
49
50int yang_print_model(struct lyout *out, struct lys_module *module);
51int tree_print_model(struct lyout *out, struct lys_module *module);
52int info_print_model(struct lyout *out, struct lys_module *module, const char *target_node);
53
54int json_print_data(struct lyout *out, struct lyd_node *root);
Radek Krejcibac81762015-10-09 10:19:52 +020055int xml_print_data(struct lyout *out, struct lyd_node *root, int format);
Radek Krejci76b07902015-10-09 09:11:25 +020056
57#endif /* LY_PRINTER_H_ */