|
Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
|
Declares shared low-level support helpers used across the Pharos native runtime. More...
#include <stddef.h>Go to the source code of this file.
Data Structures | |
| struct | Buffer |
| Growable byte buffer used by parsing and string assembly helpers. More... | |
Functions | |
Shared support helpers | |
| void | buffer_init (Buffer *buffer) |
| Initializes a growable buffer to an empty state. | |
| void | buffer_free (Buffer *buffer) |
| Releases memory owned by a growable buffer. | |
| int | buffer_reserve (Buffer *buffer, size_t needed) |
| Ensures a buffer can hold at least a requested number of bytes. | |
| int | buffer_append (Buffer *buffer, const void *data, size_t len) |
| Appends bytes to a growable buffer and maintains a trailing NUL byte. | |
| char * | dup_range (const char *start, size_t len) |
| Duplicates a byte range into a newly allocated NUL-terminated string. | |
| void | trim_in_place (char *text) |
| Trims leading and trailing ASCII whitespace from a string in place. | |
| int | starts_with (const char *value, const char *prefix) |
| Tests whether one string starts with another string. | |
| int | streq (const char *a, const char *b) |
| Tests whether two strings are exactly equal. | |
| char * | path_join (const char *left, const char *right) |
| Joins two path segments using the native path separator. | |
| char * | path_dirname (const char *path) |
| Returns the parent directory component of a path. | |
| int | path_exists (const char *path) |
| Tests whether a filesystem path currently exists. | |
| int | path_is_directory (const char *path) |
| Tests whether a filesystem path refers to a directory. | |
| int | path_is_writable (const char *path) |
| Tests whether a filesystem path is writable by the current process. | |
| char * | path_canonicalize (const char *path) |
| Normalizes a path by collapsing redundant separators and dot segments. | |
| char * | resolve_relative_to (const char *base_dir, const char *value) |
| Resolves a path value relative to a base directory when needed. | |
| char * | current_working_directory (void) |
| Returns the current working directory. | |
| char * | read_file_text (const char *path) |
| Reads an entire file into a newly allocated text buffer. | |
Declares shared low-level support helpers used across the Pharos native runtime.
Definition in file native_support.h.
| int buffer_append | ( | Buffer * | buffer, |
| const void * | data, | ||
| size_t | len ) |
Appends bytes to a growable buffer and maintains a trailing NUL byte.
| buffer | Buffer to append into. |
| data | Source bytes to append. |
| len | Number of bytes to append. |
Definition at line 68 of file native_support.c.
References buffer_reserve(), Buffer::data, Buffer::len, and len.
Referenced by append_pipe_to_buffer(), build_native_runtime_status_report_json(), capture_execv_output_env_native(), capture_postgresql_result_output_runtime_local(), compact_log_text_native(), conninfo_append_kv_runtime_local(), json_string_dup_native(), migration_expected_checksum_dup_runtime_local(), native_append_escaped_sql_char(), native_append_escaped_sql_char(), native_append_file_to_buffer(), native_append_json_item(), native_append_path_marker(), native_finish_json_array(), native_json_string_array_lines_dup(), native_legacy_expected_migration_checksum(), parse_http_request_native(), path_canonicalize(), read_file_text(), request_headers_with_client_ip_native(), and runtime_log_banner_native().
| void buffer_free | ( | Buffer * | buffer | ) |
Releases memory owned by a growable buffer.
| buffer | Buffer to clear. |
Definition at line 40 of file native_support.c.
References Buffer::cap, Buffer::data, and Buffer::len.
Referenced by build_native_runtime_status_report_json(), capture_execv_output_env_native(), capture_execv_output_split_env_native(), capture_postgresql_result_output_runtime_local(), compact_log_text_native(), json_string_dup_native(), migration_expected_checksum_dup_runtime_local(), native_capture_migrate_verify_sqlite_report_json(), native_expected_migration_checksum(), native_finish_json_array(), native_json_string_array_lines_dup(), native_legacy_expected_migration_checksum(), native_sql_literal_escape(), native_sql_literal_escape(), parse_http_request_native(), path_canonicalize(), postgresql_conninfo_dup_runtime_local(), read_file_text(), request_headers_with_client_ip_native(), and runtime_log_banner_native().
| void buffer_init | ( | Buffer * | buffer | ) |
Initializes a growable buffer to an empty state.
| buffer | Buffer to initialize. |
Definition at line 34 of file native_support.c.
References Buffer::cap, Buffer::data, and Buffer::len.
Referenced by build_native_runtime_status_report_json(), capture_execv_output_env_native(), capture_execv_output_split_env_native(), capture_postgresql_result_output_runtime_local(), compact_log_text_native(), json_string_dup_native(), migration_expected_checksum_dup_runtime_local(), native_capture_migrate_verify_sqlite_report_json(), native_expected_migration_checksum(), native_json_string_array_lines_dup(), native_legacy_expected_migration_checksum(), native_sql_literal_escape(), native_sql_literal_escape(), parse_http_request_native(), path_canonicalize(), postgresql_conninfo_dup_runtime_local(), read_file_text(), request_headers_with_client_ip_native(), and runtime_log_banner_native().
| int buffer_reserve | ( | Buffer * | buffer, |
| size_t | needed ) |
Ensures a buffer can hold at least a requested number of bytes.
| buffer | Buffer whose capacity may grow. |
| needed | Minimum required capacity in bytes. |
Definition at line 47 of file native_support.c.
References Buffer::cap, and Buffer::data.
Referenced by buffer_append().
| char * current_working_directory | ( | void | ) |
Returns the current working directory.
Definition at line 310 of file native_support.c.
References pharos_support_getcwd, and pharos_support_strdup.
Referenced by apply_serve_config_defaults_from_conf_native(), executable_dir_from_argv0(), find_repo_root(), load_app_runtime_from_artifact_native(), load_runtime_stack(), resolved_runtime_conf_path_from_config_native(), and runtime_apps_dir_native().
| char * dup_range | ( | const char * | start, |
| size_t | len ) |
Duplicates a byte range into a newly allocated NUL-terminated string.
| start | Pointer to the first byte to copy. |
| len | Number of bytes to copy. |
Definition at line 78 of file native_support.c.
References len.
Referenced by conf_lookup_value_in_text(), emit_business_admin_technician_rows_json_runtime(), emit_business_calendar_page_json_runtime(), emit_managed_appointments_json_runtime(), emit_user_appointments_json_runtime(), handle_file_generated_surface_match_command(), handle_manifest_fixture_path_raw_command(), handle_object_path_string_command(), handle_request_lines_to_booking_options_json_command(), http_status_line_from_response_native(), json_find_string_after(), json_value_tostring_dup_runtime(), multipart_boundary_dup_runtime(), multipart_find_part_runtime(), multipart_header_param_dup_runtime(), native_dynamic_dispatch_extract_param(), native_json_string_array_lines_dup(), native_request_path_without_query(), native_serve_static_file(), parse_http_request_native(), path_dirname(), render_template_text_with_default_kind_dup_runtime(), request_header_value_dup_runtime(), request_path_dup_runtime(), resource_kind_from_resource_id_runtime(), route_template_match_into_mut_obj_runtime(), and runtime_apps_fingerprint_native().
| char * path_canonicalize | ( | const char * | path | ) |
Normalizes a path by collapsing redundant separators and dot segments.
| path | Path to canonicalize. |
Definition at line 195 of file native_support.c.
References buffer_append(), buffer_free(), buffer_init(), Buffer::data, Buffer::len, PHAROS_SUPPORT_PATH_SEP, and pharos_support_strdup.
Referenced by executable_dir_from_argv0(), find_repo_root(), handle_native_noindex_command(), load_app_runtime_for_single_app(), and match_app_root_in_directory().
| char * path_dirname | ( | const char * | path | ) |
Returns the parent directory component of a path.
| path | Source path. |
Definition at line 145 of file native_support.c.
References dup_range(), PHAROS_SUPPORT_PATH_SEP, and pharos_support_strdup.
Referenced by app_build_dir_local_native(), apply_serve_config_defaults_from_conf_native(), build_dev_docs_directory_native(), build_native_restore_report_local_json(), copy_file_binary(), executable_dir_from_argv0(), find_app_root_for_target(), find_repo_root(), load_app_runtime_from_artifact_native(), load_runtime_stack(), native_app_conf_value_path(), native_db_check_json(), native_dynamic_relational_prepare_request_state(), native_dynamic_relational_sqlite_runtime_prepare(), native_dynamic_relational_sqlite_runtime_ready(), native_listener_prepare_unix_directory(), native_output_path_check_json(), native_write_access_log(), native_write_error_log(), resolve_conf_relative_path_native(), write_binary_file_runtime(), write_error_report_native(), and write_text_file().
| int path_exists | ( | const char * | path | ) |
Tests whether a filesystem path currently exists.
| path | Path to test. |
Definition at line 168 of file native_support.c.
References pharos_support_access.
Referenced by app_local_conf_path_native(), app_root_has_finalized_artifact_native(), build_app_from_root_native(), build_dev_docs_directory_native(), build_native_backup_report_local_json(), build_native_restore_report_local_json(), declared_page_relative_path_dup_runtime(), dynamic_conf_lookup_runtime(), emit_website_status_native(), find_repo_root(), generated_surface_fixture_path_dup_runtime(), handle_dynamic_file_signature_command(), handle_native_barcode_command(), handle_page_route(), load_app_local_config_native(), load_app_runtime_from_artifact_native(), load_cli_postgresql_runtime_config(), load_dynamic_postgresql_runtime_config(), load_native_libpq_api_runtime(), load_native_libpq_api_runtime_local(), load_postgresql_runtime_config_runtime_local(), load_runtime_stack(), match_app_root_in_directory(), maybe_seed_app_state_native(), migration_expected_checksum_dup_runtime(), migration_expected_checksum_dup_runtime_local(), native_app_conf_path(), native_append_seed_sources_to_buffer(), native_build_sqlite_migrate_verify_failure_report_json(), native_capture_migrate_verify_sqlite_report_json(), native_db_check_json(), native_dynamic_config_lookup_raw_dup(), native_dynamic_media_serve_asset(), native_dynamic_relational_file_signature_dup(), native_dynamic_relational_sqlite_runtime_ready(), native_dynamic_runtime_handle_request(), native_expected_migration_checksum(), native_legacy_expected_migration_checksum(), native_metadata_artifact_value(), native_migration_fixture_path(), native_migration_schema_version(), native_output_path_check_json(), native_serve_static_file(), native_sqlite_migrate_verify_preflight_ok(), native_write_backup_state_snapshot(), remove_directory_recursive(), remove_media_url_file(), render_declared_page_response_with_headers_runtime(), request_form_field_value_dup_runtime(), and resolve_route_fixture_path().
| int path_is_directory | ( | const char * | path | ) |
Tests whether a filesystem path refers to a directory.
| path | Path to test. |
Definition at line 172 of file native_support.c.
References pharos_support_stat.
Referenced by build_app_from_root_native(), build_dev_docs_directory_native(), copy_directory_recursive(), ensure_directory(), load_runtime_stack(), match_app_root_in_directory(), native_db_check_json(), native_dynamic_media_serve_asset(), native_output_path_check_json(), native_serve_static_file(), remove_directory_recursive(), and write_noindex_markers_recursive_native().
| int path_is_writable | ( | const char * | path | ) |
Tests whether a filesystem path is writable by the current process.
| path | Path to test. |
Definition at line 191 of file native_support.c.
References pharos_support_access.
Referenced by native_output_path_check_json().
| char * path_join | ( | const char * | left, |
| const char * | right ) |
Joins two path segments using the native path separator.
| left | Left path segment. |
| right | Right path segment. |
Definition at line 115 of file native_support.c.
References PHAROS_SUPPORT_PATH_SEP, and pharos_support_strdup.
Referenced by add_runtime_app_native(), app_artifact_dir_from_build_dir_native(), app_build_dir_local_native(), app_local_conf_path_native(), app_root_has_finalized_artifact_native(), app_runtime_host_profile_native(), app_state_path_local_native(), build_app_from_root_native(), build_dev_docs_directory_native(), build_native_backup_report_local_json(), build_native_restore_report_local_json(), construct_direct_route_fixture_path(), construct_packaged_route_fixture_path(), copy_directory_recursive(), effective_app_artifact_dir_native(), effective_app_state_path_native(), emit_website_status_native(), ensure_media_subtree(), executable_dir_from_argv0(), find_app_root_for_target(), find_repo_root(), handle_native_deploy_package_deb_command(), handle_page_route(), load_app_local_config_native(), load_app_runtime_for_single_app(), load_app_runtime_from_artifact_native(), load_native_libpq_api_runtime(), load_native_libpq_api_runtime_local(), load_runtime_stack(), match_app_root_in_directory(), maybe_seed_app_state_native(), media_disk_path_dup(), migration_fixture_path_dup_runtime_local(), native_app_conf_path(), native_backup_base_dir(), native_build_sqlite_migrate_verify_failure_report_json(), native_capture_migrate_verify_sqlite_report_json(), native_dispatch_response_file_for_request(), native_dynamic_media_resolve_path(), native_dynamic_media_serve_asset(), native_migration_fixture_path(), native_serve_static_file(), native_sqlite_migrate_verify_preflight_ok(), native_website_artifact_dir(), native_website_report_path(), remove_directory_recursive(), resolve_command_path_runtime(), resolve_conf_relative_path_native(), resolve_relative_to(), resolve_route_fixture_path(), resolve_seed_entrypoint_native(), runtime_build_dir_override_native(), runtime_script_path_native(), runtime_state_export_postgresql_path_dup_runtime_local(), runtime_state_export_sqlite_path_dup_runtime_local(), runtime_state_import_postgresql_path_dup_runtime_local(), runtime_state_import_sqlite_path_dup_runtime_local(), store_uploaded_media(), ucal_runtime_state_export_postgresql_path_dup_runtime(), ucal_runtime_state_export_sqlite_path_dup_runtime(), ucal_runtime_state_import_postgresql_path_dup_runtime(), ucal_runtime_state_import_sqlite_path_dup_runtime(), and write_noindex_markers_recursive_native().
| char * read_file_text | ( | const char * | path | ) |
Reads an entire file into a newly allocated text buffer.
| path | File path to read. |
Definition at line 318 of file native_support.c.
References buffer_append(), buffer_free(), buffer_init(), and Buffer::data.
Referenced by add_runtime_app_native(), app_runtime_host_profile_native(), build_app_from_root_native(), build_dev_docs_directory_native(), conf_lookup_value(), dynamic_relational_runtime_export_json_dup_runtime(), dynamic_relational_runtime_import_state_runtime(), emit_text_file_to_stdout_native(), handle_db_postgresql_exec_file_command(), handle_db_sqlite_exec_file_command(), handle_generated_surface_submitted_command(), handle_native_website_command(), handle_page_route(), handle_template_render_file_command(), load_app_local_config_native(), load_app_runtime_for_single_app(), load_app_runtime_from_artifact_native(), load_runtime_stack(), match_app_root_in_directory(), migration_expected_checksum_dup_runtime(), migration_expected_checksum_dup_runtime_local(), native_append_file_to_buffer(), native_dispatch_response_file_for_request(), native_dynamic_relational_runtime_export_json_dup(), native_dynamic_relational_runtime_import_state(), native_dynamic_runtime_handle_request(), native_json_doc_load_file(), native_legacy_expected_migration_checksum(), native_metadata_artifact_value(), native_migration_fixture_path(), native_migration_schema_version(), postgresql_apply_file_list_runtime(), postgresql_apply_file_list_runtime_local(), render_declared_page_response_with_headers_runtime(), render_file_template_dup_runtime(), request_body_text_dup_runtime(), request_form_field_value_dup_runtime(), resolve_route_fixture_path(), resolve_seed_entrypoint_native(), sqlite_apply_file_list_runtime(), and sqlite_apply_file_list_runtime_local().
| char * resolve_relative_to | ( | const char * | base_dir, |
| const char * | value ) |
Resolves a path value relative to a base directory when needed.
| base_dir | Base directory used for relative values. |
| value | Raw path value to resolve. |
Definition at line 294 of file native_support.c.
References path_join(), and pharos_support_strdup.
Referenced by apply_serve_config_defaults_from_conf_native(), load_app_runtime_from_artifact_native(), load_runtime_stack(), migration_expected_checksum_dup_runtime(), migration_expected_checksum_dup_runtime_local(), native_app_conf_value_path(), native_build_sqlite_migrate_verify_failure_report_json(), native_migration_fixture_path(), native_resolve_app_path(), native_sqlite_migrate_verify_preflight_ok(), postgresql_apply_file_list_runtime(), postgresql_apply_file_list_runtime_local(), resolve_runtime_socket_path_native(), resolved_runtime_conf_path_from_config_native(), sqlite_apply_file_list_runtime(), and sqlite_apply_file_list_runtime_local().
| int starts_with | ( | const char * | value, |
| const char * | prefix ) |
Tests whether one string starts with another string.
| value | Candidate full string. |
| prefix | Prefix to test. |
Definition at line 107 of file native_support.c.
Referenced by media_disk_path_dup(), native_dispatch_response_file_for_request(), native_dynamic_media_is_static_path(), native_dynamic_media_resolve_path(), native_dynamic_media_serve_asset(), native_serve_static_file(), remove_media_url_file(), runtime_match_app_native(), and serve_static_root().
| int streq | ( | const char * | a, |
| const char * | b ) |
Tests whether two strings are exactly equal.
| a | First string. |
| b | Second string. |
Definition at line 111 of file native_support.c.
Referenced by app_artifact_dir_from_build_dir_native(), app_build_dir_local_native(), app_local_conf_value_native(), app_state_path_local_native(), append_generated_admin_surface_form_fields_runtime(), append_generated_admin_surface_rows_runtime(), append_generated_surface_select_options_html_runtime(), apply_base_path_html_dup_runtime(), apply_deb_package_option_native(), apply_serve_config_defaults_from_conf_native(), assign_technician_for_slot_runtime(), assign_technician_for_slot_runtime_local(), build_app_from_root_native(), build_generated_surface_filter_controls_html_runtime(), build_generated_surface_form_fields_html_runtime(), build_generated_surface_sort_options_html_runtime(), build_native_app_doctor_report_local_json(), build_native_app_drift_report_local_json(), build_native_backup_report_local_json(), build_native_restore_report_local_json(), business_calendar_render_page_params_json_dup_runtime(), business_edit_page_params_json_dup_runtime(), business_open_for_slot_runtime(), business_open_for_slot_runtime_local(), capture_migrate_verify_report_json(), copy_directory_recursive(), csrf_request_valid_runtime(), day_of_week_options_html_dup_runtime(), day_of_week_options_html_dup_runtime(), default_signed_in_path_runtime(), diagnostics_render_page_params_json_dup_runtime(), dispatch_native_json_command_entries(), dynamic_config_key_is_path_runtime(), dynamic_relational_runtime_audit_count_dup_runtime(), dynamic_relational_runtime_export_json_dup_runtime(), dynamic_relational_runtime_import_state_runtime(), effective_app_artifact_dir_native(), emit_business_availability_lines_runtime(), emit_business_calendar_render_page_json_runtime(), emit_business_edit_page_json_runtime(), emit_service_book_form_page_json_runtime(), emit_technician_appointments_lines_runtime(), emit_technician_availability_lines_runtime(), emit_user_membership_tenant_ids_json_runtime(), ensure_media_subtree(), event_stream_allowed_by_scope_runtime(), event_stream_matches_filters_runtime(), find_form_field_value_runtime(), find_repo_root(), find_serve_handler_native(), generated_admin_manage_page_params_json_dup_runtime(), generated_admin_surface_descriptor_runtime(), generated_surface_append_audit_event_mut_runtime(), generated_surface_delete_button_label_dup_runtime(), generated_surface_delete_strategy_runtime(), handle_accept_invite_action_runtime(), handle_action_route(), handle_app_or_runtime_request(), handle_bundle_manifest_layer_for_slice_command(), handle_db_postgresql_audit_event_count_command(), handle_db_postgresql_create_database_if_missing_command(), handle_db_postgresql_database_exists_command(), handle_db_postgresql_table_exists_command(), handle_db_sqlite_table_exists_command(), handle_file_generated_surface_match_command(), handle_file_migration_backend_files_json_command(), handle_form_field_json_lines_command(), handle_form_options_html_command(), handle_generated_surface_coerce_candidate_command(), handle_generated_surface_list_columns_json_command(), handle_generated_surface_manage_page_json_command(), handle_generated_surface_manage_table_json_command(), handle_generated_surface_mutate_command(), handle_generated_surface_select_options_html_command(), handle_generated_surface_validation_report_command(), handle_native_backup_restore_ops_command(), handle_native_barcode_command(), handle_native_noindex_command(), handle_native_runtime_app_command(), handle_native_runtime_command(), handle_native_website_command(), handle_object_build_command(), handle_page_route(), handle_password_reset_complete_action_runtime(), handle_password_reset_request_action_runtime(), handle_state_named_command(), handle_state_ucal_import_row_json_lines_command(), handle_template_layout_page_html_command(), handle_template_layout_page_json_command(), json_option_value_runtime(), json_value_equals_text_runtime(), language_options_html_dup_runtime(), load_app_runtime_for_single_app(), load_app_runtime_from_artifact_native(), load_cli_postgresql_runtime_config(), load_dynamic_postgresql_runtime_config(), load_postgresql_runtime_config_runtime_local(), load_runtime_stack(), match_app_root_in_directory(), match_native_ops_command(), membership_role_id_for_invite_runtime_local(), multipart_find_part_runtime(), native_app_runtime_report_id(), native_capture_migrate_verify_sqlite_report_json(), native_db_check_json(), native_dispatch_response_file_for_request(), native_dynamic_config_key_is_path(), native_dynamic_media_is_static_path(), native_dynamic_media_resolve_path(), native_dynamic_media_serve_asset(), native_dynamic_relational_backend_dup(), native_dynamic_relational_postgresql_runtime_prepare(), native_dynamic_relational_postgresql_runtime_ready(), native_dynamic_relational_prepare_request_state(), native_dynamic_relational_runtime_audit_count_dup(), native_dynamic_relational_runtime_export_json_dup(), native_dynamic_relational_runtime_import_state(), native_dynamic_relational_sqlite_runtime_prepare(), native_dynamic_relational_sqlite_runtime_ready(), native_dynamic_relational_sync_back_if_changed(), native_dynamic_runtime_handle_request(), native_environment_valid(), native_migration_checksum_matches(), native_option_value(), native_sqlite_table_exists(), native_sqlite_table_exists(), normalize_base_path_native(), parse_native_app_ops_config(), parse_serve_config_native(), payment_preference_options_html_dup_runtime(), remove_directory_recursive(), render_page_html_dup_runtime(), render_service_visual_html_dup_runtime(), resolve_conf_value_key_native(), resolve_declared_page_params_json_runtime(), resolve_seed_entrypoint_native(), route_request_path_dup_runtime(), route_template_match_into_mut_obj_runtime(), runtime_verb_supported_native(), service_book_form_page_params_json_dup_runtime(), session_cookie_header_dup_runtime(), surface_compare_sort_values_runtime(), surface_context_match_runtime(), surface_filter_item_runtime(), technician_booked_for_slot_runtime(), technician_booked_for_slot_runtime_local(), ucal_declared_fragment_relative_path_runtime(), ucal_declared_page_relative_path_runtime(), user_has_active_tenant_membership_runtime_local(), user_manages_business_runtime(), valid_day_of_week_runtime(), verify_password_hash_runtime(), website_verb_mode_native(), weekday_rank_runtime(), and write_noindex_markers_recursive_native().
| void trim_in_place | ( | char * | text | ) |
Trims leading and trailing ASCII whitespace from a string in place.
| text | Mutable string buffer to normalize. |
Definition at line 88 of file native_support.c.
Referenced by capture_checksum_output_runtime(), capture_migrate_verify_report_json(), capture_postgresql_result_output_runtime(), capture_postgresql_result_output_runtime_local(), conf_lookup_value_in_text(), handle_native_deploy_package_deb_command(), native_capture_trimmed(), native_capture_trimmed(), parse_http_request_native(), request_headers_with_client_ip_native(), request_real_ip_native(), and run_sqlite_command_runtime().