Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
stringfields.h File Reference
#include "asterisk/inline_api.h"
#include "asterisk/vector.h"
Include dependency graph for stringfields.h:

Go to the source code of this file.

Data Structures

struct  ast_string_field_mgr
 
struct  ast_string_field_pool
 

Macros

#define __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, file, lineno, func)
 
#define ast_calloc_with_stringfields(n, type, size)
 Allocate a structure with embedded stringfields in a single allocation. More...
 
#define AST_DECLARE_STRING_FIELDS(field_list)
 Declare the fields needed in a structure. More...
 
#define AST_STRING_FIELD(name)   const ast_string_field name
 Declare a string field. More...
 
#define AST_STRING_FIELD_ALLOCATION(x)   *((ast_string_field_allocation *) (x - __alignof__(ast_string_field_allocation)))
 Macro to provide access to the allocation field that lives immediately in front of a string field. More...
 
#define ast_string_field_build(x, field, fmt, args...)
 Set a field to a complex (built) value. More...
 
#define ast_string_field_build_va(x, field, fmt, args)
 Set a field to a complex (built) value. More...
 
#define AST_STRING_FIELD_EXTENDED(name)   AST_STRING_FIELD(name)
 Declare an extended string field. More...
 
#define ast_string_field_free_memory(x)
 free all memory - to be called before destroying the object More...
 
#define ast_string_field_init(x, size)
 Initialize a field pool and fields. More...
 
#define ast_string_field_init_extended(x, field)
 Initialize an extended string field. More...
 
#define ast_string_field_ptr_build(x, ptr, fmt, args...)
 Set a field to a complex (built) value. More...
 
#define ast_string_field_ptr_build_va(x, ptr, fmt, args)
 Set a field to a complex (built) value with prebuilt va_lists. More...
 
#define ast_string_field_ptr_set(x, ptr, data)
 Set a field to a simple string value. More...
 
#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data)   __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 
#define ast_string_field_set(x, field, data)
 Set a field to a simple string value. More...
 
#define ast_string_fields_cmp(instance1, instance2)
 Compare the string fields in two instances of the same structure. More...
 
#define ast_string_fields_copy(copy, orig)
 Copy all string fields from one instance to another of the same structure. More...
 

Typedefs

typedef const char * ast_string_field
 
typedef uint16_t ast_string_field_allocation
 

Enumerations

enum  ast_stringfield_cleanup_type { AST_STRINGFIELD_RESET = 0, AST_STRINGFIELD_DESTROY = -1 }
 

Functions

void * __ast_calloc_with_stringfields (unsigned int num_structs, size_t struct_size, size_t field_mgr_offset, size_t field_mgr_pool_offset, size_t pool_size, const char *file, int lineno, const char *func)
 
ast_string_field __ast_string_field_alloc_space (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t needed, const char *file, int lineno, const char *func)
 
int __ast_string_field_free_memory (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, enum ast_stringfield_cleanup_type cleanup_type, const char *file, int lineno, const char *func)
 Internal cleanup function. More...
 
int __ast_string_field_init (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, int needed, const char *file, int lineno, const char *func)
 Internal initialization function. More...
 
void __ast_string_field_ptr_build (const char *file, int lineno, const char *func, struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format,...)
 
void __ast_string_field_ptr_build_va (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format, va_list ap, const char *file, int lineno, const char *func)
 
int __ast_string_field_ptr_grow (struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t needed, const ast_string_field *ptr)
 
void __ast_string_field_release_active (struct ast_string_field_pool *pool_head, const ast_string_field ptr)
 
int __ast_string_fields_cmp (struct ast_string_field_vector *left, struct ast_string_field_vector *right)
 
int __ast_string_fields_copy (struct ast_string_field_pool *copy_pool, struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr, const char *file, int lineno, const char *func)
 
 AST_VECTOR (ast_string_field_vector, const char **)
 

Variables

const char * __ast_string_field_empty
 

Macro Definition Documentation

◆ __ast_string_field_ptr_set_by_fields

#define __ast_string_field_ptr_set_by_fields (   field_mgr_pool,
  field_mgr,
  ptr,
  data,
  file,
  lineno,
  func 
)

Definition at line 479 of file stringfields.h.

Referenced by __ast_string_fields_copy().

◆ ast_calloc_with_stringfields

#define ast_calloc_with_stringfields (   n,
  type,
  size 
)
Value:
__ast_calloc_with_stringfields(n, sizeof(type), offsetof(type, __field_mgr), \
offsetof(type, __field_mgr_pool), size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
static const char type[]
Definition: chan_ooh323.c:109
void * __ast_calloc_with_stringfields(unsigned int num_structs, size_t struct_size, size_t field_mgr_offset, size_t field_mgr_pool_offset, size_t pool_size, const char *file, int lineno, const char *func)
Definition: stringfields.c:380

Allocate a structure with embedded stringfields in a single allocation.

Parameters
nCurrent imlementation only allows 1 structure to be allocated
typeThe type of structure to allocate
sizeThe number of bytes of space (minimum) to allocate for stringfields to use in each structure

This function will allocate memory for one or more structures that use stringfields, and also allocate space for the stringfields and initialize the stringfield management structure embedded in the outer structure.

Since
1.8

Definition at line 426 of file stringfields.h.

Referenced by alloc_header(), append_mailbox_mapping(), AST_TEST_DEFINE(), build_profile(), format_log_message_ap(), jack_data_alloc(), load_config(), load_module(), raise_exception(), and sip_refer_alloc().

◆ AST_DECLARE_STRING_FIELDS

#define AST_DECLARE_STRING_FIELDS (   field_list)
Value:
struct ast_string_field_pool *__field_mgr_pool; \
field_list \
struct ast_string_field_mgr __field_mgr

Declare the fields needed in a structure.

Parameters
field_listThe list of fields to declare, using AST_STRING_FIELD() for each one. Internally, string fields are stored as a pointer to the head of the pool, followed by individual string fields, and then a struct ast_string_field_mgr which describes the space allocated. We split the two variables so they can be used as markers around the field_list, and this allows us to determine how many entries are in the field, and play with them. In particular, for writing to the fields, we rely on __field_mgr_pool to be a non-const pointer, so we know it has the same size as ast_string_field, and we can use it to locate the fields.

Definition at line 337 of file stringfields.h.

Referenced by AST_TEST_DEFINE().

◆ AST_STRING_FIELD

#define AST_STRING_FIELD (   name)    const ast_string_field name

Declare a string field.

Parameters
nameThe field name

Definition at line 299 of file stringfields.h.

Referenced by AST_TEST_DEFINE().

◆ AST_STRING_FIELD_ALLOCATION

#define AST_STRING_FIELD_ALLOCATION (   x)    *((ast_string_field_allocation *) (x - __alignof__(ast_string_field_allocation)))

Macro to provide access to the allocation field that lives immediately in front of a string field.

Parameters
xPointer to the string field

Note that x must be a pointer to a byte-sized type – normally (char *) – or this calculation would break horribly

Definition at line 460 of file stringfields.h.

Referenced by __ast_string_field_alloc_space(), __ast_string_field_ptr_build_va(), __ast_string_field_ptr_grow(), __ast_string_field_release_active(), and AST_TEST_DEFINE().

◆ ast_string_field_build

#define ast_string_field_build (   x,
  field,
  fmt,
  args... 
)

◆ ast_string_field_build_va

#define ast_string_field_build_va (   x,
  field,
  fmt,
  args 
)

Set a field to a complex (built) value.

Parameters
xPointer to a structure containing fields
fieldName of the field to set
fmtprintf-style format string
argsArguments for format string in va_list format
Returns
nothing

Definition at line 588 of file stringfields.h.

Referenced by ast_msg_set_body(), ast_msg_set_context(), ast_msg_set_endpoint(), ast_msg_set_exten(), ast_msg_set_from(), ast_msg_set_tech(), and ast_msg_set_to().

◆ AST_STRING_FIELD_EXTENDED

#define AST_STRING_FIELD_EXTENDED (   name)    AST_STRING_FIELD(name)

Declare an extended string field.

Since
13.9.0
Parameters
nameThe field name

Definition at line 307 of file stringfields.h.

Referenced by AST_TEST_DEFINE().

◆ ast_string_field_free_memory

#define ast_string_field_free_memory (   x)

free all memory - to be called before destroying the object

Parameters
x

Definition at line 368 of file stringfields.h.

Referenced by action_destroy(), agent_cfg_destructor(), agent_pvt_destructor(), aor_destroy(), ast_applicationmap_item_destructor(), ast_bridge_features_limits_destroy(), ast_channel_internal_cleanup(), ast_custom_function_unregister(), AST_TEST_DEFINE(), ast_unregister_application(), ast_xml_doc_item_destructor(), ast_xmpp_client_config_destructor(), asterisk_publication_config_destroy(), attended_transfer_properties_destructor(), auth_destroy(), auth_http_callback(), bridge_profile_sounds_destroy_cb(), bridge_role_destroy(), bridge_snapshot_dtor(), bucket_destroy(), build_user(), caldav_destructor(), calendar_destructor(), calendar_event_destructor(), cdr_object_dtor(), cel_general_config_dtor(), channel_snapshot_base_dtor(), channel_snapshot_caller_dtor(), channel_snapshot_dialplan_dtor(), conf_general_dtor(), contact_destroy(), copy_to_voicemail(), db_destructor(), destroy_bridge(), destroy_fast_originate_helper(), destroy_header(), destroy_jack_data(), destroy_mailbox_mapping(), destroy_odbc(), destroy_queue(), destroy_session_details(), device_state_subscription_destroy(), domain_alias_destroy(), endpoint_destructor(), endpoint_dtor(), endpoint_snapshot_dtor(), ewscal_destructor(), exception_store_free(), exchangecal_destructor(), featuregroup_item_destructor(), featuremap_config_destructor(), free_acf_query(), free_config(), free_outgoing(), general_destructor(), global_destructor(), hepv3_config_dtor(), icalendar_destructor(), info_configuration_destroy(), ip_identify_destroy(), jingle_endpoint_destructor(), jingle_session_destructor(), load_module(), logmsg_free(), manager_event_blob_dtor(), mapping_destroy(), media_configuration_destroy(), media_variant_destroy(), mixmonitor_free(), msg_data_destructor(), msg_destructor(), mwi_state_dtor(), parked_call_payload_destructor(), parking_lot_cfg_destructor(), parking_lot_destructor(), peer_destructor(), pickup_destructor(), playback_dtor(), presence_state_dtor(), prometheus_general_config_dtor(), pvt_destructor(), queue_stasis_data_destructor(), realtime_multi_odbc(), realtime_odbc(), recording_options_dtor(), sip_contact_status_dtor(), sip_destroy_peer(), sip_monitor_instance_destructor(), sip_outbound_publish_destroy(), sip_outbound_registration_destroy(), sip_pvt_dtor(), sip_refer_destroy(), sip_registry_destroy(), sip_subscribe_mwi_destroy(), sip_transport_destroy(), skel_global_config_destructor(), skel_level_destructor(), sla_station_destructor(), sla_trunk_destructor(), stasis_app_bridge_channel_wrapper_destructor(), stir_shaken_certificate_destructor(), stir_shaken_general_destructor(), stir_shaken_store_destructor(), store_odbc(), stored_recording_dtor(), subscription_configuration_destroy(), tds_unload_module(), temp_pvt_cleanup(), test_item_destructor(), test_vm_api_destroy_mock_snapshot(), unbound_global_config_destructor(), update_odbc(), user_destructor(), vm_msg_snapshot_destroy(), and xfer_destructor().

◆ ast_string_field_init

#define ast_string_field_init (   x,
  size 
)

Initialize a field pool and fields.

Parameters
xPointer to a structure containing fields
sizeAmount of storage to allocate. Use AST_STRINGFIELD_RESET to reset fields to the default value, and release all but the most recent pool. AST_STRINGFIELD_DESTROY (used internally) means free all pools which is equivalent to calling ast_string_field_free_memory.
Returns
0 on success, non-zero on failure

Definition at line 353 of file stringfields.h.

Referenced by __ast_channel_internal_alloc(), __features_config_alloc(), __sip_alloc(), acf_retrieve_docs(), action_originate(), agent_cfg_alloc(), agent_pvt_new(), alloc_new_parking_lot(), alloc_queue(), aor_alloc(), applicationmap_item_alloc(), ast_bridge_features_limits_construct(), ast_bridge_snapshot_create(), ast_calendar_event_alloc(), ast_cel_general_config_alloc(), ast_endpoint_snapshot_create(), ast_manager_event_blob_create(), ast_manager_register2(), ast_msg_alloc(), ast_parked_call_payload_create(), ast_phoneprov_provider_register(), ast_register_application2(), ast_sip_endpoint_alloc(), AST_TEST_DEFINE(), ast_xml_doc_item_alloc(), ast_xmpp_client_config_alloc(), asterisk_publication_config_alloc(), attended_transfer_properties_alloc(), auth_alloc(), auth_http_callback(), bridge_alloc(), bridge_moh_create(), bridge_profile_sounds_alloc(), bucket_alloc(), bucket_file_alloc(), build_calendar(), build_peer(), build_profile(), build_route(), build_user(), caldav_load_calendar(), cdr_object_alloc(), channel_snapshot_base_create(), channel_snapshot_caller_create(), channel_snapshot_dialplan_create(), conf_alloc(), contact_alloc(), copy_to_voicemail(), destroy_odbc(), device_state_subscription_create(), domain_alias_alloc(), endpoint_internal_create(), ewscal_load_calendar(), exchangecal_load_calendar(), featuregroup_handler(), global_alloc(), global_config_alloc(), hepv3_config_alloc(), ical_load_calendar(), init_acf_query(), init_info_configuration(), init_media_configuration(), init_pvt(), init_subscription_configuration(), ip_identify_alloc(), jingle_alloc(), jingle_endpoint_alloc(), launch_monitor_thread(), mapping_alloc(), media_variant_alloc(), msg_data_alloc(), mwi_create_state(), new_iax(), new_outgoing(), new_realtime_sqlite3_db(), parking_lot_cfg_alloc(), playback_create(), presence_state_alloc(), prometheus_general_config_alloc(), queue_stasis_data_alloc(), realtime_multi_odbc(), realtime_odbc(), recording_alloc(), session_details_new(), setup_bridge_role_option(), sip_contact_status_alloc(), sip_monitor_instance_init(), sip_outbound_publish_alloc(), sip_outbound_registration_alloc(), sip_register(), sip_subscribe_mwi(), sip_transport_alloc(), skel_config_alloc(), skel_level_alloc(), sla_build_station(), sla_build_trunk(), stasis_app_bridge_playback_channel_add(), stasis_app_recording_options_create(), stir_shaken_certificate_alloc(), stir_shaken_general_alloc(), stir_shaken_store_alloc(), store_odbc(), tds_load_module(), temp_peer(), temp_pvt_init(), test_item_alloc(), test_vm_api_create_mock_snapshot(), transmit_response_using_temp(), unbound_config_alloc(), update_odbc(), vm_msg_snapshot_alloc(), and xmpp_client_alloc().

◆ ast_string_field_init_extended

#define ast_string_field_init_extended (   x,
  field 
)

Initialize an extended string field.

Since
13.9.0
Parameters
xPointer to a structure containing the field
fieldThe extended field to initialize
Return values
zeroon success
non-zeroon error
Note
This macro must be called on ALL fields defined with AST_STRING_FIELD_EXTENDED after ast_string_field_init has been called.

Definition at line 395 of file stringfields.h.

Referenced by AST_TEST_DEFINE().

◆ ast_string_field_ptr_build

#define ast_string_field_ptr_build (   x,
  ptr,
  fmt,
  args... 
)

Set a field to a complex (built) value.

Parameters
xPointer to a structure containing fields
ptrPointer to a field within the structure
fmtprintf-style format string
argsArguments for format string
Returns
nothing

Definition at line 531 of file stringfields.h.

◆ ast_string_field_ptr_build_va

#define ast_string_field_ptr_build_va (   x,
  ptr,
  fmt,
  args 
)

Set a field to a complex (built) value with prebuilt va_lists.

Parameters
xPointer to a structure containing fields
ptrPointer to a field within the structure
fmtprintf-style format string
argsArguments for format string in va_list format
Returns
nothing

Definition at line 569 of file stringfields.h.

Referenced by ast_manager_event_blob_create().

◆ ast_string_field_ptr_set

#define ast_string_field_ptr_set (   x,
  ptr,
  data 
)

Set a field to a simple string value.

Parameters
xPointer to a structure containing fields
ptrPointer to a field within the structure
dataString value to be copied into the field
Return values
zeroon success
non-zeroon error

Definition at line 470 of file stringfields.h.

Referenced by ast_parse_digest(), and reply_digest().

◆ ast_string_field_ptr_set_by_fields

#define ast_string_field_ptr_set_by_fields (   field_mgr_pool,
  field_mgr,
  ptr,
  data 
)    __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Definition at line 503 of file stringfields.h.

Referenced by AST_TEST_DEFINE(), and stringfield_handler_fn().

◆ ast_string_field_set

#define ast_string_field_set (   x,
  field,
  data 
)

Set a field to a simple string value.

Parameters
xPointer to a structure containing fields
fieldName of the field to set
dataString value to be copied into the field
Return values
zeroon success
non-zeroon error

Definition at line 514 of file stringfields.h.

Referenced by __find_call(), __find_callno(), __sip_alloc(), __sip_subscribe_mwi_do(), acf_faxopt_write(), acf_retrieve_docs(), action_originate(), agent_cfg_alloc(), agent_login_channel_config(), agent_pvt_new(), alloc_artificial_auth(), alloc_header(), alloc_new_parking_lot(), alloc_queue(), aor_apply_outbound_proxy(), append_mailbox_mapping(), applicationmap_item_alloc(), ast_bridge_snapshot_create(), ast_bucket_alloc(), ast_bucket_file_alloc(), ast_cdr_fork(), ast_channel_set_bridge_role_option(), ast_endpoint_snapshot_create(), ast_manager_register2(), ast_msg_alloc(), ast_parked_call_payload_create(), ast_parse_digest(), ast_phoneprov_provider_register(), ast_register_application2(), ast_res_pjsip_find_or_create_contact_status(), ast_sip_location_create_contact(), AST_TEST_DEFINE(), ast_xml_doc_item_alloc(), ast_xmpp_client_config_alloc(), attended_transfer_properties_alloc(), authenticate_reply(), authenticate_request(), authenticate_verify(), base_process_parked_channel(), base_process_party_a(), bridge_base_init(), bridge_candidate_add_to_cdr(), bridge_config_set_limits_warning_values(), bridge_moh_create(), bridge_template_handler(), bucket_copy_handler(), bucket_file_copy_handler(), build_calendar(), build_config_docs(), build_peer(), build_profile(), build_route(), build_user(), cache_get_callno_locked(), caldav_add_event(), caldav_load_calendar(), calendar_write_exec(), cdr_all_relink(), cdr_all_unlink(), cdr_object_alloc(), cdr_object_create_and_append(), change_callid_pvt(), channel_snapshot_base_create(), channel_snapshot_caller_create(), channel_snapshot_dialplan_create(), check_access(), check_peer_ok(), check_user_full(), clone_parkinglot_cfg(), config_alloc(), contact_alloc(), copy_event_data(), copy_to_voicemail(), create_addr(), create_addr_from_peer(), create_dynamic_lot_full(), custom_prepare(), device_state_subscription_create(), dial_state_process_bridge_enter(), endelm(), endpoint_internal_create(), ewscal_load_calendar(), exchangecal_load_calendar(), extensionstate_update(), extract_uri(), fax_gateway_attach(), fax_gateway_detect_t38(), fax_gateway_framehook(), fax_gateway_start(), feature_attended_transfer(), featuregroup_handler(), featuremap_set(), fetch_access_token(), forked_invite_init(), format_log_message_ap(), from_user_handler(), general_set(), generate_test_parking_lot(), generic_fax_exec(), get_also_info(), get_destination(), get_pai(), get_realm(), get_refer_info(), get_rpid(), handle_bridge_enter(), handle_bridge_leave_message(), handle_cc_notify(), handle_incoming(), handle_local_optimization_end(), handle_masquerade(), handle_options(), handle_request_bye(), handle_request_invite(), handle_request_options(), handle_request_publish(), handle_request_refer(), handle_response(), handle_response_invite(), handle_response_notify(), handle_response_publish(), handle_response_register(), handle_response_subscribe(), handle_scan_file(), iax2_call(), iax2_request(), ical_load_calendar(), icalendar_add_event(), init_acf_query(), init_pvt(), init_queue(), initreqprep(), ip_identify_apply(), jingle_alloc(), jingle_endpoint_alloc(), jingle_interpret_description(), launch_monitor_thread(), load_config(), load_module(), msg_send_exec(), msg_set_var_full(), mwi_create_state(), new_iax(), new_outgoing(), new_realtime_sqlite3_db(), on_load_attestation(), on_load_ca_file(), on_load_ca_path(), on_load_path(), on_load_public_cert_url(), parking_lot_cfg_alloc(), parking_lot_cfg_remove_extensions(), parse_line(), parse_ok_contact(), parse_register_contact(), permanent_uri_handler(), pickup_set(), play_on_channel(), playback_create(), presence_state_alloc(), process_description_file(), process_sdp_o(), queue_set_param(), queue_stasis_data_alloc(), raise_exception(), receive_message(), receivefax_exec(), reg_source_db(), register_aor_core(), register_verify(), registry_authrequest(), reply_digest(), reqprep(), respprep(), save_osptoken(), sendfax_exec(), set_peer_defaults(), set_pvt_defaults(), set_sound(), setup_bridge_role_option(), single_state_process_bridge_enter(), sip_call(), sip_monitor_instance_init(), sip_msg_send(), sip_parse_register_line(), sip_poke_peer(), sip_register(), sip_reload(), sip_request_call(), sip_send_mwi_to_peer(), sip_sendtext(), sip_set_redirstr(), sip_subscribe_mwi(), skel_level_alloc(), sla_build_station(), sla_build_trunk(), socket_process_helper(), startelm(), stasis_app_bridge_playback_channel_add(), stasis_app_control_play_uri(), stasis_app_recording_options_create(), stasis_app_stored_recording_find_by_name(), store_callerid(), t30_phase_e_handler(), tds_load_module(), test_item_alloc(), test_stir_shaken_create_cert(), test_vm_api_create_mock_snapshot(), test_vm_api_destroy_mailbox_voicemails(), test_vm_api_test_setup(), test_vm_api_update_test_snapshots(), transmit_refer(), transmit_register(), transmit_response_using_temp(), transport_tls_file_handler(), update_realtime_sqlite3_db(), verify_default_parking_lot(), vm_msg_snapshot_create(), xfer_set(), and xmpp_client_alloc().

◆ ast_string_fields_cmp

#define ast_string_fields_cmp (   instance1,
  instance2 
)

Compare the string fields in two instances of the same structure.

Since
12
Parameters
instance1The first instance of the structure to be compared
instance2The second instance of the structure to be compared
Return values
zeroif all string fields are equal (does not compare non-string field data)
non-zeroif the values of the string fields differ

Definition at line 607 of file stringfields.h.

Referenced by AST_TEST_DEFINE().

◆ ast_string_fields_copy

#define ast_string_fields_copy (   copy,
  orig 
)

Copy all string fields from one instance to another of the same structure.

Since
12
Parameters
copyThe instance of the structure to be copied into
origThe instance of the structure to be copied from
Return values
zeroon success
non-zeroon error

Definition at line 627 of file stringfields.h.

Referenced by AST_TEST_DEFINE(), bridge_features_limits_copy(), clone_parkinglot_cfg(), featuremap_copy(), general_copy(), pickup_copy(), sip_contact_status_copy(), and xfer_copy().

Typedef Documentation

◆ ast_string_field

typedef const char* ast_string_field

Definition at line 190 of file stringfields.h.

◆ ast_string_field_allocation

typedef uint16_t ast_string_field_allocation

Definition at line 194 of file stringfields.h.

Enumeration Type Documentation

◆ ast_stringfield_cleanup_type

Enumerator
AST_STRINGFIELD_RESET 

Reset all string fields and free all extra pools that may have been created The allocation or structure can be reused as is.

AST_STRINGFIELD_DESTROY 

Reset all string fields and free all pools. If the pointer was returned by ast_calloc_with_stringfields, it can NOT be reused and should be immediately freed. Otherwise, you must call ast_string_field_init again if you want to reuse it.

Definition at line 309 of file stringfields.h.

309  {
310  /*!
311  * Reset all string fields and free all extra pools that may have been created
312  * The allocation or structure can be reused as is.
313  */
315  /*!
316  * Reset all string fields and free all pools.
317  * If the pointer was returned by ast_calloc_with_stringfields, it can NOT be reused
318  * and should be immediately freed. Otherwise, you must call ast_string_field_init
319  * again if you want to reuse it.
320  */
322 };

Function Documentation

◆ __ast_calloc_with_stringfields()

void* __ast_calloc_with_stringfields ( unsigned int  num_structs,
size_t  struct_size,
size_t  field_mgr_offset,
size_t  field_mgr_pool_offset,
size_t  pool_size,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 380 of file stringfields.c.

References __ast_calloc(), __ast_string_field_empty, allocation, ast_assert, ast_free, AST_VECTOR_APPEND, AST_VECTOR_INIT, ast_string_field_mgr::embedded_pool, NULL, optimal_alloc_size(), pool, ast_string_field_pool::size, and ast_string_field_mgr::string_fields.

383 {
384  struct ast_string_field_mgr *mgr;
385  struct ast_string_field_pool *pool;
386  struct ast_string_field_pool **pool_head;
387  size_t pool_size_needed = sizeof(*pool) + pool_size;
388  size_t size_to_alloc = optimal_alloc_size(struct_size + pool_size_needed);
389  void *allocation;
390  const char **p;
391  size_t initial_vector_size;
392 
393  ast_assert(num_structs == 1);
394 
395  allocation = __ast_calloc(num_structs, size_to_alloc, file, lineno, func);
396  if (!allocation) {
397  return NULL;
398  }
399 
400  mgr = allocation + field_mgr_offset;
401 
402  pool = allocation + struct_size;
403  pool_head = allocation + field_mgr_pool_offset;
404  p = (const char **) pool_head + 1;
405  initial_vector_size = ((size_t) (((char *)mgr) - ((char *)p))) / sizeof(*p);
406 
407  if (AST_VECTOR_INIT(&mgr->string_fields, initial_vector_size)) {
408  ast_free(allocation);
409  return NULL;
410  }
411 
412  while ((struct ast_string_field_mgr *) p != mgr) {
415  }
416 
417  mgr->embedded_pool = pool;
418  *pool_head = pool;
419  pool->size = size_to_alloc - struct_size - sizeof(*pool);
420 
421  return allocation;
422 }
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc
Definition: astmm.c:1635
struct ast_string_field_pool * embedded_pool
Definition: stringfields.h:229
static pj_pool_t * pool
Global memory pool for configuration and timers.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
struct ast_string_field_vector string_fields
Definition: stringfields.h:230
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
static size_t optimal_alloc_size(size_t size)
Definition: stringfields.c:47
ast_string_field_allocation allocation
Definition: stringfields.c:39
ast_string_field __ast_string_field_empty
Definition: stringfields.c:43
#define ast_free(a)
Definition: astmm.h:182

◆ __ast_string_field_alloc_space()

ast_string_field __ast_string_field_alloc_space ( struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
size_t  needed,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 202 of file stringfields.c.

References add_string_pool(), ast_alignof, ast_assert, ast_make_room_for, AST_STRING_FIELD_ALLOCATION, ast_string_field_mgr::last_alloc, NULL, and result.

Referenced by __ast_string_field_ptr_build_va().

205 {
206  char *result = NULL;
207  size_t space = (*pool_head)->size - (*pool_head)->used;
208  size_t to_alloc;
209 
210  /* Make room for ast_string_field_allocation and make it a multiple of that. */
213 
214  if (__builtin_expect(to_alloc > space, 0)) {
215  size_t new_size = (*pool_head)->size;
216 
217  while (new_size < to_alloc) {
218  new_size *= 2;
219  }
220 
221  if (add_string_pool(mgr, pool_head, new_size, file, lineno, func)) {
222  return NULL;
223  }
224  }
225 
226  /* pool->base is always aligned (gcc aligned attribute). We ensure that
227  * to_alloc is also a multiple of ast_alignof(ast_string_field_allocation)
228  * causing result to always be aligned as well; which in turn fixes that
229  * AST_STRING_FIELD_ALLOCATION(result) is aligned. */
230  result = (*pool_head)->base + (*pool_head)->used;
231  (*pool_head)->used += to_alloc;
232  (*pool_head)->active += needed;
234  AST_STRING_FIELD_ALLOCATION(result) = needed;
235  mgr->last_alloc = result;
236 
237  return result;
238 }
uint16_t ast_string_field_allocation
Definition: stringfields.h:194
#define ast_alignof(type)
Return the number of bytes used in the alignment of type.
Definition: utils.h:738
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
static int add_string_pool(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t size, const char *file, int lineno, const char *func)
add a new block to the pool. We can only allocate from the topmost pool, so the fields in *mgr reflec...
Definition: stringfields.c:62
#define AST_STRING_FIELD_ALLOCATION(x)
Macro to provide access to the allocation field that lives immediately in front of a string field...
Definition: stringfields.h:460
#define ast_make_room_for(offset, type)
Increase offset by the required alignment of type and make sure it is a multiple of said alignment...
Definition: utils.h:781
static PGresult * result
Definition: cel_pgsql.c:88
ast_string_field last_alloc
Definition: stringfields.h:228

◆ __ast_string_field_free_memory()

int __ast_string_field_free_memory ( struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
enum ast_stringfield_cleanup_type  cleanup_type,
const char *  file,
int  lineno,
const char *  func 
)

Internal cleanup function.

Definition at line 103 of file stringfields.c.

References ast_string_field_pool::active, ast_free, ast_log, AST_STRINGFIELD_DESTROY, AST_STRINGFIELD_RESET, AST_VECTOR_CALLBACK_VOID, AST_VECTOR_FREE, ast_string_field_mgr::embedded_pool, LOG_WARNING, NULL, ast_string_field_pool::prev, reset_field(), ast_string_field_mgr::string_fields, and ast_string_field_pool::used.

Referenced by __ast_string_field_init().

106 {
107  struct ast_string_field_pool *cur = NULL;
108  struct ast_string_field_pool *preserve = NULL;
109 
110  /* reset all the fields regardless of cleanup type */
112 
113  switch (cleanup_type) {
116 
117  if (mgr->embedded_pool) { /* ALWAYS preserve the embedded pool if there is one */
118  preserve = mgr->embedded_pool;
119  preserve->used = preserve->active = 0;
120  }
121 
122  break;
124  /* Preserve the embedded pool if there is one, otherwise the last pool */
125  if (mgr->embedded_pool) {
126  preserve = mgr->embedded_pool;
127  } else {
128  if (*pool_head == NULL) {
129  ast_log(LOG_WARNING, "trying to reset empty pool\n");
130  return -1;
131  }
132  preserve = *pool_head;
133  }
134  preserve->used = preserve->active = 0;
135  break;
136  default:
137  return -1;
138  }
139 
140  cur = *pool_head;
141  while (cur) {
142  struct ast_string_field_pool *prev = cur->prev;
143 
144  if (cur != preserve) {
145  ast_free(cur);
146  }
147  cur = prev;
148  }
149 
150  *pool_head = preserve;
151  if (preserve) {
152  preserve->prev = NULL;
153  }
154 
155  return 0;
156 }
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
struct ast_string_field_pool * embedded_pool
Definition: stringfields.h:229
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
struct ast_string_field_vector string_fields
Definition: stringfields.h:230
#define ast_log
Definition: astobj2.c:42
static void reset_field(const char **p)
Definition: stringfields.c:81
#define ast_free(a)
Definition: astmm.h:182
struct ast_string_field_pool * prev
Definition: stringfields.h:209
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition: vector.h:865

◆ __ast_string_field_init()

int __ast_string_field_init ( struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
int  needed,
const char *  file,
int  lineno,
const char *  func 
)

Internal initialization function.

Definition at line 171 of file stringfields.c.

References __ast_string_field_empty, __ast_string_field_free_memory(), add_string_pool(), AST_VECTOR_APPEND, AST_VECTOR_FREE, AST_VECTOR_INIT, ast_string_field_mgr::embedded_pool, ast_string_field_mgr::last_alloc, NULL, and ast_string_field_mgr::string_fields.

173 {
174  const char **p = (const char **) pool_head + 1;
175  size_t initial_vector_size = ((size_t) (((char *)mgr) - ((char *)p))) / sizeof(*p);
176 
177  if (needed <= 0) {
178  return __ast_string_field_free_memory(mgr, pool_head, needed, file, lineno, func);
179  }
180 
181  mgr->last_alloc = NULL;
182 
183  if (AST_VECTOR_INIT(&mgr->string_fields, initial_vector_size)) {
184  return -1;
185  }
186 
187  while ((struct ast_string_field_mgr *) p != mgr) {
190  }
191 
192  *pool_head = NULL;
193  mgr->embedded_pool = NULL;
194  if (add_string_pool(mgr, pool_head, needed, file, lineno, func)) {
196  return -1;
197  }
198 
199  return 0;
200 }
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
struct ast_string_field_pool * embedded_pool
Definition: stringfields.h:229
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
int __ast_string_field_free_memory(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, enum ast_stringfield_cleanup_type cleanup_type, const char *file, int lineno, const char *func)
Internal cleanup function.
Definition: stringfields.c:103
#define NULL
Definition: resample.c:96
struct ast_string_field_vector string_fields
Definition: stringfields.h:230
static int add_string_pool(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t size, const char *file, int lineno, const char *func)
add a new block to the pool. We can only allocate from the topmost pool, so the fields in *mgr reflec...
Definition: stringfields.c:62
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
ast_string_field __ast_string_field_empty
Definition: stringfields.c:43
ast_string_field last_alloc
Definition: stringfields.h:228

◆ __ast_string_field_ptr_build()

void __ast_string_field_ptr_build ( const char *  file,
int  lineno,
const char *  func,
struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
ast_string_field ptr,
const char *  format,
  ... 
)

Definition at line 369 of file stringfields.c.

References __ast_string_field_ptr_build_va().

372 {
373  va_list ap;
374 
375  va_start(ap, format);
376  __ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap, file, lineno, func);
377  va_end(ap);
378 }
void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format, va_list ap, const char *file, int lineno, const char *func)
Definition: stringfields.c:286
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ __ast_string_field_ptr_build_va()

void __ast_string_field_ptr_build_va ( struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
ast_string_field ptr,
const char *  format,
va_list  ap,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 286 of file stringfields.c.

References __ast_string_field_alloc_space(), __ast_string_field_empty, __ast_string_field_release_active(), ast_align_for, ast_alignof, ast_assert, ast_make_room_for, AST_STRING_FIELD_ALLOCATION, available(), grow(), and ast_string_field_mgr::last_alloc.

Referenced by __ast_string_field_ptr_build().

290 {
291  size_t needed;
292  size_t available;
293  size_t space = (*pool_head)->size - (*pool_head)->used;
294  int res;
295  ssize_t grow;
296  char *target;
297  va_list ap2;
298 
299  /* if the field already has space allocated, try to reuse it;
300  otherwise, try to use the empty space at the end of the current
301  pool
302  */
303  if (*ptr != __ast_string_field_empty) {
304  target = (char *) *ptr;
305  available = AST_STRING_FIELD_ALLOCATION(*ptr);
306  if (*ptr == mgr->last_alloc) {
307  available += space;
308  }
309  } else {
310  /* pool->used is always a multiple of ast_alignof(ast_string_field_allocation)
311  * so we don't need to re-align anything here.
312  */
313  target = (*pool_head)->base + (*pool_head)->used + ast_alignof(ast_string_field_allocation);
315  available = space - ast_alignof(ast_string_field_allocation);
316  } else {
317  available = 0;
318  }
319  }
320 
321  va_copy(ap2, ap);
322  res = vsnprintf(target, available, format, ap2);
323  va_end(ap2);
324 
325  if (res < 0) {
326  /* Are we out of memory? */
327  return;
328  }
329  if (res == 0) {
330  __ast_string_field_release_active(*pool_head, *ptr);
332  return;
333  }
334  needed = (size_t)res + 1; /* NUL byte */
335 
336  if (needed > available) {
337  /* the allocation could not be satisfied using the field's current allocation
338  (if it has one), or the space available in the pool (if it does not). allocate
339  space for it, adding a new string pool if necessary.
340  */
341  target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed, file, lineno, func);
342  if (!target) {
343  return;
344  }
345  vsprintf(target, format, ap);
346  va_end(ap); /* XXX va_end without va_start? */
347  __ast_string_field_release_active(*pool_head, *ptr);
348  *ptr = target;
349  } else if (*ptr != target) {
350  /* the allocation was satisfied using available space in the pool, but not
351  using the space already allocated to the field
352  */
353  __ast_string_field_release_active(*pool_head, *ptr);
354  mgr->last_alloc = *ptr = target;
357  (*pool_head)->used += ast_make_room_for(needed, ast_string_field_allocation);
358  (*pool_head)->active += needed;
359  } else if ((grow = (needed - AST_STRING_FIELD_ALLOCATION(*ptr))) > 0) {
360  /* the allocation was satisfied by using available space in the pool *and*
361  the field was the last allocated field from the pool, so it grew
362  */
364  (*pool_head)->used += ast_align_for(grow, ast_string_field_allocation);
365  (*pool_head)->active += grow;
366  }
367 }
uint16_t ast_string_field_allocation
Definition: stringfields.h:194
#define ast_alignof(type)
Return the number of bytes used in the alignment of type.
Definition: utils.h:738
static void grow(struct ast_threadpool *pool, int delta)
Add threads to the threadpool.
Definition: threadpool.c:524
#define ast_assert(a)
Definition: utils.h:695
#define AST_STRING_FIELD_ALLOCATION(x)
Macro to provide access to the allocation field that lives immediately in front of a string field...
Definition: stringfields.h:460
#define ast_make_room_for(offset, type)
Increase offset by the required alignment of type and make sure it is a multiple of said alignment...
Definition: utils.h:781
ast_string_field __ast_string_field_empty
Definition: stringfields.c:43
static int available(struct dahdi_pvt **pvt, int is_specific_channel)
Definition: chan_dahdi.c:13058
void __ast_string_field_release_active(struct ast_string_field_pool *pool_head, const ast_string_field ptr)
Definition: stringfields.c:261
#define ast_align_for(offset, type)
Increase offset so it is a multiple of the required alignment of type.
Definition: utils.h:758
static snd_pcm_format_t format
Definition: chan_alsa.c:102
ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t needed, const char *file, int lineno, const char *func)
Definition: stringfields.c:202
ast_string_field last_alloc
Definition: stringfields.h:228

◆ __ast_string_field_ptr_grow()

int __ast_string_field_ptr_grow ( struct ast_string_field_mgr mgr,
struct ast_string_field_pool **  pool_head,
size_t  needed,
const ast_string_field ptr 
)

Definition at line 240 of file stringfields.c.

References AST_STRING_FIELD_ALLOCATION, grow(), and ast_string_field_mgr::last_alloc.

242 {
243  ssize_t grow = needed - AST_STRING_FIELD_ALLOCATION(*ptr);
244  size_t space = (*pool_head)->size - (*pool_head)->used;
245 
246  if (*ptr != mgr->last_alloc) {
247  return 1;
248  }
249 
250  if (space < grow) {
251  return 1;
252  }
253 
254  (*pool_head)->used += grow;
255  (*pool_head)->active += grow;
257 
258  return 0;
259 }
static void grow(struct ast_threadpool *pool, int delta)
Add threads to the threadpool.
Definition: threadpool.c:524
#define AST_STRING_FIELD_ALLOCATION(x)
Macro to provide access to the allocation field that lives immediately in front of a string field...
Definition: stringfields.h:460
ast_string_field last_alloc
Definition: stringfields.h:228

◆ __ast_string_field_release_active()

void __ast_string_field_release_active ( struct ast_string_field_pool pool_head,
const ast_string_field  ptr 
)

Definition at line 261 of file stringfields.c.

References __ast_string_field_empty, ast_string_field_pool::active, ast_free, AST_STRING_FIELD_ALLOCATION, NULL, pool, and ast_string_field_pool::prev.

Referenced by __ast_string_field_ptr_build_va(), and __ast_string_fields_copy().

263 {
264  struct ast_string_field_pool *pool, *prev;
265 
266  if (ptr == __ast_string_field_empty) {
267  return;
268  }
269 
270  for (pool = pool_head, prev = NULL; pool; prev = pool, pool = pool->prev) {
271  if ((ptr >= pool->base) && (ptr <= (pool->base + pool->size))) {
272  pool->active -= AST_STRING_FIELD_ALLOCATION(ptr);
273  if (pool->active == 0) {
274  if (prev) {
275  prev->prev = pool->prev;
276  ast_free(pool);
277  } else {
278  pool->used = 0;
279  }
280  }
281  break;
282  }
283  }
284 }
static pj_pool_t * pool
Global memory pool for configuration and timers.
#define NULL
Definition: resample.c:96
#define AST_STRING_FIELD_ALLOCATION(x)
Macro to provide access to the allocation field that lives immediately in front of a string field...
Definition: stringfields.h:460
ast_string_field __ast_string_field_empty
Definition: stringfields.c:43
#define ast_free(a)
Definition: astmm.h:182
struct ast_string_field_pool * prev
Definition: stringfields.h:209

◆ __ast_string_fields_cmp()

int __ast_string_fields_cmp ( struct ast_string_field_vector *  left,
struct ast_string_field_vector *  right 
)

Definition at line 424 of file stringfields.c.

References ast_assert, AST_VECTOR_GET, and AST_VECTOR_SIZE.

426 {
427  int i;
428  int res = 0;
429 
430  ast_assert(AST_VECTOR_SIZE(left) == AST_VECTOR_SIZE(right));
431 
432  for (i = 0; i < AST_VECTOR_SIZE(left); i++) {
433  if ((res = strcmp(*AST_VECTOR_GET(left, i), *AST_VECTOR_GET(right, i)))) {
434  return res;
435  }
436  }
437 
438  return res;
439 }
#define ast_assert(a)
Definition: utils.h:695
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ __ast_string_fields_copy()

int __ast_string_fields_copy ( struct ast_string_field_pool copy_pool,
struct ast_string_field_mgr copy_mgr,
struct ast_string_field_mgr orig_mgr,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 441 of file stringfields.c.

References __ast_string_field_empty, __ast_string_field_ptr_set_by_fields, __ast_string_field_release_active(), ast_assert, AST_VECTOR_GET, AST_VECTOR_SIZE, and ast_string_field_mgr::string_fields.

444 {
445  int i;
446  struct ast_string_field_vector *dest = &(copy_mgr->string_fields);
447  struct ast_string_field_vector *src = &(orig_mgr->string_fields);
448 
450 
451  for (i = 0; i < AST_VECTOR_SIZE(dest); i++) {
454  }
455 
456  for (i = 0; i < AST_VECTOR_SIZE(dest); i++) {
457  if (__ast_string_field_ptr_set_by_fields(copy_pool, *copy_mgr, AST_VECTOR_GET(dest, i),
458  *AST_VECTOR_GET(src, i), file, lineno, func)) {
459  return -1;
460  }
461  }
462 
463  return 0;
464 }
#define __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, file, lineno, func)
Definition: stringfields.h:479
#define ast_assert(a)
Definition: utils.h:695
struct ast_string_field_vector string_fields
Definition: stringfields.h:230
ast_string_field __ast_string_field_empty
Definition: stringfields.c:43
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
void __ast_string_field_release_active(struct ast_string_field_pool *pool_head, const ast_string_field ptr)
Definition: stringfields.c:261
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ AST_VECTOR()

AST_VECTOR ( ast_string_field_vector  ,
const char **   
)

Variable Documentation

◆ __ast_string_field_empty

const char* __ast_string_field_empty