From 0c8af4992cb0f7589dcafaad65ada12753c64594 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 23 Nov 2022 21:14:33 +0300 Subject: initial --- .../src/AWS/CRT/Auth/AwsCredentials.php | 69 ++++ .../src/AWS/CRT/Auth/CredentialsProvider.php | 23 ++ .../aws/aws-crt-php/src/AWS/CRT/Auth/Signable.php | 43 +++ .../aws-crt-php/src/AWS/CRT/Auth/SignatureType.php | 15 + .../src/AWS/CRT/Auth/SignedBodyHeaderType.php | 11 + .../aws/aws-crt-php/src/AWS/CRT/Auth/Signing.php | 22 ++ .../src/AWS/CRT/Auth/SigningAlgorithm.php | 11 + .../src/AWS/CRT/Auth/SigningConfigAWS.php | 75 +++++ .../aws-crt-php/src/AWS/CRT/Auth/SigningResult.php | 33 ++ .../src/AWS/CRT/Auth/StaticCredentialsProvider.php | 35 ++ vendor/aws/aws-crt-php/src/AWS/CRT/CRT.php | 358 +++++++++++++++++++++ .../aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php | 50 +++ .../aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php | 95 ++++++ .../aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php | 32 ++ .../aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php | 27 ++ .../aws-crt-php/src/AWS/CRT/IO/EventLoopGroup.php | 39 +++ .../aws/aws-crt-php/src/AWS/CRT/IO/InputStream.php | 49 +++ .../aws-crt-php/src/AWS/CRT/Internal/Encoding.php | 37 +++ .../aws-crt-php/src/AWS/CRT/Internal/Extension.php | 29 ++ vendor/aws/aws-crt-php/src/AWS/CRT/Log.php | 47 +++ .../aws/aws-crt-php/src/AWS/CRT/NativeResource.php | 42 +++ vendor/aws/aws-crt-php/src/AWS/CRT/Options.php | 77 +++++ 22 files changed, 1219 insertions(+) create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Auth/AwsCredentials.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Auth/CredentialsProvider.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signable.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignatureType.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignedBodyHeaderType.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signing.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningAlgorithm.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningConfigAWS.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningResult.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Auth/StaticCredentialsProvider.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/CRT.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/IO/EventLoopGroup.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/IO/InputStream.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Encoding.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Extension.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Log.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/NativeResource.php create mode 100644 vendor/aws/aws-crt-php/src/AWS/CRT/Options.php (limited to 'vendor/aws/aws-crt-php/src/AWS') diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/AwsCredentials.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/AwsCredentials.php new file mode 100644 index 0000000..6f6acee --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/AwsCredentials.php @@ -0,0 +1,69 @@ + '', + 'secret_access_key' => '', + 'session_token' => '', + 'expiration_timepoint_seconds' => 0, + ]; + } + + private $access_key_id; + private $secret_access_key; + private $session_token; + private $expiration_timepoint_seconds = 0; + + public function __get($name) { + return $this->$name; + } + + function __construct(array $options = []) { + parent::__construct(); + + $options = new Options($options, self::defaults()); + $this->access_key_id = $options->access_key_id->asString(); + $this->secret_access_key = $options->secret_access_key->asString(); + $this->session_token = $options->session_token ? $options->session_token->asString() : null; + $this->expiration_timepoint_seconds = $options->expiration_timepoint_seconds->asInt(); + + if (strlen($this->access_key_id) == 0) { + throw new \InvalidArgumentException("access_key_id must be provided"); + } + if (strlen($this->secret_access_key) == 0) { + throw new \InvalidArgumentException("secret_access_key must be provided"); + } + + $creds_options = self::$crt->aws_credentials_options_new(); + self::$crt->aws_credentials_options_set_access_key_id($creds_options, $this->access_key_id); + self::$crt->aws_credentials_options_set_secret_access_key($creds_options, $this->secret_access_key); + self::$crt->aws_credentials_options_set_session_token($creds_options, $this->session_token); + self::$crt->aws_credentials_options_set_expiration_timepoint_seconds($creds_options, $this->expiration_timepoint_seconds); + $this->acquire(self::$crt->aws_credentials_new($creds_options)); + self::$crt->aws_credentials_options_release($creds_options); + } + + function __destruct() { + self::$crt->aws_credentials_release($this->release()); + parent::__destruct(); + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/CredentialsProvider.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/CredentialsProvider.php new file mode 100644 index 0000000..e9d3588 --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/CredentialsProvider.php @@ -0,0 +1,23 @@ +credentials_provider_release($this->release()); + parent::__destruct(); + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signable.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signable.php new file mode 100644 index 0000000..100b56a --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signable.php @@ -0,0 +1,43 @@ +signable_new_from_http_request($http_message->native); + }); + } + + public static function fromChunk($chunk_stream, $previous_signature="") { + if (!($chunk_stream instanceof InputStream)) { + $chunk_stream = new InputStream($chunk_stream); + } + return new Signable(function() use($chunk_stream, $previous_signature) { + return self::$crt->signable_new_from_chunk($chunk_stream->native, $previous_signature); + }); + } + + public static function fromCanonicalRequest($canonical_request) { + return new Signable(function() use($canonical_request) { + return self::$crt->signable_new_from_canonical_request($canonical_request); + }); + } + + protected function __construct($ctor) { + parent::__construct(); + $this->acquire($ctor()); + } + + function __destruct() { + self::$crt->signable_release($this->release()); + parent::__destruct(); + } +} \ No newline at end of file diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignatureType.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignatureType.php new file mode 100644 index 0000000..3d3b99f --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignatureType.php @@ -0,0 +1,15 @@ +sign_request_aws($signable->native, $signing_config->native, + function($result, $error_code) use ($on_complete) { + $signing_result = SigningResult::fromNative($result); + $on_complete($signing_result, $error_code); + }, null); + } + + static function testVerifySigV4ASigning($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y) { + return self::$crt->test_verify_sigv4a_signing($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y); + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningAlgorithm.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningAlgorithm.php new file mode 100644 index 0000000..dd11059 --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningAlgorithm.php @@ -0,0 +1,11 @@ + SigningAlgorithm::SIGv4, + 'signature_type' => SignatureType::HTTP_REQUEST_HEADERS, + 'credentials_provider' => null, + 'region' => null, + 'service' => null, + 'use_double_uri_encode' => false, + 'should_normalize_uri_path' => false, + 'omit_session_token' => false, + 'signed_body_value' => null, + 'signed_body_header_type' => SignedBodyHeaderType::NONE, + 'expiration_in_seconds' => 0, + 'date' => time(), + 'should_sign_header' => null, + ]; + } + + private $options; + + public function __construct(array $options = []) { + parent::__construct(); + $this->options = $options = new Options($options, self::defaults()); + $sc = $this->acquire(self::$crt->signing_config_aws_new()); + self::$crt->signing_config_aws_set_algorithm($sc, $options->algorithm->asInt()); + self::$crt->signing_config_aws_set_signature_type($sc, $options->signature_type->asInt()); + if ($credentials_provider = $options->credentials_provider->asObject()) { + self::$crt->signing_config_aws_set_credentials_provider( + $sc, + $credentials_provider->native); + } + self::$crt->signing_config_aws_set_region( + $sc, $options->region->asString()); + self::$crt->signing_config_aws_set_service( + $sc, $options->service->asString()); + self::$crt->signing_config_aws_set_use_double_uri_encode( + $sc, $options->use_double_uri_encode->asBool()); + self::$crt->signing_config_aws_set_should_normalize_uri_path( + $sc, $options->should_normalize_uri_path->asBool()); + self::$crt->signing_config_aws_set_omit_session_token( + $sc, $options->omit_session_token->asBool()); + self::$crt->signing_config_aws_set_signed_body_value( + $sc, $options->signed_body_value->asString()); + self::$crt->signing_config_aws_set_signed_body_header_type( + $sc, $options->signed_body_header_type->asInt()); + self::$crt->signing_config_aws_set_expiration_in_seconds( + $sc, $options->expiration_in_seconds->asInt()); + self::$crt->signing_config_aws_set_date($sc, $options->date->asInt()); + if ($should_sign_header = $options->should_sign_header->asCallable()) { + self::$crt->signing_config_aws_set_should_sign_header_fn($sc, $should_sign_header); + } + } + + function __destruct() + { + self::$crt->signing_config_aws_release($this->release()); + parent::__destruct(); + } + + public function __get($name) { + return $this->options->get($name); + } +} \ No newline at end of file diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningResult.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningResult.php new file mode 100644 index 0000000..b8a4ab5 --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningResult.php @@ -0,0 +1,33 @@ +acquire($native); + } + + function __destruct() { + // No destruction necessary, SigningResults are transient, just release + $this->release(); + parent::__destruct(); + } + + public static function fromNative($ptr) { + return new SigningResult($ptr); + } + + public function applyToHttpRequest(&$http_request) { + self::$crt->signing_result_apply_to_http_request($this->native, $http_request->native); + // Update http_request from native + $http_request = Request::unmarshall($http_request->toBlob()); + } +} \ No newline at end of file diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/StaticCredentialsProvider.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/StaticCredentialsProvider.php new file mode 100644 index 0000000..8dc6249 --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/StaticCredentialsProvider.php @@ -0,0 +1,35 @@ +$name; + } + + function __construct(array $options = []) { + parent::__construct(); + $this->credentials = new AwsCredentials($options); + + $provider_options = self::$crt->credentials_provider_static_options_new(); + self::$crt->credentials_provider_static_options_set_access_key_id($provider_options, $this->credentials->access_key_id); + self::$crt->credentials_provider_static_options_set_secret_access_key($provider_options, $this->credentials->secret_access_key); + self::$crt->credentials_provider_static_options_set_session_token($provider_options, $this->credentials->session_token); + $this->acquire(self::$crt->credentials_provider_static_new($provider_options)); + self::$crt->credentials_provider_static_options_release($provider_options); + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/CRT.php b/vendor/aws/aws-crt-php/src/AWS/CRT/CRT.php new file mode 100644 index 0000000..d196a47 --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/CRT.php @@ -0,0 +1,358 @@ +aws_crt_last_error(); + } + + /** + * @param integer $error Error code from the CRT, usually delivered via callback or {@see last_error} + * @return string Human-readable description of the provided error code + */ + public static function error_str($error) { + return self::$impl->aws_crt_error_str((int) $error); + } + + /** + * @param integer $error Error code from the CRT, usually delivered via callback or {@see last_error} + * @return string Name/enum identifier for the provided error code + */ + public static function error_name($error) { + return self::$impl->aws_crt_error_name((int) $error); + } + + public static function log_to_stdout() { + return self::$impl->aws_crt_log_to_stdout(); + } + + public static function log_to_stderr() { + return self::$impl->aws_crt_log_to_stderr(); + } + + public static function log_to_file($filename) { + return self::$impl->aws_crt_log_to_file($filename); + } + + public static function log_to_stream($stream) { + return self::$impl->aws_crt_log_to_stream($stream); + } + + public static function log_set_level($level) { + return self::$impl->aws_crt_log_set_level($level); + } + + public static function log_stop() { + return self::$impl->aws_crt_log_stop(); + } + + public static function log_message($level, $message) { + return self::$impl->aws_crt_log_message($level, $message); + } + + /** + * @return object Pointer to native event_loop_group_options + */ + function event_loop_group_options_new() { + return self::$impl->aws_crt_event_loop_group_options_new(); + } + + /** + * @param object $elg_options Pointer to native event_loop_group_options + */ + function event_loop_group_options_release($elg_options) { + self::$impl->aws_crt_event_loop_group_options_release($elg_options); + } + + /** + * @param object $elg_options Pointer to native event_loop_group_options + * @param integer $max_threads Maximum number of threads to allow the event loop group to use, default: 0/1 per CPU core + */ + function event_loop_group_options_set_max_threads($elg_options, $max_threads) { + self::$impl->aws_crt_event_loop_group_options_set_max_threads($elg_options, (int)$max_threads); + } + + /** + * @param object Pointer to event_loop_group_options, {@see event_loop_group_options_new} + * @return object Pointer to the new event loop group + */ + function event_loop_group_new($options) { + return self::$impl->aws_crt_event_loop_group_new($options); + } + + /** + * @param object $elg Pointer to the event loop group to release + */ + function event_loop_group_release($elg) { + self::$impl->aws_crt_event_loop_group_release($elg); + } + + /** + * return object Pointer to native AWS credentials options + */ + function aws_credentials_options_new() { + return self::$impl->aws_crt_credentials_options_new(); + } + + function aws_credentials_options_release($options) { + self::$impl->aws_crt_credentials_options_release($options); + } + + function aws_credentials_options_set_access_key_id($options, $access_key_id) { + self::$impl->aws_crt_credentials_options_set_access_key_id($options, $access_key_id); + } + + function aws_credentials_options_set_secret_access_key($options, $secret_access_key) { + self::$impl->aws_crt_credentials_options_set_secret_access_key($options, $secret_access_key); + } + + function aws_credentials_options_set_session_token($options, $session_token) { + self::$impl->aws_crt_credentials_options_set_session_token($options, $session_token); + } + + function aws_credentials_options_set_expiration_timepoint_seconds($options, $expiration_timepoint_seconds) { + self::$impl->aws_crt_credentials_options_set_expiration_timepoint_seconds($options, $expiration_timepoint_seconds); + } + + function aws_credentials_new($options) { + return self::$impl->aws_crt_credentials_new($options); + } + + function aws_credentials_release($credentials) { + self::$impl->aws_crt_credentials_release($credentials); + } + + function credentials_provider_release($provider) { + self::$impl->aws_crt_credentials_provider_release($provider); + } + + function credentials_provider_static_options_new() { + return self::$impl->aws_crt_credentials_provider_static_options_new(); + } + + function credentials_provider_static_options_release($options) { + self::$impl->aws_crt_credentials_provider_static_options_release($options); + } + + function credentials_provider_static_options_set_access_key_id($options, $access_key_id) { + self::$impl->aws_crt_credentials_provider_static_options_set_access_key_id($options, $access_key_id); + } + + function credentials_provider_static_options_set_secret_access_key($options, $secret_access_key) { + self::$impl->aws_crt_credentials_provider_static_options_set_secret_access_key($options, $secret_access_key); + } + + function credentials_provider_static_options_set_session_token($options, $session_token) { + self::$impl->aws_crt_credentials_provider_static_options_set_session_token($options, $session_token); + } + + function credentials_provider_static_new($options) { + return self::$impl->aws_crt_credentials_provider_static_new($options); + } + + function input_stream_options_new() { + return self::$impl->aws_crt_input_stream_options_new(); + } + + function input_stream_options_release($options) { + self::$impl->aws_crt_input_stream_options_release($options); + } + + function input_stream_options_set_user_data($options, $user_data) { + self::$impl->aws_crt_input_stream_options_set_user_data($options, $user_data); + } + + function input_stream_new($options) { + return self::$impl->aws_crt_input_stream_new($options); + } + + function input_stream_release($stream) { + self::$impl->aws_crt_input_stream_release($stream); + } + + function input_stream_seek($stream, $offset, $basis) { + return self::$impl->aws_crt_input_stream_seek($stream, $offset, $basis); + } + + function input_stream_read($stream, $length) { + return self::$impl->aws_crt_input_stream_read($stream, $length); + } + + function input_stream_eof($stream) { + return self::$impl->aws_crt_input_stream_eof($stream); + } + + function input_stream_get_length($stream) { + return self::$impl->aws_crt_input_stream_get_length($stream); + } + + function http_message_new_from_blob($blob) { + return self::$impl->aws_crt_http_message_new_from_blob($blob); + } + + function http_message_to_blob($message) { + return self::$impl->aws_crt_http_message_to_blob($message); + } + + function http_message_release($message) { + self::$impl->aws_crt_http_message_release($message); + } + + function signing_config_aws_new() { + return self::$impl->aws_crt_signing_config_aws_new(); + } + + function signing_config_aws_release($signing_config) { + return self::$impl->aws_crt_signing_config_aws_release($signing_config); + } + + function signing_config_aws_set_algorithm($signing_config, $algorithm) { + self::$impl->aws_crt_signing_config_aws_set_algorithm($signing_config, (int)$algorithm); + } + + function signing_config_aws_set_signature_type($signing_config, $signature_type) { + self::$impl->aws_crt_signing_config_aws_set_signature_type($signing_config, (int)$signature_type); + } + + function signing_config_aws_set_credentials_provider($signing_config, $credentials_provider) { + self::$impl->aws_crt_signing_config_aws_set_credentials_provider($signing_config, $credentials_provider); + } + + function signing_config_aws_set_region($signing_config, $region) { + self::$impl->aws_crt_signing_config_aws_set_region($signing_config, $region); + } + + function signing_config_aws_set_service($signing_config, $service) { + self::$impl->aws_crt_signing_config_aws_set_service($signing_config, $service); + } + + function signing_config_aws_set_use_double_uri_encode($signing_config, $use_double_uri_encode) { + self::$impl->aws_crt_signing_config_aws_set_use_double_uri_encode($signing_config, $use_double_uri_encode); + } + + function signing_config_aws_set_should_normalize_uri_path($signing_config, $should_normalize_uri_path) { + self::$impl->aws_crt_signing_config_aws_set_should_normalize_uri_path($signing_config, $should_normalize_uri_path); + } + + function signing_config_aws_set_omit_session_token($signing_config, $omit_session_token) { + self::$impl->aws_crt_signing_config_aws_set_omit_session_token($signing_config, $omit_session_token); + } + + function signing_config_aws_set_signed_body_value($signing_config, $signed_body_value) { + self::$impl->aws_crt_signing_config_aws_set_signed_body_value($signing_config, $signed_body_value); + } + + function signing_config_aws_set_signed_body_header_type($signing_config, $signed_body_header_type) { + self::$impl->aws_crt_signing_config_aws_set_signed_body_header_type($signing_config, $signed_body_header_type); + } + + function signing_config_aws_set_expiration_in_seconds($signing_config, $expiration_in_seconds) { + self::$impl->aws_crt_signing_config_aws_set_expiration_in_seconds($signing_config, $expiration_in_seconds); + } + + function signing_config_aws_set_date($signing_config, $timestamp) { + self::$impl->aws_crt_signing_config_aws_set_date($signing_config, $timestamp); + } + + function signing_config_aws_set_should_sign_header_fn($signing_config, $should_sign_header_fn) { + self::$impl->aws_crt_signing_config_aws_set_should_sign_header_fn($signing_config, $should_sign_header_fn); + } + + function signable_new_from_http_request($http_message) { + return self::$impl->aws_crt_signable_new_from_http_request($http_message); + } + + function signable_new_from_chunk($chunk_stream, $previous_signature) { + return self::$impl->aws_crt_signable_new_from_chunk($chunk_stream, $previous_signature); + } + + function signable_new_from_canonical_request($canonical_request) { + return self::$impl->aws_crt_signable_new_from_canonical_request($canonical_request); + } + + function signable_release($signable) { + self::$impl->aws_crt_signable_release($signable); + } + + function signing_result_release($signing_result) { + self::$impl->aws_crt_signing_result_release($signing_result); + } + + function signing_result_apply_to_http_request($signing_result, $http_message) { + return self::$impl->aws_crt_signing_result_apply_to_http_request( + $signing_result, $http_message); + } + + function sign_request_aws($signable, $signing_config, $on_complete, $user_data) { + return self::$impl->aws_crt_sign_request_aws($signable, $signing_config, $on_complete, $user_data); + } + + function test_verify_sigv4a_signing($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y) { + return self::$impl->aws_crt_test_verify_sigv4a_signing($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y); + } + + public static function crc32($input, $previous = 0) { + return self::$impl->aws_crt_crc32($input, $previous); + } + + public static function crc32c($input, $previous = 0) { + return self::$impl->aws_crt_crc32c($input, $previous); + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php new file mode 100644 index 0000000..8d1457c --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php @@ -0,0 +1,50 @@ +headers = $headers; + } + + public static function marshall($headers) { + $buf = ""; + foreach ($headers->headers as $header => $value) { + $buf .= Encoding::encodeString($header); + $buf .= Encoding::encodeString($value); + } + return $buf; + } + + public static function unmarshall($buf) { + $strings = Encoding::readStrings($buf); + $headers = []; + for ($idx = 0; $idx < count($strings);) { + $headers[$strings[$idx++]] = $strings[$idx++]; + } + return new Headers($headers); + } + + public function count() { + return count($this->headers); + } + + public function get($header) { + return isset($this->headers[$header]) ? $this->headers[$header] : null; + } + + public function set($header, $value) { + $this->headers[$header] = $value; + } + + public function toArray() { + return $this->headers; + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php new file mode 100644 index 0000000..a8c151f --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php @@ -0,0 +1,95 @@ +method = $method; + $this->path = $path; + $this->query = $query; + $this->headers = new Headers($headers); + $this->acquire(self::$crt->http_message_new_from_blob(self::marshall($this))); + } + + public function __destruct() { + self::$crt->http_message_release($this->release()); + parent::__destruct(); + } + + public function toBlob() { + return self::$crt->http_message_to_blob($this->native); + } + + protected static function marshall($msg) { + $buf = ""; + $buf .= Encoding::encodeString($msg->method); + $buf .= Encoding::encodeString($msg->pathAndQuery()); + $buf .= Headers::marshall($msg->headers); + return $buf; + } + + protected static function _unmarshall($buf, $class=Message::class) { + $method = Encoding::readString($buf); + $path_and_query = Encoding::readString($buf); + $parts = explode("?", $path_and_query, 2); + $path = isset($parts[0]) ? $parts[0] : ""; + $query = isset($parts[1]) ? $parts[1] : ""; + $headers = Headers::unmarshall($buf); + + // Turn query params back into a dictionary + if (strlen($query)) { + $query = rawurldecode($query); + $query = explode("&", $query); + $query = array_reduce($query, function($params, $pair) { + list($param, $value) = explode("=", $pair, 2); + $params[$param] = $value; + return $params; + }, []); + } else { + $query = []; + } + + return new $class($method, $path, $query, $headers->toArray()); + } + + public function pathAndQuery() { + $path = $this->path; + $queries = []; + foreach ($this->query as $param => $value) { + $queries []= urlencode($param) . "=" . urlencode($value); + } + $query = implode("&", $queries); + if (strlen($query)) { + $path = implode("?", [$path, $query]); + } + return $path; + } + + public function method() { + return $this->method; + } + + public function path() { + return $this->path; + } + + public function query() { + return $this->query; + } + + public function headers() { + return $this->headers; + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php new file mode 100644 index 0000000..9b4f07c --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php @@ -0,0 +1,32 @@ +body_stream = $body_stream; + } + + public static function marshall($request) { + return parent::marshall($request); + } + + public static function unmarshall($buf) { + return parent::_unmarshall($buf, Request::class); + } + + public function body_stream() { + return $this->body_stream; + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php new file mode 100644 index 0000000..526edc3 --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php @@ -0,0 +1,27 @@ +status_code = $status_code; + } + + public static function marshall($response) { + return parent::marshall($response); + } + + public static function unmarshall($buf) { + return parent::_unmarshall($buf, Response::class); + } + + public function status_code() { + return $this->status_code; + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/IO/EventLoopGroup.php b/vendor/aws/aws-crt-php/src/AWS/CRT/IO/EventLoopGroup.php new file mode 100644 index 0000000..7e989e7 --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/IO/EventLoopGroup.php @@ -0,0 +1,39 @@ + 0, + ]; + } + + function __construct(array $options = []) { + parent::__construct(); + $options = new Options($options, self::defaults()); + $elg_options = self::$crt->event_loop_group_options_new(); + self::$crt->event_loop_group_options_set_max_threads($elg_options, $options->getInt('max_threads')); + $this->acquire(self::$crt->event_loop_group_new($elg_options)); + self::$crt->event_loop_group_options_release($elg_options); + } + + function __destruct() { + self::$crt->event_loop_group_release($this->release()); + parent::__destruct(); + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/IO/InputStream.php b/vendor/aws/aws-crt-php/src/AWS/CRT/IO/InputStream.php new file mode 100644 index 0000000..ae5fd46 --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/IO/InputStream.php @@ -0,0 +1,49 @@ +stream = $stream; + $options = self::$crt->input_stream_options_new(); + // The stream implementation in native just converts the PHP stream into + // a native php_stream* and executes operations entirely in native + self::$crt->input_stream_options_set_user_data($options, $stream); + $this->acquire(self::$crt->input_stream_new($options)); + self::$crt->input_stream_options_release($options); + } + + public function __destruct() { + self::$crt->input_stream_release($this->release()); + parent::__destruct(); + } + + public function eof() { + return self::$crt->input_stream_eof($this->native); + } + + public function length() { + return self::$crt->input_stream_get_length($this->native); + } + + public function read($length = 0) { + if ($length == 0) { + $length = $this->length(); + } + return self::$crt->input_stream_read($this->native, $length); + } + + public function seek($offset, $basis) { + return self::$crt->input_stream_seek($this->native, $offset, $basis); + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Encoding.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Encoding.php new file mode 100644 index 0000000..75446fc --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Encoding.php @@ -0,0 +1,37 @@ += self::NONE && $level <= self::TRACE); + CRT::log_set_level($level); + } + + public static function log($level, $message) { + CRT::log_message($level, $message); + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/NativeResource.php b/vendor/aws/aws-crt-php/src/AWS/CRT/NativeResource.php new file mode 100644 index 0000000..528df75 --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/NativeResource.php @@ -0,0 +1,42 @@ +native = $handle; + } + + protected function release() { + $native = $this->native; + $this->native = null; + return $native; + } + + function __destruct() { + // Should have been destroyed and released by derived resource + assert($this->native == null); + unset(self::$resources[spl_object_hash($this)]); + } +} diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Options.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Options.php new file mode 100644 index 0000000..363a396 --- /dev/null +++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Options.php @@ -0,0 +1,77 @@ +value = $value; + } + + public function asObject() { + return $this->value; + } + + public function asMixed() { + return $this->value; + } + + public function asInt() { + return empty($this->value) ? 0 : (int)$this->value; + } + + public function asBool() { + return boolval($this->value); + } + + public function asString() { + return !empty($this->value) ? strval($this->value) : ""; + } + + public function asArray() { + return is_array($this->value) ? $this->value : (!empty($this->value) ? [$this->value] : []); + } + + public function asCallable() { + return is_callable($this->value) ? $this->value : null; + } +} + +final class Options { + private $options; + + public function __construct($opts = [], $defaults = []) { + $this->options = array_replace($defaults, empty($opts) ? [] : $opts); + } + + public function __get($name) { + return $this->get($name); + } + + public function asArray() { + return $this->options; + } + + public function toArray() { + return array_merge_recursive([], $this->options); + } + + public function get($name) { + return new OptionValue($this->options[$name]); + } + + public function getInt($name) { + return $this->get($name)->asInt(); + } + + public function getString($name) { + return $this->get($name)->asString(); + } + + public function getBool($name) { + return $this->get($name)->asBool(); + } +} -- cgit v1.2.3