Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add multi-object delete capability #94

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ ifndef CFLAGS
endif
endif

ifeq ($(LIBS3_DEBUG),YES)
CFLAGS += -DLIBS3_DEBUG -DSIGNATURE_DEBUG
else
CFLAGS += -ULIBS3_DEBUG -USIGNATURE_DEBUG -DNDEBUG
endif

CFLAGS += -Wall -Werror -Wshadow -Wextra -Iinc \
$(CURL_CFLAGS) $(LIBXML2_CFLAGS) \
-DLIBS3_VER_MAJOR=\"$(LIBS3_VER_MAJOR)\" \
Expand Down Expand Up @@ -245,7 +251,7 @@ libs3: $(LIBS3_SHARED) $(LIBS3_STATIC)
LIBS3_SOURCES := bucket.c bucket_metadata.c error_parser.c general.c \
object.c request.c request_context.c \
response_headers_handler.c service_access_logging.c \
service.c simplexml.c util.c multipart.c
service.c simplexml.c util.c multipart.c md5base64.c

$(LIBS3_SHARED): $(LIBS3_SOURCES:%.c=$(BUILD)/obj/%.do)
$(QUIET_ECHO) $@: Building shared library
Expand Down
45 changes: 45 additions & 0 deletions inc/libs3.h
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,40 @@ void S3_delete_object(const S3BucketContext *bucketContext, const char *key,
int timeoutMs,
const S3ResponseHandler *handler, void *callbackData);

/**
* An array of allocated DeleteMultipleObjectSingleResult is passed to
* S3_delete_multiple_objects. The array must be allocated and freed by the
* client code.
**/
typedef struct DeleteMultipleObjectSingleResult
{
char key[S3_MAX_KEY_SIZE];
int keyLen;
S3Status status;
} DeleteMultipleObjectSingleResult;

/**
* Deletes multiple object from S3.
*
* @param bucketContext gives the bucket and associated parameters for this
* request
* @param keysCount is has the number of keys in the array
* @param keys is an array of key of the objects to delete
* @param requestContext if non-NULL, gives the S3RequestContext to add this
* request to, and does not perform the request immediately. If NULL,
* performs the request immediately and synchronously.
* @param timeoutMs if not 0 contains total request timeout in milliseconds
* @param handler gives the callbacks to call as the request is processed and
* completed
* @param callbackData will be passed in as the callbackData parameter to
* all callbacks for this request
**/
void S3_delete_multiple_objects(const S3BucketContext *bucketContext,
int keysCount, const char *keys[],
DeleteMultipleObjectSingleResult **results, int *resultsLen, int *errorCount,
S3RequestContext *requestContext,
int timeoutMs,
const S3ResponseHandler *handler, void *callbackData);

/** **************************************************************************
* Access Control List Functions
Expand Down Expand Up @@ -2619,4 +2653,15 @@ void S3_list_multipart_uploads(S3BucketContext *bucketContext,
}
#endif

#ifdef LIBS3_DEBUG

#define debug_printf(fmt, ...) \
fprintf(stderr, fmt"\n", __VA_ARGS__)

#else

#define debug_printf(fmt, ...)

#endif

#endif /* LIBS3_H */
41 changes: 41 additions & 0 deletions inc/md5base64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/** **************************************************************************
* md5base64.h
*
* Copyright 2008 Bryan Ischo <[email protected]>
*
* This file is part of libs3.
*
* libs3 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, version 3 or above of the License. You can also
* redistribute and/or modify it under the terms of the GNU General Public
* License, version 2 or above of the License.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of this library and its programs with the
* OpenSSL library, and distribute linked combinations including the two.
*
* libs3 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 General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with libs3, in a file named COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
* You should also have received a copy of the GNU General Public License
* version 2 along with libs3, in a file named COPYING-GPLv2. If not, see
* <http://www.gnu.org/licenses/>.
*
************************************************************************** **/

#ifndef MD5BASE64_H
#define MD5BASE64_H

#define MD5_BASE64_BUFFER_LENGTH 16 * 2

// Calculate MD5 and encode it as base64
void generate_content_md5(const char* data, int size, char* retBuffer, int retBufferSize);

#endif //MD5BASE64_H
49 changes: 2 additions & 47 deletions src/bucket_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@
#include <stdlib.h>
#include <string.h>

#ifndef __APPLE__
#include <openssl/md5.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/buffer.h>
#endif

#include "libs3.h"
#include "request.h"
#include "md5base64.h"

// Use a rather arbitrary max size for the document of 64K
#define ACL_XML_DOC_MAXSIZE (64 * 1024)
Expand Down Expand Up @@ -482,45 +476,6 @@ void S3_get_lifecycle(const S3BucketContext *bucketContext,
}


#ifndef __APPLE__
// Calculate MD5 and encode it as base64
void generate_content_md5(const char* data, int size,
char* retBuffer, int retBufferSize) {
MD5_CTX mdContext;
BIO *bio, *b64;
BUF_MEM *bufferPtr;

char md5Buffer[MD5_DIGEST_LENGTH];

MD5_Init(&mdContext);
MD5_Update(&mdContext, data, size);
MD5_Final((unsigned char*)md5Buffer, &mdContext);


b64 = BIO_new(BIO_f_base64());
bio = BIO_new(BIO_s_mem());
bio = BIO_push(b64, bio);

BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Ignore newlines - write everything in one line
BIO_write(bio, md5Buffer, sizeof(md5Buffer));
(void) BIO_flush(bio);
BIO_get_mem_ptr(bio, &bufferPtr);
(void) BIO_set_close(bio, BIO_NOCLOSE);

if ((unsigned int)retBufferSize + 1 < bufferPtr->length) {
retBuffer[0] = '\0';
BIO_free_all(bio);
return;
}

memcpy(retBuffer, bufferPtr->data, bufferPtr->length);
retBuffer[bufferPtr->length] = '\0';

BIO_free_all(bio);
}
#endif


void S3_set_lifecycle(const S3BucketContext *bucketContext,
const char *lifecycleXmlDocument,
S3RequestContext *requestContext,
Expand All @@ -535,7 +490,7 @@ void S3_set_lifecycle(const S3BucketContext *bucketContext,
(*(handler->completeCallback))(S3StatusNotSupported, 0, callbackData);
return;
#else
char md5Base64[MD5_DIGEST_LENGTH * 2];
char md5Base64[MD5_BASE64_BUFFER_LENGTH];

SetXmlData *data = (SetXmlData *) malloc(sizeof(SetXmlData));
if (!data) {
Expand Down
84 changes: 84 additions & 0 deletions src/md5base64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/** **************************************************************************
* md5base64.c
*
* Copyright 2008 Bryan Ischo <[email protected]>
*
* This file is part of libs3.
*
* libs3 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, version 3 or above of the License. You can also
* redistribute and/or modify it under the terms of the GNU General Public
* License, version 2 or above of the License.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of this library and its programs with the
* OpenSSL library, and distribute linked combinations including the two.
*
* libs3 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 General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with libs3, in a file named COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
* You should also have received a copy of the GNU General Public License
* version 2 along with libs3, in a file named COPYING-GPLv2. If not, see
* <http://www.gnu.org/licenses/>.
*
************************************************************************** **/

#ifndef __APPLE__
#include <openssl/md5.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/buffer.h>

#include <string.h>

// Calculate MD5 and encode it as base64
void generate_content_md5(const char* data, int size,
char* retBuffer, int retBufferSize) {
MD5_CTX mdContext;
BIO *bio, *b64;
BUF_MEM *bufferPtr;

char md5Buffer[MD5_DIGEST_LENGTH];

MD5_Init(&mdContext);
MD5_Update(&mdContext, data, size);
MD5_Final((unsigned char*)md5Buffer, &mdContext);


b64 = BIO_new(BIO_f_base64());
bio = BIO_new(BIO_s_mem());
bio = BIO_push(b64, bio);

BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Ignore newlines - write everything in one line
BIO_write(bio, md5Buffer, sizeof(md5Buffer));
(void) BIO_flush(bio);
BIO_get_mem_ptr(bio, &bufferPtr);
(void) BIO_set_close(bio, BIO_NOCLOSE);

#if OPENSSL_VERSION_NUMBER < 0x1000207fL
// Older version of OpenSSL have buffer lengths as ints
// 0x1000207fL is just an arbitrary version based on Ubuntu 16.04
if (retBufferSize + 1 < bufferPtr->length) {
#else
// Newer version have size_t instead of int
if ((size_t)(retBufferSize + 1UL) < bufferPtr->length) {
#endif
retBuffer[0] = '\0';
BIO_free_all(bio);
return;
}

memcpy(retBuffer, bufferPtr->data, bufferPtr->length);
retBuffer[bufferPtr->length] = '\0';

BIO_free_all(bio);
}
#endif

Loading