Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
Functions
strutil.h File Reference
#include "ws_symbol_export.h"
#include <epan/wmem/wmem.h>

Go to the source code of this file.

Functions

const guchar * find_line_end (const guchar *data, const guchar *dataend, const guchar **eol)
 
WS_DLL_PUBLIC int get_token_len (const guchar *linep, const guchar *lineend, const guchar **next_token)
 
WS_DLL_PUBLIC gchar * format_text (wmem_allocator_t *allocator, const guchar *line, size_t len)
 
WS_DLL_PUBLIC gchar * format_text_wsp (wmem_allocator_t *allocator, const guchar *line, size_t len)
 
WS_DLL_PUBLIC gchar * format_text_chr (wmem_allocator_t *allocator, const guchar *string, const size_t len, const guchar chr)
 
WS_DLL_PUBLIC gboolean hex_str_to_bytes (const char *hex_str, GByteArray *bytes, gboolean force_separators)
 
WS_DLL_PUBLIC gboolean hex_str_to_bytes_encoding (const char *hex_str, GByteArray *bytes, const char **endptr, const guint encoding, const gboolean fail_if_partial)
 
WS_DLL_PUBLIC gboolean uri_str_to_bytes (const char *uri_str, GByteArray *bytes)
 
WS_DLL_PUBLIC gchar * format_uri (wmem_allocator_t *allocator, const GByteArray *bytes, const gchar *reserved_chars)
 
WS_DLL_PUBLIC gboolean rel_oid_str_to_bytes (const char *oid_str, GByteArray *bytes, gboolean is_absolute)
 
WS_DLL_PUBLIC gboolean oid_str_to_bytes (const char *oid_str, GByteArray *bytes)
 
WS_DLL_PUBLIC GByteArray * byte_array_dup (const GByteArray *ba)
 
WS_DLL_PUBLIC gboolean byte_array_equal (GByteArray *ba1, GByteArray *ba2)
 
WS_DLL_PUBLIC gchar * xml_escape (const gchar *unescaped)
 
WS_DLL_PUBLIC const guint8 * epan_memmem (const guint8 *haystack, guint haystack_len, const guint8 *needle, guint needle_len)
 
WS_DLL_PUBLIC guint8 * convert_string_to_hex (const char *string, size_t *nbytes)
 
WS_DLL_PUBLIC char * convert_string_case (const char *string, gboolean case_insensitive)
 
WS_DLL_PUBLIC const char * epan_strcasestr (const char *haystack, const char *needle)
 
WS_DLL_PUBLIC const char * string_or_null (const char *string)
 
WS_DLL_PUBLIC int escape_string_len (const char *string)
 
WS_DLL_PUBLIC char * escape_string (char *dst, const char *string)
 
WS_DLL_PUBLIC void IA5_7BIT_decode (unsigned char *dest, const unsigned char *src, int len)
 
WS_DLL_PUBLIC gchar * ws_strdup_escape_char (const gchar *str, const gchar chr)
 
WS_DLL_PUBLIC gchar * ws_strdup_unescape_char (const gchar *str, const gchar chr)
 
WS_DLL_PUBLIC gchar * string_replace (const gchar *str, const gchar *old_val, const gchar *new_val)
 

Detailed Description

String handling and conversion utilities.

Function Documentation

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.
WS_DLL_PUBLIC gboolean 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?

WS_DLL_PUBLIC char* convert_string_case ( const char *  string,
gboolean  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.
WS_DLL_PUBLIC guint8* 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.
WS_DLL_PUBLIC const guint8* epan_memmem ( const guint8 *  haystack,
guint  haystack_len,
const guint8 *  needle,
guint  needle_len 
)

Return the first occurrence of needle in haystack. Algorithm copied from GNU's glibc 2.3.2 memcmp()

Parameters
haystackThe data to search
haystack_lenThe length of the search data
needleThe string to look for
needle_lenThe length of the search string
Returns
A pointer to the first occurrence of "needle" in "haystack". If "needle" isn't found or is NULL, or if "needle_len" is 0, NULL is returned.
WS_DLL_PUBLIC const char* epan_strcasestr ( const char *  haystack,
const char *  needle 
)

Finds the first occurrence of string 'needle' in string 'haystack'. The matching is done in a case insensitive manner.

Parameters
haystackThe string possibly containing the substring
needleThe substring to be searched
Returns
A pointer into 'haystack' where 'needle' is first found. Otherwise it returns NULL.
const guchar* find_line_end ( const guchar *  data,
const guchar *  dataend,
const guchar **  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".
WS_DLL_PUBLIC gchar* format_text ( wmem_allocator_t allocator,
const guchar *  line,
size_t  len 
)

Given a string, generate a string from it that shows non-printable characters as C-style escapes, and return a pointer to it.

Parameters
allocatorThe wmem scope
lineA pointer to the input string
lenThe length of the input string
Returns
A pointer to the formatted string
See also
tvb_format_text()
WS_DLL_PUBLIC gchar* format_text_chr ( wmem_allocator_t allocator,
const guchar *  string,
const size_t  len,
const guchar  chr 
)

Given a string, generate a string from it that shows non-printable characters as the chr parameter passed, except a whitespace character (space, tab, carriage return, new line, vertical tab, or formfeed) which will be replaced by a space, and return a pointer to it.

Parameters
allocatorThe wmem scope
stringA pointer to the input string
lenThe length of the input string
chrThe character to use to replace non-printable characters
Returns
A pointer to the formatted string
WS_DLL_PUBLIC gchar* format_text_wsp ( wmem_allocator_t allocator,
const guchar *  line,
size_t  len 
)

Given a string, generate a string from it that shows non-printable characters as C-style escapes except a whitespace character (space, tab, carriage return, new line, vertical tab, or formfeed) which will be replaced by a space, and return a pointer to it.

Parameters
allocatorThe wmem scope
lineA pointer to the input string
lenThe length of the input string
Returns
A pointer to the formatted string
WS_DLL_PUBLIC gchar* format_uri ( wmem_allocator_t allocator,
const GByteArray *  bytes,
const gchar *  reserved_chars 
)

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

Parameters
allocatorThe wmem scope
bytesThe GByteArray that will receive the bytes. This must be initialized by the caller.
reserved_charsNormally the "gen-delims" and "sub-delims" from RFC 3986 (":/?#[]@" and "!$&'()*+,;=" respectively) plus space (hex value 20) are treated as reserved characters. If this variable is non-NULL, its contents will be used instead.
Note
Any non-printing character determined by isprint(), along with the % character itself are always reserved.
See also
uri_str_to_bytes(), format_text(), isprint()
WS_DLL_PUBLIC int get_token_len ( const guchar *  linep,
const guchar *  lineend,
const guchar **  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.
WS_DLL_PUBLIC gboolean hex_str_to_bytes ( const char *  hex_str,
GByteArray *  bytes,
gboolean  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
WS_DLL_PUBLIC gboolean 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
WS_DLL_PUBLIC gboolean rel_oid_str_to_bytes ( const char *  oid_str,
GByteArray *  bytes,
gboolean  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
WS_DLL_PUBLIC const char* string_or_null ( const char *  string)

Guarantee a non-null string.

Parameters
stringThe string to check
Returns
A pointer 'string' if it's non-null, otherwise "[NULL]".
WS_DLL_PUBLIC gchar* string_replace ( const gchar *  str,
const gchar *  old_val,
const gchar *  new_val 
)

Replace values in a string

Parameters
strString containing 0 or more values to be replaced.
old_valOld value.
new_valNew value. May be NULL, in which case occurences of old_value will be removed.
Returns
A newly-allocated version of str with replacement values or NULL on failure.
WS_DLL_PUBLIC gboolean 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
See also
format_uri()
WS_DLL_PUBLIC gchar* ws_strdup_escape_char ( const gchar *  str,
const gchar  chr 
)

Copy a string, escaping the 'chr' characters in it

Parameters
strThe string to be copied
chrThe character to be escaped
Returns
A copy of the string with every original 'chr' being transformed into double 'chr'.
WS_DLL_PUBLIC gchar* ws_strdup_unescape_char ( const gchar *  str,
const gchar  chr 
)

Copy a string, unescaping the 'chr' characters in it

Parameters
strThe string to be copied
chrThe character to be escaped
Returns
A copy of the string with every occurrence of double 'chr' in the original string being copied as a single 'chr'.
WS_DLL_PUBLIC gchar* xml_escape ( const gchar *  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