/* 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__
#include "ws_symbol_export.h"
+#include <epan/wmem/wmem.h>
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** 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
* @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
* (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
* (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
*
*/
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
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.
/** 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"
* @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.
*
* @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
* 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.
*