1287111Smarcel/* 2287111Smarcel * Copyright (c) 2015, Juniper Networks, Inc. 3287111Smarcel * All rights reserved. 4287111Smarcel * This SOFTWARE is licensed under the LICENSE provided in the 5287111Smarcel * ../Copyright file. By downloading, installing, copying, or otherwise 6287111Smarcel * using the SOFTWARE, you agree to be bound by the terms of that 7287111Smarcel * LICENSE. 8287111Smarcel * Phil Shafer, August 2015 9287111Smarcel */ 10287111Smarcel 11287111Smarcel/* 12287111Smarcel * NOTE WELL: This file is needed to software that implements an 13287111Smarcel * external encoder for libxo that allows libxo data to be encoded in 14287111Smarcel * new and bizarre formats. General libxo code should _never_ 15287111Smarcel * include this header file. 16287111Smarcel */ 17287111Smarcel 18287111Smarcel#ifndef XO_ENCODER_H 19287111Smarcel#define XO_ENCODER_H 20287111Smarcel 21287111Smarcel/* 22287111Smarcel * Expose libxo's memory allocation functions 23287111Smarcel */ 24287111Smarcelextern xo_realloc_func_t xo_realloc; 25287111Smarcelextern xo_free_func_t xo_free; 26287111Smarcel 27287111Smarceltypedef unsigned xo_encoder_op_t; 28287111Smarcel 29287111Smarcel/* Encoder operations; names are in xo_encoder.c:xo_encoder_op_name() */ 30287111Smarcel#define XO_OP_UNKNOWN 0 31287111Smarcel#define XO_OP_CREATE 1 /* Called when the handle is init'd */ 32287111Smarcel#define XO_OP_OPEN_CONTAINER 2 33287111Smarcel#define XO_OP_CLOSE_CONTAINER 3 34287111Smarcel#define XO_OP_OPEN_LIST 4 35287111Smarcel#define XO_OP_CLOSE_LIST 5 36287111Smarcel#define XO_OP_OPEN_LEAF_LIST 6 37287111Smarcel#define XO_OP_CLOSE_LEAF_LIST 7 38287111Smarcel#define XO_OP_OPEN_INSTANCE 8 39287111Smarcel#define XO_OP_CLOSE_INSTANCE 9 40287111Smarcel#define XO_OP_STRING 10 /* Quoted UTF-8 string */ 41287111Smarcel#define XO_OP_CONTENT 11 /* Other content */ 42287111Smarcel#define XO_OP_FINISH 12 /* Finish any pending output */ 43287111Smarcel#define XO_OP_FLUSH 13 /* Flush any buffered output */ 44287111Smarcel#define XO_OP_DESTROY 14 /* Clean up function */ 45287111Smarcel#define XO_OP_ATTRIBUTE 15 /* Attribute name/value */ 46287111Smarcel#define XO_OP_VERSION 16 /* Version string */ 47287111Smarcel 48287111Smarcel#define XO_ENCODER_HANDLER_ARGS \ 49287111Smarcel xo_handle_t *xop __attribute__ ((__unused__)), \ 50287111Smarcel xo_encoder_op_t op __attribute__ ((__unused__)), \ 51287111Smarcel const char *name __attribute__ ((__unused__)), \ 52287111Smarcel const char *value __attribute__ ((__unused__)), \ 53322172Sphil void *private __attribute__ ((__unused__)), \ 54322172Sphil xo_xof_flags_t flags __attribute__ ((__unused__)) 55287111Smarcel 56287111Smarceltypedef int (*xo_encoder_func_t)(XO_ENCODER_HANDLER_ARGS); 57287111Smarcel 58287111Smarceltypedef struct xo_encoder_init_args_s { 59287111Smarcel unsigned xei_version; /* Current version */ 60287111Smarcel xo_encoder_func_t xei_handler; /* Encoding handler */ 61287111Smarcel} xo_encoder_init_args_t; 62287111Smarcel 63287111Smarcel#define XO_ENCODER_VERSION 1 /* Current version */ 64287111Smarcel 65287111Smarcel#define XO_ENCODER_INIT_ARGS \ 66287111Smarcel xo_encoder_init_args_t *arg __attribute__ ((__unused__)) 67287111Smarcel 68287111Smarceltypedef int (*xo_encoder_init_func_t)(XO_ENCODER_INIT_ARGS); 69287111Smarcel/* 70287111Smarcel * Each encoder library must define a function named xo_encoder_init 71287111Smarcel * that takes the arguments defined in XO_ENCODER_INIT_ARGS. It 72287111Smarcel * should return zero for success. 73287111Smarcel */ 74287111Smarcel#define XO_ENCODER_INIT_NAME_TOKEN xo_encoder_library_init 75287111Smarcel#define XO_STRINGIFY(_x) #_x 76287111Smarcel#define XO_STRINGIFY2(_x) XO_STRINGIFY(_x) 77287111Smarcel#define XO_ENCODER_INIT_NAME XO_STRINGIFY2(XO_ENCODER_INIT_NAME_TOKEN) 78287111Smarcelextern int XO_ENCODER_INIT_NAME_TOKEN (XO_ENCODER_INIT_ARGS); 79287111Smarcel 80287111Smarcelvoid 81287111Smarcelxo_encoder_register (const char *name, xo_encoder_func_t func); 82287111Smarcel 83287111Smarcelvoid 84287111Smarcelxo_encoder_unregister (const char *name); 85287111Smarcel 86287111Smarcelvoid * 87287111Smarcelxo_get_private (xo_handle_t *xop); 88287111Smarcel 89287111Smarcelvoid 90287111Smarcelxo_encoder_path_add (const char *path); 91287111Smarcel 92287111Smarcelvoid 93287111Smarcelxo_set_private (xo_handle_t *xop, void *opaque); 94287111Smarcel 95287111Smarcelxo_encoder_func_t 96287111Smarcelxo_get_encoder (xo_handle_t *xop); 97287111Smarcel 98287111Smarcelvoid 99287111Smarcelxo_set_encoder (xo_handle_t *xop, xo_encoder_func_t encoder); 100287111Smarcel 101287111Smarcelint 102287111Smarcelxo_encoder_init (xo_handle_t *xop, const char *name); 103287111Smarcel 104287111Smarcelxo_handle_t * 105287111Smarcelxo_encoder_create (const char *name, xo_xof_flags_t flags); 106287111Smarcel 107287111Smarcelint 108287111Smarcelxo_encoder_handle (xo_handle_t *xop, xo_encoder_op_t op, 109322172Sphil const char *name, const char *value, xo_xof_flags_t flags); 110287111Smarcel 111287111Smarcelvoid 112287111Smarcelxo_encoders_clean (void); 113287111Smarcel 114287111Smarcelconst char * 115287111Smarcelxo_encoder_op_name (xo_encoder_op_t op); 116287111Smarcel 117287111Smarcel#endif /* XO_ENCODER_H */ 118