Wireshark 4.5.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Macros | Functions
strutil.h File Reference
#include "ws_symbol_export.h"
#include <epan/wmem_scopes.h>
#include <wsutil/str_util.h>

Go to the source code of this file.

Macros

#define FORMAT_LABEL_REPLACE_SPACE   (0x1 << 0)
 

Functions

const unsigned char * find_line_end (const unsigned char *data, const unsigned char *dataend, const unsigned char **eol)
 
WS_DLL_PUBLIC int get_token_len (const unsigned char *linep, const unsigned char *lineend, const unsigned char **next_token)
 
WS_DLL_PUBLIC bool hex_str_to_bytes (const char *hex_str, GByteArray *bytes, bool force_separators)
 
WS_DLL_PUBLIC bool hex_str_to_bytes_encoding (const char *hex_str, GByteArray *bytes, const char **endptr, const unsigned encoding, const bool fail_if_partial)
 
WS_DLL_PUBLIC bool uri_to_bytes (const char *uri_str, GByteArray *bytes, size_t len)
 
WS_DLL_PUBLIC bool uri_str_to_bytes (const char *uri_str, GByteArray *bytes)
 
WS_DLL_PUBLIC bool rel_oid_str_to_bytes (const char *oid_str, GByteArray *bytes, bool is_absolute)
 
WS_DLL_PUBLIC bool oid_str_to_bytes (const char *oid_str, GByteArray *bytes)
 
WS_DLL_PUBLIC GByteArray * byte_array_dup (const GByteArray *ba)
 
WS_DLL_PUBLIC bool byte_array_equal (GByteArray *ba1, GByteArray *ba2)
 
WS_DLL_PUBLIC char * xml_escape (const char *unescaped)
 
WS_DLL_PUBLIC uint8_t * convert_string_to_hex (const char *string, size_t *nbytes)
 
WS_DLL_PUBLIC char * convert_string_case (const char *string, bool case_insensitive)
 
WS_DLL_PUBLIC void IA5_7BIT_decode (unsigned char *dest, const unsigned char *src, int len)
 
WS_DLL_PUBLIC size_t ws_label_strcpy (char *label_str, size_t bufsize, size_t pos, const uint8_t *str, int flags)
 
WS_DLL_PUBLIC size_t ws_label_strcat (char *label_str, size_t bufsize, const uint8_t *str, int flags)
 
WS_DLL_LOCAL unsigned char module_check_valid_name (const char *name, bool lower_only)
 

Detailed Description

String handling and conversion utilities.

Function Documentation

◆ byte_array_dup()

WS_DLL_PUBLIC GByteArray * byte_array_dup ( const GByteArray *  ba)

Create a copy of a GByteArray

Parameters
baThe byte array to be copied.
Returns
If ba exists, a freshly allocated copy. NULL otherwise.
Todo:
  • Should this be in strutil.c?

Create a copy of a GByteArray

Parameters
baThe byte array to be copied.
Returns
If ba exists, a freshly allocated copy. NULL otherwise.

◆ byte_array_equal()

WS_DLL_PUBLIC bool byte_array_equal ( GByteArray *  ba1,
GByteArray *  ba2 
)

Compare the contents of two GByteArrays

Parameters
ba1A byte array
ba2A byte array
Returns
If both arrays are non-NULL and their lengths are equal and their contents are equal, returns true. Otherwise, returns false.
Todo:
  • Should this be in strutil.c?

Compare the contents of two GByteArrays

Parameters
ba1A byte array
ba2A byte array
Returns
If both arrays are non-NULL and their lengths are equal and their contents are equal, returns true. Otherwise, returns false.

XXX - Should this be in strutil.c?

◆ convert_string_case()

WS_DLL_PUBLIC char * convert_string_case ( const char *  string,
bool  case_insensitive 
)

Prep a string for case-sensitive vs case-insensitive searching.

Parameters
stringThe search string
case_insensitivetrue if case-insensitive, false if not
Returns
A direct copy of the string if it's a case-sensitive search and an uppercased version if not. In either case the string must be g_free()d by the caller.

◆ convert_string_to_hex()

WS_DLL_PUBLIC uint8_t * convert_string_to_hex ( const char *  string,
size_t *  nbytes 
)

Scan a string to make sure it's valid hex.

Parameters
stringThe string to validate
nbytesThe length of the return buffer
Returns
A pointer to a buffer containing the converted raw bytes. This buffer must be g_free()d by the caller.

◆ find_line_end()

const unsigned char * find_line_end ( const unsigned char *  data,
const unsigned char *  dataend,
const unsigned char **  eol 
)

Given a pointer into a data buffer, and to the end of the buffer, find the end of the (putative) line at that position in the data buffer.

Parameters
dataA pointer to the beginning of the data
dataendA pointer to the end of the data
eolA pointer that will receive the EOL location
Returns
A pointer to the EOL character(s) in "*eol".

◆ get_token_len()

WS_DLL_PUBLIC int get_token_len ( const unsigned char *  linep,
const unsigned char *  lineend,
const unsigned char **  next_token 
)

Get the length of the next token in a line, and the beginning of the next token after that (if any).

Parameters
linepA pointer to the beginning of the line
lineendA pointer to the end of the line
next_tokenReceives the location of the next token
Returns
0 if there is no next token.

◆ hex_str_to_bytes()

WS_DLL_PUBLIC bool hex_str_to_bytes ( const char *  hex_str,
GByteArray *  bytes,
bool  force_separators 
)

Turn a string of hex digits with optional separators (defined by is_byte_sep() into a byte array.

Parameters
hex_strThe string of hex digits.
bytesThe GByteArray that will receive the bytes. This must be initialized by the caller.
force_separatorsIf set to true, separators MUST exist between bytes.
Returns
True if the string was converted successfully

◆ oid_str_to_bytes()

WS_DLL_PUBLIC bool oid_str_to_bytes ( const char *  oid_str,
GByteArray *  bytes 
)

Turn a OID string representation (dot notation) into a byte array.

Parameters
oid_strThe OID string (dot notaion).
bytesThe GByteArray that will receive the bytes. This must be initialized by the caller.
Returns
True if the string was converted successfully

◆ rel_oid_str_to_bytes()

WS_DLL_PUBLIC bool rel_oid_str_to_bytes ( const char *  oid_str,
GByteArray *  bytes,
bool  is_absolute 
)

Turn a OID string representation (dot notation) into a byte array.

Parameters
oid_strThe OID string (dot notaion).
bytesThe GByteArray that will receive the bytes. This must be initialized by the caller.
is_absoluteTrue if this is an absolute OID; false for relative OID.
Returns
True if the string was converted successfully

◆ uri_str_to_bytes()

WS_DLL_PUBLIC bool uri_str_to_bytes ( const char *  uri_str,
GByteArray *  bytes 
)

Turn an RFC 3986 percent-encoded string into a byte array.

Parameters
uri_strThe string of hex digits.
bytesThe GByteArray that will receive the bytes. This must be initialized by the caller.
Returns
True if the string was converted successfully

◆ uri_to_bytes()

WS_DLL_PUBLIC bool uri_to_bytes ( const char *  uri_str,
GByteArray *  bytes,
size_t  len 
)

Turn an RFC 3986 percent-encoded array of characters, not necessarily null-terminated, into a byte array.

Parameters
uri_strThe string of hex digits.
bytesThe GByteArray that will receive the bytes. This must be initialized by the caller.
Returns
True if the string was converted successfully

◆ xml_escape()

WS_DLL_PUBLIC char * xml_escape ( const char *  unescaped)

Return a XML escaped representation of the unescaped string. The returned string must be freed when no longer in use.

Parameters
unescapedThe unescaped string
Returns
An XML-escaped representation of the input string