pfcp: Update to 3GPP TS 29.244 V15.4.0
[metze/wireshark/wip.git] / epan / value_string.h
index 1fe7858dac856155e1289e32603e4f4f63de5155..fc90a1cde2737b065c1285d0f544fbefa6d02295 100644 (file)
@@ -5,19 +5,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
  */
 
 #ifndef __VALUE_STRING_H__
@@ -29,6 +17,7 @@ extern "C" {
 
 #include <glib.h>
 #include "ws_symbol_export.h"
+#include "wmem/wmem.h"
 
 /* VALUE TO STRING MATCHING */
 
@@ -72,10 +61,10 @@ typedef struct _value_string {
 #endif
 
 /* -- Public -- */
-#define VALUE_STRING_ENUM(             array_name) _VS_ENUM_XXX( array_name, _VS_ENUM_ENTRY)
-#define VALUE_STRING_ARRAY(            array_name) _VS_ARRAY_SC_XXX(array_name, _VS_ARRAY_ENTRY, static)
-#define VALUE_STRING_ARRAY_GLOBAL_DEF( array_name) _VS_ARRAY_XXX(array_name, _VS_ARRAY_ENTRY)
-#define VALUE_STRING_ARRAY_GLOBAL_DCL( array_name) _VS_ARRAY_SC_TYPE_NAME(array_name, extern)
+#define VALUE_STRING_ENUM(              array_name) _VS_ENUM_XXX( array_name, _VS_ENUM_ENTRY)
+#define VALUE_STRING_ARRAY(             array_name) _VS_ARRAY_SC_XXX(array_name, _VS_ARRAY_ENTRY, static)
+#define VALUE_STRING_ARRAY_GLOBAL_DEF(  array_name) _VS_ARRAY_XXX(array_name, _VS_ARRAY_ENTRY)
+#define VALUE_STRING_ARRAY_GLOBAL_DCL(  array_name) _VS_ARRAY_SC_TYPE_NAME(array_name, extern)
 
 #define VALUE_STRING_ENUM2(             array_name) _VS_ENUM_XXX( array_name, _VS_ENUM_ENTRY2)
 #define VALUE_STRING_ARRAY2(            array_name) _VS_ARRAY_SC_XXX(array_name, _VS_ARRAY_ENTRY2, static)
@@ -86,16 +75,17 @@ typedef struct _value_string {
 #define _VS_ENUM_XXX(array_name, macro) \
 enum { \
     array_name##_VALUE_STRING_LIST(macro) \
+    _##array_name##_ENUM_DUMMY = 0 \
 }
 
 #define _VS_ARRAY_SC_XXX(array_name, macro, sc)  \
-    _VS_ARRAY_SC_TYPE_NAME(array_name, sc) = {    \
+    _VS_ARRAY_SC_TYPE_NAME(array_name, sc) = { \
     array_name##_VALUE_STRING_LIST(macro) \
     { 0, NULL } \
 }
 
 #define _VS_ARRAY_XXX(array_name, macro)  \
-    _VS_ARRAY_TYPE_NAME(array_name) = {    \
+    _VS_ARRAY_TYPE_NAME(array_name) = { \
     array_name##_VALUE_STRING_LIST(macro) \
     { 0, NULL } \
 }
@@ -112,7 +102,13 @@ enum { \
 
 WS_DLL_PUBLIC
 const gchar *
-val_to_str(const guint32 val, const value_string *vs, const char *fmt);
+val_to_str(const guint32 val, const value_string *vs, const char *fmt)
+G_GNUC_PRINTF(3, 0);
+
+WS_DLL_PUBLIC
+gchar *
+val_to_str_wmem(wmem_allocator_t *scope, const guint32 val, const value_string *vs, const char *fmt)
+G_GNUC_PRINTF(4, 0);
 
 WS_DLL_PUBLIC
 const gchar *
@@ -135,7 +131,8 @@ typedef struct _val64_string {
 
 WS_DLL_PUBLIC
 const gchar *
-val64_to_str(const guint64 val, const val64_string *vs, const char *fmt);
+val64_to_str(const guint64 val, const val64_string *vs, const char *fmt)
+G_GNUC_PRINTF(3, 0);
 
 WS_DLL_PUBLIC
 const gchar *
@@ -161,17 +158,17 @@ str_to_val_idx(const gchar *val, const value_string *vs);
 
 /* EXTENDED VALUE TO STRING MATCHING */
 
-struct _value_string_ext;
-typedef const value_string *(*_value_string_match2_t)(const guint32, const struct _value_string_ext *);
+typedef struct _value_string_ext value_string_ext;
+typedef const value_string *(*_value_string_match2_t)(const guint32, value_string_ext*);
 
-typedef struct _value_string_ext {
+struct _value_string_ext {
     _value_string_match2_t _vs_match2;
     guint32                _vs_first_value; /* first value of the value_string array       */
     guint                  _vs_num_entries; /* number of entries in the value_string array */
                                             /*  (excluding final {0, NULL})                */
     const value_string    *_vs_p;           /* the value string array address              */
     const gchar           *_vs_name;        /* vse "Name" (for error messages)             */
-} value_string_ext;
+};
 
 #define VALUE_STRING_EXT_VS_P(x)           (x)->_vs_p
 #define VALUE_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
@@ -179,32 +176,91 @@ typedef struct _value_string_ext {
 
 WS_DLL_PUBLIC
 const value_string *
-_try_val_to_str_ext_init(const guint32 val, const value_string_ext *vse);
+_try_val_to_str_ext_init(const guint32 val, value_string_ext *vse);
 #define VALUE_STRING_EXT_INIT(x) { _try_val_to_str_ext_init, 0, G_N_ELEMENTS(x)-1, x, #x }
 
 WS_DLL_PUBLIC
-const value_string_ext *
+value_string_ext *
 value_string_ext_new(const value_string *vs, guint vs_tot_num_entries, const gchar *vs_name);
 
 WS_DLL_PUBLIC
 void
-value_string_ext_free(const value_string_ext *vse);
+value_string_ext_free(value_string_ext *vse);
+
+WS_DLL_PUBLIC
+const gchar *
+val_to_str_ext(const guint32 val, value_string_ext *vse, const char *fmt)
+G_GNUC_PRINTF(3, 0);
+
+WS_DLL_PUBLIC
+gchar *
+val_to_str_ext_wmem(wmem_allocator_t *scope, const guint32 val, value_string_ext *vse, const char *fmt)
+G_GNUC_PRINTF(4, 0);
+
+WS_DLL_PUBLIC
+const gchar *
+val_to_str_ext_const(const guint32 val, value_string_ext *vs, const char *unknown_str);
+
+WS_DLL_PUBLIC
+const gchar *
+try_val_to_str_ext(const guint32 val, value_string_ext *vse);
 
 WS_DLL_PUBLIC
 const gchar *
-val_to_str_ext(const guint32 val, const value_string_ext *vs, const char *fmt);
+try_val_to_str_idx_ext(const guint32 val, value_string_ext *vse, gint *idx);
+
+/* EXTENDED 64-BIT VALUE TO STRING MATCHING */
+
+typedef struct _val64_string_ext val64_string_ext;
+typedef const val64_string *(*_val64_string_match2_t)(const guint64, val64_string_ext*);
+
+struct _val64_string_ext {
+    _val64_string_match2_t _vs_match2;
+    guint64                _vs_first_value; /* first value of the val64_string array       */
+    guint                  _vs_num_entries; /* number of entries in the val64_string array */
+                                            /*  (excluding final {0, NULL})                */
+    const val64_string    *_vs_p;           /* the value string array address              */
+    const gchar           *_vs_name;        /* vse "Name" (for error messages)             */
+};
+
+#define VAL64_STRING_EXT_VS_P(x)           (x)->_vs_p
+#define VAL64_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
+#define VAL64_STRING_EXT_VS_NAME(x)        (x)->_vs_name
+
+WS_DLL_PUBLIC
+const val64_string *
+_try_val64_to_str_ext_init(const guint64 val, val64_string_ext *vse);
+#define VAL64_STRING_EXT_INIT(x) { _try_val64_to_str_ext_init, 0, G_N_ELEMENTS(x)-1, x, #x }
+
+WS_DLL_PUBLIC
+val64_string_ext *
+val64_string_ext_new(const val64_string *vs, guint vs_tot_num_entries, const gchar *vs_name);
+
+WS_DLL_PUBLIC
+void
+val64_string_ext_free(val64_string_ext *vse);
 
 WS_DLL_PUBLIC
 const gchar *
-val_to_str_ext_const(const guint32 val, const value_string_ext *vs, const char *unknown_str);
+val64_to_str_ext(const guint64 val, val64_string_ext *vse, const char *fmt)
+G_GNUC_PRINTF(3, 0);
+
+WS_DLL_PUBLIC
+gchar *
+val64_to_str_ext_wmem(wmem_allocator_t *scope, const guint64 val, val64_string_ext *vse, const char *fmt)
+G_GNUC_PRINTF(4, 0);
 
 WS_DLL_PUBLIC
 const gchar *
-try_val_to_str_ext(const guint32 val, const value_string_ext *vse);
+val64_to_str_ext_const(const guint64 val, val64_string_ext *vs, const char *unknown_str);
 
 WS_DLL_PUBLIC
 const gchar *
-try_val_to_str_idx_ext(const guint32 val, const value_string_ext *vse, gint *idx);
+try_val64_to_str_ext(const guint64 val, val64_string_ext *vse);
+
+WS_DLL_PUBLIC
+const gchar *
+try_val64_to_str_idx_ext(const guint64 val, val64_string_ext *vse, gint *idx);
 
 /* STRING TO STRING MATCHING */
 
@@ -215,7 +271,8 @@ typedef struct _string_string {
 
 WS_DLL_PUBLIC
 const gchar *
-str_to_str(const gchar *val, const string_string *vs, const char *fmt);
+str_to_str(const gchar *val, const string_string *vs, const char *fmt)
+G_GNUC_PRINTF(3, 0);
 
 WS_DLL_PUBLIC
 const gchar *
@@ -235,7 +292,8 @@ typedef struct _range_string {
 
 WS_DLL_PUBLIC
 const gchar *
-rval_to_str(const guint32 val, const range_string *rs, const char *fmt);
+rval_to_str(const guint32 val, const range_string *rs, const char *fmt)
+G_GNUC_PRINTF(3, 0);
 
 WS_DLL_PUBLIC
 const gchar *
@@ -249,6 +307,40 @@ WS_DLL_PUBLIC
 const gchar *
 try_rval_to_str_idx(const guint32 val, const range_string *rs, gint *idx);
 
+WS_DLL_PUBLIC
+const gchar *
+try_rval64_to_str(const guint64 val, const range_string *rs);
+
+WS_DLL_PUBLIC
+const gchar *
+try_rval64_to_str_idx(const guint64 val, const range_string *rs, gint *idx);
+
+/* BYTES TO STRING MATCHING */
+
+typedef struct _bytes_string {
+  const guint8 *value;
+  const size_t  value_length;
+  const gchar  *strptr;
+} bytes_string;
+
+WS_DLL_PUBLIC
+const gchar *
+bytesval_to_str(const guint8 *val, const size_t val_len, const bytes_string *bs, const char *fmt)
+G_GNUC_PRINTF(4, 0);
+
+WS_DLL_PUBLIC
+const gchar *
+try_bytesval_to_str(const guint8 *val, const size_t val_len, const bytes_string *bs);
+
+WS_DLL_PUBLIC
+const gchar *
+bytesprefix_to_str(const guint8 *haystack, const size_t haystack_len, const bytes_string *bs, const char *fmt)
+G_GNUC_PRINTF(4, 0);
+
+WS_DLL_PUBLIC
+const gchar *
+try_bytesprefix_to_str(const guint8 *haystack, const size_t haystack_len, const bytes_string *bs);
+
 /* MISC (generally do not use) */
 
 WS_DLL_LOCAL
@@ -259,6 +351,14 @@ WS_DLL_LOCAL
 const gchar *
 value_string_ext_match_type_str(const value_string_ext *vse);
 
+WS_DLL_LOCAL
+gboolean
+val64_string_ext_validate(const val64_string_ext *vse);
+
+WS_DLL_LOCAL
+const gchar *
+val64_string_ext_match_type_str(const val64_string_ext *vse);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */