mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-18 10:07:12 +00:00
Input Stream bindings (#18)
* Initial aws_input_stream <-> php_stream implementation * Added comments about useful references * updated aws-crt-ffi to get latest aws-lc, faster builds * Fixed inconsistency between PHP5/7 versions of php_stream_from_zval
This commit is contained in:
+1
-1
Submodule crt/aws-crt-ffi updated: 6337aabdfb...37c2cbe22f
+34
-16
@@ -16,36 +16,54 @@ function aws_crt_event_loop_group_options_release(int $elg_options): void {}
|
||||
|
||||
function aws_crt_event_loop_group_options_set_max_threads(int $elg_options, int $max_threads): void {}
|
||||
|
||||
function aws_crt_event_loop_group_new(int $options): int {}
|
||||
function aws_crt_event_loop_group_new(object $options): object {}
|
||||
|
||||
function aws_crt_event_loop_group_release(int $event_loop_group): void {}
|
||||
function aws_crt_event_loop_group_release(object $event_loop_group): void {}
|
||||
|
||||
function aws_crt_credentials_options_new(): int {}
|
||||
function aws_crt_input_stream_options_new(): object {}
|
||||
|
||||
function aws_crt_credentials_options_release(int $options): void {}
|
||||
function aws_crt_input_stream_options_release(object $options): void {}
|
||||
|
||||
function aws_crt_credentials_options_set_access_key_id(int $options, string $access_key_id): void {}
|
||||
function aws_crt_input_stream_options_set_user_data(object $options, object $user_data): void {}
|
||||
|
||||
function aws_crt_credentials_options_set_secret_access_key(int $options, string $secret_access_key): void {}
|
||||
function aws_crt_input_stream_new(object $options): object {}
|
||||
|
||||
function aws_crt_credentials_options_set_session_token(int $options, string $session_token): void {}
|
||||
function aws_crt_input_stream_release(int $stream): void {}
|
||||
|
||||
function aws_crt_credentials_options_set_expiration_timepoint_seconds(int $options, int $expiration_timepoint_seconds): void {}
|
||||
function aws_crt_input_stream_seek(int $stream, int $offset, int $basis): int {}
|
||||
|
||||
function aws_crt_credentials_new(int $options): int {}
|
||||
function aws_crt_input_stream_read(int $stream, int $length): string {}
|
||||
|
||||
function aws_crt_credentials_release(int $credentials): void {}
|
||||
function aws_crt_input_stream_eof(int $stream): bool {}
|
||||
|
||||
function aws_crt_input_stream_get_length(int $stream): int {}
|
||||
|
||||
function aws_crt_credentials_options_new(): object {}
|
||||
|
||||
function aws_crt_credentials_options_release(object $options): void {}
|
||||
|
||||
function aws_crt_credentials_options_set_access_key_id(object $options, string $access_key_id): void {}
|
||||
|
||||
function aws_crt_credentials_options_set_secret_access_key(object $options, string $secret_access_key): void {}
|
||||
|
||||
function aws_crt_credentials_options_set_session_token(object $options, string $session_token): void {}
|
||||
|
||||
function aws_crt_credentials_options_set_expiration_timepoint_seconds(object $options, int $expiration_timepoint_seconds): void {}
|
||||
|
||||
function aws_crt_credentials_new(object $options): object {}
|
||||
|
||||
function aws_crt_credentials_release(object $credentials): void {}
|
||||
|
||||
function aws_crt_credentials_provider_release(int $credentials): void {}
|
||||
|
||||
function aws_crt_credentials_provider_static_options_new(): int {}
|
||||
function aws_crt_credentials_provider_static_options_new(): object {}
|
||||
|
||||
function aws_crt_credentials_provider_static_options_release(int $options): void {}
|
||||
function aws_crt_credentials_provider_static_options_release(object $options): void {}
|
||||
|
||||
function aws_crt_credentials_provider_static_options_set_access_key_id(int $options, string $access_key_id): void {}
|
||||
function aws_crt_credentials_provider_static_options_set_access_key_id(object $options, string $access_key_id): void {}
|
||||
|
||||
function aws_crt_credentials_provider_static_options_set_secret_access_key(int $options, string $secret_access_key): void {}
|
||||
function aws_crt_credentials_provider_static_options_set_secret_access_key(object $options, string $secret_access_key): void {}
|
||||
|
||||
function aws_crt_credentials_provider_static_options_set_session_token(int $options, string $session_token): void {}
|
||||
function aws_crt_credentials_provider_static_options_set_session_token(object $options, string $session_token): void {}
|
||||
|
||||
function aws_crt_credentials_provider_static_new(int $options): int {}
|
||||
function aws_crt_credentials_provider_static_new(object $options): object {}
|
||||
|
||||
+71
-16
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: c681786667e5b7755b2874e4862ea7f162ef61ee */
|
||||
* Stub hash: 5549e1214a9a419075f5cb561adb2d7a340c5916 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_last_error, 0, 0, IS_LONG, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
@@ -23,51 +23,88 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_options
|
||||
ZEND_ARG_TYPE_INFO(0, max_threads, IS_LONG, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_new, 0, 1, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
|
||||
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_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_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, event_loop_group, IS_OBJECT, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_credentials_options_new arginfo_aws_crt_last_error
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_credentials_options_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_input_stream_options_new, 0, 0, IS_OBJECT, 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_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_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_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_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_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_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_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_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, access_key_id, IS_STRING, 0)
|
||||
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_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, secret_access_key, IS_STRING, 0)
|
||||
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_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, session_token, IS_STRING, 0)
|
||||
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_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, expiration_timepoint_seconds, IS_LONG, 0)
|
||||
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_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_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_credentials_provider_release arginfo_aws_crt_credentials_release
|
||||
#define arginfo_aws_crt_credentials_provider_static_options_new arginfo_aws_crt_input_stream_options_new
|
||||
|
||||
#define arginfo_aws_crt_credentials_provider_static_options_new arginfo_aws_crt_last_error
|
||||
|
||||
#define arginfo_aws_crt_credentials_provider_static_options_release arginfo_aws_crt_credentials_options_release
|
||||
#define arginfo_aws_crt_credentials_provider_static_options_release arginfo_aws_crt_input_stream_options_release
|
||||
|
||||
#define arginfo_aws_crt_credentials_provider_static_options_set_access_key_id arginfo_aws_crt_credentials_options_set_access_key_id
|
||||
|
||||
@@ -87,6 +124,15 @@ ZEND_FUNCTION(aws_crt_event_loop_group_options_release);
|
||||
ZEND_FUNCTION(aws_crt_event_loop_group_options_set_max_threads);
|
||||
ZEND_FUNCTION(aws_crt_event_loop_group_new);
|
||||
ZEND_FUNCTION(aws_crt_event_loop_group_release);
|
||||
ZEND_FUNCTION(aws_crt_input_stream_options_new);
|
||||
ZEND_FUNCTION(aws_crt_input_stream_options_release);
|
||||
ZEND_FUNCTION(aws_crt_input_stream_options_set_user_data);
|
||||
ZEND_FUNCTION(aws_crt_input_stream_new);
|
||||
ZEND_FUNCTION(aws_crt_input_stream_release);
|
||||
ZEND_FUNCTION(aws_crt_input_stream_seek);
|
||||
ZEND_FUNCTION(aws_crt_input_stream_read);
|
||||
ZEND_FUNCTION(aws_crt_input_stream_eof);
|
||||
ZEND_FUNCTION(aws_crt_input_stream_get_length);
|
||||
ZEND_FUNCTION(aws_crt_credentials_options_new);
|
||||
ZEND_FUNCTION(aws_crt_credentials_options_release);
|
||||
ZEND_FUNCTION(aws_crt_credentials_options_set_access_key_id);
|
||||
@@ -114,6 +160,15 @@ static const zend_function_entry ext_functions[] = {
|
||||
ZEND_FE(aws_crt_event_loop_group_options_set_max_threads, arginfo_aws_crt_event_loop_group_options_set_max_threads)
|
||||
ZEND_FE(aws_crt_event_loop_group_new, arginfo_aws_crt_event_loop_group_new)
|
||||
ZEND_FE(aws_crt_event_loop_group_release, arginfo_aws_crt_event_loop_group_release)
|
||||
ZEND_FE(aws_crt_input_stream_options_new, arginfo_aws_crt_input_stream_options_new)
|
||||
ZEND_FE(aws_crt_input_stream_options_release, arginfo_aws_crt_input_stream_options_release)
|
||||
ZEND_FE(aws_crt_input_stream_options_set_user_data, arginfo_aws_crt_input_stream_options_set_user_data)
|
||||
ZEND_FE(aws_crt_input_stream_new, arginfo_aws_crt_input_stream_new)
|
||||
ZEND_FE(aws_crt_input_stream_release, arginfo_aws_crt_input_stream_release)
|
||||
ZEND_FE(aws_crt_input_stream_seek, arginfo_aws_crt_input_stream_seek)
|
||||
ZEND_FE(aws_crt_input_stream_read, arginfo_aws_crt_input_stream_read)
|
||||
ZEND_FE(aws_crt_input_stream_eof, arginfo_aws_crt_input_stream_eof)
|
||||
ZEND_FE(aws_crt_input_stream_get_length, arginfo_aws_crt_input_stream_get_length)
|
||||
ZEND_FE(aws_crt_credentials_options_new, arginfo_aws_crt_credentials_options_new)
|
||||
ZEND_FE(aws_crt_credentials_options_release, arginfo_aws_crt_credentials_options_release)
|
||||
ZEND_FE(aws_crt_credentials_options_set_access_key_id, arginfo_aws_crt_credentials_options_set_access_key_id)
|
||||
|
||||
@@ -10,6 +10,15 @@
|
||||
|
||||
#include "awscrt_arginfo.h"
|
||||
|
||||
/* Helpful references for this file:
|
||||
* 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
|
||||
* 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
|
||||
*/
|
||||
|
||||
ZEND_DECLARE_MODULE_GLOBALS(awscrt);
|
||||
|
||||
PHP_INI_BEGIN()
|
||||
@@ -117,7 +126,7 @@ PHP_FUNCTION(aws_crt_event_loop_group_new) {
|
||||
}
|
||||
|
||||
aws_crt_event_loop_group_options *options = (void *)php_options;
|
||||
struct aws_event_loop_group *elg = aws_crt_event_loop_group_new(options);
|
||||
aws_crt_event_loop_group *elg = aws_crt_event_loop_group_new(options);
|
||||
RETURN_LONG((zend_ulong)elg);
|
||||
}
|
||||
|
||||
@@ -132,6 +141,163 @@ PHP_FUNCTION(aws_crt_event_loop_group_release) {
|
||||
aws_crt_event_loop_group_release(elg);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_options_new) {
|
||||
if (zend_parse_parameters_none() == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_options) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz", &php_options, &user_data) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
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, 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 */
|
||||
size_t length = 0, 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;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_options) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_stream) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &php_stream, &offset, &basis) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &php_stream, &length) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
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(buf, length);
|
||||
efree(buf);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_input_stream_eof) {
|
||||
zend_ulong php_stream = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_stream) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_stream) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
aws_crt_input_stream *stream = (void *)php_stream;
|
||||
size_t length = 0;
|
||||
aws_crt_input_stream_get_length(stream, &length);
|
||||
RETURN_LONG(length);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_credentials_options_new) {
|
||||
aws_crt_credentials_options *options = aws_crt_credentials_options_new();
|
||||
RETURN_LONG((zend_ulong)options);
|
||||
|
||||
+8
-1
@@ -29,11 +29,18 @@ ZEND_EXTERN_MODULE_GLOBALS(awscrt)
|
||||
|
||||
#define AWSCRT_GLOBAL(v) ZEND_MODULE_GLOBALS_ACCESSOR(awscrt, v)
|
||||
|
||||
/* PHP 7 removed the string duplicate parameter */
|
||||
|
||||
#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)
|
||||
# define AWS_PHP_STREAM_FROM_ZVAL(s, z) php_stream_from_zval(s, &z)
|
||||
|
||||
/* 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},
|
||||
|
||||
@@ -14,7 +14,7 @@ abstract class CredentialsProvider extends NativeResource {
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
self::$crt->aws_credentials_provider_release($this->release());
|
||||
self::$crt->credentials_provider_release($this->release());
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ final class StaticCredentialsProvider extends CredentialsProvider {
|
||||
}
|
||||
$this->credentials = new AwsCredentials($options);
|
||||
|
||||
$provider_options = self::$crt->aws_credentials_provider_static_options_new();
|
||||
self::$crt->aws_credentials_provider_static_options_set_access_key_id($provider_options, $this->credentials->access_key_id);
|
||||
self::$crt->aws_credentials_provider_static_options_set_secret_access_key($provider_options, $this->credentials->secret_access_key);
|
||||
self::$crt->aws_credentials_provider_static_options_set_session_token($provider_options, $this->credentials->session_token);
|
||||
$this->acquire(self::$crt->aws_credentials_provider_static_new($provider_options));
|
||||
self::$crt->aws_credentials_provider_static_options_release($provider_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);
|
||||
}
|
||||
}
|
||||
|
||||
+43
-7
@@ -140,31 +140,67 @@ final class CRT {
|
||||
self::$impl->aws_crt_credentials_release($credentials);
|
||||
}
|
||||
|
||||
function aws_credentials_provider_release($provider) {
|
||||
function credentials_provider_release($provider) {
|
||||
self::$impl->aws_crt_credentials_provider_release($provider);
|
||||
}
|
||||
|
||||
function aws_credentials_provider_static_options_new() {
|
||||
function credentials_provider_static_options_new() {
|
||||
return self::$impl->aws_crt_credentials_provider_static_options_new();
|
||||
}
|
||||
|
||||
function aws_credentials_provider_static_options_release($options) {
|
||||
function credentials_provider_static_options_release($options) {
|
||||
self::$impl->aws_crt_credentials_provider_static_options_release($options);
|
||||
}
|
||||
|
||||
function aws_credentials_provider_static_options_set_access_key_id($options, $access_key_id) {
|
||||
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 aws_credentials_provider_static_options_set_secret_access_key($options, $secret_access_key) {
|
||||
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 aws_credentials_provider_static_options_set_session_token($options, $session_token) {
|
||||
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 aws_credentials_provider_static_new($options) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
abstract class Message {
|
||||
private $path = "";
|
||||
private $query = [];
|
||||
private $headers = [];
|
||||
|
||||
public function __construct($path, $query = [], $headers = []) {
|
||||
$this->path = $path;
|
||||
$this->query = $query;
|
||||
$this->headers = $headers;
|
||||
}
|
||||
}
|
||||
|
||||
class Request extends Message {
|
||||
private $body_stream = null;
|
||||
|
||||
public function __construct($path, $query = [], $headers = [], $body_stream = null) {
|
||||
parent::__construct($path, $query, $headers);
|
||||
$this->body_stream = $body_stream;
|
||||
}
|
||||
}
|
||||
|
||||
class Response extends Message {
|
||||
private $status_code;
|
||||
|
||||
public function __construct($path, $headers, $status_code) {
|
||||
parent::__construct($path, [], $headers);
|
||||
$this->status_code = $status_code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace AWS\CRT\IO;
|
||||
|
||||
use AWS\CRT\NativeResource as NativeResource;
|
||||
|
||||
final class InputStream extends NativeResource {
|
||||
private $stream = null;
|
||||
|
||||
const SEEK_BEGIN = 0;
|
||||
const SEEK_END = 2;
|
||||
|
||||
public function __construct($stream) {
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use AWS\CRT\IO\InputStream as InputStream;
|
||||
|
||||
require_once('common.inc');
|
||||
|
||||
final class InputStreamTest extends CrtTestCase {
|
||||
|
||||
const MEM_STREAM_CONTENTS = "THIS IS A TEST";
|
||||
|
||||
private function getMemoryStream() {
|
||||
$stream = fopen("php://memory", 'r+');
|
||||
fputs($stream, self::MEM_STREAM_CONTENTS);
|
||||
rewind($stream);
|
||||
return $stream;
|
||||
}
|
||||
|
||||
public function testMemoryStream() {
|
||||
$mem_stream = $this->getMemoryStream();
|
||||
$stream = new InputStream($mem_stream);
|
||||
$this->assertNotNull($stream, "Failed to create InputStream from PHP memory stream");
|
||||
$this->assertEquals(strlen(self::MEM_STREAM_CONTENTS), $stream->length(), "Stream length doesn't match source buffer");
|
||||
$this->assertEquals(self::MEM_STREAM_CONTENTS, $stream->read(), "Stream doesn't match source buffer");
|
||||
$this->assertTrue($stream->eof(), "Stream is not EOF after reading");
|
||||
$this->assertEquals(0, $stream->seek(0, InputStream::SEEK_BEGIN), "Unable to rewind stream");
|
||||
$this->assertFalse($stream->eof(), "Stream is EOF after rewinding");
|
||||
$this->assertEquals(0, $stream->seek(0, InputStream::SEEK_END), "Unable to seek to end of stream");
|
||||
$this->assertTrue($stream->eof(), "Stream is not EOF after seeking to end");
|
||||
$stream = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user