]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libxo/libxo/xo_encoder.h
Merge compiler-rt release_40 branch r292009.
[FreeBSD/FreeBSD.git] / contrib / libxo / libxo / xo_encoder.h
1 /*
2  * Copyright (c) 2015, Juniper Networks, Inc.
3  * All rights reserved.
4  * This SOFTWARE is licensed under the LICENSE provided in the
5  * ../Copyright file. By downloading, installing, copying, or otherwise
6  * using the SOFTWARE, you agree to be bound by the terms of that
7  * LICENSE.
8  * Phil Shafer, August 2015
9  */
10
11 /*
12  * NOTE WELL: This file is needed to software that implements an
13  * external encoder for libxo that allows libxo data to be encoded in
14  * new and bizarre formats.  General libxo code should _never_
15  * include this header file.
16  */
17
18 #ifndef XO_ENCODER_H
19 #define XO_ENCODER_H
20
21 /*
22  * Expose libxo's memory allocation functions
23  */
24 extern xo_realloc_func_t xo_realloc;
25 extern xo_free_func_t xo_free;
26
27 typedef unsigned xo_encoder_op_t;
28
29 /* Encoder operations; names are in xo_encoder.c:xo_encoder_op_name() */
30 #define XO_OP_UNKNOWN           0
31 #define XO_OP_CREATE            1 /* Called when the handle is init'd */
32 #define XO_OP_OPEN_CONTAINER    2
33 #define XO_OP_CLOSE_CONTAINER   3
34 #define XO_OP_OPEN_LIST         4
35 #define XO_OP_CLOSE_LIST        5
36 #define XO_OP_OPEN_LEAF_LIST    6
37 #define XO_OP_CLOSE_LEAF_LIST   7
38 #define XO_OP_OPEN_INSTANCE     8
39 #define XO_OP_CLOSE_INSTANCE    9
40 #define XO_OP_STRING            10 /* Quoted UTF-8 string */
41 #define XO_OP_CONTENT           11 /* Other content */
42 #define XO_OP_FINISH            12 /* Finish any pending output */
43 #define XO_OP_FLUSH             13 /* Flush any buffered output */
44 #define XO_OP_DESTROY           14 /* Clean up function */
45 #define XO_OP_ATTRIBUTE         15 /* Attribute name/value */
46 #define XO_OP_VERSION           16 /* Version string */
47
48 #define XO_ENCODER_HANDLER_ARGS                                 \
49         xo_handle_t *xop __attribute__ ((__unused__)),          \
50         xo_encoder_op_t op __attribute__ ((__unused__)),        \
51         const char *name __attribute__ ((__unused__)),          \
52         const char *value __attribute__ ((__unused__)),         \
53         void *private __attribute__ ((__unused__))
54
55 typedef int (*xo_encoder_func_t)(XO_ENCODER_HANDLER_ARGS);
56
57 typedef struct xo_encoder_init_args_s {
58     unsigned xei_version;          /* Current version */
59     xo_encoder_func_t xei_handler; /* Encoding handler */
60 } xo_encoder_init_args_t;
61
62 #define XO_ENCODER_VERSION      1 /* Current version */
63
64 #define XO_ENCODER_INIT_ARGS \
65     xo_encoder_init_args_t *arg __attribute__ ((__unused__))
66
67 typedef int (*xo_encoder_init_func_t)(XO_ENCODER_INIT_ARGS);
68 /*
69  * Each encoder library must define a function named xo_encoder_init
70  * that takes the arguments defined in XO_ENCODER_INIT_ARGS.  It
71  * should return zero for success.
72  */
73 #define XO_ENCODER_INIT_NAME_TOKEN xo_encoder_library_init
74 #define XO_STRINGIFY(_x) #_x
75 #define XO_STRINGIFY2(_x) XO_STRINGIFY(_x)
76 #define XO_ENCODER_INIT_NAME XO_STRINGIFY2(XO_ENCODER_INIT_NAME_TOKEN)
77 extern int XO_ENCODER_INIT_NAME_TOKEN (XO_ENCODER_INIT_ARGS);
78
79 void
80 xo_encoder_register (const char *name, xo_encoder_func_t func);
81
82 void
83 xo_encoder_unregister (const char *name);
84
85 void *
86 xo_get_private (xo_handle_t *xop);
87
88 void
89 xo_encoder_path_add (const char *path);
90
91 void
92 xo_set_private (xo_handle_t *xop, void *opaque);
93
94 xo_encoder_func_t
95 xo_get_encoder (xo_handle_t *xop);
96
97 void
98 xo_set_encoder (xo_handle_t *xop, xo_encoder_func_t encoder);
99
100 int
101 xo_encoder_init (xo_handle_t *xop, const char *name);
102
103 xo_handle_t *
104 xo_encoder_create (const char *name, xo_xof_flags_t flags);
105
106 int
107 xo_encoder_handle (xo_handle_t *xop, xo_encoder_op_t op,
108                    const char *name, const char *value);
109
110 void
111 xo_encoders_clean (void);
112
113 const char *
114 xo_encoder_op_name (xo_encoder_op_t op);
115
116 #endif /* XO_ENCODER_H */