Wireshark 2.9.0-477-g68ec514b The Wireshark network protocol analyzer

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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__ */
format_text_wsp
WS_DLL_PUBLIC gchar * format_text_wsp(wmem_allocator_t *allocator, const guchar *line, size_t len)
Definition: strutil.c:232
hex_str_to_bytes
WS_DLL_PUBLIC gboolean hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separators)
Definition: strutil.c:389
epan_strcasestr
WS_DLL_PUBLIC const char * epan_strcasestr(const char *haystack, const char *needle)
Definition: strutil.c:1011
rel_oid_str_to_bytes
WS_DLL_PUBLIC gboolean rel_oid_str_to_bytes(const char *oid_str, GByteArray *bytes, gboolean is_absolute)
Definition: strutil.c:765
ws_strdup_unescape_char
WS_DLL_PUBLIC gchar * ws_strdup_unescape_char(const gchar *str, const gchar chr)
string_or_null
WS_DLL_PUBLIC const char * string_or_null(const char *string)
Definition: strutil.c:1025
format_uri
WS_DLL_PUBLIC gchar * format_uri(wmem_allocator_t *allocator, const GByteArray *bytes, const gchar *reserved_chars)
Definition: strutil.c:681
format_text_chr
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
get_token_len
WS_DLL_PUBLIC int get_token_len(const guchar *linep, const guchar *lineend, const guchar **next_token)
Definition: strutil.c:101
string_replace
WS_DLL_PUBLIC gchar * string_replace(const gchar *str, const gchar *old_val, const gchar *new_val)
Definition: strutil.c:1205
epan_memmem
WS_DLL_PUBLIC const guint8 * epan_memmem(const guint8 *haystack, guint haystack_len, const guint8 *needle, guint needle_len)
Definition: strutil.c:894
convert_string_case
WS_DLL_PUBLIC char * convert_string_case(const char *string, gboolean case_insensitive)
Definition: strutil.c:1000
convert_string_to_hex
WS_DLL_PUBLIC guint8 * convert_string_to_hex(const char *string, size_t *nbytes)
Definition: strutil.c:924
_wmem_allocator_t
Definition: wmem_allocator.h:26
ws_strdup_escape_char
WS_DLL_PUBLIC gchar * ws_strdup_escape_char(const gchar *str, const gchar chr)
Definition: strutil.c:1151
find_line_end
const guchar * find_line_end(const guchar *data, const guchar *dataend, const guchar **eol)
Definition: strutil.c:37
byte_array_equal
WS_DLL_PUBLIC gboolean byte_array_equal(GByteArray *ba1, GByteArray *ba2)
Definition: strutil.c:835
byte_array_dup
WS_DLL_PUBLIC GByteArray * byte_array_dup(const GByteArray *ba)
Definition: strutil.c:746
oid_str_to_bytes
WS_DLL_PUBLIC gboolean oid_str_to_bytes(const char *oid_str, GByteArray *bytes)
Definition: strutil.c:760
xml_escape
WS_DLL_PUBLIC gchar * xml_escape(const gchar *unescaped)
Definition: strutil.c:853
format_text
WS_DLL_PUBLIC gchar * format_text(wmem_allocator_t *allocator, const guchar *line, size_t len)
Definition: strutil.c:135
uri_str_to_bytes
WS_DLL_PUBLIC gboolean uri_str_to_bytes(const char *uri_str, GByteArray *bytes)
Definition: strutil.c:639