pytest.ini: declare minimum version requirement
[metze/wireshark/wip.git] / epan / strutil.h
index f975ea49e32e5b2fa6b7515df14ddceefbc8f870..2046cb0506715f522cd930bd0c113edba0e2bd67 100644 (file)
@@ -1,25 +1,11 @@
 /* strutil.h
  * String utility definitions
  *
- * $Id$
- *
  * Wireshark - Network traffic analyzer
  * 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 __STRUTIL_H__
@@ -27,6 +13,8 @@
 
 #include "ws_symbol_export.h"
 
+#include <epan/wmem/wmem.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -61,6 +49,7 @@ int        get_token_len(const guchar *linep, const guchar *lineend,
 /** Given a string, generate a string from it that shows non-printable
  *  characters as C-style escapes, and return a pointer to it.
  *
+ * @param allocator The wmem scope
  * @param line A pointer to the input string
  * @param len The length of the input string
  * @return A pointer to the formatted string
@@ -68,7 +57,7 @@ int        get_token_len(const guchar *linep, const guchar *lineend,
  * @see tvb_format_text()
  */
 WS_DLL_PUBLIC
-gchar*     format_text(const guchar *line, size_t len);
+gchar*     format_text(wmem_allocator_t* allocator, const guchar *line, size_t len);
 
 /**
  * Given a string, generate a string from it that shows non-printable
@@ -76,13 +65,14 @@ gchar*     format_text(const guchar *line, size_t len);
  * (space, tab, carriage return, new line, vertical tab, or formfeed)
  * which will be replaced by a space, and return a pointer to it.
  *
+ * @param allocator The wmem scope
  * @param line A pointer to the input string
  * @param len The length of the input string
  * @return A pointer to the formatted string
  *
  */
 WS_DLL_PUBLIC
-gchar*     format_text_wsp(const guchar *line, size_t len);
+gchar*     format_text_wsp(wmem_allocator_t* allocator, const guchar *line, size_t len);
 
 /**
  * Given a string, generate a string from it that shows non-printable
@@ -90,6 +80,7 @@ gchar*     format_text_wsp(const guchar *line, size_t len);
  * (space, tab, carriage return, new line, vertical tab, or formfeed)
  * which will be replaced by a space, and return a pointer to it.
  *
+ * @param allocator The wmem scope
  * @param string A pointer to the input string
  * @param len The length of the input string
  * @param chr The character to use to replace non-printable characters
@@ -97,7 +88,7 @@ gchar*     format_text_wsp(const guchar *line, size_t len);
  *
  */
 WS_DLL_PUBLIC
-gchar*     format_text_chr(const guchar *string, const size_t len, const guchar chr);
+gchar*     format_text_chr(wmem_allocator_t* allocator, const guchar *string, const size_t len, const guchar chr);
 
 
 /** Turn a string of hex digits with optional separators (defined by
@@ -114,6 +105,34 @@ WS_DLL_PUBLIC
 gboolean   hex_str_to_bytes(const char *hex_str, GByteArray *bytes,
     gboolean force_separators);
 
+/* Turn a string of hex digits with optional separators (defined by encoding)
+ * into a byte array. Unlike hex_str_to_bytes(), this will read as many hex-char
+ * pairs as possible and not error if it hits a non-hex-char; instead it just ends
+ * there. (i.e., like strtol()/atoi()/etc.) But it must see two hex chars at the
+ * beginning or it will return FALSE.
+ *
+ * @param hex_str The string of hex digits.
+ * @param bytes The GByteArray that will receive the bytes.  This
+ *        must be initialized by the caller.
+ * @param endptr if not NULL, is set to the char after the last hex character consumed.
+ * @param encoding set to one or more bitwise-or'ed ENC_SEP_* (see proto.h)
+ * @param fail_if_partial If set to TRUE, then the conversion fails if the whole
+ *    hex_str is not consumed.
+ * @return FALSE only if no bytes were generated; or if fail_if_partial is TRUE
+ *    and the entire hex_str was not consumed.
+ *
+ * If no ENC_SEP_* is set, then no separators are allowed. If multiple ENC_SEP_* are
+ * bit-or'ed, any of them can be a separator, but once the separator is seen then
+ * only its same type is accepted for the rest of the string. (i.e., it won't convert
+ * a "01:23-4567" even if ENC_SEP_COLON|ENC_SEP_DASH|ENC_SEP_NONE is passed in)
+ *
+ * This is done this way because it's likely a malformed scenario if they're mixed,
+ * and this routine is used by dissectors via tvb_get_string_XXX routines.
+ */
+WS_DLL_PUBLIC
+gboolean hex_str_to_bytes_encoding(const char *hex_str, GByteArray *bytes, const char **endptr,
+                                   const guint encoding, const gboolean fail_if_partial);
+
 /** Turn an RFC 3986 percent-encoded string into a byte array.
  *
  * @param uri_str The string of hex digits.
@@ -127,6 +146,7 @@ gboolean   uri_str_to_bytes(const char *uri_str, GByteArray *bytes);
 
 /** Turn a byte array into an RFC 3986 percent-encoded string.
  *
+ * @param allocator The wmem scope
  * @param bytes The GByteArray that will receive the bytes.  This
  *        must be initialized by the caller.
  * @param reserved_chars Normally the "gen-delims" and "sub-delims"
@@ -139,7 +159,7 @@ gboolean   uri_str_to_bytes(const char *uri_str, GByteArray *bytes);
  * @see uri_str_to_bytes(),  format_text(), isprint()
  */
 WS_DLL_PUBLIC
-const gchar* format_uri(const GByteArray *bytes, const gchar *reserved_chars);
+gchar* format_uri(wmem_allocator_t* allocator, const GByteArray *bytes, const gchar *reserved_chars);
 
 /** Turn a OID string representation (dot notation) into a byte array.
  *
@@ -171,7 +191,7 @@ gboolean   oid_str_to_bytes(const char *oid_str, GByteArray *bytes);
  * @todo - Should this be in strutil.c?
  */
 WS_DLL_PUBLIC
-GByteArray *byte_array_dup(GByteArray *ba);
+GByteArray *byte_array_dup(const GByteArray *ba);
 
 /**
  * Compare the contents of two GByteArrays
@@ -243,7 +263,7 @@ char * convert_string_case(const char *string, gboolean case_insensitive);
  *   Otherwise it returns NULL.
  */
 WS_DLL_PUBLIC
-char * epan_strcasestr(const char *haystack, const char *needle);
+const char * epan_strcasestr(const char *haystack, const char *needle);
 
 /** Guarantee a non-null string.
  *