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 xo_xof_flags_t flags __attribute__ ((__unused__)) 55 56 typedef int (*xo_encoder_func_t)(XO_ENCODER_HANDLER_ARGS); 57 58 typedef struct xo_encoder_init_args_s { 59 unsigned xei_version; /* Current version */ 60 xo_encoder_func_t xei_handler; /* Encoding handler */ 61 } xo_encoder_init_args_t; 62 63 #define XO_ENCODER_VERSION 1 /* Current version */ 64 65 #define XO_ENCODER_INIT_ARGS \ 66 xo_encoder_init_args_t *arg __attribute__ ((__unused__)) 67 68 typedef int (*xo_encoder_init_func_t)(XO_ENCODER_INIT_ARGS); 69 /* 70 * Each encoder library must define a function named xo_encoder_init 71 * that takes the arguments defined in XO_ENCODER_INIT_ARGS. It 72 * should return zero for success. 73 */ 74 #define XO_ENCODER_INIT_NAME_TOKEN xo_encoder_library_init 75 #define XO_STRINGIFY(_x) #_x 76 #define XO_STRINGIFY2(_x) XO_STRINGIFY(_x) 77 #define XO_ENCODER_INIT_NAME XO_STRINGIFY2(XO_ENCODER_INIT_NAME_TOKEN) 78 extern int XO_ENCODER_INIT_NAME_TOKEN (XO_ENCODER_INIT_ARGS); 79 80 void 81 xo_encoder_register (const char *name, xo_encoder_func_t func); 82 83 void 84 xo_encoder_unregister (const char *name); 85 86 void * 87 xo_get_private (xo_handle_t *xop); 88 89 void 90 xo_encoder_path_add (const char *path); 91 92 void 93 xo_set_private (xo_handle_t *xop, void *opaque); 94 95 xo_encoder_func_t 96 xo_get_encoder (xo_handle_t *xop); 97 98 void 99 xo_set_encoder (xo_handle_t *xop, xo_encoder_func_t encoder); 100 101 int 102 xo_encoder_init (xo_handle_t *xop, const char *name); 103 104 xo_handle_t * 105 xo_encoder_create (const char *name, xo_xof_flags_t flags); 106 107 int 108 xo_encoder_handle (xo_handle_t *xop, xo_encoder_op_t op, 109 const char *name, const char *value, xo_xof_flags_t flags); 110 111 void 112 xo_encoders_clean (void); 113 114 const char * 115 xo_encoder_op_name (xo_encoder_op_t op); 116 117 #endif /* XO_ENCODER_H */ 118