2 * Copyright (c) 2015, Juniper Networks, Inc.
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
8 * Phil Shafer, August 2015
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.
22 * Expose libxo's memory allocation functions
24 extern xo_realloc_func_t xo_realloc;
25 extern xo_free_func_t xo_free;
27 typedef unsigned xo_encoder_op_t;
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 */
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__))
55 typedef int (*xo_encoder_func_t)(XO_ENCODER_HANDLER_ARGS);
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;
62 #define XO_ENCODER_VERSION 1 /* Current version */
64 #define XO_ENCODER_INIT_ARGS \
65 xo_encoder_init_args_t *arg __attribute__ ((__unused__))
67 typedef int (*xo_encoder_init_func_t)(XO_ENCODER_INIT_ARGS);
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.
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);
80 xo_encoder_register (const char *name, xo_encoder_func_t func);
83 xo_encoder_unregister (const char *name);
86 xo_get_private (xo_handle_t *xop);
89 xo_encoder_path_add (const char *path);
92 xo_set_private (xo_handle_t *xop, void *opaque);
95 xo_get_encoder (xo_handle_t *xop);
98 xo_set_encoder (xo_handle_t *xop, xo_encoder_func_t encoder);
101 xo_encoder_init (xo_handle_t *xop, const char *name);
104 xo_encoder_create (const char *name, xo_xof_flags_t flags);
107 xo_encoder_handle (xo_handle_t *xop, xo_encoder_op_t op,
108 const char *name, const char *value);
111 xo_encoders_clean (void);
114 xo_encoder_op_name (xo_encoder_op_t op);
116 #endif /* XO_ENCODER_H */