Get rid of TestBigEndian and AC_C_BIGENDIAN.
[metze/wireshark/wip.git] / epan / oids.c
index 37f0770ce6b12af6745de9b16fc6931941079455..28ea769d8352c2852e84d4d6446e43f3c7fa46a8 100644 (file)
@@ -7,19 +7,7 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include "config.h"
@@ -28,7 +16,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <wsutil/report_err.h>
+#include <wsutil/report_message.h>
 
 #include "wmem/wmem.h"
 #include "uat.h"
@@ -37,6 +25,7 @@
 #include "packet.h"
 #include "wsutil/filesystem.h"
 #include "dissectors/packet-ber.h"
+#include <wsutil/ws_printf.h> /* ws_debug_printf */
 
 #ifdef HAVE_LIBSMI
 #include <smi.h>
@@ -46,7 +35,7 @@ static gboolean load_smi_modules = FALSE;
 static gboolean suppress_smi_errors = FALSE;
 #endif
 
-#define D(level,args) do if (debuglevel >= level) { printf args; printf("\n"); fflush(stdout); } while(0)
+#define D(level,args) do if (debuglevel >= level) { ws_debug_printf args; ws_debug_printf("\n"); fflush(stdout); } while(0)
 
 #include "oids.h"
 
@@ -635,24 +624,28 @@ static void register_mibs(void) {
                        if ( typedata && oid_data->value_hfid == -2 ) {
                                SmiNamedNumber* smiEnum;
                                hf_register_info hf;
+                               char *name;
+                               char *blurb;
+
+                               name = g_strdup(oid_data->name);
+                               blurb = smiRenderOID(smiNode->oidlen, smiNode->oid, SMI_RENDER_ALL);
+                               /* Don't allow duplicate blurb/name */
+                               if (strcmp(blurb, name) == 0) {
+                                       smi_free(blurb);
+                                       blurb = NULL;
+                               }
 
                                hf.p_id                     = &(oid_data->value_hfid);
-                               hf.hfinfo.name              = g_strdup(oid_data->name);
+                               hf.hfinfo.name              = name;
                                hf.hfinfo.abbrev            = alnumerize(oid_data->name);
                                hf.hfinfo.type              = typedata->ft_type;
                                hf.hfinfo.display           = typedata->display;
                                hf.hfinfo.strings           = NULL;
                                hf.hfinfo.bitmask           = 0;
-                               hf.hfinfo.blurb             = smiRenderOID(smiNode->oidlen, smiNode->oid, SMI_RENDER_ALL);
+                               hf.hfinfo.blurb             = blurb;
                                /* HFILL */
                                HFILL_INIT(hf);
 
-                               /* Don't allow duplicate blurb/name */
-                               if (strcmp(hf.hfinfo.blurb, hf.hfinfo.name) == 0) {
-                                       smi_free((void *) hf.hfinfo.blurb);
-                                       hf.hfinfo.blurb = NULL;
-                               }
-
                                oid_data->value_hfid = -1;
 
                                if ( IS_ENUMABLE(hf.hfinfo.type) && (smiEnum = smiGetFirstNamedNumber(smiType))) {
@@ -709,27 +702,25 @@ static void register_mibs(void) {
 
                        if ((key = oid_data->key)) {
                                for(; key; key = key->next) {
-                                       hf_register_info hf;
-
-                                       hf.p_id                     = &(key->hfid);
-                                       hf.hfinfo.name              = key->name;
-                                       hf.hfinfo.abbrev            = alnumerize(key->name);
-                                       hf.hfinfo.type              = key->ft_type;
-                                       hf.hfinfo.display           = key->display;
-                                       hf.hfinfo.strings           = NULL;
-                                       hf.hfinfo.bitmask           = 0;
-                                       hf.hfinfo.blurb             = NULL;
-                                       /* HFILL */
-                                       HFILL_INIT(hf);
-
                                        D(5,("\t\t\tIndex: name=%s subids=%u key_type=%d",
                                                 key->name, key->num_subids, key->key_type ));
 
                                        if (key->hfid == -2) {
+                                               hf_register_info hf;
+
+                                               hf.p_id                     = &(key->hfid);
+                                               hf.hfinfo.name              = key->name;
+                                               hf.hfinfo.abbrev            = alnumerize(key->name);
+                                               hf.hfinfo.type              = key->ft_type;
+                                               hf.hfinfo.display           = key->display;
+                                               hf.hfinfo.strings           = NULL;
+                                               hf.hfinfo.bitmask           = 0;
+                                               hf.hfinfo.blurb             = NULL;
+                                               /* HFILL */
+                                               HFILL_INIT(hf);
+
                                                wmem_array_append_one(hfa,hf);
                                                key->hfid = -1;
-                                       } else {
-                                               g_free((void*)hf.hfinfo.abbrev);
                                        }
                                }
                        }
@@ -760,12 +751,16 @@ void oid_pref_init(module_t *nameres)
 
     prefs_register_bool_preference(nameres, "load_smi_modules",
                                   "Enable OID resolution",
-                                  "You must restart Wireshark for this change to take effect",
+                                  "Resolve Object IDs to object names from the MIB and PIB"
+                                  " modules defined below."
+                                  " You must restart Wireshark for this change to take effect",
                                   &load_smi_modules);
 
     prefs_register_bool_preference(nameres, "suppress_smi_errors",
                                   "Suppress SMI errors",
-                                  "Some errors can be ignored. If unsure, set to false.",
+                                  "While loading MIB or PIB modules errors may be detected,"
+                                  " which are reported. Some errors can be ignored."
+                                  " If unsure, set to false.",
                                   &suppress_smi_errors);
 
     smi_paths_uat = uat_new("SMI Paths",
@@ -787,13 +782,14 @@ void oid_pref_init(module_t *nameres)
                             NULL,
                             smi_mod_free_cb,
                             restart_needed_warning,
+                            NULL,
                             smi_paths_fields);
 
     prefs_register_uat_preference(nameres,
                                   "smi_paths",
                                   "SMI (MIB and PIB) paths",
-                                  "Search paths for SMI (MIB and PIB) modules. You must\n"
-                                  "restart Wireshark for these changes to take effect.",
+                                  "Search paths for SMI (MIB and PIB) modules. You must"
+                                  " restart Wireshark for these changes to take effect.",
                                   smi_paths_uat);
 
     smi_modules_uat = uat_new("SMI Modules",
@@ -815,13 +811,14 @@ void oid_pref_init(module_t *nameres)
                               NULL,
                               smi_mod_free_cb,
                               restart_needed_warning,
+                              NULL,
                               smi_fields);
 
     prefs_register_uat_preference(nameres,
                                   "smi_modules",
                                   "SMI (MIB and PIB) modules",
-                                  "List of enabled SMI (MIB and PIB) modules. You must\n"
-                                  "restart Wireshark for these changes to take effect.",
+                                  "List of SMI (MIB and PIB) modules to load. You must"
+                                  " restart Wireshark for these changes to take effect.",
                                   smi_modules_uat);
 
 #else
@@ -940,6 +937,7 @@ guint oid_string2subid(wmem_allocator_t *scope, const char* str, guint32** subid
                        subid += *r - '0';
 
                        if( subids >= subids_overflow ||  subid > 0xffffffff) {
+                               wmem_free(scope, *subids_p);
                                *subids_p=NULL;
                                return 0;
                        }
@@ -1125,9 +1123,13 @@ guint oid_subid2encoded(wmem_allocator_t *scope, guint subids_len, guint32* subi
                switch(len) {
                        default: *bytes_p=NULL; return 0;
                        case 5: *(b++) = ((subid & 0xF0000000) >> 28) | 0x80;
+                       /* FALL THROUGH */
                        case 4: *(b++) = ((subid & 0x0FE00000) >> 21) | 0x80;
+                       /* FALL THROUGH */
                        case 3: *(b++) = ((subid & 0x001FC000) >> 14) | 0x80;
+                       /* FALL THROUGH */
                        case 2: *(b++) = ((subid & 0x00003F80) >> 7)  | 0x80;
+                       /* FALL THROUGH */
                        case 1: *(b++) =   subid & 0x0000007F ; break;
                }
        }