Re-enable capture tests now that a a dumpcap problem has been corrected.
[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@gmail.com>
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 #define BER_TAG_ANY -1 
31
32 struct _oid_bit_t {
33         guint offset;
34         int hfid;
35 };
36
37 typedef struct _oid_bits_info_t {
38         guint num;
39         gint ett;
40         struct _oid_bit_t* data;
41 } oid_bits_info_t;
42
43 typedef enum _oid_key_type_t {
44         OID_KEY_TYPE_WRONG,
45         OID_KEY_TYPE_INTEGER,
46         OID_KEY_TYPE_FIXED_STRING,
47         OID_KEY_TYPE_FIXED_BYTES,
48         OID_KEY_TYPE_STRING,
49         OID_KEY_TYPE_BYTES,
50         OID_KEY_TYPE_NSAP,
51         OID_KEY_TYPE_OID,
52         OID_KEY_TYPE_IPADDR
53 } oid_key_type_t;
54
55 typedef struct _oid_value_type_t {
56         enum ftenum ft_type;
57         int display;
58         gint8 ber_class;
59         gint32 ber_tag;
60         int min_len; 
61         int max_len;
62         oid_key_type_t keytype;
63         int keysize;
64 } oid_value_type_t; 
65
66 typedef enum _oid_kind_t {
67         OID_KIND_UNKNOWN = 0,
68         OID_KIND_NODE,
69         OID_KIND_SCALAR,
70         OID_KIND_TABLE,
71         OID_KIND_ROW,
72         OID_KIND_COLUMN,
73         OID_KIND_NOTIFICATION,
74         OID_KIND_GROUP,
75         OID_KIND_COMPLIANCE,
76         OID_KIND_CAPABILITIES
77 } oid_kind_t;
78
79 typedef struct _oid_key_t {
80         char* name;
81         guint32 num_subids;
82         oid_key_type_t key_type;
83         int hfid;
84         enum ftenum ft_type;
85         int display;
86         struct _oid_key_t* next;
87 } oid_key_t;
88
89 typedef struct _oid_info_t {
90         guint32 subid;
91         char* name;
92         oid_kind_t kind;
93         void* children; /* an emem_tree_t* */
94         const oid_value_type_t* value_type;
95         int value_hfid;
96         oid_key_t* key;
97         oid_bits_info_t* bits;
98         struct _oid_info_t* parent;
99 } oid_info_t;
100
101 /* init funcion called from epan.h */
102 extern void oids_init(void);
103
104 /*
105  * The objects returned by all these functions are all allocated with a 
106  * packet lifetime and does not have have to be freed. 
107  * However, take into account that when the packet dissection
108  * completes, these buffers will be automatically reclaimed/freed.
109  * If you need the buffer to remain for a longer scope than packet lifetime
110  * you must copy the content to an se_alloc() buffer.
111  */
112
113 /*
114  * These functions convert through the various formats:
115  * string: is  like "0.1.3.4.5.30" (not resolved)
116  * encoded: is BER encoded (as per X.690 section 8.19)
117  * subids: is an array of guint32s
118  */
119
120 /* return lenght of encoded buffer */
121 guint oid_subid2encoded(guint len, guint32* subids, guint8** encoded_p);
122 guint oid_string2encoded(const gchar *oid_str, guint8** encoded_p);
123
124 /* return lenght of subid array */
125 guint oid_encoded2subid(const guint8 *oid, gint len, guint32** subids_p);
126 guint oid_string2subid(const gchar *oid_str, guint32** subids_p);
127
128 extern const gchar* oid_encoded2string(const guint8* encoded, guint len);
129 extern const gchar* oid_subid2string(guint32 *subids, guint len);
130
131 /* these return a formated string as human readable as posible */
132 extern const gchar *oid_resolved(guint len, guint32 *subids);
133 extern const gchar *oid_resolved_from_encoded(const guint8 *oid, gint len);
134 extern const gchar *oid_resolved_from_string(const gchar *oid_str);
135
136 /* these yield two formated strings one resolved and one numeric */
137 extern void oid_both(guint oid_len, guint32 *subids, char** resolved_p, char** numeric_p);
138 extern void oid_both_from_encoded(const guint8 *oid, gint oid_len, char** resolved_p, char** numeric_p);
139 extern void oid_both_from_string(const gchar *oid_str, char** resolved_p, char** numeric_p);
140
141 /*
142  * These return the info for the best match.
143  *  *matched_p will be set to the number of nodes used by the returned oid
144  *  *left_p will be set to the number of remaining unresolved subids 
145  */
146 extern oid_info_t* oid_get(guint oid_len, guint32 *subids, guint* matched_p, guint* left_p);
147 extern oid_info_t* oid_get_from_encoded(const guint8 *oid, gint oid_len, guint32 **subids, guint* matched, guint* left);
148 extern oid_info_t* oid_get_from_string(const gchar *oid_str, guint32 **subids, guint* matched, guint* left);
149
150 /* these are used to add oids to the collection */
151 extern void oid_add(const char* name, guint oid_len, guint32 *subids);
152 extern void oid_add_from_encoded(const char* name, const guint8 *oid, gint oid_len);
153 extern void oid_add_from_string(const char* name, const gchar *oid_str);
154
155
156 /* macros for legacy oid functions */
157 /* from former oid_resolv.h */
158 #define add_oid_str_name(oidstr,oidname) oid_add_from_string(oidname, oidstr)
159 #define add_oid_name(oid, oid_len, name) oid_add_from_encoded(name,oid,oid_len)
160 #define get_oid_str_name(oidstr) oid_resolved_from_string(oidstr)
161 #define get_oid_name(encoid, encoid_len) oid_resolved_from_encoded(encoid, encoid_len)
162 #define oid_resolv_enabled() (1)
163 #define oid_resolv_cleanup() ((void)0)
164
165 /* from to_str.h */
166 #define oid_to_str(encoid, encoid_len) oid_encoded2string(encoid, encoid_len)
167
168 /* from former dissectors/format_oid.h */
169 #define format_oid(oid, oid_length) ((void*)oid_resolved(oid_length,oid))
170 #define new_format_oid(oid, oid_length, non_decoded, decoded) oid_both(oid_length, oid, non_decoded, decoded)
171
172 #define subid_t guint32
173
174
175
176 #ifdef DEBUG_OIDS
177 extern char* oid_test_a2b(guint32 num_subids, guint32* subids);
178 extern void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree);
179 #else 
180 #define add_oid_debug_subtree(a,b) ((void)0)
181 #endif
182
183 #endif