Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add streams API, ProcessGlobals, FileGlobals and SapiGlobals #249

Merged
merged 42 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7b2dd27
Add ProcessGlobals
joehoyle Jul 7, 2023
21c4bf6
Update bindings
joehoyle Jul 7, 2023
01060ff
Support ZTS
joehoyle Jul 7, 2023
36d6159
update bindings
joehoyle Jul 7, 2023
ca04318
Add support for SapiGlobals
joehoyle Jul 12, 2023
fcf9c20
Add export
joehoyle Jul 12, 2023
003eb8a
Add support for headers etc
joehoyle Jul 13, 2023
f3bf835
Add bindings for zend_llist
joehoyle Jul 13, 2023
5395f25
Import
joehoyle Jul 13, 2023
c564f55
Fix missing bindings
joehoyle Jul 13, 2023
368800b
Merge branch 'process-globals' into sapi-globals
joehoyle Jul 13, 2023
b6a2d18
Add missing binding
joehoyle Jul 13, 2023
a396085
fmt
joehoyle Jul 13, 2023
aee2625
Clippy
joehoyle Jul 13, 2023
910c552
Update bindings
joehoyle Jul 13, 2023
8464a25
Generate with debug
joehoyle Jul 13, 2023
9173f06
Merge pull request #250 from davidcole1340/sapi-globals
joehoyle Jul 13, 2023
48980a1
Bindings from php 8.2-debug
joehoyle Jul 13, 2023
5acdfe6
Add FileGlobals too
joehoyle Jul 19, 2023
c9db20c
Merge branch 'master' into process-globals
joehoyle Jul 19, 2023
1c55085
Add StreamWrapper API
joehoyle Jul 19, 2023
a138296
Add php_var include for auto globals
joehoyle Jul 19, 2023
cb89c7b
Revert change to function
joehoyle Jul 19, 2023
06e190e
fmt
joehoyle Jul 19, 2023
95ce652
Merge branch 'process-globals' into streams-api
joehoyle Jul 19, 2023
52525f2
Fix allowed bindings duplication
joehoyle Jul 19, 2023
a616c4b
ZTS support for file globals
joehoyle Jul 19, 2023
0a2ecbc
Add helper function
joehoyle Jul 19, 2023
ef52ef6
Remove file.h
joehoyle Jul 19, 2023
e30f127
Add file_globals_id to allowed bindings
joehoyle Jul 19, 2023
6501082
Merge branch 'master' into process-globals
joehoyle Jul 19, 2023
7803a45
Merge branch 'process-globals' into streams-api
joehoyle Jul 19, 2023
87ab718
Remove additional unrelated functions
joehoyle Jul 19, 2023
b5adbb9
Merge branch 'streams-api' of github.com:davidcole1340/ext-php-rs int…
joehoyle Jul 19, 2023
21134fb
Merge remote-tracking branch 'origin/master' into process-globals
danog Nov 24, 2023
025f603
Fixup
danog Nov 24, 2023
9ff4bd4
Merge branch 'streams-api' into process-globals
danog Nov 24, 2023
582a387
Cleanup
danog Nov 24, 2023
28b190a
Cleanup
danog Nov 24, 2023
75eb6d7
fmt
joehoyle Nov 24, 2023
2c5bd2a
Cleanup
danog Nov 24, 2023
961b948
Fmt
danog Nov 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion allowed_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ bind! {
zend_class_serialize_deny,
zend_class_unserialize_deny,
zend_executor_globals,
sapi_globals_struct,
sapi_module_struct,
zend_objects_store_del,
zend_hash_move_forward_ex,
Expand All @@ -257,13 +256,39 @@ bind! {
gc_possible_root,
ZEND_ACC_NOT_SERIALIZABLE,
executor_globals,
php_core_globals,
core_globals,
sapi_globals_struct,
sapi_globals,
sapi_module,
php_printf,
__zend_malloc,
tsrm_get_ls_cache,
executor_globals_offset,
core_globals_offset,
sapi_globals_offset,
php_file_globals,
file_globals,
file_globals_id,
TRACK_VARS_POST,
TRACK_VARS_GET,
TRACK_VARS_COOKIE,
TRACK_VARS_SERVER,
TRACK_VARS_ENV,
TRACK_VARS_FILES,
TRACK_VARS_REQUEST,
sapi_request_info,
sapi_header_struct,
zend_is_auto_global,
zend_llist_get_next_ex,
zend_llist_get_prev_ex,
php_register_url_stream_wrapper,
php_stream_locate_url_wrapper,
php_unregister_url_stream_wrapper,
php_unregister_url_stream_wrapper_volatile,
php_register_url_stream_wrapper_volatile,
php_stream_wrapper,
php_stream_stdio_ops,
zend_atomic_bool_store,
zend_interrupt_function,
zend_eval_string,
Expand Down
175 changes: 175 additions & 0 deletions docsrs_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ pub const ZEND_MODULE_API_NO: u32 = 20230831;
pub const USING_ZTS: u32 = 0;
pub const MAY_BE_BOOL: u32 = 12;
pub const MAY_BE_ANY: u32 = 1022;
pub const TRACK_VARS_POST: u32 = 0;
pub const TRACK_VARS_GET: u32 = 1;
pub const TRACK_VARS_COOKIE: u32 = 2;
pub const TRACK_VARS_SERVER: u32 = 3;
pub const TRACK_VARS_ENV: u32 = 4;
pub const TRACK_VARS_FILES: u32 = 5;
pub const TRACK_VARS_REQUEST: u32 = 6;
pub const PHP_INI_USER: u32 = 1;
pub const PHP_INI_PERDIR: u32 = 2;
pub const PHP_INI_SYSTEM: u32 = 4;
Expand Down Expand Up @@ -506,6 +513,19 @@ pub struct _zend_llist {
pub traverse_ptr: *mut zend_llist_element,
}
pub type zend_llist = _zend_llist;
pub type zend_llist_position = *mut zend_llist_element;
extern "C" {
pub fn zend_llist_get_next_ex(
l: *mut zend_llist,
pos: *mut zend_llist_position,
) -> *mut ::std::os::raw::c_void;
}
extern "C" {
pub fn zend_llist_get_prev_ex(
l: *mut zend_llist,
pos: *mut zend_llist_position,
) -> *mut ::std::os::raw::c_void;
}
pub type zend_string_init_interned_func_t = ::std::option::Option<
unsafe extern "C" fn(
str_: *const ::std::os::raw::c_char,
Expand Down Expand Up @@ -1469,6 +1489,9 @@ pub struct _zend_executor_globals {
pub reserved_stack_size: zend_ulong,
pub reserved: [*mut ::std::os::raw::c_void; 6usize],
}
extern "C" {
pub fn zend_is_auto_global(name: *mut zend_string) -> bool;
}
pub type zend_module_entry = _zend_module_entry;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -2094,6 +2117,127 @@ impl _php_stream {
__bindgen_bitfield_unit
}
}
extern "C" {
pub static mut php_stream_stdio_ops: php_stream_ops;
}
extern "C" {
pub fn php_register_url_stream_wrapper(
protocol: *const ::std::os::raw::c_char,
wrapper: *const php_stream_wrapper,
) -> zend_result;
}
extern "C" {
pub fn php_unregister_url_stream_wrapper(
protocol: *const ::std::os::raw::c_char,
) -> zend_result;
}
extern "C" {
pub fn php_register_url_stream_wrapper_volatile(
protocol: *mut zend_string,
wrapper: *mut php_stream_wrapper,
) -> zend_result;
}
extern "C" {
pub fn php_unregister_url_stream_wrapper_volatile(protocol: *mut zend_string) -> zend_result;
}
extern "C" {
pub fn php_stream_locate_url_wrapper(
path: *const ::std::os::raw::c_char,
path_for_open: *mut *const ::std::os::raw::c_char,
options: ::std::os::raw::c_int,
) -> *mut php_stream_wrapper;
}
pub type php_core_globals = _php_core_globals;
#[repr(C)]
pub struct _php_core_globals {
pub output_buffering: zend_long,
pub implicit_flush: bool,
pub enable_dl: bool,
pub display_errors: u8,
pub display_startup_errors: bool,
pub log_errors: bool,
pub ignore_repeated_errors: bool,
pub ignore_repeated_source: bool,
pub report_memleaks: bool,
pub output_handler: *mut ::std::os::raw::c_char,
pub unserialize_callback_func: *mut ::std::os::raw::c_char,
pub serialize_precision: zend_long,
pub memory_limit: zend_long,
pub max_input_time: zend_long,
pub error_log: *mut ::std::os::raw::c_char,
pub doc_root: *mut ::std::os::raw::c_char,
pub user_dir: *mut ::std::os::raw::c_char,
pub include_path: *mut ::std::os::raw::c_char,
pub open_basedir: *mut ::std::os::raw::c_char,
pub open_basedir_modified: bool,
pub extension_dir: *mut ::std::os::raw::c_char,
pub php_binary: *mut ::std::os::raw::c_char,
pub sys_temp_dir: *mut ::std::os::raw::c_char,
pub upload_tmp_dir: *mut ::std::os::raw::c_char,
pub upload_max_filesize: zend_long,
pub error_append_string: *mut ::std::os::raw::c_char,
pub error_prepend_string: *mut ::std::os::raw::c_char,
pub auto_prepend_file: *mut ::std::os::raw::c_char,
pub auto_append_file: *mut ::std::os::raw::c_char,
pub input_encoding: *mut ::std::os::raw::c_char,
pub internal_encoding: *mut ::std::os::raw::c_char,
pub output_encoding: *mut ::std::os::raw::c_char,
pub arg_separator: arg_separators,
pub variables_order: *mut ::std::os::raw::c_char,
pub rfc1867_protected_variables: HashTable,
pub connection_status: ::std::os::raw::c_short,
pub ignore_user_abort: bool,
pub header_is_being_sent: ::std::os::raw::c_uchar,
pub tick_functions: zend_llist,
pub http_globals: [zval; 6usize],
pub expose_php: bool,
pub register_argc_argv: bool,
pub auto_globals_jit: bool,
pub html_errors: bool,
pub xmlrpc_errors: bool,
pub docref_root: *mut ::std::os::raw::c_char,
pub docref_ext: *mut ::std::os::raw::c_char,
pub xmlrpc_error_number: zend_long,
pub activated_auto_globals: [bool; 8usize],
pub modules_activated: bool,
pub file_uploads: bool,
pub during_request_startup: bool,
pub allow_url_fopen: bool,
pub enable_post_data_reading: bool,
pub report_zend_debug: bool,
pub last_error_type: ::std::os::raw::c_int,
pub last_error_lineno: ::std::os::raw::c_int,
pub last_error_message: *mut zend_string,
pub last_error_file: *mut zend_string,
pub php_sys_temp_dir: *mut ::std::os::raw::c_char,
pub disable_classes: *mut ::std::os::raw::c_char,
pub max_input_nesting_level: zend_long,
pub max_input_vars: zend_long,
pub user_ini_filename: *mut ::std::os::raw::c_char,
pub user_ini_cache_ttl: zend_long,
pub request_order: *mut ::std::os::raw::c_char,
pub mail_log: *mut ::std::os::raw::c_char,
pub mail_x_header: bool,
pub mail_mixed_lf_and_crlf: bool,
pub in_error_log: bool,
pub allow_url_include: bool,
pub in_user_include: bool,
pub have_called_openlog: bool,
pub syslog_facility: zend_long,
pub syslog_ident: *mut ::std::os::raw::c_char,
pub syslog_filter: zend_long,
pub error_log_mode: zend_long,
}
extern "C" {
pub static mut core_globals: _php_core_globals;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _arg_separators {
pub output: *mut ::std::os::raw::c_char,
pub input: *mut ::std::os::raw::c_char,
}
pub type arg_separators = _arg_separators;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _zend_ini_entry_def {
Expand Down Expand Up @@ -2201,6 +2345,37 @@ extern "C" {
extern "C" {
pub fn php_info_print_table_end();
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct hostent {
pub h_name: *mut ::std::os::raw::c_char,
pub h_aliases: *mut *mut ::std::os::raw::c_char,
pub h_addrtype: ::std::os::raw::c_int,
pub h_length: ::std::os::raw::c_int,
pub h_addr_list: *mut *mut ::std::os::raw::c_char,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct php_file_globals {
pub pclose_ret: ::std::os::raw::c_int,
pub def_chunk_size: usize,
pub auto_detect_line_endings: bool,
pub default_socket_timeout: zend_long,
pub user_agent: *mut ::std::os::raw::c_char,
pub from_address: *mut ::std::os::raw::c_char,
pub user_stream_current_filename: *const ::std::os::raw::c_char,
pub default_context: *mut php_stream_context,
pub stream_wrappers: *mut HashTable,
pub stream_filters: *mut HashTable,
pub wrapper_errors: *mut HashTable,
pub pclose_wait: ::std::os::raw::c_int,
pub tmp_host_info: hostent,
pub tmp_host_buf: *mut ::std::os::raw::c_char,
pub tmp_host_buf_len: usize,
}
extern "C" {
pub static mut file_globals: php_file_globals;
}
extern "C" {
pub static mut zend_ce_throwable: *mut zend_class_entry;
}
Expand Down
13 changes: 13 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ pub enum Error {
IntegerOverflow,
/// An exception was thrown in a function.
Exception(ZBox<ZendObject>),
/// A failure occurred while registering the stream wrapper
StreamWrapperRegistrationFailure,
/// A failure occurred while unregistering the stream wrapper
StreamWrapperUnregistrationFailure,
}

impl Display for Error {
Expand Down Expand Up @@ -99,6 +103,15 @@ impl Display for Error {
write!(f, "Converting integer arguments resulted in an overflow.")
}
Error::Exception(e) => write!(f, "Exception was thrown: {e:?}"),
Error::StreamWrapperRegistrationFailure => {
write!(f, "A failure occurred while registering the stream wrapper")
}
Error::StreamWrapperUnregistrationFailure => {
write!(
f,
"A failure occurred while unregistering the stream wrapper"
)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl PhpException {

/// Set the Zval object for the exception.
///
/// Exceptions can be based of instantiated Zval objects when you are throwing a custom exception with
/// stateful properties.
/// Exceptions can be based of instantiated Zval objects when you are
/// throwing a custom exception with stateful properties.
///
/// # Parameters
///
Expand Down
2 changes: 2 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ extern "C" {
pub fn ext_php_rs_zend_object_alloc(obj_size: usize, ce: *mut zend_class_entry) -> *mut c_void;
pub fn ext_php_rs_zend_object_release(obj: *mut zend_object);
pub fn ext_php_rs_executor_globals() -> *mut zend_executor_globals;
pub fn ext_php_rs_process_globals() -> *mut php_core_globals;
pub fn ext_php_rs_sapi_globals() -> *mut sapi_globals_struct;
pub fn ext_php_rs_file_globals() -> *mut php_file_globals;
pub fn ext_php_rs_sapi_module() -> *mut sapi_module_struct;
pub fn ext_php_rs_zend_try_catch(
func: unsafe extern "C" fn(*const c_void) -> *const c_void,
Expand Down
3 changes: 2 additions & 1 deletion src/types/zval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ impl Zval {
}
}

/// Returns a mutable reference to the zval if it is an internal indirect reference.
/// Returns a mutable reference to the zval if it is an internal indirect
/// reference.
pub fn indirect_mut(&self) -> Option<&mut Zval> {
if self.is_indirect() {
Some(unsafe { &mut *(self.value.zv as *mut Zval) })
Expand Down
20 changes: 20 additions & 0 deletions src/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ zend_executor_globals *ext_php_rs_executor_globals() {
#endif
}

php_core_globals *ext_php_rs_process_globals() {
#ifdef ZTS
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
return TSRMG_FAST_BULK_STATIC(core_globals_offset, php_core_globals);
#else
return TSRMG_FAST_BULK(core_globals_offset, php_core_globals *);
#endif
#else
return &core_globals;
#endif
}

sapi_globals_struct *ext_php_rs_sapi_globals() {
#ifdef ZTS
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
Expand All @@ -52,6 +64,14 @@ sapi_globals_struct *ext_php_rs_sapi_globals() {
#endif
}

php_file_globals *ext_php_rs_file_globals() {
#ifdef ZTS
return TSRMG_FAST_BULK(file_globals_id, php_file_globals *);
#else
return &file_globals;
#endif
}

sapi_module_struct *ext_php_rs_sapi_module() {
return &sapi_module;
}
Expand Down
7 changes: 6 additions & 1 deletion src/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
#include "php.h"

#include "ext/standard/info.h"
#include "ext/standard/php_var.h"
#include "ext/standard/file.h"
#include "zend_exceptions.h"
#include "zend_inheritance.h"
#include "zend_interfaces.h"
#include "php_variables.h"
#include "zend_ini.h"
#include "main/SAPI.h"

Expand All @@ -31,8 +34,10 @@ void ext_php_rs_set_known_valid_utf8(zend_string *zs);
const char *ext_php_rs_php_build_id();
void *ext_php_rs_zend_object_alloc(size_t obj_size, zend_class_entry *ce);
void ext_php_rs_zend_object_release(zend_object *obj);
zend_executor_globals *ext_php_rs_executor_globals();;
zend_executor_globals *ext_php_rs_executor_globals();
php_core_globals *ext_php_rs_process_globals();
sapi_globals_struct *ext_php_rs_sapi_globals();
php_file_globals *ext_php_rs_file_globals();
sapi_module_struct *ext_php_rs_sapi_module();
bool ext_php_rs_zend_try_catch(void* (*callback)(void *), void *ctx, void **result);
void ext_php_rs_zend_bailout();
Loading