Minor updates to debug output.
[obnox/wireshark/wip.git] / epan / oids.h
1 /* oids.h
2  * Object IDentifier Support
3  *
4  * $Id$
5  *
6  * (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifndef __OIDS_H__
28 #define __OIDS_H__
29
30 #include <epan/ftypes/ftypes.h>
31 /**
32  *@file
33  */
34 #define BER_TAG_ANY -1
35
36 struct _oid_bit_t {
37         guint offset;
38         int hfid;
39 };
40
41 typedef struct _oid_bits_info_t {
42         guint num;
43         gint ett;
44         struct _oid_bit_t* data;
45 } oid_bits_info_t;
46
47 typedef enum _oid_key_type_t {
48         OID_KEY_TYPE_WRONG,
49         OID_KEY_TYPE_INTEGER,
50         OID_KEY_TYPE_OID,
51         OID_KEY_TYPE_STRING,
52         OID_KEY_TYPE_BYTES,
53         OID_KEY_TYPE_NSAP,
54         OID_KEY_TYPE_IPADDR,
55         OID_KEY_TYPE_IMPLIED_OID,
56         OID_KEY_TYPE_IMPLIED_STRING,
57         OID_KEY_TYPE_IMPLIED_BYTES,
58         OID_KEY_TYPE_ETHER
59 } oid_key_type_t;
60
61 typedef struct _oid_value_type_t {
62         enum ftenum ft_type;
63         int display;
64         gint8 ber_class;
65         gint32 ber_tag;
66         int min_len;
67         int max_len;
68         oid_key_type_t keytype;
69         int keysize;
70 } oid_value_type_t;
71
72 typedef enum _oid_kind_t {
73         OID_KIND_UNKNOWN = 0,
74         OID_KIND_NODE,
75         OID_KIND_SCALAR,
76         OID_KIND_TABLE,
77         OID_KIND_ROW,
78         OID_KIND_COLUMN,
79         OID_KIND_NOTIFICATION,
80         OID_KIND_GROUP,
81         OID_KIND_COMPLIANCE,
82         OID_KIND_CAPABILITIES
83 } oid_kind_t;
84
85 typedef struct _oid_key_t {
86         char* name;
87         guint32 num_subids;
88         oid_key_type_t key_type;
89         int hfid;
90         enum ftenum ft_type;
91         int display;
92         struct _oid_key_t* next;
93 } oid_key_t;
94
95 typedef struct _oid_info_t {
96         guint32 subid;
97         char* name;
98         oid_kind_t kind;
99         void* children; /**< an emem_tree_t* */
100         const oid_value_type_t* value_type;
101         int value_hfid;
102         oid_key_t* key;
103         oid_bits_info_t* bits;
104         struct _oid_info_t* parent;
105 } oid_info_t;
106
107 /** init funcion called from epan.h */
108 extern void oids_init(void);
109
110 /** init funcion called from epan.h */
111 extern void oids_cleanup(void);
112
113 /*
114  * The objects returned by all these functions are all allocated with a
115  * packet lifetime and does not have have to be freed.
116  * However, take into account that when the packet dissection
117  * completes, these buffers will be automatically reclaimed/freed.
118  * If you need the buffer to remain for a longer scope than packet lifetime
119  * you must copy the content to an se_alloc() buffer.
120  */
121
122 /*
123  * These functions convert through the various formats:
124  * string: is  like "0.1.3.4.5.30" (not resolved)
125  * encoded: is BER encoded (as per X.690 section 8.19)
126  * subids: is an array of guint32s
127  */
128
129 /* return length of encoded buffer */
130 guint oid_subid2encoded(guint len, guint32* subids, guint8** encoded_p);
131 guint oid_string2encoded(const gchar *oid_str, guint8** encoded_p);
132
133 /* return length of subid array */
134 guint oid_encoded2subid(const guint8 *oid, gint len, guint32** subids_p);
135 guint oid_string2subid(const gchar *oid_str, guint32** subids_p);
136
137 extern const gchar* oid_encoded2string(const guint8* encoded, guint len);
138 extern const gchar* oid_subid2string(guint32 *subids, guint len);
139
140 /* these return a formated string as human readable as posible */
141 extern const gchar *oid_resolved(guint len, guint32 *subids);
142 extern const gchar *oid_resolved_from_encoded(const guint8 *oid, gint len);
143 extern const gchar *oid_resolved_from_string(const gchar *oid_str);
144
145 /* these yield two formated strings one resolved and one numeric */
146 extern void oid_both(guint oid_len, guint32 *subids, char** resolved_p, char** numeric_p);
147 extern void oid_both_from_encoded(const guint8 *oid, gint oid_len, char** resolved_p, char** numeric_p);
148 extern void oid_both_from_string(const gchar *oid_str, char** resolved_p, char** numeric_p);
149
150 /*
151  * These return the info for the best match.
152  *  *matched_p will be set to the number of nodes used by the returned oid
153  *  *left_p will be set to the number of remaining unresolved subids
154  */
155 extern oid_info_t* oid_get(guint oid_len, guint32 *subids, guint* matched_p, guint* left_p);
156 extern oid_info_t* oid_get_from_encoded(const guint8 *oid, gint oid_len, guint32 **subids, guint* matched, guint* left);
157 extern oid_info_t* oid_get_from_string(const gchar *oid_str, guint32 **subids, guint* matched, guint* left);
158
159 /* these are used to add oids to the collection */
160 extern void oid_add(const char* name, guint oid_len, guint32 *subids);
161 extern void oid_add_from_encoded(const char* name, const guint8 *oid, gint oid_len);
162 extern void oid_add_from_string(const char* name, const gchar *oid_str);
163
164 /**
165  * Fetch the default MIB/PIB path
166  *
167  * @return A string containing the default MIB/PIB path.  It must be
168  * g_free()d by the caller.
169  */
170 extern gchar *oid_get_default_mib_path(void);
171
172 /* macros for legacy oid functions */
173 #define oid_resolv_cleanup() ((void)0)
174 #define subid_t guint32
175
176
177
178 #ifdef DEBUG_OIDS
179 extern char* oid_test_a2b(guint32 num_subids, guint32* subids);
180 extern void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree);
181 #else
182 #define add_oid_debug_subtree(a,b) ((void)0)
183 #endif
184
185 #endif