Tor
0.4.7.0-alpha-dev
|
Implements the core functionality of a smartlist (a resizeable dynamic array). For more functionality and helper functions, see the container library. More...
#include "lib/err/torerr.h"
#include "lib/malloc/malloc.h"
#include "lib/smartlist_core/smartlist_core.h"
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Macros | |
#define | SMARTLIST_DEFAULT_CAPACITY 16 |
#define | MAX_CAPACITY (int)((SIZE_MAX / (sizeof(void*)))) |
Functions | |
smartlist_t * | smartlist_new (void) |
void | smartlist_free_ (smartlist_t *sl) |
void | smartlist_clear (smartlist_t *sl) |
static void | smartlist_ensure_capacity (smartlist_t *sl, size_t size) |
void | smartlist_grow (smartlist_t *sl, size_t new_size) |
void | smartlist_add (smartlist_t *sl, void *element) |
void | smartlist_add_all (smartlist_t *s1, const smartlist_t *s2) |
void | smartlist_add_strdup (struct smartlist_t *sl, const char *string) |
void | smartlist_remove (smartlist_t *sl, const void *element) |
void | smartlist_remove_keeporder (smartlist_t *sl, const void *element) |
void * | smartlist_pop_last (smartlist_t *sl) |
int | smartlist_contains (const smartlist_t *sl, const void *element) |
void | smartlist_del (smartlist_t *sl, int idx) |
void | smartlist_del_keeporder (smartlist_t *sl, int idx) |
void | smartlist_insert (smartlist_t *sl, int idx, void *val) |
Implements the core functionality of a smartlist (a resizeable dynamic array). For more functionality and helper functions, see the container library.
Definition in file smartlist_core.c.
#define SMARTLIST_DEFAULT_CAPACITY 16 |
All newly allocated smartlists have this capacity.
Definition at line 21 of file smartlist_core.c.
void smartlist_add | ( | smartlist_t * | sl, |
void * | element | ||
) |
Append element to the end of the list.
Definition at line 117 of file smartlist_core.c.
Referenced by add_connection_to_closeable_list(), authdir_type_to_string(), authority_cert_get_all(), build_vanguard_middle_exclude_list(), circuit_add_to_origin_circuit_list(), circuit_describe_status_for_controller(), circuit_get_all_pending_on_channel(), circuit_unlink_all_from_channel(), config_mgr_list_deprecated_vars(), config_mgr_list_vars(), connection_start_reading_from_linked_conn(), consensus_cache_find_all(), consensus_split_lines(), controller_get_routerdescs(), decode_hashed_passwords(), dir_server_add(), dircollator_collate_by_ed25519(), entry_connection_describe_status_for_controller(), entry_guards_update_confirmed(), extrainfo_dump_to_string_stats_helper(), get_all_possible_sybil(), get_authmethods(), get_detached_signatures_from_pending_consensuses(), get_eligible_guards(), get_frequent_members(), get_ns_str_from_sr_values(), getinfo_helper_entry_guards(), handle_control_hspost(), handle_get_keys(), hs_circuitmap_get_all_intro_circ_relay_side(), hs_service_get_metrics_stores(), hs_set_conn_addr_port(), init_circuit_base(), metrics_store_entry_add_label(), nodelist_add_node_and_family(), nodelist_find_nodes_with_microdesc(), parse_protocol_list(), pick_restricted_middle_node(), policy_expand_private(), policy_expand_unspec(), process_append_argument(), pubsub_adjmap_add(), relay_metrics_get_stores(), retry_all_listeners(), retry_listener_ports(), service_add_fnames_to_list(), setup_intro_point_exclude_list(), smartlist_add_linecpy(), smartlist_add_vasprintf(), smartlist_pqueue_add(), storage_dir_save_bytes_to_file(), storage_dir_save_labeled_to_file(), tor_mainloop_connect_pubsub_events(), and transport_add().
void smartlist_add_all | ( | smartlist_t * | s1, |
const smartlist_t * | s2 | ||
) |
Append each element from S2 to the end of S1.
Definition at line 125 of file smartlist_core.c.
Referenced by directory_remove_invalid(), entry_guards_update_primary(), gen_ed_diff(), hs_service_stage_services(), lint_message_consistency(), and retry_listener_ports().
void smartlist_add_strdup | ( | struct smartlist_t * | sl, |
const char * | string | ||
) |
Append a copy of string to sl
Definition at line 137 of file smartlist_core.c.
Referenced by add_transport_to_proxy(), encode_protocol_list(), extrainfo_dump_to_string(), extrainfo_dump_to_string_ed_sig_helper(), get_current_process_environment_variables(), hs_service_lists_fnames_for_sandbox(), and write_short_policy().
void smartlist_clear | ( | smartlist_t * | sl | ) |
Remove all elements from the list.
Definition at line 50 of file smartlist_core.c.
Referenced by consdiffmgr_consensus_load(), control_reply_clear(), entry_guards_update_confirmed(), microdesc_reset_outdated_dirservers_list(), pt_prepare_proxy_list_for_config_read(), rep_hist_reset_buffer_stats(), router_reset_warnings(), and routerlist_reset_warnings().
int smartlist_contains | ( | const smartlist_t * | sl, |
const void * | element | ||
) |
Return true iff some element E of sl has E==element.
Definition at line 201 of file smartlist_core.c.
Referenced by add_connection_to_closeable_list(), connection_in_array(), connection_is_on_closeable_list(), connection_start_reading_from_linked_conn(), connection_stop_reading_from_linked_conn(), smartlist_intersect(), and smartlist_overlap().
void smartlist_del | ( | smartlist_t * | sl, |
int | idx | ||
) |
Remove the idxth element of sl; if idx is not the last element, swap the last element of sl into the idxth space.
Definition at line 214 of file smartlist_core.c.
Referenced by circuit_close_all_marked(), and routerlist_insert().
void smartlist_del_keeporder | ( | smartlist_t * | sl, |
int | idx | ||
) |
Remove the idxth element of sl; if idx is not the last element, moving all subsequent elements back one space. Return the old value of the idxth element.
Definition at line 228 of file smartlist_core.c.
Referenced by smartlist_uniq().
|
inlinestatic |
Make sure that sl can hold at least size entries.
Definition at line 62 of file smartlist_core.c.
Referenced by smartlist_add(), and smartlist_grow().
void smartlist_free_ | ( | smartlist_t * | sl | ) |
Deallocate a smartlist. Does not release storage associated with the list's elements.
Definition at line 39 of file smartlist_core.c.
Referenced by control_reply_free_().
void smartlist_grow | ( | smartlist_t * | sl, |
size_t | new_size | ||
) |
Expand sl so that its length is at least new_size, filling in previously unused entries with NULL>
Do nothing if sl already had at least new_size elements.
Definition at line 97 of file smartlist_core.c.
Referenced by dcfg_add_recv(), and dcfg_msg_set_chan().
void smartlist_insert | ( | smartlist_t * | sl, |
int | idx, | ||
void * | val | ||
) |
Insert the value val as the new idxth element of sl, moving all items previously at idx or later forward one space.
Definition at line 244 of file smartlist_core.c.
smartlist_t* smartlist_new | ( | void | ) |
Allocate and return an empty smartlist.
Definition at line 26 of file smartlist_core.c.
Referenced by accept_encoding_header(), add_onion_helper_keyarg(), add_wildcarded_test_address(), append_cell_stats_by_command(), authdir_type_to_string(), bridge_list_get(), build_middle_exclude_list(), build_service_desc_encrypted(), build_vanguard_middle_exclude_list(), circuit_count_pending_on_channel(), circuit_describe_status_for_controller(), circuit_get_global_list(), circuit_get_global_origin_circuit_list(), circuit_list_path_impl(), circuit_log_ancient_one_hop_circuits(), circuit_unlink_all_from_channel(), cleanup_intro_points(), clear_bridge_list(), clear_transport_list(), client_check_address_changed(), client_likes_consensus(), compute_consensus_method(), compute_consensus_versions_list(), compute_frac_paths_available(), compute_nth_protocol_set(), config_mgr_list_deprecated_vars(), config_mgr_list_vars(), config_register_addressmaps(), connection_dir_bridge_routerdesc_failed(), connection_or_report_broken_states(), consdiffmgr_cleanup(), consdiffmgr_consensus_load(), consdiffmgr_diffs_load(), consdiffmgr_ensure_space_for_files(), consdiffmgr_rescan_flavor_(), consdiffmgr_set_cache_flags(), consdiffmgr_validate(), consensus_cache_find_first(), consensus_cache_rescan(), control_event_conf_changed(), control_event_descriptors_changed(), control_ports_write_to_file(), controller_get_routerdescs(), create_initial_guard_context(), create_managed_proxy_environment(), decode_auth_type(), decode_create2_list(), decode_hashed_passwords(), decode_intro_points(), decode_introduction_point(), desc_encode_v3(), dir_server_add(), dir_split_resource_into_fingerprint_pairs(), dir_split_resource_into_spoolable(), dirclient_dump_total_dls(), dircollator_collate(), directory_get_consensus_url(), directory_remove_invalid(), directory_send_command(), dirvote_add_vote(), dirvote_clear_votes(), dirvote_compute_consensuses(), dirvote_fetch_missing_votes(), disk_state_parse_srv(), dump_desc_fifo_add_and_clean(), encode_client_auth_cred_for_control_port(), encode_intro_point(), encode_protocol_list(), entry_connection_describe_status_for_controller(), entry_guard_chan_failed(), entry_guard_encode_for_state(), entry_guard_parse_from_state(), entry_guards_load_guards_from_state(), entry_guards_update_primary(), extrainfo_dump_to_string(), find_all_exitpolicy(), format_cell_stats(), format_networkstatus_vote(), format_recommended_version_list(), gen_ed_diff(), geoip_get_request_history(), geoip_get_transport_history(), geoip_parse_entry(), get_all_auth_client_lines(), get_all_possible_sybil(), get_authmethods(), get_bindaddr_for_server_proxy(), get_bindaddr_from_transport_listen_line(), get_configured_ports(), get_connection_array(), get_current_process_environment_variables(), get_detached_signatures_from_pending_consensuses(), get_eligible_guards(), get_glob_paths(), get_inner_encrypted_layer_plaintext(), get_majority_srv_from_votes(), get_my_declared_family(), get_ns_str_from_sr_values(), get_options_from_transport_options_line(), get_outer_encrypted_layer_plaintext(), get_transport_in_state_by_name(), get_transport_options_for_server_proxy(), get_transport_proxy_ports(), getinfo_helper_config(), getinfo_helper_entry_guards(), handle_control_extendcircuit(), handle_control_getconf(), handle_control_getinfo(), handle_control_hspost(), handle_control_mapaddress(), handle_control_onion_client_auth_add(), handle_control_onion_client_auth_view(), handle_get_keys(), handle_get_microdesc(), handle_get_status_vote(), hs_circ_handle_introduce2(), hs_circuitmap_get_all_intro_circ_relay_side(), hs_config_service_all(), hs_get_responsible_hsdirs(), hs_parse_port_config(), hs_pick_hsdir(), hs_service_get_metrics_stores(), hs_service_stage_services(), hs_set_conn_addr_port(), init_geoip_countries(), init_logging(), lint_message_consistency(), list_authority_ids_with_downloads(), list_bridge_identities(), list_getinfo_options(), list_pending_downloads(), list_pending_fpsk_downloads(), list_sk_digests_for_authority_id(), list_v3_auth_ids(), make_consensus_method_list(), mark_bridge_list(), mark_transport_list(), metrics_parse_ports(), microdesc_list_missing_digest256(), microdesc_parse_fields(), microdescs_add_to_cache(), microdescs_parse_from_string(), namemap_init(), networkstatus_check_consensus_signature(), networkstatus_parse_detached_signatures(), networkstatus_parse_vote_from_string(), node_get_all_orports(), nodefamily_canonicalize(), nodelist_find_nodes_with_microdesc(), normalize_nickname_list(), ob_option_parse(), options_init_logs(), parse_addr_policy(), parse_auth_file_content(), parse_authorized_client(), parse_dir_fallback_line(), parse_ports(), parse_private_key_from_control_port(), parse_protocol_list(), parse_tcp_proxy_line(), periodic_events_register(), pick_hsdir_v3(), pick_needed_intro_points(), pick_restricted_middle_node(), policies_parse_exit_policy_from_options(), policy_dump_to_string(), policy_expand_private(), policy_expand_unspec(), port_parse_ports_relay(), predicted_ports_alloc(), process_init(), pt_configure_remaining_proxies(), pt_get_extra_info_descriptor_string(), pubsub_adjmap_add(), relay_metrics_get_stores(), rep_hist_get_overload_stats_lines(), rep_hist_get_predicted_ports(), rep_hist_log_link_protocol_counts(), rep_hist_reset_buffer_stats(), resolved_cell_parse(), retry_all_listeners(), retry_listener_ports(), router_add_exit_policy(), router_get_descriptor_digests_in_consensus(), router_get_trusted_dir_servers_mutable(), router_load_extrainfo_from_string(), router_load_routers_from_string(), router_parse_entry_from_string(), routerlist_reset_warnings(), routerset_parse(), service_authorized_client_config_equal(), service_desc_hsdirs_changed(), set_expiry(), set_service_default_config(), sr_get_string_for_vote(), state_transport_line_is_valid(), storage_dir_save_bytes_to_file(), storage_dir_save_labeled_to_file(), string_is_valid_nonrfc_hostname(), sweep_bridge_list(), sweep_transport_list(), tor_inet_aton(), tor_init_connection_lists(), tor_mainloop_connect_pubsub_events(), transport_add(), trusted_dirs_flush_certs_to_disk(), unglob_opened_files(), update_consensus_router_descriptor_downloads(), update_extrainfo_downloads(), upload_descriptor_to_all(), and write_short_policy().
void* smartlist_pop_last | ( | smartlist_t * | sl | ) |
If sl is nonempty, remove and return the final element. Otherwise, return NULL.
Definition at line 187 of file smartlist_core.c.
void smartlist_remove | ( | smartlist_t * | sl, |
const void * | element | ||
) |
Remove all elements E from sl such that E==element. Preserve the order of any elements before E, but elements after E can be rearranged.
Definition at line 151 of file smartlist_core.c.
Referenced by circuit_about_to_free(), connection_stop_reading_from_linked_conn(), connection_unlink(), and smartlist_subtract().
void smartlist_remove_keeporder | ( | smartlist_t * | sl, |
const void * | element | ||
) |
As smartlist_remove, but do not change the order of any elements not removed
Definition at line 167 of file smartlist_core.c.
Referenced by remove_guard_from_confirmed_and_primary_lists().