Tor
0.4.7.0-alpha-dev
|
Non-standard string functions used throughout Tor. More...
#include "lib/string/util_string.h"
#include "lib/string/compat_ctype.h"
#include "lib/err/torerr.h"
#include "lib/ctime/di_ops.h"
#include "lib/defs/digest_sizes.h"
#include <string.h>
#include <stdlib.h>
Go to the source code of this file.
Macros | |
#define | TOP_BITS(x) ((uint8_t)(0xFF << (8 - (x)))) |
#define | LOW_BITS(x) ((uint8_t)(0xFF >> (8 - (x)))) |
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 | fast_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_strstrip (char *s, const char *strip) |
void | tor_strlower (char *s) |
void | tor_strupper (char *s) |
void | tor_strreplacechar (char *s, char find, char replacement) |
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 | fast_memcmpstart (const void *mem, size_t memlen, const char *prefix) |
int | strcmpend (const char *s1, const char *s2) |
int | strcasecmpend (const char *s1, const char *s2) |
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) |
static uint8_t | bytes_in_char (uint8_t b) |
static bool | is_continuation_byte (uint8_t b) |
static bool | validate_char (const uint8_t *c, uint8_t len) |
int | string_is_utf8 (const char *str, size_t len) |
int | string_is_utf8_no_bom (const char *str, size_t len) |
Non-standard string functions used throughout Tor.
Definition in file util_string.c.
#define LOW_BITS | ( | x | ) | ((uint8_t)(0xFF >> (8 - (x)))) |
A byte with the lowest x bits set.
Definition at line 449 of file util_string.c.
#define TOP_BITS | ( | x | ) | ((uint8_t)(0xFF << (8 - (x)))) |
A byte with the top x bits set.
Definition at line 447 of file util_string.c.
|
static |
Given the leading byte b, return the total number of bytes in the UTF-8 character. Returns 0 if it's an invalid leading byte.
Definition at line 455 of file util_string.c.
Referenced by string_is_utf8().
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 277 of file util_string.c.
Referenced by parse_log_severity_config(), port_cfg_line_extract_addrport(), router_parse_addr_policy_item_from_string(), router_parse_addr_policy_private(), tor_addr_port_lookup(), and tor_version_parse_platform().
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 304 of file util_string.c.
Referenced by authority_cert_parse_from_string(), find_start_of_next_microdesc(), find_start_of_next_router_or_extrainfo(), microdescs_parse_from_string(), and pem_decode().
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 342 of file util_string.c.
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 332 of file util_string.c.
Referenced by parse_http_command().
int fast_mem_is_zero | ( | const char * | mem, |
size_t | len | ||
) |
Return true iff the 'len' bytes at 'mem' are all zero.
Definition at line 74 of file util_string.c.
Referenced by build_service_desc_keys(), build_service_desc_plaintext(), check_sockaddr(), commit_has_reveal_value(), construct_ntor_key_map(), crypto_read_tagged_contents_from_file(), decrypt_descriptor_cookie(), dirauth_get_voting_schedule(), disk_state_put_commit_line(), hs_build_blinded_keypair(), hs_build_blinded_pubkey(), hs_desc_build_authorized_client(), microdesc_has_curve25519_onion_key(), and routerinfo_incompatible_with_extrainfo().
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 238 of file util_string.c.
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 400 of file util_string.c.
Referenced by get_total_system_memory_impl().
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 353 of file util_string.c.
Referenced by parse_http_command(), tor_version_parse_platform(), and version_from_platform().
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 375 of file util_string.c.
|
static |
Returns true iff b is a UTF-8 continuation byte.
Definition at line 472 of file util_string.c.
Referenced by validate_char().
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 264 of file util_string.c.
Referenced by address_is_in_virtual_range(), addressmap_address_should_automap(), hostname_in_track_host_exits(), tor_addr_hostname_is_local(), and tor_addr_parse_PTR_name().
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 225 of file util_string.c.
Referenced by circuit_purpose_from_string(), config_lines_dup_and_filter(), handle_control_hspost(), http_get_header(), parse_dirauth_dirport(), and tor_version_parse().
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 197 of file util_string.c.
Referenced by bridge_resolve_conflicts(), compare_by_valid_after_(), connection_dir_list_by_purpose_and_resource(), connection_dir_list_by_purpose_resource_and_state(), opt_streq(), and proxy_needs_restart().
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 251 of file util_string.c.
Referenced by auth_key_filename_is_valid(), client_filename_is_valid(), crypto_read_tagged_contents_from_file(), get_onion_public_key(), and storage_dir_clean_tmpfiles().
int strcmpstart | ( | const char * | s1, |
const char * | s2 | ||
) |
Compares the first strlen(s2) characters of s1 with s2. Returns as for strcmp.
Definition at line 215 of file util_string.c.
Referenced by address_is_invalid_mapaddress_target(), body_is_plausible(), connection_dir_bridge_routerdesc_failed(), controller_get_routerdescs(), crypto_read_tagged_contents_from_file(), decode_hashed_passwords(), dirvote_get_intermediate_param_value(), evdns_log_cb(), extract_param_buggy(), find_start_of_next_router_or_extrainfo(), get_net_param_from_list(), get_transport_bindaddr(), getinfo_helper_dir(), getinfo_helper_downloads(), getinfo_helper_downloads_cert(), getinfo_helper_geoip(), handle_get_descriptor(), handle_get_hs_descriptor_v3(), handle_get_keys(), handle_getinfo_helper(), handle_response_fetch_desc(), list_pending_fpsk_downloads(), metrics_connection_process_inbuf(), parse_dirauth_dirport(), parse_http_command(), parse_http_url(), parse_openssl_version_str(), port_cfg_line_extract_addrport(), router_parse_addr_policy_private(), string_is_utf8_no_bom(), summarize_protover_flags(), tor_version_parse_platform(), and version_from_platform().
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 423 of file util_string.c.
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 516 of file util_string.c.
Referenced by 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 557 of file util_string.c.
int tor_digest256_is_zero | ( | const char * | digest | ) |
Return true iff the DIGEST256_LEN bytes in digest are all zero.
Definition at line 103 of file util_string.c.
int tor_digest_is_zero | ( | const char * | digest | ) |
Return true iff the DIGEST_LEN bytes in digest are all zero.
Definition at line 96 of file util_string.c.
Referenced by bridge_get_rsa_id_digest(), bridge_has_digest(), bridge_resolve_conflicts(), channel_dump_statistics(), circuit_get_all_pending_on_channel(), connection_ap_fail_onehop(), connection_or_client_learned_peer_id(), connection_unlink(), directory_request_dir_contact_info_specified(), entry_guard_learned_bridge_identity(), get_bridge_info_for_guard(), get_configured_bridge_by_addr_port_digest(), get_configured_bridge_by_orports_digest(), get_or_history(), learned_bridge_descriptor(), learned_router_identity(), lookup_cached_dir_by_fp(), and orconn_target_get_name().
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.
int tor_strisnonupper | ( | const char * | s | ) |
Return 1 if no character in s is uppercase, else return 0.
Definition at line 171 of file util_string.c.
Referenced by assert_resolve_ok().
int tor_strisprint | ( | const char * | s | ) |
Return 1 if every character in s is printable, else return 0.
Definition at line 158 of file util_string.c.
int tor_strisspace | ( | const char * | s | ) |
Return true iff every character in s is whitespace space; else return false.
Definition at line 184 of file util_string.c.
void tor_strlower | ( | char * | s | ) |
Convert all alphabetic characters in the nul-terminated string s to lowercase.
Definition at line 127 of file util_string.c.
Referenced by clear_trackexithost_mappings().
void tor_strreplacechar | ( | char * | s, |
char | find, | ||
char | replacement | ||
) |
Replaces old with replacement in s
Definition at line 148 of file util_string.c.
void tor_strstrip | ( | char * | s, |
const char * | strip | ||
) |
Remove from the string s every character which appears in strip.
Definition at line 111 of file util_string.c.
void tor_strupper | ( | char * | s | ) |
Convert all alphabetic characters in the nul-terminated string s to lowercase.
Definition at line 138 of file util_string.c.
|
static |
Returns true iff the len bytes in c are a valid UTF-8 character.
Definition at line 482 of file util_string.c.
Referenced by string_is_utf8().