From d8bf53ffde8f1a2c62806a35879a1a208a14a1bc Mon Sep 17 00:00:00 2001 From: DenverM80 Date: Wed, 12 Jul 2017 10:58:37 -0600 Subject: [PATCH] update templates to current c sdk match after https://github.com/SpectraLogic/ds3_c_sdk/pull/205 --- .../source-templates/ds3_init_requests.ftl | 18 ++++++++++++------ .../source-templates/ds3_requests.ftl | 18 ++++++++---------- .../internal_request_processors.ftl | 9 +++++---- .../source-templates/modify_request.ftl | 12 ++++++------ 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/ds3-autogen-c/src/main/resources/templates/source-templates/ds3_init_requests.ftl b/ds3-autogen-c/src/main/resources/templates/source-templates/ds3_init_requests.ftl index 239c4a43..9d4a00a9 100644 --- a/ds3-autogen-c/src/main/resources/templates/source-templates/ds3_init_requests.ftl +++ b/ds3-autogen-c/src/main/resources/templates/source-templates/ds3_init_requests.ftl @@ -10,12 +10,18 @@ #include "ds3_request.h" #include "ds3_net.h" -//The max size of an uint32_t should be 10 characters + NULL -static const char UNSIGNED_LONG_BASE_10[] = "4294967296"; -static const unsigned int UNSIGNED_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_BASE_10) + 1; -//The max size of an uint64_t should be 20 characters + NULL -static const char UNSIGNED_LONG_LONG_BASE_10[] = "18446744073709551615"; -static const unsigned int UNSIGNED_LONG_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_LONG_BASE_10) + 1; +#ifdef _WIN32 + #include + #ifndef PRIu64 + #define PRIu64 "I64u" + #endif +#else + #include +#endif + +//The max size of an uint32_t is 10 characters + NULL +//The max size of an uint64_t is 20 characters + NULL +#define STRING_BUFFER_SIZE 32 <#-- ********************************************* --> <#-- Generate "_get_enum_str()" --> diff --git a/ds3-autogen-c/src/main/resources/templates/source-templates/ds3_requests.ftl b/ds3-autogen-c/src/main/resources/templates/source-templates/ds3_requests.ftl index b966589d..0c6aa369 100644 --- a/ds3-autogen-c/src/main/resources/templates/source-templates/ds3_requests.ftl +++ b/ds3-autogen-c/src/main/resources/templates/source-templates/ds3_requests.ftl @@ -12,19 +12,17 @@ #include "ds3_utils.h" #ifdef _WIN32 -#include + #include + #ifndef PRIu64 + #define PRIu64 "I64u" + #endif #else -#include + #include #endif - -//The max size of an uint32_t should be 10 characters + NULL -static const char UNSIGNED_LONG_BASE_10[] = "4294967296"; -static const unsigned int UNSIGNED_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_BASE_10) + 1; -//The max size of an uint64_t should be 20 characters + NULL -static const char UNSIGNED_LONG_LONG_BASE_10[] = "18446744073709551615"; -static const unsigned int UNSIGNED_LONG_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_LONG_BASE_10) + 1; - +//The max size of an uint32_t is 10 characters + NULL +//The max size of an uint64_t is 20 characters + NULL +#define STRING_BUFFER_SIZE 32 <#include "metadata.ftl"/> <#include "xml_helpers.ftl"/> diff --git a/ds3-autogen-c/src/main/resources/templates/source-templates/internal_request_processors.ftl b/ds3-autogen-c/src/main/resources/templates/source-templates/internal_request_processors.ftl index f54a00fc..85d3b37f 100644 --- a/ds3-autogen-c/src/main/resources/templates/source-templates/internal_request_processors.ftl +++ b/ds3-autogen-c/src/main/resources/templates/source-templates/internal_request_processors.ftl @@ -70,7 +70,7 @@ static ds3_error* _get_request_xml_nodes( } static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_response* obj_list, object_list_type list_type, ds3_job_chunk_client_processing_order_guarantee order) { - char size_buff[UNSIGNED_LONG_LONG_BASE_10_STR_LEN]; + char size_buff[STRING_BUFFER_SIZE]; xmlDocPtr doc; ds3_bulk_object_response* obj; xmlNodePtr objects_node, object_node; @@ -93,7 +93,8 @@ static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_resp for (obj_index = 0; obj_index < obj_list->num_objects; obj_index++) { obj = obj_list->objects[obj_index]; - g_snprintf(size_buff, sizeof(char) * UNSIGNED_LONG_LONG_BASE_10_STR_LEN, "%" PRIu64, obj->length); + memset(size_buff, 0, sizeof(size_buff)); + g_snprintf(size_buff, STRING_BUFFER_SIZE, "%" PRIu64, obj->length); object_node = xmlNewNode(NULL, (xmlChar*) "Object"); xmlAddChild(objects_node, object_node); @@ -110,7 +111,7 @@ static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_resp } static xmlDocPtr _generate_xml_complete_mpu(const ds3_complete_multipart_upload_response* mpu_list) { - char size_buff[UNSIGNED_LONG_LONG_BASE_10_STR_LEN]; + char size_buff[STRING_BUFFER_SIZE]; xmlDocPtr doc; ds3_multipart_upload_part_response* part; xmlNodePtr parts_node, part_node; @@ -126,7 +127,7 @@ static xmlDocPtr _generate_xml_complete_mpu(const ds3_complete_multipart_upload_ part_node = xmlNewNode(NULL, (xmlChar*) "Part"); xmlAddChild(parts_node, part_node); - g_snprintf(size_buff, sizeof(char) * UNSIGNED_LONG_LONG_BASE_10_STR_LEN, "%d", part->part_number); + g_snprintf(size_buff, STRING_BUFFER_SIZE, "%d", part->part_number); xmlNewTextChild(part_node, NULL, (xmlChar*) "PartNumber", (xmlChar*) size_buff); xmlNewTextChild(part_node, NULL, (xmlChar*) "ETag", (xmlChar*) part->etag->value); diff --git a/ds3-autogen-c/src/main/resources/templates/source-templates/modify_request.ftl b/ds3-autogen-c/src/main/resources/templates/source-templates/modify_request.ftl index 390f6276..b5fea7e6 100644 --- a/ds3-autogen-c/src/main/resources/templates/source-templates/modify_request.ftl +++ b/ds3-autogen-c/src/main/resources/templates/source-templates/modify_request.ftl @@ -101,23 +101,23 @@ static void _set_query_param_flag(const ds3_request* _request, const char* key, } static void _set_query_param_uint64_t(const ds3_request* _request, const char* key, uint64_t value) { - char string_buffer[UNSIGNED_LONG_LONG_BASE_10_STR_LEN]; + char string_buffer[STRING_BUFFER_SIZE]; memset(string_buffer, 0, sizeof(string_buffer)); - snprintf(string_buffer, sizeof(string_buffer), "%" PRIu64, value); + g_snprintf(string_buffer, sizeof(string_buffer), "%" PRIu64, value); _set_query_param(_request, key, string_buffer); } static void _set_query_param_int(const ds3_request* _request, const char* key, int value) { - char string_buffer[UNSIGNED_LONG_BASE_10_STR_LEN]; + char string_buffer[STRING_BUFFER_SIZE]; memset(string_buffer, 0, sizeof(string_buffer)); - snprintf(string_buffer, sizeof(string_buffer), "%d", value); + g_snprintf(string_buffer, sizeof(string_buffer), "%d", value); _set_query_param(_request, key, string_buffer); } static void _set_query_param_float(const ds3_request* _request, const char* key, float value) { - char string_buffer[UNSIGNED_LONG_BASE_10_STR_LEN]; + char string_buffer[STRING_BUFFER_SIZE]; memset(string_buffer, 0, sizeof(string_buffer)); - snprintf(string_buffer, sizeof(string_buffer), "%f", value); + g_snprintf(string_buffer, sizeof(string_buffer), "%f", value); _set_query_param(_request, key, string_buffer); }