tor  0.4.1.0-alpha-dev
Macros | Functions
util_string.h File Reference
#include "orconfig.h"
#include "lib/cc/compat_compiler.h"
#include <stddef.h>

Go to the source code of this file.

Macros

#define HEX_CHARACTERS   "0123456789ABCDEFabcdef"
 

Functions

const void * tor_memmem (const void *haystack, size_t hlen, const void *needle, size_t nlen)
 
const void * tor_memstr (const void *haystack, size_t hlen, const char *needle)
 
int tor_mem_is_zero (const char *mem, size_t len)
 
int tor_digest_is_zero (const char *digest)
 
int tor_digest256_is_zero (const char *digest)
 
void tor_strlower (char *s)
 
void tor_strupper (char *s)
 
int tor_strisprint (const char *s)
 
int tor_strisnonupper (const char *s)
 
int tor_strisspace (const char *s)
 
int strcmp_opt (const char *s1, const char *s2)
 
int strcmpstart (const char *s1, const char *s2)
 
int strcasecmpstart (const char *s1, const char *s2)
 
int strcmpend (const char *s1, const char *s2)
 
int strcasecmpend (const char *s1, const char *s2)
 
int fast_memcmpstart (const void *mem, size_t memlen, const char *prefix)
 
void tor_strstrip (char *s, const char *strip)
 
const char * eat_whitespace (const char *s)
 
const char * eat_whitespace_eos (const char *s, const char *eos)
 
const char * eat_whitespace_no_nl (const char *s)
 
const char * eat_whitespace_eos_no_nl (const char *s, const char *eos)
 
const char * find_whitespace (const char *s)
 
const char * find_whitespace_eos (const char *s, const char *eos)
 
const char * find_str_at_start_of_line (const char *haystack, const char *needle)
 
int string_is_C_identifier (const char *string)
 
int string_is_utf8 (const char *str, size_t len)
 
int string_is_utf8_no_bom (const char *str, size_t len)
 

Detailed Description

Header for util_string.c.

Definition in file util_string.h.

Macro Definition Documentation

◆ HEX_CHARACTERS

#define HEX_CHARACTERS   "0123456789ABCDEFabcdef"

Allowable characters in a hexadecimal string.

Definition at line 28 of file util_string.h.

Referenced by is_legal_hexdigest().

Function Documentation

◆ eat_whitespace()

const char* eat_whitespace ( const char *  s)

Return a pointer to the first char of s that is not whitespace and not a comment, or to the terminating NUL if no such character exists.

Definition at line 271 of file util_string.c.

Referenced by config_parse_units(), MOCK_IMPL(), parse_log_severity_config(), port_cfg_line_extract_addrport(), rend_parse_client_keys(), router_parse_addr_policy_private(), tor_addr_port_lookup(), and tor_version_parse_platform().

◆ eat_whitespace_eos()

const char* eat_whitespace_eos ( const char *  s,
const char *  eos 
)

Return a pointer to the first char of s that is not whitespace and not a comment, or to the terminating NUL if no such character exists.

Definition at line 298 of file util_string.c.

Referenced by authority_cert_parse_from_string(), find_start_of_next_microdesc(), find_start_of_next_router_or_extrainfo(), and pem_decode().

◆ eat_whitespace_eos_no_nl()

const char* eat_whitespace_eos_no_nl ( const char *  s,
const char *  eos 
)

As eat_whitespace_no_nl, but stop at eos whether we have found a non-whitespace character or not.

Definition at line 336 of file util_string.c.

◆ eat_whitespace_no_nl()

const char* eat_whitespace_no_nl ( const char *  s)

Return a pointer to the first char of s that is not a space or a tab or a \r, or to the terminating NUL if no such character exists.

Definition at line 326 of file util_string.c.

Referenced by parse_http_command().

◆ fast_memcmpstart()

int fast_memcmpstart ( const void *  mem,
size_t  memlen,
const char *  prefix 
)

Compare the value of the string prefix with the start of the memlen-byte memory chunk at mem. Return as for strcmp.

[As fast_memcmp(mem, prefix, strlen(prefix)) but returns -1 if memlen is less than strlen(prefix).]

Definition at line 232 of file util_string.c.

References fast_memcmp.

◆ find_str_at_start_of_line()

const char* find_str_at_start_of_line ( const char *  haystack,
const char *  needle 
)

Return the first occurrence of needle in haystack that occurs at the start of a line (that is, at the beginning of haystack or immediately after a newline). Return NULL if no such string is found.

Definition at line 394 of file util_string.c.

◆ find_whitespace()

const char* find_whitespace ( const char *  s)

Return a pointer to the first char of s that is whitespace or #, or to the terminating NUL if no such character exists.

Definition at line 347 of file util_string.c.

Referenced by parse_http_command(), tor_version_parse_platform(), and version_from_platform().

◆ find_whitespace_eos()

const char* find_whitespace_eos ( const char *  s,
const char *  eos 
)

As find_whitespace, but stop at eos whether we have found a whitespace or not.

Definition at line 369 of file util_string.c.

◆ strcasecmpend()

int strcasecmpend ( const char *  s1,
const char *  s2 
)

Compares the last strlen(s2) characters of s1 with s2. Returns as for strcasecmp.

Definition at line 258 of file util_string.c.

Referenced by address_is_in_virtual_range(), addressmap_address_should_automap(), hostname_in_track_host_exits(), and tor_addr_parse_PTR_name().

◆ strcasecmpstart()

int strcasecmpstart ( const char *  s1,
const char *  s2 
)

Compares the first strlen(s2) characters of s1 with s2. Returns as for strcasecmp.

Definition at line 219 of file util_string.c.

Referenced by circuit_purpose_from_string(), config_lines_dup_and_filter(), http_get_header(), and tor_version_parse().

◆ strcmp_opt()

int strcmp_opt ( const char *  s1,
const char *  s2 
)

As strcmp, except that either string may be NULL. The NULL string is considered to be before any non-NULL string.

Definition at line 191 of file util_string.c.

Referenced by bridge_resolve_conflicts(), connection_dir_list_by_purpose_and_resource(), connection_dir_list_by_purpose_resource_and_state(), opt_streq(), and proxy_needs_restart().

◆ strcmpend()

int strcmpend ( const char *  s1,
const char *  s2 
)

Compares the last strlen(s2) characters of s1 with s2. Returns as for strcmp.

Definition at line 245 of file util_string.c.

Referenced by crypto_read_tagged_contents_from_file(), and storage_dir_clean_tmpfiles().

◆ strcmpstart()

int strcmpstart ( const char *  s1,
const char *  s2 
)

◆ string_is_C_identifier()

int string_is_C_identifier ( const char *  string)

Returns true if string could be a C identifier. A C identifier must begin with a letter or an underscore and the rest of its characters can be letters, numbers or underscores. No length limit is imposed.

Definition at line 417 of file util_string.c.

◆ string_is_utf8()

int string_is_utf8 ( const char *  str,
size_t  len 
)

Returns true iff the first len bytes in str are a valid UTF-8 string.

Definition at line 510 of file util_string.c.

References bytes_in_char(), and validate_char().

Referenced by string_is_utf8_no_bom().

◆ string_is_utf8_no_bom()

int string_is_utf8_no_bom ( const char *  str,
size_t  len 
)

As string_is_utf8(), but returns false if the string begins with a UTF-8 byte order mark (BOM).

Definition at line 534 of file util_string.c.

References strcmpstart(), and string_is_utf8().

◆ tor_digest256_is_zero()

int tor_digest256_is_zero ( const char *  digest)

Return true iff the DIGEST256_LEN bytes in digest are all zero.

Definition at line 106 of file util_string.c.

References DIGEST256_LEN, and tor_mem_is_zero().

◆ tor_digest_is_zero()

int tor_digest_is_zero ( const char *  digest)

◆ tor_mem_is_zero()

int tor_mem_is_zero ( const char *  mem,
size_t  len 
)

◆ tor_memmem()

const void* tor_memmem ( const void *  _haystack,
size_t  hlen,
const void *  _needle,
size_t  nlen 
)

Given hlen bytes at haystack and nlen bytes at needle, return a pointer to the first occurrence of the needle within the haystack, or NULL if there is no such occurrence.

This function is not timing-safe.

Requires that nlen be greater than zero.

Definition at line 29 of file util_string.c.

◆ tor_strisnonupper()

int tor_strisnonupper ( const char *  s)

Return 1 if no character in s is uppercase, else return 0.

Definition at line 165 of file util_string.c.

Referenced by assert_resolve_ok().

◆ tor_strisprint()

int tor_strisprint ( const char *  s)

Return 1 if every character in s is printable, else return 0.

Definition at line 152 of file util_string.c.

◆ tor_strisspace()

int tor_strisspace ( const char *  s)

Return true iff every character in s is whitespace space; else return false.

Definition at line 178 of file util_string.c.

◆ tor_strlower()

void tor_strlower ( char *  s)

Convert all alphabetic characters in the nul-terminated string s to lowercase.

Definition at line 130 of file util_string.c.

Referenced by clear_trackexithost_mappings().

◆ tor_strstrip()

void tor_strstrip ( char *  s,
const char *  strip 
)

Remove from the string s every character which appears in strip.

Definition at line 114 of file util_string.c.

◆ tor_strupper()

void tor_strupper ( char *  s)

Convert all alphabetic characters in the nul-terminated string s to lowercase.

Definition at line 141 of file util_string.c.