Wireshark 2.9.0-477-g68ec514b The Wireshark network protocol analyzer

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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

  ba | The 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

  ba | The 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

  ba1 | A byte array
  ba2 | A 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

  ba1 | A byte array
  ba2 | A 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

  string | The search string
  case_insensitive | TRUE 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

  string | The string to validate
  nbytes | The 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

  haystack | The data to search
  haystack_len | The length of the search data
  needle | The string to look for
  needle_len | The 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

  haystack | The string possibly containing the substring
  needle | The 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

  data | A pointer to the beginning of the data
  dataend | A pointer to the end of the data
  eol | A 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

  allocator | The wmem scope
  line | A pointer to the input string
  len | The 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

  allocator | The wmem scope
  string | A pointer to the input string
  len | The length of the input string
  chr | The 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

  allocator | The wmem scope
  line | A pointer to the input string
  len | The 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

  allocator | The wmem scope
  bytes | The GByteArray that will receive the bytes. This must be initialized by the caller.
  reserved_chars | Normally 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

  linep | A pointer to the beginning of the line
  lineend | A pointer to the end of the line
  next_token | Receives 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_str | The string of hex digits.
  bytes | The GByteArray that will receive the bytes. This must be initialized by the caller.
  force_separators | If 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_str | The OID string (dot notaion).
  bytes | The 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_str | The OID string (dot notaion).
  bytes | The GByteArray that will receive the bytes. This must be initialized by the caller.
  is_absolute | True 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

  string | The 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

  str | String containing 0 or more values to be replaced.
  old_val | Old value.
  new_val | New 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_str | The string of hex digits.
  bytes | The 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

  str | The string to be copied
  chr | The 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

  str | The string to be copied
  chr | The 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

  unescaped | The unescaped string

Returns
  An XML-escaped representation of the input string