Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ add_library(ds3 SHARED
ds3_uint64_string_map.h ds3_uint64_string_map.c
ds3_response_header_utils.h ds3_response_header_utils.c
ds3_bool.h
ds3_library_exports.h)
ds3_library_exports.h
ds3_marshaling.h)

if (WIN32)
set(CMAKE_BUILD_TYPE Release)
Expand Down Expand Up @@ -89,6 +90,7 @@ else(WIN32)
"ds3_response_header_utils.h"
"ds3_bool.h"
"ds3_library_exports.h"
"ds3_marshaling.h"
DESTINATION
"/usr/local/include")
install(TARGETS ds3 DESTINATION lib)
Expand Down
2 changes: 1 addition & 1 deletion src/ds3_library_exports.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ******************************************************************************
* Copyright 2014-2017 Spectra Logic Corporation. All Rights Reserved.
* Copyright 2014-2018 Spectra Logic Corporation. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
Expand Down
51 changes: 51 additions & 0 deletions src/ds3_marshaling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* ******************************************************************************
* Copyright 2014-2018 Spectra Logic Corporation. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* ****************************************************************************
*/

#ifndef DS3_MARSHALING_H
#define DS3_MARSHALING_H

#include <libxml/parser.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
BULK_PUT,
BULK_GET,
BULK_DELETE,
GET_PHYSICAL_PLACEMENT,
COMPLETE_MPU,
STRING,
STRING_LIST,
ID_LIST,
DATA
}object_list_type;

typedef struct {
char* buff;
size_t size;
size_t total_read;
}ds3_xml_send_buff;

xmlDocPtr ds3_generate_xml_ids(ds3_ids_list* ids_list);
xmlDocPtr ds3_generate_xml_delete_objects(ds3_delete_objects_response* keys_list);
xmlDocPtr ds3_generate_xml_complete_mpu(const ds3_complete_multipart_upload_response* mpu_list);
xmlDocPtr ds3_generate_xml_bulk_objects_list(const ds3_bulk_object_list_response* obj_list, object_list_type list_type);

#ifdef __cplusplus
}
#endif
#endif
38 changes: 10 additions & 28 deletions src/ds3_requests.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "ds3_string_multimap_impl.h"
#include "ds3_uint64_string_map.h"
#include "ds3_utils.h"
#include "ds3_marshaling.h"

#ifdef _WIN32
#include <io.h>
Expand Down Expand Up @@ -311,13 +312,6 @@ static ds3_bool xml_get_bool_from_attribute(const ds3_log* log, xmlDocPtr doc, s
return xml_get_bool(log, doc, (xmlNodePtr) attribute);
}

typedef struct {
char* buff;
size_t size;
size_t total_read;
}ds3_xml_send_buff;


static size_t _ds3_send_xml_buff(void* buffer, size_t size, size_t nmemb, void* user_data) {
size_t to_read;
size_t remaining;
Expand All @@ -336,18 +330,6 @@ static size_t _ds3_send_xml_buff(void* buffer, size_t size, size_t nmemb, void*
return to_read;
}

typedef enum {
BULK_PUT,
BULK_GET,
BULK_DELETE,
GET_PHYSICAL_PLACEMENT,
COMPLETE_MPU,
STRING,
STRING_LIST,
ID_LIST,
DATA
}object_list_type;

static ds3_error* _internal_request_dispatcher(
const ds3_client* client,
const ds3_request* request,
Expand Down Expand Up @@ -408,7 +390,7 @@ static ds3_error* _get_request_xml_nodes(
return NULL;
}

static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_response* obj_list, object_list_type list_type) {
xmlDocPtr ds3_generate_xml_bulk_objects_list(const ds3_bulk_object_list_response* obj_list, object_list_type list_type) {
char size_buff[STRING_BUFFER_SIZE];
xmlDocPtr doc;
ds3_bulk_object_response* obj;
Expand Down Expand Up @@ -442,7 +424,7 @@ static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_resp
return doc;
}

static xmlDocPtr _generate_xml_complete_mpu(const ds3_complete_multipart_upload_response* mpu_list) {
xmlDocPtr ds3_generate_xml_complete_mpu(const ds3_complete_multipart_upload_response* mpu_list) {
char size_buff[STRING_BUFFER_SIZE];
xmlDocPtr doc;
ds3_multipart_upload_part_response* part;
Expand All @@ -469,7 +451,7 @@ static xmlDocPtr _generate_xml_complete_mpu(const ds3_complete_multipart_upload_
return doc;
}

static xmlDocPtr _generate_xml_delete_objects(ds3_delete_objects_response* keys_list) {
xmlDocPtr ds3_generate_xml_delete_objects(ds3_delete_objects_response* keys_list) {
xmlDocPtr doc;
ds3_str* key;
xmlNodePtr del_node, obj_node;
Expand All @@ -492,7 +474,7 @@ static xmlDocPtr _generate_xml_delete_objects(ds3_delete_objects_response* keys_
return doc;
}

static xmlDocPtr _generate_xml_ids(ds3_ids_list* ids_list) {
xmlDocPtr ds3_generate_xml_ids(ds3_ids_list* ids_list) {
xmlDocPtr doc;
ds3_str* key;
xmlNodePtr ids_node, id_node;
Expand All @@ -505,7 +487,7 @@ static xmlDocPtr _generate_xml_ids(ds3_ids_list* ids_list) {
for (id_num = 0; id_num < ids_list->num_strings; id_num++) {
key = ids_list->strings_list[id_num];

xmlNewTextChild(id_node, NULL, (xmlChar*) "Id", (xmlChar*) key->value);
id_node = xmlNewTextChild(ids_node, NULL, (xmlChar*) "Id", (xmlChar*) key->value);
xmlAddChild(ids_node, id_node);
}

Expand All @@ -530,29 +512,29 @@ static ds3_error* _init_request_payload(const ds3_request* _request,
if (request->object_list == NULL || request->object_list->num_objects == 0) {
return ds3_create_error(DS3_ERROR_MISSING_ARGS, "The bulk command requires a list of objects to process");
}
doc = _generate_xml_bulk_objects_list(request->object_list, operation_type);
doc = ds3_generate_xml_bulk_objects_list(request->object_list, operation_type);
break;

case COMPLETE_MPU:
if (request->mpu_list == NULL || request->mpu_list->num_parts == 0) {
return ds3_create_error(DS3_ERROR_MISSING_ARGS, "The complete multipart upload command requires a list of objects to process");
}
doc = _generate_xml_complete_mpu(request->mpu_list);
doc = ds3_generate_xml_complete_mpu(request->mpu_list);
break;

case BULK_DELETE:
case STRING_LIST:
if (request->delete_objects == NULL || request->delete_objects->num_strings == 0) {
return ds3_create_error(DS3_ERROR_MISSING_ARGS, "The delete objects command requires a list of objects to process");
}
doc = _generate_xml_delete_objects(request->delete_objects);
doc = ds3_generate_xml_delete_objects(request->delete_objects);
break;

case ID_LIST:
if (request->ids == NULL || request->ids->num_strings == 0) {
return ds3_create_error(DS3_ERROR_MISSING_ARGS, "The suspect blob command requires a list of ids to process");
}
doc = _generate_xml_ids(request->ids);
doc = ds3_generate_xml_ids(request->ids);
break;

case STRING: // *** not XML - do not interpret
Expand Down
51 changes: 30 additions & 21 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../modules/")

add_definitions(-DCURL_STATICLIB)

add_executable(ds3_c_tests
bucket_tests.cpp
bulk_get.cpp
bulk_put.cpp
checksum.cpp
connection_tests.cpp
deletes_test.cpp
get_object.cpp
get_physical_placement.cpp
job_tests.cpp
metadata_tests.cpp
multimap_tests.cpp
negative_tests.cpp
put_directory.cpp
search_tests.cpp
service_tests.cpp
unit_tests.cpp
test.cpp)

add_test(regression_tests ds3_c_tests)

if (WIN32)
find_package(Boost 1.59.0)
include_directories(${Boost_INCLUDE_DIRS})
Expand All @@ -33,7 +54,16 @@ if (WIN32)
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${WINDOWS_VS_OUTPUT_DIR} )
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )

target_link_libraries(ds3_c_tests ${WINDOWS_INSTALL_LIB_DIR}/libxml2_a.lib)

else(WIN32) # POSIX
find_package(LibXml2 2.9 REQUIRED)

if (LIBXML2_FOUND)
include_directories(${LIBXML2_INCLUDE_DIR})
target_link_libraries (ds3_c_tests ${LIBXML2_LIBRARIES})
endif (LIBXML2_FOUND)

add_definitions(-DBOOST_TEST_DYN_LINK)
set(CMAKE_CXX_FLAGS "-g -Wall")

Expand Down Expand Up @@ -63,27 +93,6 @@ else(WIN32) # POSIX
#set(CMAKE_BUILD_TYPE Debug)
endif(WIN32)

add_executable(ds3_c_tests
bucket_tests.cpp
bulk_get.cpp
bulk_put.cpp
checksum.cpp
connection_tests.cpp
deletes_test.cpp
get_object.cpp
get_physical_placement.cpp
job_tests.cpp
metadata_tests.cpp
multimap_tests.cpp
negative_tests.cpp
put_directory.cpp
search_tests.cpp
service_tests.cpp
unit_tests.cpp
test.cpp)

add_test(regression_tests ds3_c_tests)

target_link_libraries(ds3_c_tests ds3 glib-2.0 boost_unit_test_framework)

find_program(VALGRIND "valgrind")
Expand Down
Loading