1 /*********************************************************************************************************
2 * Software License Agreement (BSD License)                                                               *
3 * Author: Sebastien Decugis <sdecugis@freediameter.net>							 *
4 *													 *
5 * Copyright (c) 2020, WIDE Project and NICT								 *
6 * All rights reserved.											 *
7 * 													 *
8 * Redistribution and use of this software in source and binary forms, with or without modification, are  *
9 * permitted provided that the following conditions are met:						 *
10 * 													 *
11 * * Redistributions of source code must retain the above 						 *
12 *   copyright notice, this list of conditions and the 							 *
13 *   following disclaimer.										 *
14 *    													 *
15 * * Redistributions in binary form must reproduce the above 						 *
16 *   copyright notice, this list of conditions and the 							 *
17 *   following disclaimer in the documentation and/or other						 *
18 *   materials provided with the distribution.								 *
19 * 													 *
20 * * Neither the name of the WIDE Project or NICT nor the 						 *
21 *   names of its contributors may be used to endorse or 						 *
22 *   promote products derived from this software without 						 *
23 *   specific prior written permission of WIDE Project and 						 *
24 *   NICT.												 *
25 * 													 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
34 *********************************************************************************************************/
35 
36 #ifndef HAD_DICTIONARY_INTERNAL_H
37 #define HAD_DICTIONARY_INTERNAL_H
38 
39 /* Names of the base types */
40 extern const char * type_base_name[];
41 
42 /* The number of lists in an object */
43 #define NB_LISTS_PER_OBJ	3
44 
45 /* Definition of the dictionary objects */
46 struct dict_object {
47 	enum dict_object_type	type;	/* What type of object is this? */
48 	int			objeyec;/* eyecatcher for this object */
49 	int			typeyec;/* eyecatcher for this type of object */
50 	struct dictionary	*dico;  /* The dictionary this object belongs to */
51 
52 	union {
53 		struct dict_vendor_data		vendor;		/* datastr_len = strlen(vendor_name) */
54 		struct dict_application_data	application;	/* datastr_len = strlen(application_name) */
55 		struct dict_type_data		type;		/* datastr_len = strlen(type_name) */
56 		struct dict_enumval_data	enumval;	/* datastr_len = strlen(enum_name) */
57 		struct dict_avp_data		avp;		/* datastr_len = strlen(avp_name) */
58 		struct dict_cmd_data		cmd;		/* datastr_len = strlen(cmd_name) */
59 		struct dict_rule_data		rule;		/* datastr_len = 0 */
60 	} data;				/* The data of this object */
61 
62 	size_t			datastr_len; /* cached length of the string inside the data. Saved when the object is created. */
63 
64 	struct dict_object *	parent; /* The parent of this object, if any */
65 
66 	struct fd_list		list[NB_LISTS_PER_OBJ];/* used to chain objects.*/
67 	/* More information about the lists :
68 
69 	 - the use for each list depends on the type of object. See detail below.
70 
71 	 - a sentinel for a list has its 'o' field cleared. (this is the criteria to detect end of a loop)
72 
73 	 - The lists are always ordered. The criteria are described below. the functions to order them are referenced in dict_obj_info
74 
75 	 - The dict_lock must be held for any list operation.
76 
77 	 => VENDORS:
78 	 list[0]: list of the vendors, ordered by their id. The sentinel is g_dict_vendors (vendor with id 0)
79 	 list[1]: sentinel for the list of AVPs from this vendor, ordered by AVP code.
80 	 list[2]: sentinel for the list of AVPs from this vendor, ordered by AVP name (fd_os_cmp).
81 
82 	 => APPLICATIONS:
83 	 list[0]: list of the applications, ordered by their id. The sentinel is g_dict_applications (application with id 0)
84 	 list[1]: not used
85 	 list[2]: not used.
86 
87 	 => TYPES:
88 	 list[0]: list of the types, ordered by their names. The sentinel is g_list_types.
89 	 list[1]: sentinel for the type_enum list of this type, ordered by their constant name (fd_os_cmp).
90 	 list[2]: sentinel for the type_enum list of this type, ordered by their constant value.
91 
92 	 => TYPE_ENUMS:
93 	 list[0]: list of the contants for a given type, ordered by the constant name (fd_os_cmp). Sentinel is a (list[1]) element of a TYPE object.
94 	 list[1]: list of the contants for a given type, ordered by the constant value. Sentinel is a (list[2]) element of a TYPE object.
95 	 list[2]: not used
96 
97 	 => AVPS:
98 	 list[0]: list of the AVP from a given vendor, ordered by avp code. Sentinel is a list[1] element of a VENDOR object.
99 	 list[1]: list of the AVP from a given vendor, ordered by avp name (fd_os_cmp). Sentinel is a list[2] element of a VENDOR object.
100 	 list[2]: sentinel for the rule list that apply to this AVP.
101 
102 	 => COMMANDS:
103 	 list[0]: list of the commands, ordered by their names (fd_os_cmp). The sentinel is g_list_cmd_name.
104 	 list[1]: list of the commands, ordered by their command code and 'R' flag. The sentinel is g_list_cmd_code.
105 	 list[2]: sentinel for the rule list that apply to this command.
106 
107 	 => RULES:
108 	 list[0]: list of the rules for a given (grouped) AVP or Command, ordered by the AVP vendor & code to which they refer. sentinel is list[2] of a command or (grouped) avp.
109 	 list[1]: not used
110 	 list[2]: not used.
111 
112 	 */
113 
114 	 /* Sentinel for the dispatch callbacks */
115 	 struct fd_list		disp_cbs;
116 
117 };
118 
119 /* Definition of the dictionary structure */
120 struct dictionary {
121 	int		 	dict_eyec;		/* Eye-catcher for the dictionary (DICT_EYECATCHER) */
122 
123 	pthread_rwlock_t 	dict_lock;		/* The global rwlock for the dictionary */
124 
125 	struct dict_object	dict_vendors;		/* Sentinel for the list of vendors, corresponding to vendor 0 */
126 	struct dict_object	dict_applications;	/* Sentinel for the list of applications, corresponding to app 0 */
127 	struct fd_list		dict_types;		/* Sentinel for the list of types */
128 	struct fd_list		dict_cmd_name;		/* Sentinel for the list of commands, ordered by names */
129 	struct fd_list		dict_cmd_code;		/* Sentinel for the list of commands, ordered by codes */
130 
131 	struct dict_object	dict_cmd_error;		/* Special command object for answers with the 'E' bit set */
132 
133 	int			dict_count[DICT_TYPE_MAX + 1]; /* Number of objects of each type */
134 };
135 
136 #endif /* HAD_DICTIONARY_INTERNAL_H */
137