2 * Routines for OBJECT IDENTIFIER name resolution
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include "oid_resolv.h"
34 #include "epan/dissectors/format-oid.h"
36 static GHashTable *oid_table = NULL;
38 void oid_resolv_init(void) {
39 oid_table = g_hash_table_new(g_str_hash, g_str_equal);
42 static void free_oid_str(gpointer key, gpointer value _U_,
43 gpointer user_data _U_) {
47 void oid_resolv_cleanup(void) {
48 g_hash_table_foreach(oid_table, free_oid_str, NULL);
49 g_hash_table_destroy(oid_table);
53 gboolean oid_resolv_enabled(void) {
57 const gchar *get_oid_name(const guint8 *oid, gint oid_len) {
60 guint subid_oid_length;
62 gchar *non_decoded_oid;
64 name = g_hash_table_lookup(oid_table, oid_to_str(oid, oid_len));
65 if (name) return name;
66 subid_oid = g_malloc((oid_len+1) * sizeof(gulong));
67 subid_oid_length = oid_to_subid_buf(oid, oid_len, subid_oid, ((oid_len+1) * sizeof(gulong)));
68 new_format_oid(subid_oid, subid_oid_length, &non_decoded_oid, &decoded_oid);
73 const gchar *get_oid_str_name(const gchar *oid_str) {
78 bytes = g_byte_array_new();
79 res = oid_str_to_bytes(oid_str, bytes);
81 /* just try a direct lookup - this allows backward compatibility
82 with non-OIDs used for X.411 standard extensions and DISP initiators */
83 return g_hash_table_lookup(oid_table, oid_str);
85 name = get_oid_name(bytes->data, bytes->len);
86 g_byte_array_free(bytes, TRUE);
91 extern void add_oid_name(const guint8 *oid, gint oid_len, const gchar *name) {
92 add_oid_str_name(oid_to_str(oid, oid_len), name);
95 extern void add_oid_str_name(const gchar *oid_str, const gchar *name) {
96 g_hash_table_insert(oid_table, (gpointer)g_strdup(oid_str), (gpointer)name);