Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1 | /** |
| 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 | |
| 29 | typedef enum LYOUT_TYPE { |
| 30 | LYOUT_FD, /**< file descriptor */ |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 31 | LYOUT_STREAM, /**< FILE stream */ |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 32 | LYOUT_MEMORY, /**< memory */ |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 33 | LYOUT_CALLBACK /**< print via provided callback */ |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 34 | } LYOUT_TYPE; |
| 35 | |
| 36 | struct lyout { |
| 37 | LYOUT_TYPE type; |
| 38 | union { |
| 39 | int fd; |
| 40 | FILE *f; |
Radek Krejci | 50929eb | 2015-10-09 18:14:15 +0200 | [diff] [blame] | 41 | struct { |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 42 | char *buf; |
| 43 | size_t len; |
| 44 | size_t size; |
| 45 | } mem; |
| 46 | struct { |
Radek Krejci | 50929eb | 2015-10-09 18:14:15 +0200 | [diff] [blame] | 47 | ssize_t (*f)(void *arg, const void *buf, size_t count); |
| 48 | void *arg; |
| 49 | } clb; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 50 | } method; |
| 51 | }; |
| 52 | |
| 53 | /** |
| 54 | * @brief Generic printer, replacement for printf() / write() / etc |
| 55 | */ |
| 56 | int ly_print(struct lyout *out, const char *format, ...); |
| 57 | int ly_write(struct lyout *out, const char *buf, size_t count); |
| 58 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame^] | 59 | int yang_print_model(struct lyout *out, const struct lys_module *module); |
| 60 | int tree_print_model(struct lyout *out, const struct lys_module *module); |
| 61 | int info_print_model(struct lyout *out, const struct lys_module *module, const char *target_node); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 62 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame^] | 63 | int json_print_data(struct lyout *out, const struct lyd_node *root); |
| 64 | int xml_print_data(struct lyout *out, const struct lyd_node *root, int format); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 65 | |
Radek Krejci | 998a750 | 2015-10-26 15:54:33 +0100 | [diff] [blame] | 66 | /* 0 - same, 1 - different */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame^] | 67 | int nscmp(const struct lyd_node *node1, const struct lyd_node *node2); |
Radek Krejci | 998a750 | 2015-10-26 15:54:33 +0100 | [diff] [blame] | 68 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 69 | #endif /* LY_PRINTER_H_ */ |