mirror of
https://github.com/mariadb-corporation/libmarias3.git
synced 2025-04-18 16:24:01 +03:00
Fix warnings and add force protocol option
Add the warning -Wdeclaration-after-statement and fix everything it finds. Add MS3_OPT_FORCE_PROTOCOL_VERSION to ms3_set_option() with a test to force protocol version when the autodetection does the wrong thing.
This commit is contained in:
parent
2a6b3e4d63
commit
e850cd25b9
@ -45,7 +45,7 @@ PROTECT_AC_USE_SYSTEM_EXTENSIONS
|
||||
AC_CONFIG_HEADERS([config.h:config.in])dnl Keep filename to 8.3 for MS-DOS.
|
||||
|
||||
# shared library versioning
|
||||
LIBMARIAS3_LIBRARY_VERSION=3:3:0
|
||||
LIBMARIAS3_LIBRARY_VERSION=3:0:1
|
||||
# | | |
|
||||
# +------+ | +---+
|
||||
# | | |
|
||||
|
@ -47,8 +47,8 @@ Constants
|
||||
* ``MS3_OPT_USE_HTTP`` - Use ``http://`` instead of ``https://``. The ``value`` parameter of :c:func:`ms3_set_option` is unused and each call to this toggles the flag (HTTPS is used by default)
|
||||
* ``MS3_OPT_DISABLE_SSL_VERIFY`` - Disable SSL verification. The ``value`` parameter of :c:func:`ms3_set_option` is unused and each call to this toggles the flag (SSL verification is on by default)
|
||||
* ``MS3_OPT_BUFFER_CHUNK_SIZE`` - Set the chunk size in bytes for the receive buffer. Default is 1MB. If you are receiving a large file a realloc will have to happen every time the buffer is full. For performance reasons you may want to increase the size of this buffer to reduce the reallocs and associated memory copies. The ``value`` parameter of :c:func:`ms3_set_option` should be a pointer to a :c:type:`size_t` greater than 1.
|
||||
* ``MS3_OPT_FORCE_LIST_VERSION`` - Forces :c:func:`ms3_list` to use a specific version of the List Bucket API call. Default is ``2`` for Amazon S3 and ``1`` for other hosts. The ``value`` parameter of :c:func:`ms3_set_option` should be a pointer to a :c:type:`uint8_t` of value ``1`` or ``2``
|
||||
|
||||
* ``MS3_OPT_FORCE_LIST_VERSION`` - An internal option for the regression suite only. The ``value`` parameter of :c:func:`ms3_set_option` should be a pointer to a :c:type:`uint8_t` of value ``1`` or ``2``
|
||||
* ``MS3_OPT_FORCE_PROTOCOL_VERSION`` - Set to 1 to force talking to the S3 server using path buckets and version 1 of the List Bucket API, this is for S3 compatible servers. Set to 2 to force talking to the S3 server using domain buckets and version 2 of the List Bucket API. This is for use when the autodetect bsaed on providing a base_domain does the wrong thing. The ``value`` parameter of :c:func:`ms3_set_option` should be a pointer to a :c:type:`uint8_t` of value ``1`` or ``2``
|
||||
|
||||
Built-In Types
|
||||
==============
|
||||
|
@ -4,10 +4,11 @@ Version History
|
||||
Version 3.0
|
||||
-----------
|
||||
|
||||
Version 3.0.3
|
||||
Version 3.1.0
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
* Fix compiling issue in C90 mode
|
||||
* Fix compiling issues when -Wdeclaration-after-statement is enabled
|
||||
* Add ``MS3_OPT_FORCE_PROTOCOL_VERSION`` for use with :c:func:`ms3_set_option` which will force use of AWS S3 methods and paths (version 2) or compatible methods and paths (version 1)
|
||||
|
||||
Version 3.0.2 GA (2019-05-24)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -79,7 +79,8 @@ enum ms3_set_option_t
|
||||
MS3_OPT_USE_HTTP,
|
||||
MS3_OPT_DISABLE_SSL_VERIFY,
|
||||
MS3_OPT_BUFFER_CHUNK_SIZE,
|
||||
MS3_OPT_FORCE_LIST_VERSION
|
||||
MS3_OPT_FORCE_LIST_VERSION,
|
||||
MS3_OPT_FORCE_PROTOCOL_VERSION
|
||||
};
|
||||
|
||||
typedef enum ms3_set_option_t ms3_set_option_t;
|
||||
|
@ -126,6 +126,7 @@ AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS],
|
||||
_APPEND_COMPILE_FLAGS_ERROR([-Wformat=2])
|
||||
_APPEND_COMPILE_FLAGS_ERROR([-Wformat-y2k])
|
||||
_APPEND_COMPILE_FLAGS_ERROR([-Wmissing-field-initializers])
|
||||
_APPEND_COMPILE_FLAGS_ERROR([-Wdeclaration-after-statement])
|
||||
AS_IF([test "x$MINGW" = xyes],
|
||||
[_APPEND_COMPILE_FLAGS_ERROR([-Wno-missing-noreturn])],
|
||||
[_APPEND_COMPILE_FLAGS_ERROR([-Wmissing-noreturn])])
|
||||
|
@ -96,11 +96,13 @@ ms3_st *ms3_init(const char *s3key, const char *s3secret,
|
||||
ms3->base_domain = ms3_cstrdup(base_domain);
|
||||
// Assume that S3-compatible APIs can't support v2 list
|
||||
ms3->list_version = 1;
|
||||
ms3->protocol_version = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ms3->base_domain = NULL;
|
||||
ms3->list_version = 2;
|
||||
ms3->protocol_version = 2;
|
||||
}
|
||||
|
||||
ms3->buffer_chunk_size = READ_BUFFER_DEFAULT_SIZE;
|
||||
@ -391,6 +393,27 @@ uint8_t ms3_set_option(ms3_st *ms3, ms3_set_option_t option, void *value)
|
||||
break;
|
||||
}
|
||||
|
||||
case MS3_OPT_FORCE_PROTOCOL_VERSION:
|
||||
{
|
||||
uint8_t protocol_version;
|
||||
|
||||
if (!value)
|
||||
{
|
||||
return MS3_ERR_PARAMETER;
|
||||
}
|
||||
|
||||
protocol_version = *(uint8_t *)value;
|
||||
|
||||
if (protocol_version < 1 || protocol_version > 2)
|
||||
{
|
||||
return MS3_ERR_PARAMETER;
|
||||
}
|
||||
|
||||
ms3->protocol_version = protocol_version;
|
||||
ms3->list_version = protocol_version;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return MS3_ERR_PARAMETER;
|
||||
}
|
||||
|
@ -52,7 +52,8 @@ static void set_error_nocopy(ms3_st *ms3, char *error)
|
||||
}
|
||||
|
||||
static uint8_t build_request_uri(CURL *curl, const char *base_domain,
|
||||
const char *bucket, const char *object, const char *query, bool use_http)
|
||||
const char *bucket, const char *object, const char *query, bool use_http,
|
||||
uint8_t protocol_version)
|
||||
{
|
||||
char uri_buffer[MAX_URI_LENGTH];
|
||||
const char *domain;
|
||||
@ -87,7 +88,7 @@ static uint8_t build_request_uri(CURL *curl, const char *base_domain,
|
||||
return MS3_ERR_URI_TOO_LONG;
|
||||
}
|
||||
|
||||
if (base_domain)
|
||||
if (protocol_version == 1)
|
||||
{
|
||||
snprintf(uri_buffer, MAX_URI_LENGTH - 1, "%s://%s/%s%s?%s", protocol,
|
||||
domain, bucket,
|
||||
@ -108,7 +109,7 @@ static uint8_t build_request_uri(CURL *curl, const char *base_domain,
|
||||
return MS3_ERR_URI_TOO_LONG;
|
||||
}
|
||||
|
||||
if (base_domain)
|
||||
if (protocol_version == 1)
|
||||
{
|
||||
snprintf(uri_buffer, MAX_URI_LENGTH - 1, "%s://%s/%s%s", protocol,
|
||||
domain,
|
||||
@ -392,7 +393,8 @@ static uint8_t build_request_headers(CURL *curl, struct curl_slist **head,
|
||||
const char *base_domain, const char *region, const char *key,
|
||||
const char *secret, const char *object, const char *query,
|
||||
uri_method_t method, const char *bucket, const char *source_bucket,
|
||||
const char *source_key, struct put_buffer_st *post_data)
|
||||
const char *source_key, struct put_buffer_st *post_data,
|
||||
uint8_t protocol_version)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
time_t now;
|
||||
@ -463,7 +465,7 @@ static uint8_t build_request_headers(CURL *curl, struct curl_slist **head,
|
||||
}
|
||||
|
||||
// Builds the request hash
|
||||
if (base_domain)
|
||||
if (protocol_version == 1)
|
||||
{
|
||||
ret = generate_request_hash(method, object, bucket, query, post_hash, headers,
|
||||
has_source,
|
||||
@ -708,7 +710,7 @@ uint8_t execute_request(ms3_st *ms3, command_t cmd, const char *bucket,
|
||||
}
|
||||
|
||||
res = build_request_uri(curl, ms3->base_domain, bucket, path, query,
|
||||
ms3->use_http);
|
||||
ms3->use_http, ms3->protocol_version);
|
||||
|
||||
if (res)
|
||||
{
|
||||
@ -753,7 +755,7 @@ uint8_t execute_request(ms3_st *ms3, command_t cmd, const char *bucket,
|
||||
|
||||
res = build_request_headers(curl, &headers, ms3->base_domain, ms3->region,
|
||||
ms3->s3key, ms3->s3secret, path, query, method, bucket, source_bucket,
|
||||
source_object, &post_data);
|
||||
source_object, &post_data, ms3->protocol_version);
|
||||
|
||||
if (res)
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ struct ms3_st
|
||||
bool use_http;
|
||||
bool disable_verification;
|
||||
uint8_t list_version;
|
||||
uint8_t protocol_version;
|
||||
bool first_run;
|
||||
char *path_buffer;
|
||||
char *query_buffer;
|
||||
|
@ -24,15 +24,16 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
int res;
|
||||
ms3_list_st *list = NULL, *list_it = NULL;
|
||||
uint8_t *data;
|
||||
size_t length;
|
||||
int i;
|
||||
bool found;
|
||||
uint8_t list_version;
|
||||
const char *test_string = "Another one bites the dust";
|
||||
ms3_status_st status;
|
||||
ms3_st *ms3;
|
||||
char *s3key = getenv("S3KEY");
|
||||
char *s3secret = getenv("S3SECRET");
|
||||
char *s3region = getenv("S3REGION");
|
||||
@ -45,8 +46,11 @@ int main(int argc, char *argv[])
|
||||
SKIP_IF_(!s3region, "Environemnt variable S3REGION missing");
|
||||
SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing");
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
ms3_library_init();
|
||||
ms3_st *ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
|
||||
if (s3noverify && !strcmp(s3noverify, "1"))
|
||||
{
|
||||
@ -68,7 +72,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
res = ms3_list(ms3, s3bucket, NULL, &list);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
bool found = false;
|
||||
found = false;
|
||||
list_it = list;
|
||||
|
||||
while (list_it)
|
||||
@ -97,7 +101,7 @@ int main(int argc, char *argv[])
|
||||
ms3_list_free(list);
|
||||
|
||||
// Retry list with V1 API
|
||||
uint8_t list_version = 1;
|
||||
list_version = 1;
|
||||
list = NULL;
|
||||
ms3_set_option(ms3, MS3_OPT_FORCE_LIST_VERSION, &list_version);
|
||||
res = ms3_list(ms3, s3bucket, NULL, &list);
|
||||
|
145
tests/basic_host.c
Normal file
145
tests/basic_host.c
Normal file
@ -0,0 +1,145 @@
|
||||
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
||||
* Copyright 2019 MariaDB Corporation Ab. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <yatl/lite.h>
|
||||
#include <libmarias3/marias3.h>
|
||||
|
||||
/* Tests basic calls with an expicit hostname */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int res;
|
||||
ms3_list_st *list = NULL, *list_it = NULL;
|
||||
uint8_t *data;
|
||||
size_t length;
|
||||
int i;
|
||||
bool found;
|
||||
uint8_t protocol_version;
|
||||
const char *test_string = "Another one bites the dust";
|
||||
const char *default_host = "s3.amazonaws.com";
|
||||
ms3_status_st status;
|
||||
ms3_st *ms3;
|
||||
char *s3key = getenv("S3KEY");
|
||||
char *s3secret = getenv("S3SECRET");
|
||||
char *s3region = getenv("S3REGION");
|
||||
char *s3bucket = getenv("S3BUCKET");
|
||||
char *s3host = getenv("S3HOST");
|
||||
char *s3noverify = getenv("S3NOVERIFY");
|
||||
|
||||
SKIP_IF_(!s3key, "Environemnt variable S3KEY missing");
|
||||
SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing");
|
||||
SKIP_IF_(!s3region, "Environemnt variable S3REGION missing");
|
||||
SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing");
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
if (!s3host || s3host[0] == '\0')
|
||||
{
|
||||
s3host = (char*)default_host;
|
||||
}
|
||||
|
||||
|
||||
ms3_library_init();
|
||||
ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
protocol_version = 2;
|
||||
ms3_set_option(ms3, MS3_OPT_FORCE_PROTOCOL_VERSION, &protocol_version);
|
||||
if (s3noverify && !strcmp(s3noverify, "1"))
|
||||
{
|
||||
ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL);
|
||||
}
|
||||
|
||||
// ms3_debug();
|
||||
ASSERT_NOT_NULL(ms3);
|
||||
|
||||
res = ms3_put(ms3, s3bucket, "test/basic_host.txt",
|
||||
(const uint8_t *)test_string,
|
||||
strlen(test_string));
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
|
||||
// A prefix that will give no results;
|
||||
res = ms3_list(ms3, s3bucket, "asdfghjkl", &list);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
ASSERT_NULL_(list, "List not empty");
|
||||
|
||||
res = ms3_list(ms3, s3bucket, NULL, &list);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
found = false;
|
||||
list_it = list;
|
||||
|
||||
while (list_it)
|
||||
{
|
||||
if (!strncmp(list_it->key, "test/basic_host.txt", 19))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
list_it = list_it->next;
|
||||
}
|
||||
|
||||
ASSERT_EQ_(found, 1, "Created file not found");
|
||||
|
||||
if (list_it)
|
||||
{
|
||||
ASSERT_EQ_(list_it->length, 26, "Created file is unexpected length");
|
||||
ASSERT_NEQ_(list_it->created, 0, "Created file timestamp is bad");
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_TRUE_(false, "No resuts from list");
|
||||
}
|
||||
|
||||
ms3_list_free(list);
|
||||
|
||||
res = ms3_get(ms3, s3bucket, "test/basic_host.txt", &data, &length);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
ASSERT_EQ(length, 26);
|
||||
ASSERT_STREQ((char *)data, test_string);
|
||||
|
||||
for (i = 0; i <= 3; i++)
|
||||
{
|
||||
res = ms3_status(ms3, s3bucket, "test/basic_host.txt", &status);
|
||||
|
||||
if (res == MS3_ERR_NOT_FOUND)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
|
||||
if (res == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(status.length, 26);
|
||||
ASSERT_NEQ(status.created, 0);
|
||||
res = ms3_delete(ms3, s3bucket, "test/basic_host.txt");
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
ms3_free(data);
|
||||
res = ms3_get(ms3, s3bucket, "test/basic_host.txt", &data, &length);
|
||||
ASSERT_NEQ_(res, 0, "Object should error");
|
||||
ASSERT_NULL_(data, "Data should be NULL");
|
||||
ASSERT_EQ_(length, 0, "There should be no data");
|
||||
ms3_deinit(ms3);
|
||||
ms3_library_deinit();
|
||||
return 0;
|
||||
}
|
15
tests/copy.c
15
tests/copy.c
@ -24,12 +24,12 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
int res;
|
||||
ms3_list_st *list = NULL, *list_it = NULL;
|
||||
uint8_t *data;
|
||||
size_t length;
|
||||
bool found, found_orig, found_new;
|
||||
ms3_st *ms3;
|
||||
const char *test_string = "Another one bites the dust";
|
||||
char *s3key = getenv("S3KEY");
|
||||
char *s3secret = getenv("S3SECRET");
|
||||
@ -43,8 +43,11 @@ int main(int argc, char *argv[])
|
||||
SKIP_IF_(!s3region, "Environemnt variable S3REGION missing");
|
||||
SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing");
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
ms3_library_init();
|
||||
ms3_st *ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
|
||||
if (s3noverify && !strcmp(s3noverify, "1"))
|
||||
{
|
||||
@ -65,7 +68,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
res = ms3_list(ms3, s3bucket, NULL, &list);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
bool found = false;
|
||||
found = false;
|
||||
list_it = list;
|
||||
|
||||
while (list_it)
|
||||
@ -98,8 +101,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
res = ms3_list(ms3, s3bucket, NULL, &list);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
bool found_orig = false;
|
||||
bool found_new = false;
|
||||
found_orig = false;
|
||||
found_new = false;
|
||||
list_it = list;
|
||||
|
||||
while (list_it)
|
||||
|
@ -54,15 +54,16 @@ static void *cust_calloc(size_t nmemb, size_t size)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
int res;
|
||||
int i;
|
||||
ms3_list_st *list = NULL, *list_it = NULL;
|
||||
uint8_t *data;
|
||||
size_t length;
|
||||
bool found;
|
||||
uint8_t list_version;
|
||||
const char *test_string = "Another one bites the dust";
|
||||
ms3_status_st status;
|
||||
ms3_st *ms3;
|
||||
char *s3key = getenv("S3KEY");
|
||||
char *s3secret = getenv("S3SECRET");
|
||||
char *s3region = getenv("S3REGION");
|
||||
@ -75,9 +76,12 @@ int main(int argc, char *argv[])
|
||||
SKIP_IF_(!s3region, "Environemnt variable S3REGION missing");
|
||||
SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing");
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
ms3_library_init_malloc(cust_malloc, cust_free, cust_realloc, cust_strdup,
|
||||
cust_calloc);
|
||||
ms3_st *ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
|
||||
if (s3noverify && !strcmp(s3noverify, "1"))
|
||||
{
|
||||
@ -99,7 +103,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
res = ms3_list(ms3, s3bucket, NULL, &list);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
bool found = false;
|
||||
found = false;
|
||||
list_it = list;
|
||||
|
||||
while (list_it)
|
||||
@ -128,7 +132,7 @@ int main(int argc, char *argv[])
|
||||
ms3_list_free(list);
|
||||
|
||||
// Retry list with V1 API
|
||||
uint8_t list_version = 1;
|
||||
list_version = 1;
|
||||
list = NULL;
|
||||
ms3_set_option(ms3, MS3_OPT_FORCE_LIST_VERSION, &list_version);
|
||||
res = ms3_list(ms3, s3bucket, NULL, &list);
|
||||
|
@ -24,22 +24,24 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
uint8_t *data;
|
||||
size_t length;
|
||||
|
||||
const char *errmsg;
|
||||
uint8_t res;
|
||||
ms3_st *ms3 = ms3_init("12345678901234567890",
|
||||
"1234567890123456789012345678901234567890", "us-east-1", NULL);
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
// Enable here so cppcheck shows coverage
|
||||
ms3_debug();
|
||||
ASSERT_NOT_NULL(ms3);
|
||||
const char *errmsg = ms3_error(255);
|
||||
errmsg = ms3_error(255);
|
||||
ASSERT_STREQ(errmsg, "No such error code");
|
||||
errmsg = ms3_error(0);
|
||||
ASSERT_STREQ(errmsg, "No error");
|
||||
uint8_t res = ms3_get(ms3, "bad", "bad/file.txt", &data, &length);
|
||||
res = ms3_get(ms3, "bad", "bad/file.txt", &data, &length);
|
||||
printf("%d\n", res);
|
||||
printf("%s\n", ms3_server_error(ms3));
|
||||
ASSERT_EQ(res, MS3_ERR_AUTH); // Bad auth
|
||||
|
@ -21,6 +21,11 @@ t_basic_LDADD= src/libmarias3.la
|
||||
check_PROGRAMS+= t/basic
|
||||
noinst_PROGRAMS+= t/basic
|
||||
|
||||
t_basic_host_SOURCES= tests/basic_host.c
|
||||
t_basic_host_LDADD= src/libmarias3.la
|
||||
check_PROGRAMS+= t/basic_host
|
||||
noinst_PROGRAMS+= t/basic_host
|
||||
|
||||
t_copy_SOURCES= tests/copy.c
|
||||
t_copy_LDADD= src/libmarias3.la
|
||||
check_PROGRAMS+= t/copy
|
||||
|
@ -24,19 +24,22 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
int res;
|
||||
uint8_t *data;
|
||||
size_t length;
|
||||
size_t new_buffer_size;
|
||||
ms3_st *ms3;
|
||||
char *test_string = malloc(64 * 1024 * 1024);
|
||||
memset(test_string, 'a', 64 * 1024 * 1024);
|
||||
char *s3key = getenv("S3KEY");
|
||||
char *s3secret = getenv("S3SECRET");
|
||||
char *s3region = getenv("S3REGION");
|
||||
char *s3bucket = getenv("S3BUCKET");
|
||||
char *s3host = getenv("S3HOST");
|
||||
char *s3noverify = getenv("S3NOVERIFY");
|
||||
memset(test_string, 'a', 64 * 1024 * 1024);
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
SKIP_IF_(!s3key, "Environemnt variable S3KEY missing");
|
||||
SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing");
|
||||
@ -44,7 +47,7 @@ int main(int argc, char *argv[])
|
||||
SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing");
|
||||
|
||||
ms3_library_init();
|
||||
ms3_st *ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
|
||||
if (s3noverify && !strcmp(s3noverify, "1"))
|
||||
{
|
||||
@ -58,7 +61,7 @@ int main(int argc, char *argv[])
|
||||
(const uint8_t *)test_string,
|
||||
64 * 1024 * 1024);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
size_t new_buffer_size = 4 * 1024 * 1024;
|
||||
new_buffer_size = 4 * 1024 * 1024;
|
||||
res = ms3_set_option(ms3, MS3_OPT_BUFFER_CHUNK_SIZE, &new_buffer_size);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
res = ms3_get(ms3, s3bucket, "test/large_file.dat", &data, &length);
|
||||
|
16
tests/list.c
16
tests/list.c
@ -24,10 +24,11 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
int res;
|
||||
ms3_list_st *list = NULL, *list_it = NULL;
|
||||
ms3_st *ms3;
|
||||
bool found, found_bad;
|
||||
uint8_t list_version;
|
||||
const char *test_string = "Another one bites the dust";
|
||||
char *s3key = getenv("S3KEY");
|
||||
char *s3secret = getenv("S3SECRET");
|
||||
@ -41,8 +42,11 @@ int main(int argc, char *argv[])
|
||||
SKIP_IF_(!s3region, "Environemnt variable S3REGION missing");
|
||||
SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing");
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
ms3_library_init();
|
||||
ms3_st *ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
|
||||
if (s3noverify && !strcmp(s3noverify, "1"))
|
||||
{
|
||||
@ -69,8 +73,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
res = ms3_list_dir(ms3, s3bucket, NULL, &list);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
bool found = false;
|
||||
bool found_bad = false;
|
||||
found = false;
|
||||
found_bad = false;
|
||||
list_it = list;
|
||||
|
||||
while (list_it)
|
||||
@ -99,7 +103,7 @@ int main(int argc, char *argv[])
|
||||
ms3_list_free(list);
|
||||
|
||||
// Retry list with V1 API
|
||||
uint8_t list_version = 1;
|
||||
list_version = 1;
|
||||
list = NULL;
|
||||
ms3_set_option(ms3, MS3_OPT_FORCE_LIST_VERSION, &list_version);
|
||||
res = ms3_list_dir(ms3, s3bucket, NULL, &list);
|
||||
|
@ -97,8 +97,7 @@ static void *delete_thread(void *arg)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
|
||||
int tnum;
|
||||
char *s3key = getenv("S3KEY");
|
||||
@ -108,31 +107,33 @@ int main(int argc, char *argv[])
|
||||
char *s3host = getenv("S3HOST");
|
||||
char *s3noverify = getenv("S3NOVERIFY");
|
||||
bool noverify = false;
|
||||
struct thread_info *tinfo;
|
||||
int start_count;
|
||||
uint8_t res;
|
||||
uint8_t list_version;
|
||||
pthread_attr_t attr;
|
||||
ms3_st *ms3;
|
||||
int res_count;
|
||||
ms3_list_st *list = NULL, *list_it = NULL;
|
||||
|
||||
if (s3noverify && !strcmp(s3noverify, "1"))
|
||||
{
|
||||
noverify = true;
|
||||
}
|
||||
|
||||
struct thread_info *tinfo;
|
||||
|
||||
SKIP_IF_(!s3key, "Environemnt variable S3KEY missing");
|
||||
|
||||
SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing");
|
||||
|
||||
SKIP_IF_(!s3region, "Environemnt variable S3REGION missing");
|
||||
|
||||
SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing");
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
ms3_library_init();
|
||||
|
||||
// ms3_debug(true);
|
||||
|
||||
tinfo = calloc(10, sizeof(struct thread_info));
|
||||
|
||||
int start_count = 1000;
|
||||
|
||||
pthread_attr_t attr;
|
||||
start_count = 1000;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
|
||||
@ -161,19 +162,17 @@ int main(int argc, char *argv[])
|
||||
|
||||
free(tinfo);
|
||||
|
||||
uint8_t res;
|
||||
ms3_st *ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
|
||||
if (noverify)
|
||||
{
|
||||
ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL);
|
||||
}
|
||||
|
||||
ms3_list_st *list = NULL, *list_it = NULL;
|
||||
res = ms3_list(ms3, s3bucket, "listtest/", &list);
|
||||
ASSERT_EQ(res, 0);
|
||||
list_it = list;
|
||||
int res_count = 0;
|
||||
res_count = 0;
|
||||
|
||||
while (list_it)
|
||||
{
|
||||
@ -186,7 +185,7 @@ int main(int argc, char *argv[])
|
||||
ms3_list_free(list);
|
||||
|
||||
// Reattempt with list version 1
|
||||
uint8_t list_version = 1;
|
||||
list_version = 1;
|
||||
list = NULL;
|
||||
ms3_set_option(ms3, MS3_OPT_FORCE_LIST_VERSION, &list_version);
|
||||
res = ms3_list(ms3, s3bucket, "listtest/", &list);
|
||||
|
@ -25,11 +25,12 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
int res;
|
||||
ms3_list_st *list = NULL, *list_it = NULL;
|
||||
int i;
|
||||
ms3_st *ms3;
|
||||
bool found_good, found_bad;
|
||||
uint8_t file_count;
|
||||
const char *test_string = "Another one bites the dust";
|
||||
char *s3key = getenv("S3KEY");
|
||||
char *s3secret = getenv("S3SECRET");
|
||||
@ -43,7 +44,10 @@ int main(int argc, char *argv[])
|
||||
SKIP_IF_(!s3region, "Environemnt variable S3REGION missing");
|
||||
SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing");
|
||||
|
||||
ms3_st *ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
|
||||
if (s3noverify && !strcmp(s3noverify, "1"))
|
||||
{
|
||||
@ -60,15 +64,15 @@ int main(int argc, char *argv[])
|
||||
strlen(test_string));
|
||||
ASSERT_EQ(res, 0);
|
||||
|
||||
bool found_good = false;
|
||||
bool found_bad = false;
|
||||
found_good = false;
|
||||
found_bad = false;
|
||||
|
||||
for (i = 0; i <= 3; i++)
|
||||
{
|
||||
res = ms3_list(ms3, s3bucket, "test", &list);
|
||||
ASSERT_EQ(res, 0);
|
||||
list_it = list;
|
||||
uint8_t file_count = 0;
|
||||
file_count = 0;
|
||||
|
||||
while (list_it)
|
||||
{
|
||||
|
@ -24,27 +24,30 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
int res;
|
||||
uint8_t *data;
|
||||
size_t length;
|
||||
size_t new_buffer_size;
|
||||
ms3_st *ms3;
|
||||
char *test_string = malloc(64 * 1024);
|
||||
memset(test_string, 'a', 64 * 1024);
|
||||
char *s3key = getenv("S3KEY");
|
||||
char *s3secret = getenv("S3SECRET");
|
||||
char *s3region = getenv("S3REGION");
|
||||
char *s3bucket = getenv("S3BUCKET");
|
||||
char *s3host = getenv("S3HOST");
|
||||
char *s3noverify = getenv("S3NOVERIFY");
|
||||
memset(test_string, 'a', 64 * 1024);
|
||||
|
||||
SKIP_IF_(!s3key, "Environemnt variable S3KEY missing");
|
||||
SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing");
|
||||
SKIP_IF_(!s3region, "Environemnt variable S3REGION missing");
|
||||
SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing");
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
ms3_library_init();
|
||||
ms3_st *ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
ms3 = ms3_init(s3key, s3secret, s3region, s3host);
|
||||
|
||||
if (s3noverify && !strcmp(s3noverify, "1"))
|
||||
{
|
||||
@ -58,7 +61,7 @@ int main(int argc, char *argv[])
|
||||
(const uint8_t *)test_string,
|
||||
64 * 1024);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
size_t new_buffer_size = 64 * 1024;
|
||||
new_buffer_size = 64 * 1024;
|
||||
res = ms3_set_option(ms3, MS3_OPT_BUFFER_CHUNK_SIZE, &new_buffer_size);
|
||||
ASSERT_EQ_(res, 0, "Result: %u", res);
|
||||
res = ms3_get(ms3, s3bucket, "test/small_buffer.dat", &data, &length);
|
||||
|
15
yatl/lite.h
15
yatl/lite.h
@ -139,8 +139,9 @@ do \
|
||||
{ \
|
||||
if ((__expression)) { \
|
||||
size_t ask= snprintf(0, 0, __VA_ARGS__); \
|
||||
char *buffer; \
|
||||
ask++; \
|
||||
char *buffer= (char*)alloca(sizeof(char) * ask); \
|
||||
buffer= (char*)alloca(sizeof(char) * ask); \
|
||||
snprintf(buffer, ask, __VA_ARGS__); \
|
||||
if (YATL_FULL) { \
|
||||
SKIP(#__expression, buffer); \
|
||||
@ -179,8 +180,9 @@ do \
|
||||
{ \
|
||||
if ((__expression) != NULL) { \
|
||||
size_t ask= snprintf(0, 0, __VA_ARGS__); \
|
||||
char *buffer; \
|
||||
ask++; \
|
||||
char *buffer= (char*)alloca(sizeof(char) * ask); \
|
||||
buffer= (char*)alloca(sizeof(char) * ask); \
|
||||
snprintf(buffer, ask, __VA_ARGS__); \
|
||||
if (YATL_FULL) { \
|
||||
FAIL("Assertion '%s' != NULL [ %s ]", #__expression, buffer);\
|
||||
@ -223,8 +225,9 @@ do \
|
||||
{ \
|
||||
if (! (__expression)) { \
|
||||
size_t ask= snprintf(0, 0, __VA_ARGS__); \
|
||||
char *buffer; \
|
||||
ask++; \
|
||||
char *buffer= (char*)alloca(sizeof(char) * ask); \
|
||||
buffer= (char*)alloca(sizeof(char) * ask); \
|
||||
snprintf(buffer, ask, __VA_ARGS__); \
|
||||
if (YATL_FULL) { \
|
||||
FAIL("Assertion '%s' [ %s ]", #__expression, buffer); \
|
||||
@ -251,8 +254,9 @@ do \
|
||||
{ \
|
||||
if ((__expected) != (__actual)) { \
|
||||
size_t ask= snprintf(0, 0, __VA_ARGS__); \
|
||||
char *buffer; \
|
||||
ask++; \
|
||||
char *buffer= (char*)alloca(sizeof(char) * ask); \
|
||||
buffer= (char*)alloca(sizeof(char) * ask); \
|
||||
snprintf(buffer, ask, __VA_ARGS__); \
|
||||
if (YATL_FULL) { \
|
||||
FAIL("Assertion '%s' != '%s' [ %s ]", #__expected, #__actual, buffer); \
|
||||
@ -391,8 +395,9 @@ do \
|
||||
{ \
|
||||
if ((__expected) == (__actual)) { \
|
||||
size_t ask= snprintf(0, 0, __VA_ARGS__); \
|
||||
char *buffer; \
|
||||
ask++; \
|
||||
char *buffer= (char*)alloca(sizeof(char) * ask); \
|
||||
buffer= (char*)alloca(sizeof(char) * ask); \
|
||||
snprintf(buffer, ask, __VA_ARGS__); \
|
||||
if (YATL_FULL) { \
|
||||
FAIL("Assertion '%s' == '%s' [ %s ]", #__expected, #__actual, buffer); \
|
||||
|
Loading…
x
Reference in New Issue
Block a user