Wireshark 4.5.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 <[email protected]>
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
36const unsigned char *find_line_end(const unsigned char *data, const unsigned char *dataend,
37 const unsigned char **eol);
38
46WS_DLL_PUBLIC
47int get_token_len(const unsigned char *linep, const unsigned char *lineend,
48 const unsigned char **next_token);
49
60WS_DLL_PUBLIC
61bool 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 */
88WS_DLL_PUBLIC
89bool hex_str_to_bytes_encoding(const char *hex_str, GByteArray *bytes, const char **endptr,
90 const unsigned encoding, const bool fail_if_partial);
91
100WS_DLL_PUBLIC
101bool uri_to_bytes(const char *uri_str, GByteArray *bytes, size_t len);
102
110WS_DLL_PUBLIC
111bool uri_str_to_bytes(const char *uri_str, GByteArray *bytes);
112
121WS_DLL_PUBLIC
122bool rel_oid_str_to_bytes(const char *oid_str, GByteArray *bytes, bool is_absolute);
123
131WS_DLL_PUBLIC
132bool oid_str_to_bytes(const char *oid_str, GByteArray *bytes);
133
142WS_DLL_PUBLIC
143GByteArray *byte_array_dup(const GByteArray *ba);
144
156WS_DLL_PUBLIC
157bool byte_array_equal(GByteArray *ba1, GByteArray *ba2);
158
159
166WS_DLL_PUBLIC
167char* xml_escape(const char *unescaped);
168
176WS_DLL_PUBLIC
177uint8_t * convert_string_to_hex(const char *string, size_t *nbytes);
178
187WS_DLL_PUBLIC
188char * convert_string_case(const char *string, bool case_insensitive);
189
190WS_DLL_PUBLIC
191void IA5_7BIT_decode(unsigned char * dest, const unsigned char* src, int len);
192
193#define FORMAT_LABEL_REPLACE_SPACE (0x1 << 0)
194
195WS_DLL_PUBLIC
196size_t ws_label_strcpy(char *label_str, size_t bufsize, size_t pos, const uint8_t *str, int flags);
197
198WS_DLL_PUBLIC
199size_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 */
205WS_DLL_LOCAL unsigned char
206module_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 GByteArray * byte_array_dup(const GByteArray *ba)
Definition strutil.c:459
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
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 char * convert_string_case(const char *string, bool case_insensitive)
Definition strutil.c:696
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 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
const unsigned char * find_line_end(const unsigned char *data, const unsigned char *dataend, const unsigned char **eol)
Definition strutil.c:36