| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
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_scopes.h>
17#include <wsutil/str_util.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif /* __cplusplus */
22
36WS_DLL_PUBLIC
37const unsigned char *find_line_end(const unsigned char *data, const unsigned char *dataend,
38 const unsigned char **eol);
39
47WS_DLL_PUBLIC
48int get_token_len(const unsigned char *linep, const unsigned char *lineend,
49 const unsigned char **next_token);
50
61WS_DLL_PUBLIC
62bool hex_str_to_bytes(const char *hex_str, GByteArray *bytes,
63 bool force_separators);
64
65/* Turn a string of hex digits with optional separators (defined by encoding)
66 * into a byte array. Unlike hex_str_to_bytes(), this will read as many hex-char
67 * pairs as possible and not error if it hits a non-hex-char; instead it just ends
68 * there. (i.e., like strtol()/atoi()/etc.) But it must see two hex chars at the
69 * beginning or it will return false.
70 *
71 * @param hex_str The string of hex digits.
72 * @param bytes The GByteArray that will receive the bytes. This
73 * must be initialized by the caller.
74 * @param endptr if not NULL, is set to the char after the last hex character consumed.
75 * @param encoding set to one or more bitwise-or'ed ENC_SEP_* (see proto.h)
76 * @param fail_if_partial If set to true, then the conversion fails if the whole
77 * hex_str is not consumed.
78 * @return false only if no bytes were generated; or if fail_if_partial is true
79 * and the entire hex_str was not consumed.
80 *
81 * If no ENC_SEP_* is set, then no separators are allowed. If multiple ENC_SEP_* are
82 * bit-or'ed, any of them can be a separator, but once the separator is seen then
83 * only its same type is accepted for the rest of the string. (i.e., it won't convert
84 * a "01:23-4567" even if ENC_SEP_COLON|ENC_SEP_DASH|ENC_SEP_NONE is passed in)
85 *
86 * This is done this way because it's likely a malformed scenario if they're mixed,
87 * and this routine is used by dissectors via tvb_get_string_XXX routines.
88 */
89WS_DLL_PUBLIC
90bool hex_str_to_bytes_encoding(const char *hex_str, GByteArray *bytes, const char **endptr,
91 const unsigned encoding, const bool fail_if_partial);
92
101WS_DLL_PUBLIC
102bool uri_to_bytes(const char *uri_str, GByteArray *bytes, size_t len);
103
111WS_DLL_PUBLIC
112bool uri_str_to_bytes(const char *uri_str, GByteArray *bytes);
113
122WS_DLL_PUBLIC
123bool rel_oid_str_to_bytes(const char *oid_str, GByteArray *bytes, bool is_absolute);
124
132WS_DLL_PUBLIC
133bool oid_str_to_bytes(const char *oid_str, GByteArray *bytes);
134
143WS_DLL_PUBLIC
144GByteArray *byte_array_dup(const GByteArray *ba);
145
157WS_DLL_PUBLIC
158bool byte_array_equal(GByteArray *ba1, GByteArray *ba2);
159
160
167WS_DLL_PUBLIC
168char* xml_escape(const char *unescaped);
169
177WS_DLL_PUBLIC
178uint8_t * convert_string_to_hex(const char *string, size_t *nbytes);
179
188WS_DLL_PUBLIC
189char * convert_string_case(const char *string, bool case_insensitive);
190
191WS_DLL_PUBLIC
192void IA5_7BIT_decode(unsigned char * dest, const unsigned char* src, int len);
193
194#define FORMAT_LABEL_REPLACE_SPACE (0x1 << 0)
195
210WS_DLL_PUBLIC
211size_t ws_label_strcpy(char *label_str, size_t bufsize, size_t pos, const uint8_t *str, int flags);
212
226WS_DLL_PUBLIC
227size_t ws_label_strcat(char *label_str, size_t bufsize, const uint8_t *str, int flags);
228
229/*
230 * Check name is valid. This covers names for display filter fields, dissector
231 * tables, preference modules, etc. Lower case is preferred.
232 */
233WS_DLL_LOCAL unsigned char
234module_check_valid_name(const char *name, bool lower_only);
235
236#ifdef __cplusplus
237}
238#endif /* __cplusplus */
239
240#endif /* __STRUTIL_H__ */
str_util.h
byte_array_dup
WS_DLL_PUBLIC GByteArray * byte_array_dup(const GByteArray *ba)
Definition strutil.c:459
xml_escape
WS_DLL_PUBLIC char * xml_escape(const char *unescaped)
Definition strutil.c:566
convert_string_to_hex
WS_DLL_PUBLIC uint8_t * convert_string_to_hex(const char *string, size_t *nbytes)
Definition strutil.c:620
oid_str_to_bytes
WS_DLL_PUBLIC bool oid_str_to_bytes(const char *oid_str, GByteArray *bytes)
Definition strutil.c:473
hex_str_to_bytes
WS_DLL_PUBLIC bool hex_str_to_bytes(const char *hex_str, GByteArray *bytes, bool force_separators)
Definition strutil.c:140
convert_string_case
WS_DLL_PUBLIC char * convert_string_case(const char *string, bool case_insensitive)
Definition strutil.c:696
uri_to_bytes
WS_DLL_PUBLIC bool uri_to_bytes(const char *uri_str, GByteArray *bytes, size_t len)
Definition strutil.c:402
find_line_end
WS_DLL_PUBLIC const unsigned char * find_line_end(const unsigned char *data, const unsigned char *dataend, const unsigned char **eol)
Definition strutil.c:36
byte_array_equal
WS_DLL_PUBLIC bool byte_array_equal(GByteArray *ba1, GByteArray *ba2)
Definition strutil.c:548
rel_oid_str_to_bytes
WS_DLL_PUBLIC bool rel_oid_str_to_bytes(const char *oid_str, GByteArray *bytes, bool is_absolute)
Definition strutil.c:478
get_token_len
WS_DLL_PUBLIC int get_token_len(const unsigned char *linep, const unsigned char *lineend, const unsigned char **next_token)
Definition strutil.c:100
uri_str_to_bytes
WS_DLL_PUBLIC bool uri_str_to_bytes(const char *uri_str, GByteArray *bytes)
Definition strutil.c:446
ws_label_strcat
WS_DLL_PUBLIC size_t ws_label_strcat(char *label_str, size_t bufsize, const uint8_t *str, int flags)
Definition strutil.c:959
ws_label_strcpy
WS_DLL_PUBLIC size_t ws_label_strcpy(char *label_str, size_t bufsize, size_t pos, const uint8_t *str, int flags)
Definition strutil.c:823
wmem_scopes.h