mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-17 17:47:12 +00:00
Implemented async callbacks to PHP regardless of thread model, Sigv4 signing (#24)
* Updated to get latest aws-crt-ffi * Added implementation for signing_result * Added main thread queue and callback queueing to signing process * Updated to get support for date on signing_config_aws * added date support to SigningConfigAWS, fixed up reference issues on http message signing * Broke C code into separate files, moved common stuff to php_aws_crt.h * Use a unity build to make PHP do the right thing with our lib * Updated aws-crt-ffi to v0.1.3 to get sigv4 changes * Added CRT::isAvailable for safe runtime detection of CRT * Fixed up test resource safety, added tests to prove it * Added CI jobs for every version of PHP on linux (#26)
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
/* This is a unity-build style source file, as PHP's build system is simplest with 1 source file per extension */
|
||||
|
||||
#include "credentials.c"
|
||||
#include "crt.c"
|
||||
#include "event_loop.c"
|
||||
#include "http.c"
|
||||
#include "signing.c"
|
||||
#include "stream.c"
|
||||
@@ -103,6 +103,8 @@ function aws_crt_signing_config_aws_set_signed_body_header_type(int $config, int
|
||||
|
||||
function aws_crt_signing_config_aws_set_expiration_in_seconds(int $config, int $expiration_in_seconds): void {}
|
||||
|
||||
function aws_crt_signing_config_aws_set_date(int $config, int $timestamp): void {}
|
||||
|
||||
function aws_crt_signable_new_from_http_request(int $http_message): int {}
|
||||
|
||||
function aws_crt_signable_new_from_chunk(int $input_stream, string $previous_signature): int {}
|
||||
@@ -111,4 +113,8 @@ function aws_crt_signable_new_from_canonical_request(string $request): int {}
|
||||
|
||||
function aws_crt_signable_release(int $signable): void {}
|
||||
|
||||
function aws_crt_signing_result_release(int $signing_result): void {}
|
||||
|
||||
function aws_crt_signing_result_apply_to_http_request(object $signing_result, object $http_request): void {}
|
||||
|
||||
function aws_crt_sign_request_aws(int $signable, int $signing_config, object $on_complete, object $user_data): int {}
|
||||
|
||||
+123
-103
@@ -1,11 +1,11 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 8694d01fdcf4c8ffa26a6462b6c4546671ce7aa5 */
|
||||
* Stub hash: 8ee94b778eb6d2eeabc8c2695aaded9fb18de88f */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_last_error, 0, 0, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_last_error, 0, 0, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_error_name, 0, 1, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, error_code, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_error_name, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, error_code)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_error_str arginfo_aws_crt_error_name
|
||||
@@ -14,104 +14,104 @@ ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_event_loop_group_options_new arginfo_aws_crt_last_error
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_options_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, elg_options, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_event_loop_group_options_release, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, elg_options)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_options_set_max_threads, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, elg_options, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, max_threads, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_event_loop_group_options_set_max_threads, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, elg_options)
|
||||
ZEND_ARG_INFO(0, max_threads)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_new, 0, 1, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_event_loop_group_new, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, event_loop_group, IS_OBJECT, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_event_loop_group_release, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, event_loop_group)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_input_stream_options_new, 0, 0, IS_OBJECT, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_input_stream_options_new, 0, 0, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_input_stream_options_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_input_stream_options_release, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_input_stream_options_set_user_data, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, user_data, IS_OBJECT, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_input_stream_options_set_user_data, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_ARG_INFO(0, user_data)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_input_stream_new arginfo_aws_crt_event_loop_group_new
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_input_stream_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, stream, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_input_stream_release, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, stream)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_input_stream_seek, 0, 3, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, stream, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, basis, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_input_stream_seek, 0, 0, 3)
|
||||
ZEND_ARG_INFO(0, stream)
|
||||
ZEND_ARG_INFO(0, offset)
|
||||
ZEND_ARG_INFO(0, basis)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_input_stream_read, 0, 2, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, stream, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_input_stream_read, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, stream)
|
||||
ZEND_ARG_INFO(0, length)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_input_stream_eof, 0, 1, _IS_BOOL, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, stream, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_input_stream_eof, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, stream)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_input_stream_get_length, 0, 1, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, stream, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_input_stream_get_length, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, stream)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_http_message_new_from_blob, 0, 1, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, blob, IS_STRING, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_http_message_new_from_blob, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, blob)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_http_message_to_blob, 0, 1, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, message, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_http_message_to_blob, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, message)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_http_message_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, message, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_http_message_release, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, message)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_credentials_options_new arginfo_aws_crt_input_stream_options_new
|
||||
|
||||
#define arginfo_aws_crt_credentials_options_release arginfo_aws_crt_input_stream_options_release
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_credentials_options_set_access_key_id, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, access_key_id, IS_STRING, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_credentials_options_set_access_key_id, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_ARG_INFO(0, access_key_id)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_credentials_options_set_secret_access_key, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, secret_access_key, IS_STRING, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_credentials_options_set_secret_access_key, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_ARG_INFO(0, secret_access_key)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_credentials_options_set_session_token, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, session_token, IS_STRING, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_credentials_options_set_session_token, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_ARG_INFO(0, session_token)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_credentials_options_set_expiration_timepoint_seconds, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, expiration_timepoint_seconds, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_credentials_options_set_expiration_timepoint_seconds, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
ZEND_ARG_INFO(0, expiration_timepoint_seconds)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_credentials_new arginfo_aws_crt_event_loop_group_new
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_credentials_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, credentials, IS_OBJECT, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_credentials_release, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, credentials)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_credentials_provider_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, credentials, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_credentials_provider_release, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, credentials)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_credentials_provider_static_options_new arginfo_aws_crt_input_stream_options_new
|
||||
@@ -128,87 +128,101 @@ ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_signing_config_aws_new arginfo_aws_crt_last_error
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_release, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_algorithm, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, algorithm, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_algorithm, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, algorithm)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_signature_type, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, signature_type, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_signature_type, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, signature_type)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_credentials_provider, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, credentials_provider, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_credentials_provider, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, credentials_provider)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_region, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, region, IS_STRING, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_region, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, region)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_service, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, service, IS_STRING, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_service, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, service)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_use_double_uri_encode, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, use_double_uri_encode, _IS_BOOL, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_use_double_uri_encode, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, use_double_uri_encode)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_should_normalize_uri_path, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, should_normalize_uri_path, _IS_BOOL, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_should_normalize_uri_path, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, should_normalize_uri_path)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_omit_session_token, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, omit_session_token, _IS_BOOL, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_omit_session_token, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, omit_session_token)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_signed_body_value, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, signed_body_value, IS_STRING, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_signed_body_value, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, signed_body_value)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_signed_body_header_type, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, signed_body_header_type, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_signed_body_header_type, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, signed_body_header_type)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signing_config_aws_set_expiration_in_seconds, 0, 2, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, expiration_in_seconds, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_expiration_in_seconds, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, expiration_in_seconds)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signable_new_from_http_request, 0, 1, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, http_message, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_config_aws_set_date, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, config)
|
||||
ZEND_ARG_INFO(0, timestamp)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signable_new_from_chunk, 0, 2, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, input_stream, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, previous_signature, IS_STRING, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signable_new_from_http_request, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, http_message)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signable_new_from_canonical_request, 0, 1, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, request, IS_STRING, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signable_new_from_chunk, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, input_stream)
|
||||
ZEND_ARG_INFO(0, previous_signature)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_signable_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, signable, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signable_new_from_canonical_request, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, request)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_sign_request_aws, 0, 4, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, signable, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, signing_config, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, on_complete, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, user_data, IS_OBJECT, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signable_release, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, signable)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_result_release, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, signing_result)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_signing_result_apply_to_http_request, 0, 0, 2)
|
||||
ZEND_ARG_INFO(0, signing_result)
|
||||
ZEND_ARG_INFO(0, http_request)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_aws_crt_sign_request_aws, 0, 0, 4)
|
||||
ZEND_ARG_INFO(0, signable)
|
||||
ZEND_ARG_INFO(0, signing_config)
|
||||
ZEND_ARG_INFO(0, on_complete)
|
||||
ZEND_ARG_INFO(0, user_data)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
|
||||
@@ -261,10 +275,13 @@ ZEND_FUNCTION(aws_crt_signing_config_aws_set_omit_session_token);
|
||||
ZEND_FUNCTION(aws_crt_signing_config_aws_set_signed_body_value);
|
||||
ZEND_FUNCTION(aws_crt_signing_config_aws_set_signed_body_header_type);
|
||||
ZEND_FUNCTION(aws_crt_signing_config_aws_set_expiration_in_seconds);
|
||||
ZEND_FUNCTION(aws_crt_signing_config_aws_set_date);
|
||||
ZEND_FUNCTION(aws_crt_signable_new_from_http_request);
|
||||
ZEND_FUNCTION(aws_crt_signable_new_from_chunk);
|
||||
ZEND_FUNCTION(aws_crt_signable_new_from_canonical_request);
|
||||
ZEND_FUNCTION(aws_crt_signable_release);
|
||||
ZEND_FUNCTION(aws_crt_signing_result_release);
|
||||
ZEND_FUNCTION(aws_crt_signing_result_apply_to_http_request);
|
||||
ZEND_FUNCTION(aws_crt_sign_request_aws);
|
||||
|
||||
|
||||
@@ -318,10 +335,13 @@ static const zend_function_entry ext_functions[] = {
|
||||
ZEND_FE(aws_crt_signing_config_aws_set_signed_body_value, arginfo_aws_crt_signing_config_aws_set_signed_body_value)
|
||||
ZEND_FE(aws_crt_signing_config_aws_set_signed_body_header_type, arginfo_aws_crt_signing_config_aws_set_signed_body_header_type)
|
||||
ZEND_FE(aws_crt_signing_config_aws_set_expiration_in_seconds, arginfo_aws_crt_signing_config_aws_set_expiration_in_seconds)
|
||||
ZEND_FE(aws_crt_signing_config_aws_set_date, arginfo_aws_crt_signing_config_aws_set_date)
|
||||
ZEND_FE(aws_crt_signable_new_from_http_request, arginfo_aws_crt_signable_new_from_http_request)
|
||||
ZEND_FE(aws_crt_signable_new_from_chunk, arginfo_aws_crt_signable_new_from_chunk)
|
||||
ZEND_FE(aws_crt_signable_new_from_canonical_request, arginfo_aws_crt_signable_new_from_canonical_request)
|
||||
ZEND_FE(aws_crt_signable_release, arginfo_aws_crt_signable_release)
|
||||
ZEND_FE(aws_crt_signing_result_release, arginfo_aws_crt_signing_result_release)
|
||||
ZEND_FE(aws_crt_signing_result_apply_to_http_request, arginfo_aws_crt_signing_result_apply_to_http_request)
|
||||
ZEND_FE(aws_crt_sign_request_aws, arginfo_aws_crt_sign_request_aws)
|
||||
ZEND_FE_END
|
||||
};
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include "php_aws_crt.h"
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_new) {
|
||||
aws_crt_credentials_options *options = aws_crt_credentials_options_new();
|
||||
RETURN_LONG((zend_ulong)options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_release) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials_options_release(options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_set_access_key_id) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *access_key_id = NULL;
|
||||
size_t access_key_id_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_options, &access_key_id, &access_key_id_len);
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials_options_set_access_key_id(options, (uint8_t *)access_key_id, access_key_id_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_set_secret_access_key) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *secret_access_key = NULL;
|
||||
size_t secret_access_key_len = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &php_options, &secret_access_key, &secret_access_key_len) ==
|
||||
FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials_options_set_secret_access_key(options, (uint8_t *)secret_access_key, secret_access_key_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_set_session_token) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *session_token = NULL;
|
||||
size_t session_token_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_options, &session_token, &session_token_len);
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials_options_set_session_token(options, (uint8_t *)session_token, session_token_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_set_expiration_timepoint_seconds) {
|
||||
zend_ulong php_options = 0;
|
||||
zend_ulong expiration_timepoint_seconds = 0;
|
||||
aws_php_parse_parameters("ll", &php_options, &expiration_timepoint_seconds);
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials_options_set_expiration_timepoint_seconds(options, expiration_timepoint_seconds);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_new) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials *credentials = aws_crt_credentials_new(options);
|
||||
RETURN_LONG((zend_ulong)credentials);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_release) {
|
||||
zend_ulong php_credentials = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_credentials);
|
||||
|
||||
aws_crt_credentials *credentials = (void *)php_credentials;
|
||||
aws_crt_credentials_release(credentials);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_release) {
|
||||
zend_ulong php_creds_provider = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_creds_provider);
|
||||
|
||||
aws_crt_credentials_provider *provider = (void *)php_creds_provider;
|
||||
aws_crt_credentials_provider_release(provider);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_options_new) {
|
||||
aws_crt_credentials_provider_static_options *options = aws_crt_credentials_provider_static_options_new();
|
||||
RETURN_LONG((zend_ulong)options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_options_release) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_credentials_provider_static_options *options = (void *)php_options;
|
||||
aws_crt_credentials_provider_static_options_release(options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_options_set_access_key_id) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *access_key_id = NULL;
|
||||
size_t access_key_id_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_options, &access_key_id, &access_key_id_len);
|
||||
|
||||
aws_crt_credentials_provider_static_options *options = (void *)php_options;
|
||||
aws_crt_credentials_provider_static_options_set_access_key_id(options, (uint8_t *)access_key_id, access_key_id_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_options_set_secret_access_key) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *secret_access_key = NULL;
|
||||
size_t secret_access_key_len = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &php_options, &secret_access_key, &secret_access_key_len) ==
|
||||
FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
aws_crt_credentials_provider_static_options *options = (void *)php_options;
|
||||
aws_crt_credentials_provider_static_options_set_secret_access_key(
|
||||
options, (uint8_t *)secret_access_key, secret_access_key_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_options_set_session_token) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *session_token = NULL;
|
||||
size_t session_token_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_options, &session_token, &session_token_len);
|
||||
|
||||
aws_crt_credentials_provider_static_options *options = (void *)php_options;
|
||||
aws_crt_credentials_provider_static_options_set_session_token(options, (uint8_t *)session_token, session_token_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_new) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_credentials_provider_static_options *options = (void *)php_options;
|
||||
aws_crt_credentials_provider *provider = aws_crt_credentials_provider_static_new(options);
|
||||
RETURN_LONG((zend_ulong)provider);
|
||||
}
|
||||
@@ -6,82 +6,22 @@
|
||||
|
||||
#include "php_aws_crt.h"
|
||||
|
||||
#include "api.h"
|
||||
|
||||
#include "awscrt_arginfo.h"
|
||||
|
||||
/* Helpful references for this file:
|
||||
/* Helpful references for this extension:
|
||||
* zend_parse_parameters and friends -
|
||||
* https://git.php.net/?p=php-src.git;a=blob;f=docs/parameter-parsing-api.md;h=c962fc6ee58cc756aaac9e65759b7d5ea5c18fc4;hb=HEAD
|
||||
* https://git.php.net/?p=php-src.git;a=blob;f=docs/self-contained-extensions.md;h=47f4c636baca8ca195118e2cc234ac7fd2842c1b;hb=HEAD
|
||||
* Threads:
|
||||
* http://blog.jpauli.tech/2017-01-12-threads-and-php-html/
|
||||
* Examples:
|
||||
* Curl extension: https://github.com/php/php-src/blob/PHP-5.6/ext/curl/interface.c
|
||||
* libuv extension: https://github.com/amphp/ext-uv/blob/master/php_uv.c
|
||||
*/
|
||||
|
||||
/* Macros borrowed from aws-c-common */
|
||||
#define GLUE(x, y) x y
|
||||
|
||||
#define RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, count, ...) count
|
||||
#define EXPAND_ARGS(args) RETURN_ARG_COUNT args
|
||||
#define COUNT_ARGS_MAX5(...) EXPAND_ARGS((__VA_ARGS__, 5, 4, 3, 2, 1, 0))
|
||||
|
||||
#define OVERLOAD_MACRO2(name, count) name##count
|
||||
#define OVERLOAD_MACRO1(name, count) OVERLOAD_MACRO2(name, count)
|
||||
#define OVERLOAD_MACRO(name, count) OVERLOAD_MACRO1(name, count)
|
||||
|
||||
#define CALL_OVERLOAD(name, ...) GLUE(OVERLOAD_MACRO(name, COUNT_ARGS_MAX5(__VA_ARGS__)), (__VA_ARGS__))
|
||||
|
||||
#define VARIABLE_LENGTH_ARRAY(type, name, length) type *name = alloca(sizeof(type) * (length))
|
||||
|
||||
/*
|
||||
* Exception throwing mechanism, will never return
|
||||
*/
|
||||
#define aws_php_throw_exception(...) CALL_OVERLOAD(_AWS_PHP_THROW_EXCEPTION, __VA_ARGS__);
|
||||
#define _AWS_PHP_THROW_EXCEPTION5(format, ...) zend_error_noreturn(E_ERROR, format, __VA_ARGS__)
|
||||
#define _AWS_PHP_THROW_EXCEPTION4(format, ...) zend_error_noreturn(E_ERROR, format, __VA_ARGS__)
|
||||
#define _AWS_PHP_THROW_EXCEPTION3(format, ...) zend_error_noreturn(E_ERROR, format, __VA_ARGS__)
|
||||
#define _AWS_PHP_THROW_EXCEPTION2(format, ...) zend_error_noreturn(E_ERROR, format, __VA_ARGS__)
|
||||
#define _AWS_PHP_THROW_EXCEPTION1(format) zend_error_noreturn(E_ERROR, format)
|
||||
|
||||
/**
|
||||
* throws an exception resulting from argument parsing, notes the current function name in the exception
|
||||
*/
|
||||
#define aws_php_argparse_fail() \
|
||||
do { \
|
||||
aws_php_throw_exception("Failed to parse arguments to %s", __func__); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* calls zend_parse_parameters() with the arguments and throws an exception if parsing fails
|
||||
*/
|
||||
#define aws_php_parse_parameters(type_spec, ...) \
|
||||
do { \
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), type_spec, __VA_ARGS__) == FAILURE) { \
|
||||
aws_php_argparse_fail(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* calls zend_parse_parameters_none() and throws an exception if parsing fails
|
||||
*/
|
||||
#define aws_php_parse_parameters_none() \
|
||||
do { \
|
||||
if (zend_parse_parameters_none() == FAILURE) { \
|
||||
aws_php_argparse_fail(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* generic dispatch mechanism to call a callback provided as a zval with arguments
|
||||
* that are converted to zvals based on the arg_types format string
|
||||
* Uses the same format string as zend_parse_parameters
|
||||
*/
|
||||
static zval *aws_php_invoke_callback(zval *callback, const char *arg_types, ...) {
|
||||
zval aws_php_invoke_callback(zval *callback, const char *arg_types, ...) {
|
||||
|
||||
char *error = NULL;
|
||||
zend_fcall_info fci = {0};
|
||||
zend_fcall_info_cache fcc = {0};
|
||||
zend_fcall_info_cache fcc = empty_fcall_info_cache;
|
||||
if (zend_fcall_info_init(callback, IS_CALLABLE_CHECK_SYNTAX_ONLY, &fci, &fcc, NULL, &error) == FAILURE) {
|
||||
aws_php_throw_exception("Unable to initialize callback from callable via zend_fcall_info_init: %s", error);
|
||||
}
|
||||
@@ -89,7 +29,6 @@ static zval *aws_php_invoke_callback(zval *callback, const char *arg_types, ...)
|
||||
/* Allocate the stack frame of zval arguments and fill them in */
|
||||
const size_t num_args = strlen(arg_types);
|
||||
zval *stack = alloca(sizeof(zval) * num_args);
|
||||
zval *retval = NULL;
|
||||
int arg_idx = 0;
|
||||
va_list va;
|
||||
va_start(va, arg_types);
|
||||
@@ -159,38 +98,132 @@ static zval *aws_php_invoke_callback(zval *callback, const char *arg_types, ...)
|
||||
zend_fcall_info_argp(&fci, num_args, stack);
|
||||
#else
|
||||
/* PHP5.6 may mutate the arguments due to coercion */
|
||||
zval **args = alloca(sizeof(zval *) * num_args);
|
||||
zval **arg_ptrs = alloca(sizeof(zval *) * num_args);
|
||||
zval ***args = alloca(sizeof(zval **) * num_args);
|
||||
for (int arg_idx = 0; arg_idx < num_args; ++arg_idx) {
|
||||
args[arg_idx] = &stack[arg_idx];
|
||||
arg_ptrs[arg_idx] = &stack[arg_idx];
|
||||
args[arg_idx] = &arg_ptrs[arg_idx];
|
||||
}
|
||||
zend_fcall_info_argp(&fci, num_args, &args);
|
||||
fci.param_count = num_args;
|
||||
fci.params = args;
|
||||
#endif
|
||||
|
||||
/* PHP5 requires us to have a retval on the stack that zend fills out */
|
||||
zval retval;
|
||||
/* PHP5 allocates its own return value, 7+ uses an existing one we provide */
|
||||
#if !AWS_PHP_AT_LEAST_7
|
||||
fci.retval_ptr_ptr = &retval;
|
||||
zval *retval5 = NULL;
|
||||
fci.retval_ptr_ptr = &retval5;
|
||||
#else
|
||||
fci.retval = &retval;
|
||||
#endif
|
||||
|
||||
if (zend_call_function(&fci, &fcc) == FAILURE) {
|
||||
aws_php_throw_exception("zend_call_function failed in aws_php_invoke_callback");
|
||||
}
|
||||
|
||||
/* PHP7+ allocates its own retval, so we need to copy it out */
|
||||
#if AWS_PHP_AT_LEAST_7
|
||||
retval = fci.retval;
|
||||
#if !AWS_PHP_AT_LEAST_7
|
||||
/* initialize the local retval from the retval in retval_ptr_ptr above */
|
||||
if (retval5) {
|
||||
ZVAL_ZVAL(&retval, retval5, 1, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Clean up arguments */
|
||||
for (int arg_idx = 0; arg_idx < num_args; ++arg_idx) {
|
||||
#if !AWS_PHP_AT_LEAST_7
|
||||
zval_ptr_dtor(args[arg_idx]);
|
||||
#endif
|
||||
#else
|
||||
zval_ptr_dtor(&stack[arg_idx]);
|
||||
#endif
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
aws_php_thread_queue s_aws_php_main_thread_queue;
|
||||
|
||||
bool aws_php_is_main_thread(void) {
|
||||
return s_aws_php_main_thread_queue.thread_id == aws_thread_current_thread_id();
|
||||
}
|
||||
|
||||
void aws_php_thread_queue_init(aws_php_thread_queue *queue) {
|
||||
aws_mutex_init(&queue->mutex);
|
||||
memset(queue->queue, 0, sizeof(aws_php_task) * AWS_PHP_THREAD_QUEUE_MAX_DEPTH);
|
||||
queue->write_slot = 0;
|
||||
queue->thread_id = aws_thread_current_thread_id();
|
||||
}
|
||||
|
||||
void aws_php_thread_queue_clean_up(aws_php_thread_queue *queue) {
|
||||
assert(queue->write_slot == 0 && "aws_php_thread_queue cannot be cleaned up while queue is not empty");
|
||||
aws_mutex_clean_up(&queue->mutex);
|
||||
}
|
||||
|
||||
void aws_php_thread_queue_push(aws_php_thread_queue *queue, aws_php_task task) {
|
||||
aws_mutex_lock(&queue->mutex);
|
||||
assert(queue->write_slot < AWS_PHP_THREAD_QUEUE_MAX_DEPTH && "thread queue is full");
|
||||
queue->queue[queue->write_slot++] = task;
|
||||
aws_mutex_unlock(&queue->mutex);
|
||||
}
|
||||
|
||||
bool aws_php_thread_queue_drain(aws_php_thread_queue *queue) {
|
||||
assert(
|
||||
queue->thread_id == aws_thread_current_thread_id() &&
|
||||
"thread queue cannot be drained from a thread other than its home");
|
||||
aws_php_task drain_queue[AWS_PHP_THREAD_QUEUE_MAX_DEPTH];
|
||||
aws_mutex_lock(&queue->mutex);
|
||||
/* copy any queued tasks into the drain queue, then reset the queue */
|
||||
memcpy(drain_queue, queue->queue, sizeof(aws_php_task) * AWS_PHP_THREAD_QUEUE_MAX_DEPTH);
|
||||
memset(queue->queue, 0, sizeof(aws_php_task) * AWS_PHP_THREAD_QUEUE_MAX_DEPTH);
|
||||
queue->write_slot = 0;
|
||||
aws_mutex_unlock(&queue->mutex);
|
||||
|
||||
bool did_work = false;
|
||||
for (int idx = 0; idx < AWS_PHP_THREAD_QUEUE_MAX_DEPTH; ++idx) {
|
||||
aws_php_task *task = &drain_queue[idx];
|
||||
if (!task->callback) {
|
||||
break;
|
||||
}
|
||||
did_work = true;
|
||||
task->callback(task->data);
|
||||
if (task->dtor) {
|
||||
task->dtor(task->data);
|
||||
}
|
||||
}
|
||||
|
||||
return did_work;
|
||||
}
|
||||
|
||||
/* called on main thread after delivery */
|
||||
static void s_thread_queue_complete_promise(void *data) {
|
||||
struct aws_promise *promise = data;
|
||||
aws_promise_complete(promise, NULL, NULL);
|
||||
}
|
||||
|
||||
/* called from worker thread to wait for the main thread to execute any queued work in PHP */
|
||||
void aws_php_thread_queue_yield(aws_php_thread_queue *queue) {
|
||||
/* If on the main thread, then just drain the queue */
|
||||
if (aws_php_is_main_thread()) {
|
||||
aws_php_thread_queue_drain(queue);
|
||||
} else {
|
||||
/* push a task onto the end of the queue, we will return once this task completes our promise */
|
||||
struct aws_promise *queue_drained = aws_promise_new(aws_crt_default_allocator());
|
||||
aws_php_task queue_drained_task = {
|
||||
.callback = s_thread_queue_complete_promise,
|
||||
.data = queue_drained,
|
||||
};
|
||||
aws_php_thread_queue_push(queue, queue_drained_task);
|
||||
aws_promise_wait(queue_drained);
|
||||
aws_promise_release(queue_drained);
|
||||
}
|
||||
}
|
||||
|
||||
/* called from PHP thread to wait on async queued jobs, one of which should complete the promise */
|
||||
void aws_php_thread_queue_wait(aws_php_thread_queue *queue, struct aws_promise *promise) {
|
||||
while (!aws_promise_is_complete(promise)) {
|
||||
aws_php_thread_queue_drain(queue);
|
||||
}
|
||||
}
|
||||
|
||||
ZEND_DECLARE_MODULE_GLOBALS(awscrt);
|
||||
|
||||
PHP_INI_BEGIN()
|
||||
@@ -208,11 +241,13 @@ static PHP_MINIT_FUNCTION(awscrt) {
|
||||
REGISTER_INI_ENTRIES();
|
||||
|
||||
aws_crt_init();
|
||||
aws_php_thread_queue_init(&s_aws_php_main_thread_queue);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
static PHP_MSHUTDOWN_FUNCTION(awscrt) {
|
||||
UNREGISTER_INI_ENTRIES();
|
||||
aws_php_thread_queue_clean_up(&s_aws_php_main_thread_queue);
|
||||
aws_crt_clean_up();
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -224,595 +259,6 @@ static PHP_GINIT_FUNCTION(awscrt) {
|
||||
awscrt_globals->log_level = 0;
|
||||
}
|
||||
|
||||
/* aws_crt_last_error() */
|
||||
PHP_FUNCTION(aws_crt_last_error) {
|
||||
RETURN_LONG(aws_crt_last_error());
|
||||
}
|
||||
|
||||
/* aws_crt_error_str(int error_code) */
|
||||
PHP_FUNCTION(aws_crt_error_str) {
|
||||
zend_ulong error_code = 0;
|
||||
aws_php_parse_parameters("l", &error_code);
|
||||
|
||||
AWS_RETURN_STRING(aws_crt_error_str(error_code));
|
||||
}
|
||||
|
||||
/* aws_crt_error_name(int error_code) */
|
||||
PHP_FUNCTION(aws_crt_error_name) {
|
||||
zend_ulong error_code = 0;
|
||||
aws_php_parse_parameters("l", &error_code);
|
||||
|
||||
AWS_RETURN_STRING(aws_crt_error_name(error_code));
|
||||
}
|
||||
|
||||
/* aws_crt_error_debug_str(int error_code) */
|
||||
PHP_FUNCTION(aws_crt_error_debug_str) {
|
||||
zend_ulong error_code = 0;
|
||||
aws_php_parse_parameters("l", &error_code);
|
||||
|
||||
AWS_RETURN_STRING(aws_crt_error_debug_str(error_code));
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_options_new) {
|
||||
aws_php_parse_parameters_none();
|
||||
aws_crt_event_loop_group_options *options = aws_crt_event_loop_group_options_new();
|
||||
RETURN_LONG((zend_ulong)options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_options_release) {
|
||||
zend_ulong php_options = 0;
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_event_loop_group_options *options = (void *)php_options;
|
||||
aws_crt_event_loop_group_options_release(options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_options_set_max_threads) {
|
||||
zend_ulong php_options = 0;
|
||||
zend_ulong num_threads = 0;
|
||||
aws_php_parse_parameters("ll", &php_options, &num_threads);
|
||||
|
||||
aws_crt_event_loop_group_options *options = (void *)php_options;
|
||||
aws_crt_event_loop_group_options_set_max_threads(options, num_threads);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_new) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_event_loop_group_options *options = (void *)php_options;
|
||||
aws_crt_event_loop_group *elg = aws_crt_event_loop_group_new(options);
|
||||
RETURN_LONG((zend_ulong)elg);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_release) {
|
||||
zend_ulong php_elg = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_elg);
|
||||
|
||||
struct aws_event_loop_group *elg = (void *)php_elg;
|
||||
aws_crt_event_loop_group_release(elg);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_options_new) {
|
||||
if (zend_parse_parameters_none() == FAILURE) {
|
||||
aws_php_argparse_fail();
|
||||
}
|
||||
|
||||
aws_crt_input_stream_options *options = aws_crt_input_stream_options_new();
|
||||
RETURN_LONG((zend_ulong)options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_options_release) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_input_stream_options *options = (void *)php_options;
|
||||
aws_crt_input_stream_options_release(options);
|
||||
}
|
||||
|
||||
/* PHP streams info:
|
||||
* https://git.php.net/?p=php-src.git;a=blob;f=docs/streams.md;h=0ec3846d68bf70067297d8a6c691d2591c49b48a;hb=HEAD
|
||||
* https://github.com/php/php-src/blob/PHP-5.6.0/main/php_streams.h
|
||||
*/
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_options_set_user_data) {
|
||||
zend_ulong php_options = 0;
|
||||
zval *user_data = NULL;
|
||||
|
||||
aws_php_parse_parameters("lz", &php_options, &user_data);
|
||||
|
||||
aws_crt_input_stream_options *options = (void *)php_options;
|
||||
php_stream *stream = NULL;
|
||||
AWS_PHP_STREAM_FROM_ZVAL(stream, user_data);
|
||||
aws_crt_input_stream_options_set_user_data(options, stream);
|
||||
}
|
||||
|
||||
static int s_php_stream_seek(void *user_data, int64_t offset, aws_crt_input_stream_seek_basis basis) {
|
||||
php_stream *stream = user_data;
|
||||
return php_stream_seek(stream, offset, basis);
|
||||
}
|
||||
|
||||
static int s_php_stream_read(void *user_data, uint8_t *dest, size_t dest_length) {
|
||||
php_stream *stream = user_data;
|
||||
return php_stream_read(stream, (char *)dest, dest_length) != 0;
|
||||
}
|
||||
|
||||
static int s_php_stream_get_length(void *user_data, int64_t *out_length) {
|
||||
php_stream *stream = user_data;
|
||||
size_t pos = php_stream_tell(stream);
|
||||
php_stream_seek(stream, 0, SEEK_END);
|
||||
*out_length = php_stream_tell(stream);
|
||||
php_stream_seek(stream, pos, SEEK_SET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int s_php_stream_get_status(void *user_data, aws_crt_input_stream_status *out_status) {
|
||||
php_stream *stream = user_data;
|
||||
out_status->is_valid = stream != NULL;
|
||||
/* We would like to use php_stream_eof here, but certain streams (notably php://memory)
|
||||
* are not actually capable of EOF, so we get to do it the hard way */
|
||||
int64_t length = 0;
|
||||
int64_t pos = 0;
|
||||
s_php_stream_get_length(stream, &length);
|
||||
pos = php_stream_tell(stream);
|
||||
out_status->is_end_of_stream = pos == length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void s_php_stream_destroy(void *user_data) {
|
||||
(void)user_data;
|
||||
/* no op, stream will be freed by PHP refcount dropping from InputStream::stream */
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_new) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_input_stream_options *options = (void *)php_options;
|
||||
aws_crt_input_stream_options_set_seek(options, s_php_stream_seek);
|
||||
aws_crt_input_stream_options_set_read(options, s_php_stream_read);
|
||||
aws_crt_input_stream_options_set_get_status(options, s_php_stream_get_status);
|
||||
aws_crt_input_stream_options_set_get_length(options, s_php_stream_get_length);
|
||||
aws_crt_input_stream_options_set_destroy(options, s_php_stream_destroy);
|
||||
aws_crt_input_stream *stream = aws_crt_input_stream_new(options);
|
||||
RETURN_LONG((zend_ulong)stream);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_release) {
|
||||
zend_ulong php_stream = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_stream);
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
aws_crt_input_stream_release(stream);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_seek) {
|
||||
zend_ulong php_stream = 0;
|
||||
zend_ulong offset = 0;
|
||||
zend_ulong basis = 0;
|
||||
|
||||
aws_php_parse_parameters("lll", &php_stream, &offset, &basis);
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
RETURN_LONG(aws_crt_input_stream_seek(stream, offset, basis));
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_read) {
|
||||
zend_ulong php_stream = 0;
|
||||
zend_ulong length = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_stream, &length);
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
uint8_t *buf = emalloc(length);
|
||||
int ret = aws_crt_input_stream_read(stream, buf, length);
|
||||
AWS_RETURN_STRINGL((const char *)buf, length);
|
||||
efree(buf);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_eof) {
|
||||
zend_ulong php_stream = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_stream);
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
aws_crt_input_stream_status status = {0};
|
||||
aws_crt_input_stream_get_status(stream, &status);
|
||||
RETURN_BOOL(status.is_end_of_stream);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_get_length) {
|
||||
zend_ulong php_stream = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_stream);
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
int64_t length = 0;
|
||||
aws_crt_input_stream_get_length(stream, &length);
|
||||
RETURN_LONG(length);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_http_message_new_from_blob) {
|
||||
const char *blob = NULL;
|
||||
size_t blob_len = 0;
|
||||
|
||||
aws_php_parse_parameters("s", &blob, &blob_len);
|
||||
|
||||
aws_crt_http_message *message = aws_crt_http_message_new_from_blob((uint8_t *)blob, blob_len);
|
||||
RETURN_LONG((zend_ulong)message);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_http_message_to_blob) {
|
||||
zend_ulong php_msg = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_msg);
|
||||
|
||||
aws_crt_http_message *message = (void *)php_msg;
|
||||
uint8_t *blob = NULL;
|
||||
size_t blob_len = 0;
|
||||
aws_crt_http_message_to_blob(message, &blob, &blob_len);
|
||||
AWS_RETURN_STRINGL((const char *)blob, blob_len);
|
||||
aws_crt_mem_release(blob);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_http_message_release) {
|
||||
zend_ulong php_msg = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_msg);
|
||||
|
||||
aws_crt_http_message *message = (void *)php_msg;
|
||||
aws_crt_http_message_release(message);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_new) {
|
||||
aws_crt_credentials_options *options = aws_crt_credentials_options_new();
|
||||
RETURN_LONG((zend_ulong)options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_release) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials_options_release(options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_set_access_key_id) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *access_key_id = NULL;
|
||||
size_t access_key_id_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_options, &access_key_id, &access_key_id_len);
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials_options_set_access_key_id(options, (uint8_t *)access_key_id, access_key_id_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_set_secret_access_key) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *secret_access_key = NULL;
|
||||
size_t secret_access_key_len = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &php_options, &secret_access_key, &secret_access_key_len) ==
|
||||
FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials_options_set_secret_access_key(options, (uint8_t *)secret_access_key, secret_access_key_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_set_session_token) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *session_token = NULL;
|
||||
size_t session_token_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_options, &session_token, &session_token_len);
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials_options_set_session_token(options, (uint8_t *)session_token, session_token_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_set_expiration_timepoint_seconds) {
|
||||
zend_ulong php_options = 0;
|
||||
zend_ulong expiration_timepoint_seconds = 0;
|
||||
aws_php_parse_parameters("ll", &php_options, &expiration_timepoint_seconds);
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials_options_set_expiration_timepoint_seconds(options, expiration_timepoint_seconds);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_new) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_credentials_options *options = (void *)php_options;
|
||||
aws_crt_credentials *credentials = aws_crt_credentials_new(options);
|
||||
RETURN_LONG((zend_ulong)credentials);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_release) {
|
||||
zend_ulong php_credentials = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_credentials);
|
||||
|
||||
aws_crt_credentials *credentials = (void *)php_credentials;
|
||||
aws_crt_credentials_release(credentials);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_release) {
|
||||
zend_ulong php_creds_provider = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_creds_provider);
|
||||
|
||||
aws_crt_credentials_provider *provider = (void *)php_creds_provider;
|
||||
aws_crt_credentials_provider_release(provider);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_options_new) {
|
||||
aws_crt_credentials_provider_static_options *options = aws_crt_credentials_provider_static_options_new();
|
||||
RETURN_LONG((zend_ulong)options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_options_release) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_credentials_provider_static_options *options = (void *)php_options;
|
||||
aws_crt_credentials_provider_static_options_release(options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_options_set_access_key_id) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *access_key_id = NULL;
|
||||
size_t access_key_id_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_options, &access_key_id, &access_key_id_len);
|
||||
|
||||
aws_crt_credentials_provider_static_options *options = (void *)php_options;
|
||||
aws_crt_credentials_provider_static_options_set_access_key_id(options, (uint8_t *)access_key_id, access_key_id_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_options_set_secret_access_key) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *secret_access_key = NULL;
|
||||
size_t secret_access_key_len = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &php_options, &secret_access_key, &secret_access_key_len) ==
|
||||
FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
aws_crt_credentials_provider_static_options *options = (void *)php_options;
|
||||
aws_crt_credentials_provider_static_options_set_secret_access_key(
|
||||
options, (uint8_t *)secret_access_key, secret_access_key_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_options_set_session_token) {
|
||||
zend_ulong php_options = 0;
|
||||
const char *session_token = NULL;
|
||||
size_t session_token_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_options, &session_token, &session_token_len);
|
||||
|
||||
aws_crt_credentials_provider_static_options *options = (void *)php_options;
|
||||
aws_crt_credentials_provider_static_options_set_session_token(options, (uint8_t *)session_token, session_token_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_provider_static_new) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_credentials_provider_static_options *options = (void *)php_options;
|
||||
aws_crt_credentials_provider *provider = aws_crt_credentials_provider_static_new(options);
|
||||
RETURN_LONG((zend_ulong)provider);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_new) {
|
||||
if (zend_parse_parameters_none() == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = aws_crt_signing_config_aws_new();
|
||||
RETURN_LONG((zend_ulong)signing_config);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_release) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_signing_config);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_release(signing_config);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_algorithm) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_algorithm = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_algorithm);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_algorithm algorithm = php_algorithm;
|
||||
aws_crt_signing_config_aws_set_algorithm(signing_config, algorithm);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_signature_type) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_signature_type = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_signature_type);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signature_type signature_type = php_signature_type;
|
||||
aws_crt_signing_config_aws_set_signature_type(signing_config, signature_type);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_credentials_provider) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_credentials_provider = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_credentials_provider);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_credentials_provider *credentials_provider = (void *)php_credentials_provider;
|
||||
aws_crt_signing_config_aws_set_credentials_provider(signing_config, credentials_provider);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_region) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
const char *region = NULL;
|
||||
size_t region_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_signing_config, ®ion, ®ion_len);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_region(signing_config, (uint8_t *)region, region_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_service) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
const char *service = NULL;
|
||||
size_t service_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_signing_config, &service, &service_len);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_service(signing_config, (uint8_t *)service, service_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_use_double_uri_encode) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_bool php_use_double_uri_encode = 0;
|
||||
|
||||
aws_php_parse_parameters("lb", &php_signing_config, &php_use_double_uri_encode);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_use_double_uri_encode(signing_config, php_use_double_uri_encode);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_should_normalize_uri_path) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_bool php_should_normalize_uri_path = 0;
|
||||
|
||||
aws_php_parse_parameters("lb", &php_signing_config, &php_should_normalize_uri_path);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_should_normalize_uri_path(signing_config, php_should_normalize_uri_path);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_omit_session_token) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_bool php_omit_session_token = 0;
|
||||
|
||||
aws_php_parse_parameters("lb", &php_signing_config, &php_omit_session_token);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_omit_session_token(signing_config, php_omit_session_token);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_signed_body_value) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
const char *signed_body_value = NULL;
|
||||
size_t signed_body_value_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_signing_config, &signed_body_value, &signed_body_value_len);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_signed_body_value(
|
||||
signing_config, (uint8_t *)signed_body_value, signed_body_value_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_signed_body_header_type) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_signed_body_header_type = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_signed_body_header_type);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signed_body_header_type signed_body_header_type = php_signed_body_header_type;
|
||||
aws_crt_signing_config_aws_set_signed_body_header_type(signing_config, signed_body_header_type);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_expiration_in_seconds) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_expiration_in_seconds = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_expiration_in_seconds);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_expiration_in_seconds(signing_config, php_expiration_in_seconds);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signable_new_from_http_request) {
|
||||
zend_ulong php_http_message = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_http_message);
|
||||
|
||||
const aws_crt_http_message *http_message = (void *)php_http_message;
|
||||
aws_crt_signable *signable = aws_crt_signable_new_from_http_request(http_message);
|
||||
RETURN_LONG((zend_ulong)signable);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signable_new_from_chunk) {
|
||||
zend_ulong php_input_stream = 0;
|
||||
const char *previous_signature = NULL;
|
||||
size_t previous_signature_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_input_stream, &previous_signature, &previous_signature_len);
|
||||
|
||||
aws_crt_input_stream *input_stream = (void *)php_input_stream;
|
||||
aws_crt_signable *signable =
|
||||
aws_crt_signable_new_from_chunk(input_stream, (uint8_t *)previous_signature, previous_signature_len);
|
||||
RETURN_LONG((zend_ulong)signable);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signable_new_from_canonical_request) {
|
||||
const char *canonical_request = NULL;
|
||||
size_t canonical_request_len = 0;
|
||||
|
||||
aws_crt_signable *signable =
|
||||
aws_crt_signable_new_from_canonical_request((uint8_t *)canonical_request, canonical_request_len);
|
||||
RETURN_LONG((zend_ulong)signable);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signable_release) {
|
||||
zend_ulong php_signable = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_signable);
|
||||
|
||||
aws_crt_signable *signable = (void *)php_signable;
|
||||
aws_crt_signable_release(signable);
|
||||
}
|
||||
|
||||
static void s_on_sign_request_aws_complete(aws_crt_signing_result *result, int error_code, void *user_data) {
|
||||
zval *on_complete = user_data;
|
||||
|
||||
aws_php_invoke_callback(on_complete, "ll", (zend_ulong)result, (zend_ulong)error_code);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_sign_request_aws) {
|
||||
zend_ulong php_signable = 0;
|
||||
zend_ulong php_signing_config = 0;
|
||||
zval *php_on_complete = 0;
|
||||
|
||||
aws_php_parse_parameters("llz", &php_signable, &php_signing_config, &php_on_complete);
|
||||
|
||||
aws_crt_signable *signable = (void *)php_signable;
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
int ret = aws_crt_sign_request_aws(signable, signing_config, s_on_sign_request_aws_complete, php_on_complete);
|
||||
RETURN_LONG(ret);
|
||||
}
|
||||
|
||||
zend_module_entry awscrt_module_entry = {
|
||||
STANDARD_MODULE_HEADER,
|
||||
"awscrt",
|
||||
@@ -833,3 +279,32 @@ zend_module_entry awscrt_module_entry = {
|
||||
#ifdef COMPILE_DL_AWSCRT
|
||||
ZEND_GET_MODULE(awscrt)
|
||||
#endif
|
||||
|
||||
/* aws_crt_last_error() */
|
||||
PHP_FUNCTION(aws_crt_last_error) {
|
||||
RETURN_LONG(aws_crt_last_error());
|
||||
}
|
||||
|
||||
/* aws_crt_error_str(int error_code) */
|
||||
PHP_FUNCTION(aws_crt_error_str) {
|
||||
zend_ulong error_code = 0;
|
||||
aws_php_parse_parameters("l", &error_code);
|
||||
|
||||
RETURN_STRING(aws_crt_error_str(error_code));
|
||||
}
|
||||
|
||||
/* aws_crt_error_name(int error_code) */
|
||||
PHP_FUNCTION(aws_crt_error_name) {
|
||||
zend_ulong error_code = 0;
|
||||
aws_php_parse_parameters("l", &error_code);
|
||||
|
||||
RETURN_STRING(aws_crt_error_name(error_code));
|
||||
}
|
||||
|
||||
/* aws_crt_error_debug_str(int error_code) */
|
||||
PHP_FUNCTION(aws_crt_error_debug_str) {
|
||||
zend_ulong error_code = 0;
|
||||
aws_php_parse_parameters("l", &error_code);
|
||||
|
||||
RETURN_STRING(aws_crt_error_debug_str(error_code));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include "php_aws_crt.h"
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_options_new) {
|
||||
aws_php_parse_parameters_none();
|
||||
aws_crt_event_loop_group_options *options = aws_crt_event_loop_group_options_new();
|
||||
RETURN_LONG((zend_ulong)options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_options_release) {
|
||||
zend_ulong php_options = 0;
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_event_loop_group_options *options = (void *)php_options;
|
||||
aws_crt_event_loop_group_options_release(options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_options_set_max_threads) {
|
||||
zend_ulong php_options = 0;
|
||||
zend_ulong num_threads = 0;
|
||||
aws_php_parse_parameters("ll", &php_options, &num_threads);
|
||||
|
||||
aws_crt_event_loop_group_options *options = (void *)php_options;
|
||||
aws_crt_event_loop_group_options_set_max_threads(options, num_threads);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_new) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_event_loop_group_options *options = (void *)php_options;
|
||||
aws_crt_event_loop_group *elg = aws_crt_event_loop_group_new(options);
|
||||
RETURN_LONG((zend_ulong)elg);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_release) {
|
||||
zend_ulong php_elg = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_elg);
|
||||
|
||||
struct aws_event_loop_group *elg = (void *)php_elg;
|
||||
aws_crt_event_loop_group_release(elg);
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include "php_aws_crt.h"
|
||||
|
||||
PHP_FUNCTION(aws_crt_http_message_new_from_blob) {
|
||||
const char *blob = NULL;
|
||||
size_t blob_len = 0;
|
||||
|
||||
aws_php_parse_parameters("s", &blob, &blob_len);
|
||||
|
||||
aws_crt_http_message *message = aws_crt_http_message_new_from_blob((uint8_t *)blob, blob_len);
|
||||
RETURN_LONG((zend_ulong)message);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_http_message_to_blob) {
|
||||
zend_ulong php_msg = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_msg);
|
||||
|
||||
aws_crt_http_message *message = (void *)php_msg;
|
||||
uint8_t *blob = NULL;
|
||||
size_t blob_len = 0;
|
||||
aws_crt_http_message_to_blob(message, &blob, &blob_len);
|
||||
RETURN_STRINGL((const char *)blob, blob_len);
|
||||
aws_crt_mem_release(blob);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_http_message_release) {
|
||||
zend_ulong php_msg = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_msg);
|
||||
|
||||
aws_crt_http_message *message = (void *)php_msg;
|
||||
aws_crt_http_message_release(message);
|
||||
}
|
||||
+130
-18
@@ -15,11 +15,27 @@
|
||||
|
||||
#include "Zend/zend_extensions.h" /* for ZEND_EXTENSION_API_NO */
|
||||
|
||||
#if ZEND_EXTENSION_API_NO < 220131226
|
||||
# error "PHP >= 5.6 is required"
|
||||
#include <aws/common/common.h>
|
||||
#include <aws/common/mutex.h>
|
||||
#include <aws/common/promise.h>
|
||||
#include <aws/common/thread.h>
|
||||
|
||||
/* ZEND_EXTENSION_API_NO from each branch of the PHP source */
|
||||
#define AWS_PHP_EXTENSION_API_5_5 220121212
|
||||
#define AWS_PHP_EXTENSION_API_5_6 220131226
|
||||
#define AWS_PHP_EXTENSION_API_7_0 320151012
|
||||
#define AWS_PHP_EXTENSION_API_7_1 320160303
|
||||
#define AWS_PHP_EXTENSION_API_7_2 320170718
|
||||
#define AWS_PHP_EXTENSION_API_7_3 320180731
|
||||
#define AWS_PHP_EXTENSION_API_7_4 320190902
|
||||
#define AWS_PHP_EXTENSION_API_8_0 420200930
|
||||
|
||||
#if ZEND_EXTENSION_API_NO < AWS_PHP_EXTENSION_API_5_5
|
||||
# error "PHP >= 5.5 is required"
|
||||
#endif
|
||||
|
||||
#define AWS_PHP_AT_LEAST_7 (ZEND_EXTENSION_API_NO >= 320151012)
|
||||
#define AWS_PHP_AT_LEAST_7 (ZEND_EXTENSION_API_NO >= AWS_PHP_EXTENSION_API_7_0)
|
||||
#define AWS_PHP_AT_LEAST_7_2 (ZEND_EXTENSION_API_NO >= AWS_PHP_EXTENSION_API_7_2)
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(awscrt)
|
||||
long log_level;
|
||||
@@ -29,26 +45,122 @@ ZEND_EXTERN_MODULE_GLOBALS(awscrt)
|
||||
|
||||
#define AWSCRT_GLOBAL(v) ZEND_MODULE_GLOBALS_ACCESSOR(awscrt, v)
|
||||
|
||||
|
||||
#if AWS_PHP_AT_LEAST_7
|
||||
/* PHP 7 removed the string duplicate parameter */
|
||||
# define AWS_RETURN_STRING(s) RETURN_STRING(s)
|
||||
# define AWS_RETURN_STRINGL(s, l) RETURN_STRINGL(s, l)
|
||||
/* PHP 7 takes a zval*, PHP5 takes a zval** */
|
||||
# define AWS_PHP_STREAM_FROM_ZVAL(s, z) php_stream_from_zval(s, z)
|
||||
#else
|
||||
# define AWS_RETURN_STRING(s) RETURN_STRING(s, 1)
|
||||
# define AWS_RETURN_STRINGL(s, l) RETURN_STRINGL(s, l, 1)
|
||||
#else /* PHP 5.5-5.6, 7.0-7.1 */
|
||||
/* PHP 7.2+ always duplicate string return values */
|
||||
# undef RETURN_STRING
|
||||
# define RETURN_STRING(s) \
|
||||
{ \
|
||||
RETVAL_STRING(s, 1); \
|
||||
return; \
|
||||
}
|
||||
# undef RETURN_STRINGL
|
||||
# define RETURN_STRINGL(s, l) \
|
||||
{ \
|
||||
RETVAL_STRINGL(s, l, 1); \
|
||||
return; \
|
||||
}
|
||||
# define AWS_PHP_STREAM_FROM_ZVAL(s, z) php_stream_from_zval(s, &z)
|
||||
#endif /* PHP 5.x */
|
||||
|
||||
/* definitions for ZEND API macros taken from PHP7 and backported to 5.6 */
|
||||
# define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
|
||||
static const zend_arg_info name[] = {{NULL, 0, NULL, required_num_args, return_reference, 0, 0},
|
||||
#include "api.h"
|
||||
#include "awscrt_arginfo.h"
|
||||
|
||||
/* PHP5 doesn't really handle type hints well, so elide them */
|
||||
# undef ZEND_ARG_TYPE_INFO
|
||||
# define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) \
|
||||
{#name, sizeof(#name) - 1, NULL, 0, 0, pass_by_ref, allow_null, 0},
|
||||
#endif
|
||||
/* Utility macros borrowed from common */
|
||||
#define GLUE(x, y) x y
|
||||
|
||||
#define RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, count, ...) count
|
||||
#define EXPAND_ARGS(args) RETURN_ARG_COUNT args
|
||||
#define COUNT_ARGS_MAX5(...) EXPAND_ARGS((__VA_ARGS__, 5, 4, 3, 2, 1, 0))
|
||||
|
||||
#define OVERLOAD_MACRO2(name, count) name##count
|
||||
#define OVERLOAD_MACRO1(name, count) OVERLOAD_MACRO2(name, count)
|
||||
#define OVERLOAD_MACRO(name, count) OVERLOAD_MACRO1(name, count)
|
||||
|
||||
#define CALL_OVERLOAD(name, ...) GLUE(OVERLOAD_MACRO(name, COUNT_ARGS_MAX5(__VA_ARGS__)), (__VA_ARGS__))
|
||||
|
||||
#define VARIABLE_LENGTH_ARRAY(type, name, length) type *name = alloca(sizeof(type) * (length))
|
||||
|
||||
/*
|
||||
* PHP utility APIs for this extension
|
||||
*/
|
||||
/*
|
||||
* Exception throwing mechanism, will never return
|
||||
*/
|
||||
#define aws_php_throw_exception(...) CALL_OVERLOAD(_AWS_PHP_THROW_EXCEPTION, __VA_ARGS__);
|
||||
#define _AWS_PHP_THROW_EXCEPTION5(format, ...) zend_error_noreturn(E_ERROR, format, __VA_ARGS__)
|
||||
#define _AWS_PHP_THROW_EXCEPTION4(format, ...) zend_error_noreturn(E_ERROR, format, __VA_ARGS__)
|
||||
#define _AWS_PHP_THROW_EXCEPTION3(format, ...) zend_error_noreturn(E_ERROR, format, __VA_ARGS__)
|
||||
#define _AWS_PHP_THROW_EXCEPTION2(format, ...) zend_error_noreturn(E_ERROR, format, __VA_ARGS__)
|
||||
#define _AWS_PHP_THROW_EXCEPTION1(format) zend_error_noreturn(E_ERROR, format)
|
||||
|
||||
/**
|
||||
* throws an exception resulting from argument parsing, notes the current function name in the exception
|
||||
*/
|
||||
#define aws_php_argparse_fail() \
|
||||
do { \
|
||||
aws_php_throw_exception("Failed to parse arguments to %s", __func__); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* calls zend_parse_parameters() with the arguments and throws an exception if parsing fails
|
||||
*/
|
||||
#define aws_php_parse_parameters(type_spec, ...) \
|
||||
do { \
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), type_spec, __VA_ARGS__) == FAILURE) { \
|
||||
aws_php_argparse_fail(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* calls zend_parse_parameters_none() and throws an exception if parsing fails
|
||||
*/
|
||||
#define aws_php_parse_parameters_none() \
|
||||
do { \
|
||||
if (zend_parse_parameters_none() == FAILURE) { \
|
||||
aws_php_argparse_fail(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Thread queue functions for managing PHP's optional threading situation */
|
||||
typedef struct _aws_php_task {
|
||||
void (*callback)(void *); /* task function */
|
||||
void (*dtor)(void *); /* deletes task_data, if non-null */
|
||||
void *data;
|
||||
} aws_php_task;
|
||||
|
||||
/* maximum number of queued callbacks to execute at once. Since this is to support single-threaded usage,
|
||||
* this can be a fairly small number, as how many callbacks could we reasonably be stacking up?! */
|
||||
#define AWS_PHP_THREAD_QUEUE_MAX_DEPTH 32
|
||||
|
||||
typedef struct _aws_php_thread_queue {
|
||||
struct aws_mutex mutex;
|
||||
aws_php_task queue[AWS_PHP_THREAD_QUEUE_MAX_DEPTH];
|
||||
size_t write_slot;
|
||||
aws_thread_id_t thread_id;
|
||||
} aws_php_thread_queue;
|
||||
|
||||
extern aws_php_thread_queue s_aws_php_main_thread_queue;
|
||||
bool aws_php_is_main_thread(void);
|
||||
|
||||
void aws_php_thread_queue_init(aws_php_thread_queue *queue);
|
||||
void aws_php_thread_queue_clean_up(aws_php_thread_queue *queue);
|
||||
void aws_php_thread_queue_push(aws_php_thread_queue *queue, aws_php_task task);
|
||||
bool aws_php_thread_queue_drain(aws_php_thread_queue *queue);
|
||||
|
||||
/* called from worker thread to wait for the main thread to execute any queued work in PHP */
|
||||
void aws_php_thread_queue_yield(aws_php_thread_queue *queue);
|
||||
|
||||
/* called from PHP thread to wait on async queued jobs, one of which MUST complete the promise */
|
||||
void aws_php_thread_queue_wait(aws_php_thread_queue *queue, struct aws_promise *promise);
|
||||
|
||||
/**
|
||||
* generic dispatch mechanism to call a callback provided as a zval with arguments
|
||||
* that are converted to zvals based on the arg_types format string
|
||||
* Uses the same format string as zend_parse_parameters
|
||||
*/
|
||||
zval aws_php_invoke_callback(zval *callback, const char *arg_types, ...);
|
||||
|
||||
#endif /* PHP_AWS_CRT_H */
|
||||
|
||||
+285
@@ -0,0 +1,285 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include "php_aws_crt.h"
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_new) {
|
||||
if (zend_parse_parameters_none() == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = aws_crt_signing_config_aws_new();
|
||||
RETURN_LONG((zend_ulong)signing_config);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_release) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_signing_config);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_release(signing_config);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_algorithm) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_algorithm = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_algorithm);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_algorithm algorithm = php_algorithm;
|
||||
aws_crt_signing_config_aws_set_algorithm(signing_config, algorithm);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_signature_type) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_signature_type = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_signature_type);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signature_type signature_type = php_signature_type;
|
||||
aws_crt_signing_config_aws_set_signature_type(signing_config, signature_type);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_credentials_provider) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_credentials_provider = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_credentials_provider);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_credentials_provider *credentials_provider = (void *)php_credentials_provider;
|
||||
aws_crt_signing_config_aws_set_credentials_provider(signing_config, credentials_provider);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_region) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
const char *region = NULL;
|
||||
size_t region_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_signing_config, ®ion, ®ion_len);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_region(signing_config, (uint8_t *)region, region_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_service) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
const char *service = NULL;
|
||||
size_t service_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_signing_config, &service, &service_len);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_service(signing_config, (uint8_t *)service, service_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_use_double_uri_encode) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_bool php_use_double_uri_encode = 0;
|
||||
|
||||
aws_php_parse_parameters("lb", &php_signing_config, &php_use_double_uri_encode);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_use_double_uri_encode(signing_config, php_use_double_uri_encode);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_should_normalize_uri_path) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_bool php_should_normalize_uri_path = 0;
|
||||
|
||||
aws_php_parse_parameters("lb", &php_signing_config, &php_should_normalize_uri_path);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_should_normalize_uri_path(signing_config, php_should_normalize_uri_path);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_omit_session_token) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_bool php_omit_session_token = 0;
|
||||
|
||||
aws_php_parse_parameters("lb", &php_signing_config, &php_omit_session_token);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_omit_session_token(signing_config, php_omit_session_token);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_signed_body_value) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
const char *signed_body_value = NULL;
|
||||
size_t signed_body_value_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_signing_config, &signed_body_value, &signed_body_value_len);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_signed_body_value(
|
||||
signing_config, (uint8_t *)signed_body_value, signed_body_value_len);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_signed_body_header_type) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_signed_body_header_type = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_signed_body_header_type);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signed_body_header_type signed_body_header_type = php_signed_body_header_type;
|
||||
aws_crt_signing_config_aws_set_signed_body_header_type(signing_config, signed_body_header_type);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_expiration_in_seconds) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_expiration_in_seconds = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_expiration_in_seconds);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_expiration_in_seconds(signing_config, php_expiration_in_seconds);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_config_aws_set_date) {
|
||||
zend_ulong php_signing_config = 0;
|
||||
zend_ulong php_timestamp = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_config, &php_timestamp);
|
||||
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
aws_crt_signing_config_aws_set_date(signing_config, php_timestamp);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signable_new_from_http_request) {
|
||||
zend_ulong php_http_message = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_http_message);
|
||||
|
||||
const aws_crt_http_message *http_message = (void *)php_http_message;
|
||||
aws_crt_signable *signable = aws_crt_signable_new_from_http_request(http_message);
|
||||
RETURN_LONG((zend_ulong)signable);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signable_new_from_chunk) {
|
||||
zend_ulong php_input_stream = 0;
|
||||
const char *previous_signature = NULL;
|
||||
size_t previous_signature_len = 0;
|
||||
|
||||
aws_php_parse_parameters("ls", &php_input_stream, &previous_signature, &previous_signature_len);
|
||||
|
||||
aws_crt_input_stream *input_stream = (void *)php_input_stream;
|
||||
aws_crt_signable *signable =
|
||||
aws_crt_signable_new_from_chunk(input_stream, (uint8_t *)previous_signature, previous_signature_len);
|
||||
RETURN_LONG((zend_ulong)signable);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signable_new_from_canonical_request) {
|
||||
const char *canonical_request = NULL;
|
||||
size_t canonical_request_len = 0;
|
||||
|
||||
aws_crt_signable *signable =
|
||||
aws_crt_signable_new_from_canonical_request((uint8_t *)canonical_request, canonical_request_len);
|
||||
RETURN_LONG((zend_ulong)signable);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signable_release) {
|
||||
zend_ulong php_signable = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_signable);
|
||||
|
||||
aws_crt_signable *signable = (void *)php_signable;
|
||||
aws_crt_signable_release(signable);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_result_release) {
|
||||
zend_ulong php_signing_result = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_signing_result);
|
||||
aws_crt_signing_result *result = (void *)php_signing_result;
|
||||
aws_crt_signing_result_release(result);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_signing_result_apply_to_http_request) {
|
||||
zend_ulong php_signing_result = 0;
|
||||
zend_ulong php_http_request = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_signing_result, &php_http_request);
|
||||
aws_crt_signing_result *result = (void *)php_signing_result;
|
||||
aws_crt_http_message *request = (void *)php_http_request;
|
||||
|
||||
if (aws_crt_signing_result_apply_to_http_request(result, request)) {
|
||||
aws_php_throw_exception(
|
||||
"Failed to apply signing result to HTTP request: %s", aws_crt_error_name(aws_crt_last_error()));
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct _signing_state {
|
||||
struct aws_promise *promise;
|
||||
zval *on_complete;
|
||||
aws_crt_signing_result *signing_result;
|
||||
int error_code;
|
||||
} signing_state;
|
||||
|
||||
/* called on main thread to deliver result to php */
|
||||
static void s_sign_aws_complete(void *data) {
|
||||
signing_state *state = data;
|
||||
zval *on_complete = state->on_complete;
|
||||
aws_php_invoke_callback(on_complete, "ll", (zend_ulong)state->signing_result, (zend_ulong)state->error_code);
|
||||
}
|
||||
|
||||
/* called from signing process in aws_sign_request_aws */
|
||||
static void s_on_sign_request_aws_complete(aws_crt_signing_result *result, int error_code, void *user_data) {
|
||||
signing_state *state = user_data;
|
||||
struct aws_promise *promise = state->promise;
|
||||
|
||||
state->signing_result = result;
|
||||
state->error_code = error_code;
|
||||
|
||||
/*
|
||||
* Must execute PHP callback before this function returns, or signing_result will be killed
|
||||
* so the callback is queued back to the main thread and will have run when yield returns
|
||||
*/
|
||||
aws_php_task complete_callback_task = {
|
||||
.callback = s_sign_aws_complete,
|
||||
.data = state,
|
||||
};
|
||||
aws_php_thread_queue_push(&s_aws_php_main_thread_queue, complete_callback_task);
|
||||
aws_php_thread_queue_yield(&s_aws_php_main_thread_queue);
|
||||
|
||||
if (error_code) {
|
||||
aws_promise_fail(promise, error_code);
|
||||
} else {
|
||||
aws_promise_complete(promise, result, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_sign_request_aws) {
|
||||
zend_ulong php_signable = 0;
|
||||
zend_ulong php_signing_config = 0;
|
||||
zval *php_on_complete = 0;
|
||||
|
||||
aws_php_parse_parameters("llz", &php_signable, &php_signing_config, &php_on_complete);
|
||||
|
||||
aws_crt_signable *signable = (void *)php_signable;
|
||||
aws_crt_signing_config_aws *signing_config = (void *)php_signing_config;
|
||||
|
||||
struct aws_promise *promise = aws_promise_new(aws_crt_default_allocator());
|
||||
signing_state state = {
|
||||
.promise = promise,
|
||||
.on_complete = php_on_complete,
|
||||
};
|
||||
int ret = aws_crt_sign_request_aws(signable, signing_config, s_on_sign_request_aws_complete, &state);
|
||||
if (ret != 0) {
|
||||
int last_error = aws_crt_last_error();
|
||||
aws_promise_fail(promise, last_error);
|
||||
aws_php_throw_exception(
|
||||
"aws_crt_sign_request_aws: error starting signing process: %s", aws_crt_error_name(last_error));
|
||||
}
|
||||
|
||||
aws_php_thread_queue_wait(&s_aws_php_main_thread_queue, promise);
|
||||
|
||||
done:
|
||||
aws_promise_release(promise);
|
||||
RETURN_LONG(ret);
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
#include "php_aws_crt.h"
|
||||
|
||||
/* PHP streams info:
|
||||
* https://git.php.net/?p=php-src.git;a=blob;f=docs/streams.md;h=0ec3846d68bf70067297d8a6c691d2591c49b48a;hb=HEAD
|
||||
* https://github.com/php/php-src/blob/PHP-5.6.0/main/php_streams.h
|
||||
*/
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_options_new) {
|
||||
if (zend_parse_parameters_none() == FAILURE) {
|
||||
aws_php_argparse_fail();
|
||||
}
|
||||
|
||||
aws_crt_input_stream_options *options = aws_crt_input_stream_options_new();
|
||||
RETURN_LONG((zend_ulong)options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_options_release) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_input_stream_options *options = (void *)php_options;
|
||||
aws_crt_input_stream_options_release(options);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_options_set_user_data) {
|
||||
zend_ulong php_options = 0;
|
||||
zval *user_data = NULL;
|
||||
|
||||
aws_php_parse_parameters("lz", &php_options, &user_data);
|
||||
|
||||
aws_crt_input_stream_options *options = (void *)php_options;
|
||||
php_stream *stream = NULL;
|
||||
AWS_PHP_STREAM_FROM_ZVAL(stream, user_data);
|
||||
aws_crt_input_stream_options_set_user_data(options, stream);
|
||||
}
|
||||
|
||||
static int s_php_stream_seek(void *user_data, int64_t offset, aws_crt_input_stream_seek_basis basis) {
|
||||
php_stream *stream = user_data;
|
||||
return php_stream_seek(stream, offset, basis);
|
||||
}
|
||||
|
||||
static int s_php_stream_read(void *user_data, uint8_t *dest, size_t dest_length) {
|
||||
php_stream *stream = user_data;
|
||||
return php_stream_read(stream, (char *)dest, dest_length) != 0;
|
||||
}
|
||||
|
||||
static int s_php_stream_get_length(void *user_data, int64_t *out_length) {
|
||||
php_stream *stream = user_data;
|
||||
size_t pos = php_stream_tell(stream);
|
||||
php_stream_seek(stream, 0, SEEK_END);
|
||||
*out_length = php_stream_tell(stream);
|
||||
php_stream_seek(stream, pos, SEEK_SET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int s_php_stream_get_status(void *user_data, aws_crt_input_stream_status *out_status) {
|
||||
php_stream *stream = user_data;
|
||||
out_status->is_valid = stream != NULL;
|
||||
/* We would like to use php_stream_eof here, but certain streams (notably php://memory)
|
||||
* are not actually capable of EOF, so we get to do it the hard way */
|
||||
int64_t length = 0;
|
||||
int64_t pos = 0;
|
||||
s_php_stream_get_length(stream, &length);
|
||||
pos = php_stream_tell(stream);
|
||||
out_status->is_end_of_stream = pos == length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void s_php_stream_destroy(void *user_data) {
|
||||
(void)user_data;
|
||||
/* no op, stream will be freed by PHP refcount dropping from InputStream::stream */
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_new) {
|
||||
zend_ulong php_options = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_options);
|
||||
|
||||
aws_crt_input_stream_options *options = (void *)php_options;
|
||||
aws_crt_input_stream_options_set_seek(options, s_php_stream_seek);
|
||||
aws_crt_input_stream_options_set_read(options, s_php_stream_read);
|
||||
aws_crt_input_stream_options_set_get_status(options, s_php_stream_get_status);
|
||||
aws_crt_input_stream_options_set_get_length(options, s_php_stream_get_length);
|
||||
aws_crt_input_stream_options_set_destroy(options, s_php_stream_destroy);
|
||||
aws_crt_input_stream *stream = aws_crt_input_stream_new(options);
|
||||
RETURN_LONG((zend_ulong)stream);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_release) {
|
||||
zend_ulong php_stream = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_stream);
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
aws_crt_input_stream_release(stream);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_seek) {
|
||||
zend_ulong php_stream = 0;
|
||||
zend_ulong offset = 0;
|
||||
zend_ulong basis = 0;
|
||||
|
||||
aws_php_parse_parameters("lll", &php_stream, &offset, &basis);
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
RETURN_LONG(aws_crt_input_stream_seek(stream, offset, basis));
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_read) {
|
||||
zend_ulong php_stream = 0;
|
||||
zend_ulong length = 0;
|
||||
|
||||
aws_php_parse_parameters("ll", &php_stream, &length);
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
uint8_t *buf = emalloc(length);
|
||||
int ret = aws_crt_input_stream_read(stream, buf, length);
|
||||
RETURN_STRINGL((const char *)buf, length);
|
||||
efree(buf);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_eof) {
|
||||
zend_ulong php_stream = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_stream);
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
aws_crt_input_stream_status status = {0};
|
||||
aws_crt_input_stream_get_status(stream, &status);
|
||||
RETURN_BOOL(status.is_end_of_stream);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_get_length) {
|
||||
zend_ulong php_stream = 0;
|
||||
|
||||
aws_php_parse_parameters("l", &php_stream);
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
int64_t length = 0;
|
||||
aws_crt_input_stream_get_length(stream, &length);
|
||||
RETURN_LONG(length);
|
||||
}
|
||||
Reference in New Issue
Block a user