1 /* 2 * Copyright (c) 2001, 2002, 2003, 2004, 2005 Netli, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $Id: ncnf_int.h,v 1.1 2005/05/26 12:08:19 vlm Exp $ 27 */ 28 /* 29 * Internal declarations. 30 */ 31 #ifndef __NCNF_INT_H__ 32 #define __NCNF_INT_H__ 33 34 #include <bstr.h> 35 36 #include "ncnf_coll.h" 37 #include "ncnf_notif.h" 38 #include "ncnf_walk.h" 39 #include "ncnf_diff.h" 40 41 enum obj_class { 42 NOBJ_INVALID = 0, /* INVALID */ 43 NOBJ_ROOT = 1, /* Root */ 44 NOBJ_COMPLEX = 2, /* Complex object */ 45 NOBJ_ATTRIBUTE = 3, /* Plain attribute */ 46 NOBJ_INSERTION = 4, /* Content insertion */ 47 NOBJ_REFERENCE = 5, /* Indirect object reference */ 48 NOBJ_ITERATOR = 6, /* Iterator */ 49 NOBJ_LAZY_NOTIF = 7, /* Lazy notification functions holder */ 50 }; 51 #define _NOBJ_CONTAINER(obj) ((obj)->obj_class <= NOBJ_COMPLEX) 52 53 enum collections_e { 54 COLLECTION_ATTRIBUTES = 0, 55 COLLECTION_OBJECTS = 1, 56 COLLECTION_INSERTS = 2, 57 COLLECTION_LAZY_NOTIF = 3, 58 MAX_COLLECTIONS = 4, 59 }; 60 61 struct ncnf_obj_s { 62 /* 63 * Common header 64 */ 65 enum obj_class obj_class; 66 67 bstr_t type; 68 bstr_t value; 69 70 struct ncnf_obj_s *parent; 71 int config_line; 72 73 /* For building run-time chains */ 74 struct ncnf_obj_s *chain_next; 75 struct ncnf_obj_s *chain_cur; 76 77 /* 78 * User callbacks and data 79 */ 80 int (*notify)(ncnf_obj *, enum ncnf_notify_event, void *notify_key); 81 void *notify_key; 82 void *user_data; 83 84 /**************************** 85 * Class-specific properties * 86 ****************************/ 87 88 union { 89 struct { 90 /* 91 * Properties for NOBJ_COMPLEX and NOBJ_ROOT 92 */ 93 collection_t collection[MAX_COLLECTIONS]; 94 } property_CONTAINER; 95 struct { 96 int attr_flags; /* &1 = not resolved */ 97 } property_ATTRIBUTE; 98 struct { 99 /* 100 * Properties for NOBJ_ITERATOR 101 */ 102 collection_t iterator_collection; 103 int iterator_position; 104 } property_ITERATOR; 105 struct { 106 /* 107 * Properties for NOBJ_REFERENCE 108 */ 109 bstr_t ref_type; 110 bstr_t ref_value; 111 int ref_flags; /* &1 = Dependent */ 112 113 bstr_t new_ref_type; 114 bstr_t new_ref_value; 115 116 /* 117 * Configuration diffing of NOBJ_REFERENCE 118 * requires special handling to preserve links 119 */ 120 struct ncnf_obj_s *direct_reference; 121 } property_REFERENCE; 122 struct { 123 /* 124 * Properties for NOBJ_INSERTION 125 */ 126 int insert_flags; /* &1 = inheritance */ 127 } property_INSERTION; 128 } un; 129 #define m_collection un.property_CONTAINER.collection 130 #define m_attr_flags un.property_ATTRIBUTE.attr_flags 131 #define m_iterator_collection un.property_ITERATOR.iterator_collection 132 #define m_iterator_position un.property_ITERATOR.iterator_position 133 #define m_ref_type un.property_REFERENCE.ref_type 134 #define m_ref_value un.property_REFERENCE.ref_value 135 #define m_ref_flags un.property_REFERENCE.ref_flags 136 #define m_new_ref_type un.property_REFERENCE.new_ref_type 137 #define m_new_ref_value un.property_REFERENCE.new_ref_value 138 #define m_direct_reference un.property_REFERENCE.direct_reference 139 #define m_insert_flags un.property_INSERTION.insert_flags 140 141 /* 142 * Auxiliary temporary variables. 143 */ 144 145 int mark; /* Sometimes we need to mark object somehow */ 146 147 int uses; /* Someone relies on this. Used by ncnf-strip */ 148 149 void *mr; /* Allocated in this memory region (optional) */ 150 }; 151 152 #include "ncnf_constr.h" 153 154 155 /* Recursively dump the object tree */ 156 void _ncnf_obj_dump_recursive(FILE *f, struct ncnf_obj_s *obj, const char *flatten_type, int marked_only, int verbose, int indent, int indent_shift, int single_level, int *recursive_size); 157 158 void _ncnf_debug_print(int, const char *, ...) 159 __attribute__ ((format (printf, 2, 3) )); 160 161 162 #endif /* __NCNF_INT_H__ */ 163