Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
strutil.h
Go to the documentation of this file.
1 /* strutil.h
2  * String utility definitions
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #ifndef __STRUTIL_H__
12 #define __STRUTIL_H__
13 
14 #include "ws_symbol_export.h"
15 
16 #include <epan/wmem/wmem.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif /* __cplusplus */
21 
35 const guchar *find_line_end(const guchar *data, const guchar *dataend,
36  const guchar **eol);
37 
45 WS_DLL_PUBLIC
46 int get_token_len(const guchar *linep, const guchar *lineend,
47  const guchar **next_token);
48 
59 WS_DLL_PUBLIC
60 gchar* format_text(wmem_allocator_t* allocator, const guchar *line, size_t len);
61 
74 WS_DLL_PUBLIC
75 gchar* format_text_wsp(wmem_allocator_t* allocator, const guchar *line, size_t len);
76 
90 WS_DLL_PUBLIC
91 gchar* format_text_chr(wmem_allocator_t* allocator, const guchar *string, const size_t len, const guchar chr);
92 
93 
104 WS_DLL_PUBLIC
105 gboolean hex_str_to_bytes(const char *hex_str, GByteArray *bytes,
106  gboolean force_separators);
107 
108 /* Turn a string of hex digits with optional separators (defined by encoding)
109  * into a byte array. Unlike hex_str_to_bytes(), this will read as many hex-char
110  * pairs as possible and not error if it hits a non-hex-char; instead it just ends
111  * there. (i.e., like strtol()/atoi()/etc.) But it must see two hex chars at the
112  * beginning or it will return FALSE.
113  *
114  * @param hex_str The string of hex digits.
115  * @param bytes The GByteArray that will receive the bytes. This
116  * must be initialized by the caller.
117  * @param endptr if not NULL, is set to the char after the last hex character consumed.
118  * @param encoding set to one or more bitwise-or'ed ENC_SEP_* (see proto.h)
119  * @param fail_if_partial If set to TRUE, then the conversion fails if the whole
120  * hex_str is not consumed.
121  * @return FALSE only if no bytes were generated; or if fail_if_partial is TRUE
122  * and the entire hex_str was not consumed.
123  *
124  * If no ENC_SEP_* is set, then no separators are allowed. If multiple ENC_SEP_* are
125  * bit-or'ed, any of them can be a separator, but once the separator is seen then
126  * only its same type is accepted for the rest of the string. (i.e., it won't convert
127  * a "01:23-4567" even if ENC_SEP_COLON|ENC_SEP_DASH|ENC_SEP_NONE is passed in)
128  *
129  * This is done this way because it's likely a malformed scenario if they're mixed,
130  * and this routine is used by dissectors via tvb_get_string_XXX routines.
131  */
132 WS_DLL_PUBLIC
133 gboolean hex_str_to_bytes_encoding(const char *hex_str, GByteArray *bytes, const char **endptr,
134  const guint encoding, const gboolean fail_if_partial);
135 
144 WS_DLL_PUBLIC
145 gboolean uri_str_to_bytes(const char *uri_str, GByteArray *bytes);
146 
161 WS_DLL_PUBLIC
162 gchar* format_uri(wmem_allocator_t* allocator, const GByteArray *bytes, const gchar *reserved_chars);
163 
172 WS_DLL_PUBLIC
173 gboolean rel_oid_str_to_bytes(const char *oid_str, GByteArray *bytes, gboolean is_absolute);
174 
182 WS_DLL_PUBLIC
183 gboolean oid_str_to_bytes(const char *oid_str, GByteArray *bytes);
184 
193 WS_DLL_PUBLIC
194 GByteArray *byte_array_dup(const GByteArray *ba);
195 
207 WS_DLL_PUBLIC
208 gboolean byte_array_equal(GByteArray *ba1, GByteArray *ba2);
209 
210 
217 WS_DLL_PUBLIC
218 gchar* xml_escape(const gchar *unescaped);
219 
232 WS_DLL_PUBLIC
233 const guint8 * epan_memmem(const guint8 *haystack, guint haystack_len,
234  const guint8 *needle, guint needle_len);
235 
243 WS_DLL_PUBLIC
244 guint8 * convert_string_to_hex(const char *string, size_t *nbytes);
245 
254 WS_DLL_PUBLIC
255 char * convert_string_case(const char *string, gboolean case_insensitive);
256 
265 WS_DLL_PUBLIC
266 const char * epan_strcasestr(const char *haystack, const char *needle);
267 
273 WS_DLL_PUBLIC
274 const char * string_or_null(const char *string);
275 
276 WS_DLL_PUBLIC
277 int escape_string_len(const char *string);
278 WS_DLL_PUBLIC
279 char * escape_string(char *dst, const char *string);
280 
281 
282 WS_DLL_PUBLIC
283 void IA5_7BIT_decode(unsigned char * dest, const unsigned char* src, int len);
284 
292 WS_DLL_PUBLIC
293 gchar* ws_strdup_escape_char (const gchar *str, const gchar chr);
294 
302 WS_DLL_PUBLIC
303 gchar* ws_strdup_unescape_char (const gchar *str, const gchar chr);
304 
314 WS_DLL_PUBLIC
315 gchar *string_replace(const gchar* str, const gchar *old_val, const gchar *new_val);
316 
317 #ifdef __cplusplus
318 }
319 #endif /* __cplusplus */
320 
321 #endif /* __STRUTIL_H__ */
WS_DLL_PUBLIC gchar * format_text_wsp(wmem_allocator_t *allocator, const guchar *line, size_t len)
Definition: strutil.c:232
WS_DLL_PUBLIC gboolean hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separators)
Definition: strutil.c:389
WS_DLL_PUBLIC const char * epan_strcasestr(const char *haystack, const char *needle)
Definition: strutil.c:1011
WS_DLL_PUBLIC gboolean rel_oid_str_to_bytes(const char *oid_str, GByteArray *bytes, gboolean is_absolute)
Definition: strutil.c:765
WS_DLL_PUBLIC gchar * ws_strdup_unescape_char(const gchar *str, const gchar chr)
WS_DLL_PUBLIC const char * string_or_null(const char *string)
Definition: strutil.c:1025
WS_DLL_PUBLIC gchar * format_uri(wmem_allocator_t *allocator, const GByteArray *bytes, const gchar *reserved_chars)
Definition: strutil.c:681
WS_DLL_PUBLIC gchar * format_text_chr(wmem_allocator_t *allocator, const guchar *string, const size_t len, const guchar chr)
Definition: strutil.c:331
WS_DLL_PUBLIC int get_token_len(const guchar *linep, const guchar *lineend, const guchar **next_token)
Definition: strutil.c:101
WS_DLL_PUBLIC gchar * string_replace(const gchar *str, const gchar *old_val, const gchar *new_val)
Definition: strutil.c:1205
WS_DLL_PUBLIC const guint8 * epan_memmem(const guint8 *haystack, guint haystack_len, const guint8 *needle, guint needle_len)
Definition: strutil.c:894
WS_DLL_PUBLIC char * convert_string_case(const char *string, gboolean case_insensitive)
Definition: strutil.c:1000
WS_DLL_PUBLIC guint8 * convert_string_to_hex(const char *string, size_t *nbytes)
Definition: strutil.c:924
Definition: wmem_allocator.h:26
WS_DLL_PUBLIC gchar * ws_strdup_escape_char(const gchar *str, const gchar chr)
Definition: strutil.c:1151
const guchar * find_line_end(const guchar *data, const guchar *dataend, const guchar **eol)
Definition: strutil.c:37
WS_DLL_PUBLIC gboolean byte_array_equal(GByteArray *ba1, GByteArray *ba2)
Definition: strutil.c:835
WS_DLL_PUBLIC GByteArray * byte_array_dup(const GByteArray *ba)
Definition: strutil.c:746
WS_DLL_PUBLIC gboolean oid_str_to_bytes(const char *oid_str, GByteArray *bytes)
Definition: strutil.c:760
WS_DLL_PUBLIC gchar * xml_escape(const gchar *unescaped)
Definition: strutil.c:853
WS_DLL_PUBLIC gchar * format_text(wmem_allocator_t *allocator, const guchar *line, size_t len)
Definition: strutil.c:135
WS_DLL_PUBLIC gboolean uri_str_to_bytes(const char *uri_str, GByteArray *bytes)
Definition: strutil.c:639