blob: eb13049f6489a10431beae0878ad1093fc8e9471 [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 */
Radek Krejci2fa0fc12015-10-14 18:14:29 +020032 LYOUT_MEMORY, /**< memory */
Radek Krejci6140e4e2015-10-09 15:50:55 +020033 LYOUT_CALLBACK /**< print via provided callback */
Radek Krejci76b07902015-10-09 09:11:25 +020034} LYOUT_TYPE;
35
36struct lyout {
37 LYOUT_TYPE type;
38 union {
39 int fd;
40 FILE *f;
Radek Krejci50929eb2015-10-09 18:14:15 +020041 struct {
Radek Krejci2fa0fc12015-10-14 18:14:29 +020042 char *buf;
43 size_t len;
44 size_t size;
45 } mem;
46 struct {
Radek Krejci50929eb2015-10-09 18:14:15 +020047 ssize_t (*f)(void *arg, const void *buf, size_t count);
48 void *arg;
49 } clb;
Radek Krejci76b07902015-10-09 09:11:25 +020050 } method;
51};
52
53/**
54 * @brief Generic printer, replacement for printf() / write() / etc
55 */
56int ly_print(struct lyout *out, const char *format, ...);
57int ly_write(struct lyout *out, const char *buf, size_t count);
58
Michal Vasko1e62a092015-12-01 12:27:20 +010059int yang_print_model(struct lyout *out, const struct lys_module *module);
60int tree_print_model(struct lyout *out, const struct lys_module *module);
61int info_print_model(struct lyout *out, const struct lys_module *module, const char *target_node);
Radek Krejci76b07902015-10-09 09:11:25 +020062
Michal Vasko1e62a092015-12-01 12:27:20 +010063int json_print_data(struct lyout *out, const struct lyd_node *root);
64int xml_print_data(struct lyout *out, const struct lyd_node *root, int format);
Radek Krejci76b07902015-10-09 09:11:25 +020065
Radek Krejci998a7502015-10-26 15:54:33 +010066/* 0 - same, 1 - different */
Michal Vasko1e62a092015-12-01 12:27:20 +010067int nscmp(const struct lyd_node *node1, const struct lyd_node *node2);
Radek Krejci998a7502015-10-26 15:54:33 +010068
Radek Krejci76b07902015-10-09 09:11:25 +020069#endif /* LY_PRINTER_H_ */