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