Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of azure_c_shared_utility by
Revision 19:2e0811512ceb, committed 2017-01-28
- Comitter:
- AzureIoTClient
- Date:
- Sat Jan 28 09:35:22 2017 -0800
- Parent:
- 18:6d8a413a4d9a
- Child:
- 20:95abdea56064
- Commit message:
- 1.1.6
Changed in this revision
--- a/azure_c_shared_utility/crt_abstractions.h Fri Jan 13 18:41:15 2017 -0800 +++ b/azure_c_shared_utility/crt_abstractions.h Sat Jan 28 09:35:22 2017 -0800 @@ -93,8 +93,6 @@ #define STRUNCATE 80 #endif /* !defined (STRUNCATE) */ -typedef int errno_t; - extern int strcpy_s(char* dst, size_t dstSizeInBytes, const char* src); extern int strcat_s(char* dst, size_t dstSizeInBytes, const char* src); extern int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount);
--- a/azure_c_shared_utility/gballoc.h Fri Jan 13 18:41:15 2017 -0800
+++ b/azure_c_shared_utility/gballoc.h Sat Jan 28 09:35:22 2017 -0800
@@ -4,16 +4,12 @@
#ifndef GBALLOC_H
#define GBALLOC_H
-
#ifdef __cplusplus
-#include <cstdlib>
+#include <cstddef>
extern "C"
{
#else
-#include <stdlib.h>
-#endif
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
+#include <stddef.h>
#endif
#include "azure_c_shared_utility/umock_c_prod.h"
@@ -34,6 +30,8 @@
/* if GB_MEASURE_MEMORY_FOR_THIS is defined then we want to redirect memory allocation functions to gballoc_xxx functions */
#ifdef GB_MEASURE_MEMORY_FOR_THIS
+/* Unfortunately this is still needed here for things to still compile when using _CRTDBG_MAP_ALLOC.
+That is because there is a rogue component (most likely CppUnitTest) including crtdbg. */
#if defined(_CRTDBG_MAP_ALLOC) && defined(_DEBUG)
#undef _malloc_dbg
#undef _calloc_dbg
--- a/azure_c_shared_utility/optionhandler.h Fri Jan 13 18:41:15 2017 -0800 +++ b/azure_c_shared_utility/optionhandler.h Sat Jan 28 09:35:22 2017 -0800 @@ -35,10 +35,11 @@ /*returns 0 if _SetOption succeeded, any other value is error, if the option is not intended for that module, returns 0*/ typedef int (*pfSetOption)(void* handle, const char* name, const void* value); -MOCKABLE_FUNCTION(,OPTIONHANDLER_HANDLE, OptionHandler_Create, pfCloneOption, cloneOption, pfDestroyOption, destroyOption, pfSetOption, setOption); -MOCKABLE_FUNCTION(,OPTIONHANDLER_RESULT, OptionHandler_AddOption, OPTIONHANDLER_HANDLE, handle, const char*, name, const void*, value); -MOCKABLE_FUNCTION(,OPTIONHANDLER_RESULT, OptionHandler_FeedOptions, OPTIONHANDLER_HANDLE, handle, void*, destinationHandle); -MOCKABLE_FUNCTION(,void, OptionHandler_Destroy, OPTIONHANDLER_HANDLE, handle); +MOCKABLE_FUNCTION(, OPTIONHANDLER_HANDLE, OptionHandler_Create, pfCloneOption, cloneOption, pfDestroyOption, destroyOption, pfSetOption, setOption); +MOCKABLE_FUNCTION(, OPTIONHANDLER_HANDLE, OptionHandler_Clone, OPTIONHANDLER_HANDLE, handler); +MOCKABLE_FUNCTION(, OPTIONHANDLER_RESULT, OptionHandler_AddOption, OPTIONHANDLER_HANDLE, handle, const char*, name, const void*, value); +MOCKABLE_FUNCTION(, OPTIONHANDLER_RESULT, OptionHandler_FeedOptions, OPTIONHANDLER_HANDLE, handle, void*, destinationHandle); +MOCKABLE_FUNCTION(, void, OptionHandler_Destroy, OPTIONHANDLER_HANDLE, handle); #ifdef __cplusplus }
--- a/azure_c_shared_utility/refcount.h Fri Jan 13 18:41:15 2017 -0800 +++ b/azure_c_shared_utility/refcount.h Sat Jan 28 09:35:22 2017 -0800 @@ -24,7 +24,7 @@ #include <stdint.h> #endif - +#include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/macro_utils.h" #if defined(__STDC_VERSION__) && (__STDC_VERSION__ == 201112) && (__STDC_NO_ATOMICS__!=1)
--- a/azure_c_shared_utility/vector.h Fri Jan 13 18:41:15 2017 -0800 +++ b/azure_c_shared_utility/vector.h Sat Jan 28 09:35:22 2017 -0800 @@ -17,12 +17,11 @@ #include <stdbool.h> #endif -typedef struct VECTOR_TAG* VECTOR_HANDLE; - -typedef bool(*PREDICATE_FUNCTION)(const void* element, const void* value); +#include "azure_c_shared_utility/vector_types.h" /* creation */ MOCKABLE_FUNCTION(, VECTOR_HANDLE, VECTOR_create, size_t, elementSize); +MOCKABLE_FUNCTION(, VECTOR_HANDLE, VECTOR_move, VECTOR_HANDLE, handle); MOCKABLE_FUNCTION(, void, VECTOR_destroy, VECTOR_HANDLE, handle); /* insertion */ @@ -33,17 +32,16 @@ MOCKABLE_FUNCTION(, void, VECTOR_clear, VECTOR_HANDLE, handle); /* access */ -MOCKABLE_FUNCTION(, void*, VECTOR_element, const VECTOR_HANDLE, handle, size_t, index); -MOCKABLE_FUNCTION(, void*, VECTOR_front, const VECTOR_HANDLE, handle); -MOCKABLE_FUNCTION(, void*, VECTOR_back, const VECTOR_HANDLE, handle); -MOCKABLE_FUNCTION(, void*, VECTOR_find_if, const VECTOR_HANDLE, handle, PREDICATE_FUNCTION, pred, const void*, value); +MOCKABLE_FUNCTION(, void*, VECTOR_element, VECTOR_HANDLE, handle, size_t, index); +MOCKABLE_FUNCTION(, void*, VECTOR_front, VECTOR_HANDLE, handle); +MOCKABLE_FUNCTION(, void*, VECTOR_back, VECTOR_HANDLE, handle); +MOCKABLE_FUNCTION(, void*, VECTOR_find_if, VECTOR_HANDLE, handle, PREDICATE_FUNCTION, pred, const void*, value); /* capacity */ -MOCKABLE_FUNCTION(, size_t, VECTOR_size, const VECTOR_HANDLE, handle); +MOCKABLE_FUNCTION(, size_t, VECTOR_size, VECTOR_HANDLE, handle); #ifdef __cplusplus } -#else #endif #endif /* VECTOR_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/azure_c_shared_utility/vector_types.h Sat Jan 28 09:35:22 2017 -0800
@@ -0,0 +1,23 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+#ifndef VECTOR_TYPES_H
+#define VECTOR_TYPES_H
+
+#ifdef __cplusplus
+#include <cstdbool>
+extern "C"
+{
+#else
+#include <stdbool.h>
+#endif
+
+typedef struct VECTOR_TAG* VECTOR_HANDLE;
+
+typedef bool(*PREDICATE_FUNCTION)(const void* element, const void* value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* VECTOR_TYPES_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/azure_c_shared_utility/vector_types_internal.h Sat Jan 28 09:35:22 2017 -0800
@@ -0,0 +1,20 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+#ifndef VECTOR_TYPES_INTERNAL_H
+#define VECTOR_TYPES_INTERNAL_H
+
+#ifdef __cplusplus
+#include <cstddef>
+#else
+#include <stddef.h>
+#endif
+
+typedef struct VECTOR_TAG
+{
+ void* storage;
+ size_t count;
+ size_t elementSize;
+} VECTOR;
+
+#endif /* VECTOR_TYPES_INTERNAL_H */
--- a/base64.c Fri Jan 13 18:41:15 2017 -0800 +++ b/base64.c Sat Jan 28 09:35:22 2017 -0800 @@ -1,21 +1,10 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -// -// PUT NO INCLUDES BEFORE HERE !!!! -// #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include "azure_c_shared_utility/gballoc.h" - #include <stddef.h> -#include <string.h> #include <stdint.h> -// -// PUT NO CLIENT LIBRARY INCLUDES BEFORE HERE !!!! -// #include "azure_c_shared_utility/base64.h" #include "azure_c_shared_utility/xlogging.h"
--- a/buffer.c Fri Jan 13 18:41:15 2017 -0800
+++ b/buffer.c Sat Jan 28 09:35:22 2017 -0800
@@ -1,21 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-// PUT NO INCLUDES BEFORE HERE
-//
#include <stdlib.h>
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
-#include "azure_c_shared_utility/gballoc.h"
-
#include <stddef.h>
#include <string.h>
-//
-// PUT NO CLIENT LIBRARY INCLUDES BEFORE HERE
-//
-
+#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/buffer_.h"
#include "azure_c_shared_utility/xlogging.h"
@@ -90,7 +79,7 @@
else
{
/*Codes_SRS_BUFFER_02_004: [Otherwise, BUFFER_create shall return a non-NULL handle.] */
- memcpy(result->buffer, source, size);
+ (void)memcpy(result->buffer, source, size);
}
}
}
@@ -472,7 +461,7 @@
}
else
{
- memcpy(b->buffer, suppliedBuff->buffer, suppliedBuff->size);
+ (void)memcpy(b->buffer, suppliedBuff->buffer, suppliedBuff->size);
b->size = suppliedBuff->size;
result = (BUFFER_HANDLE)b;
}
--- a/condition_rtx_mbed.cpp Fri Jan 13 18:41:15 2017 -0800 +++ b/condition_rtx_mbed.cpp Sat Jan 28 09:35:22 2017 -0800 @@ -1,11 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#include <cstdlib> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif - #include "azure_c_shared_utility/lock.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/condition.h"
--- a/consolelogger.c Fri Jan 13 18:41:15 2017 -0800 +++ b/consolelogger.c Sat Jan 28 09:35:22 2017 -0800 @@ -1,12 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include <stdarg.h> #include <stdio.h> +#include <time.h> #include "azure_c_shared_utility/xlogging.h" void consolelogger_log(LOG_CATEGORY log_category, const char* file, const char* func, const int line, unsigned int options, const char* format, ...)
--- a/constbuffer.c Fri Jan 13 18:41:15 2017 -0800
+++ b/constbuffer.c Sat Jan 28 09:35:22 2017 -0800
@@ -5,11 +5,8 @@
// PUT NO INCLUDES BEFORE HERE
//
#include <stdlib.h>
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
+#include <stddef.h>
#include "azure_c_shared_utility/gballoc.h"
-
#include "azure_c_shared_utility/constbuffer.h"
#include "azure_c_shared_utility/xlogging.h"
#include "azure_c_shared_utility/refcount.h"
@@ -59,7 +56,7 @@
/*Codes_SRS_CONSTBUFFER_02_004: [Otherwise CONSTBUFFER_Create shall return a non-NULL handle.]*/
/*Codes_SRS_CONSTBUFFER_02_007: [Otherwise, CONSTBUFFER_CreateFromBuffer shall copy the content of buffer.]*/
/*Codes_SRS_CONSTBUFFER_02_009: [Otherwise, CONSTBUFFER_CreateFromBuffer shall return a non-NULL handle.]*/
- memcpy(temp, source, size);
+ (void)memcpy(temp, source, size);
result->alias.buffer = temp;
}
}
--- a/constmap.c Fri Jan 13 18:41:15 2017 -0800 +++ b/constmap.c Sat Jan 28 09:35:22 2017 -0800 @@ -2,11 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif +#include <stdbool.h> +#include <stddef.h> #include "azure_c_shared_utility/gballoc.h" - #include "azure_c_shared_utility/map.h" #include "azure_c_shared_utility/constmap.h" #include "azure_c_shared_utility/xlogging.h"
--- a/crt_abstractions.c Fri Jan 13 18:41:15 2017 -0800
+++ b/crt_abstractions.c Sat Jan 28 09:35:22 2017 -0800
@@ -4,17 +4,14 @@
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdlib.h>
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
-#include "azure_c_shared_utility/gballoc.h"
-
-#include "azure_c_shared_utility/crt_abstractions.h"
-#include "errno.h"
#include <stddef.h>
+#include <stdarg.h>
#include <limits.h>
#include <float.h>
#include <math.h>
+#include <errno.h>
+#include "azure_c_shared_utility/gballoc.h"
+#include "azure_c_shared_utility/crt_abstractions.h"
#if defined (WINCE) || defined (TIZENRT)
@@ -36,8 +33,6 @@
#ifdef _MSC_VER
#else
-#include <stdarg.h>
-
/*Codes_SRS_CRT_ABSTRACTIONS_99_008: [strcat_s shall append the src to dst and terminates the resulting string with a null character.]*/
int strcat_s(char* dst, size_t dstSizeInBytes, const char* src)
{
@@ -202,7 +197,7 @@
}
else
{
- memcpy(dst, src, neededBuffer + 1);
+ (void)memcpy(dst, src, neededBuffer + 1);
/*Codes_SRS_CRT_ABSTRACTIONS_99_011: [strcpy_s shall return Zero upon success]*/
result = 0;
}
--- a/doublylinkedlist.c Fri Jan 13 18:41:15 2017 -0800 +++ b/doublylinkedlist.c Sat Jan 28 09:35:22 2017 -0800 @@ -1,10 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include "azure_c_shared_utility/doublylinkedlist.h" void
--- a/gballoc.c Fri Jan 13 18:41:15 2017 -0800 +++ b/gballoc.c Sat Jan 28 09:35:22 2017 -0800 @@ -2,13 +2,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif - +#include <stdint.h> +#include <stddef.h> #include "azure_c_shared_utility/lock.h" #include "azure_c_shared_utility/xlogging.h" -#include <stdint.h> #ifndef SIZE_MAX #define SIZE_MAX ((size_t)~(size_t)0)
--- a/hmac.c Fri Jan 13 18:41:15 2017 -0800 +++ b/hmac.c Sat Jan 28 09:35:22 2017 -0800 @@ -10,12 +10,6 @@ * various SHA algorithms. */ -#include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif -#include "azure_c_shared_utility/gballoc.h" - #include "azure_c_shared_utility/sha.h" /*
--- a/hmacsha256.c Fri Jan 13 18:41:15 2017 -0800
+++ b/hmacsha256.c Sat Jan 28 09:35:22 2017 -0800
@@ -1,15 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-#include <stdlib.h>
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
-#include "azure_c_shared_utility/gballoc.h"
-
+#include <stddef.h>
#include "azure_c_shared_utility/hmacsha256.h"
#include "azure_c_shared_utility/hmac.h"
-#include "azure_c_shared_utility/strings.h"
+#include "azure_c_shared_utility/buffer_.h"
HMACSHA256_RESULT HMACSHA256_ComputeHash(const unsigned char* key, size_t keyLen, const unsigned char* payload, size_t payloadLen, BUFFER_HANDLE hash)
{
--- a/httpapi_compact.c Fri Jan 13 18:41:15 2017 -0800 +++ b/httpapi_compact.c Sat Jan 28 09:35:22 2017 -0800 @@ -2,12 +2,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif - #include <stdio.h> #include <ctype.h> +#include <string.h> +#include <limits.h> #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/httpheaders.h" #include "azure_c_shared_utility/crt_abstractions.h" @@ -17,8 +15,6 @@ #include "azure_c_shared_utility/tlsio.h" #include "azure_c_shared_utility/threadapi.h" #include "azure_c_shared_utility/shared_util_options.h" -#include <string.h> -#include <limits.h> /*Codes_SRS_HTTPAPI_COMPACT_21_001: [ The httpapi_compact shall implement the methods defined by the `httpapi.h`. ]*/ /*Codes_SRS_HTTPAPI_COMPACT_21_002: [ The httpapi_compact shall support the http requests. ]*/
--- a/httpapiex.c Fri Jan 13 18:41:15 2017 -0800 +++ b/httpapiex.c Sat Jan 28 09:35:22 2017 -0800 @@ -2,11 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include "azure_c_shared_utility/gballoc.h" - #include "azure_c_shared_utility/httpapiex.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/strings.h"
--- a/httpapiexsas.c Fri Jan 13 18:41:15 2017 -0800 +++ b/httpapiexsas.c Sat Jan 28 09:35:22 2017 -0800 @@ -2,14 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include "azure_c_shared_utility/gballoc.h" - #include <stddef.h> #include <time.h> - #include "azure_c_shared_utility/agenttime.h" #include "azure_c_shared_utility/strings.h" #include "azure_c_shared_utility/buffer_.h"
--- a/httpheaders.c Fri Jan 13 18:41:15 2017 -0800 +++ b/httpheaders.c Sat Jan 28 09:35:22 2017 -0800 @@ -2,11 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include "azure_c_shared_utility/gballoc.h" - #include "azure_c_shared_utility/map.h" #include "azure_c_shared_utility/httpheaders.h" #include <string.h>
--- a/lock_rtx_mbed.cpp Fri Jan 13 18:41:15 2017 -0800 +++ b/lock_rtx_mbed.cpp Sat Jan 28 09:35:22 2017 -0800 @@ -1,11 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#include <cstdlib> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif - #include "azure_c_shared_utility/lock.h" #include "azure_c_shared_utility/xlogging.h" #include "rtos.h"
--- a/map.c Fri Jan 13 18:41:15 2017 -0800
+++ b/map.c Sat Jan 28 09:35:22 2017 -0800
@@ -2,10 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdlib.h>
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
-
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/map.h"
#include "azure_c_shared_utility/xlogging.h"
@@ -431,7 +427,7 @@
}
else
{
- memcpy(newValue, value, valueLength + 1);
+ (void)memcpy(newValue, value, valueLength + 1);
handleData->values[index] = newValue;
/*Codes_SRS_MAP_02_019: [Otherwise, Map_AddOrUpdate shall return MAP_OK.] */
result = MAP_OK;
--- a/optionhandler.c Fri Jan 13 18:41:15 2017 -0800
+++ b/optionhandler.c Sat Jan 28 09:35:22 2017 -0800
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+#include <stdlib.h>
#include "azure_c_shared_utility/optionhandler.h"
#include "azure_c_shared_utility/xlogging.h"
#include "azure_c_shared_utility/gballoc.h"
@@ -20,6 +21,102 @@
VECTOR_HANDLE storage;
}OPTIONHANDLER_HANDLE_DATA;
+static OPTIONHANDLER_HANDLE CreateInternal(pfCloneOption cloneOption, pfDestroyOption destroyOption, pfSetOption setOption)
+{
+ OPTIONHANDLER_HANDLE result;
+
+ result = (OPTIONHANDLER_HANDLE_DATA*)malloc(sizeof(OPTIONHANDLER_HANDLE_DATA));
+ if (result == NULL)
+ {
+ /*Codes_SRS_OPTIONHANDLER_02_004: [ Otherwise, OptionHandler_Create shall fail and return NULL. ]*/
+ LogError("unable to malloc");
+ /*return as is*/
+ }
+ else
+ {
+ /*Codes_SRS_OPTIONHANDLER_02_002: [ OptionHandler_Create shall create an empty VECTOR that will hold pairs of const char* and void*. ]*/
+ result->storage = VECTOR_create(sizeof(OPTION));
+ if (result->storage == NULL)
+ {
+ /*Codes_SRS_OPTIONHANDLER_02_004: [ Otherwise, OptionHandler_Create shall fail and return NULL. ]*/
+ LogError("unable to VECTOR_create");
+ free(result);
+ result = NULL;
+ }
+ else
+ {
+ /*Codes_SRS_OPTIONHANDLER_02_003: [ If all the operations succeed then OptionHandler_Create shall succeed and return a non-NULL handle. ]*/
+ result->cloneOption = cloneOption;
+ result->destroyOption = destroyOption;
+ result->setOption = setOption;
+ /*return as is*/
+ }
+ }
+
+ return result;
+}
+
+static OPTIONHANDLER_RESULT AddOptionInternal(OPTIONHANDLER_HANDLE handle, const char* name, const void* value)
+{
+ OPTIONHANDLER_RESULT result;
+ const char* cloneOfName;
+ if (mallocAndStrcpy_s((char**)&cloneOfName, name) != 0)
+ {
+ /*Codes_SRS_OPTIONHANDLER_02_009: [ Otherwise, OptionHandler_AddProperty shall succeed and return OPTIONHANDLER_ERROR. ]*/
+ LogError("unable to clone name");
+ result = OPTIONHANDLER_ERROR;
+ }
+ else
+ {
+ /*Codes_SRS_OPTIONHANDLER_02_006: [ OptionHandler_AddProperty shall call pfCloneOption passing name and value. ]*/
+ void* cloneOfValue = handle->cloneOption(name, value);
+ if (cloneOfValue == NULL)
+ {
+ /*Codes_SRS_OPTIONHANDLER_02_009: [ Otherwise, OptionHandler_AddProperty shall succeed and return OPTIONHANDLER_ERROR. ]*/
+ LogError("unable to clone value");
+ free((void*)cloneOfName);
+ result = OPTIONHANDLER_ERROR;
+ }
+ else
+ {
+ OPTION temp;
+ temp.name = cloneOfName;
+ temp.storage = cloneOfValue;
+ /*Codes_SRS_OPTIONHANDLER_02_007: [ OptionHandler_AddProperty shall use VECTOR APIs to save the name and the newly created clone of value. ]*/
+ if (VECTOR_push_back(handle->storage, &temp, 1) != 0)
+ {
+ /*Codes_SRS_OPTIONHANDLER_02_009: [ Otherwise, OptionHandler_AddProperty shall succeed and return OPTIONHANDLER_ERROR. ]*/
+ LogError("unable to VECTOR_push_back");
+ handle->destroyOption(name, cloneOfValue);
+ free((void*)cloneOfName);
+ result = OPTIONHANDLER_ERROR;
+ }
+ else
+ {
+ /*Codes_SRS_OPTIONHANDLER_02_008: [ If all the operations succed then OptionHandler_AddProperty shall succeed and return OPTIONHANDLER_OK. ]*/
+ result = OPTIONHANDLER_OK;
+ }
+ }
+ }
+
+ return result;
+}
+
+static void DestroyInternal(OPTIONHANDLER_HANDLE handle)
+{
+ /*Codes_SRS_OPTIONHANDLER_02_016: [ Otherwise, OptionHandler_Destroy shall free all used resources. ]*/
+ size_t nOptions = VECTOR_size(handle->storage), i;
+ for (i = 0; i < nOptions; i++)
+ {
+ OPTION* option = (OPTION*)VECTOR_element(handle->storage, i);
+ handle->destroyOption(option->name, option->storage);
+ free((void*)option->name);
+ }
+
+ VECTOR_destroy(handle->storage);
+ free(handle);
+}
+
OPTIONHANDLER_HANDLE OptionHandler_Create(pfCloneOption cloneOption, pfDestroyOption destroyOption, pfSetOption setOption)
{
/*Codes_SRS_OPTIONHANDLER_02_001: [ OptionHandler_Create shall fail and retun NULL if any parameters are NULL. ]*/
@@ -35,36 +132,64 @@
}
else
{
- result = (OPTIONHANDLER_HANDLE_DATA*)malloc(sizeof(OPTIONHANDLER_HANDLE_DATA));
+ result = CreateInternal(cloneOption, destroyOption, setOption);
+ }
+
+ return result;
+
+}
+
+OPTIONHANDLER_HANDLE OptionHandler_Clone(OPTIONHANDLER_HANDLE handler)
+{
+ OPTIONHANDLER_HANDLE_DATA* result;
+
+ if (handler == NULL)
+ {
+ /* Codes_SRS_OPTIONHANDLER_01_010: [ If `handler` is NULL, OptionHandler_Clone shall fail and return NULL. ]*/
+ LogError("NULL argument: handler");
+ result = NULL;
+ }
+ else
+ {
+ /* Codes_SRS_OPTIONHANDLER_01_001: [ `OptionHandler_Clone` shall clone an existing option handler instance. ]*/
+ /* Codes_SRS_OPTIONHANDLER_01_002: [ On success it shall return a non-NULL handle. ]*/
+ /* Codes_SRS_OPTIONHANDLER_01_003: [ `OptionHandler_Clone` shall allocate memory for the new option handler instance. ]*/
+ result = CreateInternal(handler->cloneOption, handler->destroyOption, handler->setOption);
if (result == NULL)
{
- /*Codes_SRS_OPTIONHANDLER_02_004: [ Otherwise, OptionHandler_Create shall fail and return NULL. ]*/
- LogError("unable to malloc");
- /*return as is*/
+ /* Codes_SRS_OPTIONHANDLER_01_004: [ If allocating memory fails, `OptionHandler_Clone` shall return NULL. ]*/
+ LogError("unable to create option handler");
}
else
{
- /*Codes_SRS_OPTIONHANDLER_02_002: [ OptionHandler_Create shall create an empty VECTOR that will hold pairs of const char* and void*. ]*/
- result->storage = VECTOR_create(sizeof(OPTION));
- if (result->storage == NULL)
+ /* Codes_SRS_OPTIONHANDLER_01_005: [ `OptionHandler_Clone` shall iterate through all the options stored by the option handler to be cloned by using VECTOR's iteration mechanism. ]*/
+ size_t option_count = VECTOR_size(handler->storage);
+ size_t i;
+
+ for (i = 0; i < option_count; i++)
{
- /*Codes_SRS_OPTIONHANDLER_02_004: [ Otherwise, OptionHandler_Create shall fail and return NULL. ]*/
- LogError("unable to VECTOR_create");
- free(result);
- result= NULL;
+ OPTION* option = (OPTION*)VECTOR_element(handler->storage, i);
+
+ /* Codes_SRS_OPTIONHANDLER_01_006: [ For each option the option name shall be cloned by calling `mallocAndStrcpy_s`. ]*/
+ /* Codes_SRS_OPTIONHANDLER_01_007: [ For each option the value shall be cloned by using the cloning function associated with the source option handler `handler`. ]*/
+ if (AddOptionInternal(result, option->name, option->storage) != OPTIONHANDLER_OK)
+ {
+ /* Codes_SRS_OPTIONHANDLER_01_008: [ If cloning one of the option names fails, `OptionHandler_Clone` shall return NULL. ]*/
+ /* Codes_SRS_OPTIONHANDLER_01_009: [ If cloning one of the option values fails, `OptionHandler_Clone` shall return NULL. ]*/
+ LogError("Error cloning option %s", option->name);
+ break;
+ }
}
- else
+
+ if (i < option_count)
{
- /*Codes_SRS_OPTIONHANDLER_02_003: [ If all the operations succeed then OptionHandler_Create shall succeed and return a non-NULL handle. ]*/
- result->cloneOption = cloneOption;
- result->destroyOption = destroyOption;
- result->setOption = setOption;
- /*return as is*/
+ DestroyInternal(result);
+ result = NULL;
}
}
}
+
return result;
-
}
OPTIONHANDLER_RESULT OptionHandler_AddOption(OPTIONHANDLER_HANDLE handle, const char* name, const void* value)
@@ -82,46 +207,9 @@
}
else
{
- const char* cloneOfName;
- if (mallocAndStrcpy_s((char**)&cloneOfName, name) != 0)
- {
- /*Codes_SRS_OPTIONHANDLER_02_009: [ Otherwise, OptionHandler_AddProperty shall succeed and return OPTIONHANDLER_ERROR. ]*/
- LogError("unable to clone name");
- result = OPTIONHANDLER_ERROR;
- }
- else
- {
- /*Codes_SRS_OPTIONHANDLER_02_006: [ OptionHandler_AddProperty shall call pfCloneOption passing name and value. ]*/
- void* cloneOfValue = handle->cloneOption(name, value);
- if (cloneOfValue == NULL)
- {
- /*Codes_SRS_OPTIONHANDLER_02_009: [ Otherwise, OptionHandler_AddProperty shall succeed and return OPTIONHANDLER_ERROR. ]*/
- LogError("unable to clone value");
- free((void*)cloneOfName);
- result = OPTIONHANDLER_ERROR;
- }
- else
- {
- OPTION temp;
- temp.name = cloneOfName;
- temp.storage = cloneOfValue;
- /*Codes_SRS_OPTIONHANDLER_02_007: [ OptionHandler_AddProperty shall use VECTOR APIs to save the name and the newly created clone of value. ]*/
- if (VECTOR_push_back(handle->storage, &temp, 1) != 0)
- {
- /*Codes_SRS_OPTIONHANDLER_02_009: [ Otherwise, OptionHandler_AddProperty shall succeed and return OPTIONHANDLER_ERROR. ]*/
- LogError("unable to VECTOR_push_back");
- handle->destroyOption(name, cloneOfValue);
- free((void*)cloneOfName);
- result = OPTIONHANDLER_ERROR;
- }
- else
- {
- /*Codes_SRS_OPTIONHANDLER_02_008: [ If all the operations succed then OptionHandler_AddProperty shall succeed and return OPTIONHANDLER_OK. ]*/
- result = OPTIONHANDLER_OK;
- }
- }
- }
+ result = AddOptionInternal(handle, name, value);
}
+
return result;
}
@@ -175,16 +263,6 @@
}
else
{
- /*Codes_SRS_OPTIONHANDLER_02_016: [ Otherwise, OptionHandler_Destroy shall free all used resources. ]*/
- size_t nOptions = VECTOR_size(handle->storage), i;
- for (i = 0;i < nOptions;i++)
- {
- OPTION* option = (OPTION*)VECTOR_element(handle->storage, i);
- handle->destroyOption(option->name, option->storage);
- free((void*)option->name);
- }
-
- VECTOR_destroy(handle->storage);
- free(handle);
+ DestroyInternal(handle);
}
}
--- a/platform_mbed.cpp Fri Jan 13 18:41:15 2017 -0800 +++ b/platform_mbed.cpp Sat Jan 28 09:35:22 2017 -0800 @@ -1,10 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include "azure_c_shared_utility/platform.h" #include "EthernetInterface.h" #include "NTPClient.h"
--- a/sastoken.c Fri Jan 13 18:41:15 2017 -0800 +++ b/sastoken.c Sat Jan 28 09:35:22 2017 -0800 @@ -1,10 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif - +#include <stdlib.h> #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/sastoken.h" #include "azure_c_shared_utility/urlencode.h"
--- a/sha1.c Fri Jan 13 18:41:15 2017 -0800 +++ b/sha1.c Sat Jan 28 09:35:22 2017 -0800 @@ -39,9 +39,6 @@ */ #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/sha.h"
--- a/sha224.c Fri Jan 13 18:41:15 2017 -0800 +++ b/sha224.c Sat Jan 28 09:35:22 2017 -0800 @@ -40,9 +40,6 @@ */ #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/sha.h"
--- a/sha384-512.c Fri Jan 13 18:41:15 2017 -0800 +++ b/sha384-512.c Sat Jan 28 09:35:22 2017 -0800 @@ -43,9 +43,6 @@ */ #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/sha.h"
--- a/singlylinkedlist.c Fri Jan 13 18:41:15 2017 -0800 +++ b/singlylinkedlist.c Sat Jan 28 09:35:22 2017 -0800 @@ -2,11 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif -#include <stdbool.h> - #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/singlylinkedlist.h"
--- a/socketio_mbed.c Fri Jan 13 18:41:15 2017 -0800
+++ b/socketio_mbed.c Sat Jan 28 09:35:22 2017 -0800
@@ -2,10 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdlib.h>
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
-
#include <stddef.h>
#include <stdio.h>
#include <string.h>
@@ -249,15 +245,15 @@
socket_io_instance->io_state = IO_STATE_OPEN;
- if (on_io_open_complete != NULL)
- {
- on_io_open_complete(on_io_open_complete_context, IO_OPEN_OK);
- }
-
result = 0;
}
}
}
+
+ if (on_io_open_complete != NULL)
+ {
+ on_io_open_complete(on_io_open_complete_context, result == 0 ? IO_OPEN_OK : IO_OPEN_ERROR);
+ }
return result;
}
--- a/string_tokenizer.c Fri Jan 13 18:41:15 2017 -0800 +++ b/string_tokenizer.c Sat Jan 28 09:35:22 2017 -0800 @@ -1,19 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -// -// PUT NO INCLUDES BEFORE HERE -// -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif +#include <stdlib.h> #include "azure_c_shared_utility/gballoc.h" - -// -// PUT NO CLIENT LIBRARY INCLUDES BEFORE HERE -// - -#include <stdlib.h> #include <stdbool.h> #include "azure_c_shared_utility/string_tokenizer.h" #include "azure_c_shared_utility/xlogging.h"
--- a/strings.c Fri Jan 13 18:41:15 2017 -0800
+++ b/strings.c Sat Jan 28 09:35:22 2017 -0800
@@ -5,11 +5,7 @@
// PUT NO INCLUDES BEFORE HERE
//
#include <stdlib.h>
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
#include "azure_c_shared_utility/gballoc.h"
-
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
@@ -75,7 +71,7 @@
}
else
{
- memcpy(result->s, source->s, sourceLen + 1);
+ (void)memcpy(result->s, source->s, sourceLen + 1);
}
}
else
@@ -103,7 +99,7 @@
size_t nLen = strlen(psz) + 1;
if ((str->s = (char*)malloc(nLen)) != NULL)
{
- memcpy(str->s, psz, nLen);
+ (void)memcpy(str->s, psz, nLen);
result = (STRING_HANDLE)str;
}
/* Codes_SRS_STRING_07_032: [STRING_construct encounters any error it shall return a NULL value.] */
@@ -232,7 +228,7 @@
if ((result->s = (char*)malloc(sourceLength + 3)) != NULL)
{
result->s[0] = '"';
- memcpy(result->s + 1, source, sourceLength);
+ (void)memcpy(result->s + 1, source, sourceLength);
result->s[sourceLength + 1] = '"';
result->s[sourceLength + 2] = '\0';
}
@@ -386,7 +382,7 @@
else
{
s1->s = temp;
- memcpy(s1->s + s1Length, s2, s2Length + 1);
+ (void)memcpy(s1->s + s1Length, s2, s2Length + 1);
result = 0;
}
}
@@ -422,7 +418,7 @@
{
dest->s = temp;
/* Codes_SRS_STRING_07_034: [String_Concat_with_STRING shall concatenate a given STRING_HANDLE variable with a source STRING_HANDLE.] */
- memcpy(dest->s + s1Length, src->s, s2Length + 1);
+ (void)memcpy(dest->s + s1Length, src->s, s2Length + 1);
result = 0;
}
}
@@ -501,7 +497,7 @@
else
{
s1->s = temp;
- memcpy(s1->s, s2, s2Length);
+ (void)memcpy(s1->s, s2, s2Length);
s1->s[s2Length] = 0;
result = 0;
}
@@ -715,7 +711,7 @@
{
if ((str->s = (char*)malloc(len + 1)) != NULL)
{
- memcpy(str->s, psz, n);
+ (void)memcpy(str->s, psz, n);
str->s[n] = '\0';
result = (STRING_HANDLE)str;
}
@@ -797,7 +793,7 @@
}
else
{
- memcpy(result->s, source, size);
+ (void)memcpy(result->s, source, size);
result->s[size] = '\0'; /*all is fine*/
}
}
--- a/threadapi_rtx_mbed.cpp Fri Jan 13 18:41:15 2017 -0800 +++ b/threadapi_rtx_mbed.cpp Sat Jan 28 09:35:22 2017 -0800 @@ -2,10 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif - #include "azure_c_shared_utility/threadapi.h" #include "azure_c_shared_utility/xlogging.h" #include "rtos.h"
--- a/tickcounter_mbed.cpp Fri Jan 13 18:41:15 2017 -0800 +++ b/tickcounter_mbed.cpp Sat Jan 28 09:35:22 2017 -0800 @@ -1,14 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#include <cstdlib> - -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif - -#include <cstdio> -#include <cctype> #include "mbed.h" #include "azure_c_shared_utility/tickcounter.h"
--- a/tlsio_wolfssl.c Fri Jan 13 18:41:15 2017 -0800
+++ b/tlsio_wolfssl.c Sat Jan 28 09:35:22 2017 -0800
@@ -2,10 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdlib.h>
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
-
#include "wolfssl/ssl.h"
#include "wolfssl/error-ssl.h"
#include <stdio.h>
@@ -136,17 +132,58 @@
static OPTIONHANDLER_HANDLE tlsio_wolfssl_retrieveoptions(CONCRETE_IO_HANDLE tls_io)
{
OPTIONHANDLER_HANDLE result;
- (void)tls_io;
-
- result = OptionHandler_Create(tlsio_wolfssl_CloneOption, tlsio_wolfssl_DestroyOption, tlsio_wolfssl_setoption);
- if (result == NULL)
+ if (tls_io == NULL)
{
- /*return as is*/
+ LogError("NULL tls_io parameter");
+ result = NULL;
}
else
{
- /*insert here work to add the options to "result" handle*/
+ result = OptionHandler_Create(tlsio_wolfssl_CloneOption, tlsio_wolfssl_DestroyOption, tlsio_wolfssl_setoption);
+ if (result == NULL)
+ {
+ LogError("unable to OptionHandler_Create");
+ /*return as is*/
+ }
+ else
+ {
+ /*this layer cares about the certificates and the x509 credentials*/
+ TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;
+ if (
+ (tls_io_instance->x509certificate != NULL) &&
+ (OptionHandler_AddOption(result, SU_OPTION_X509_CERT, tls_io_instance->x509certificate) != 0)
+ )
+ {
+ LogError("unable to save x509certificate option");
+ OptionHandler_Destroy(result);
+ result = NULL;
+ }
+ else if (
+ (tls_io_instance->x509privatekey != NULL) &&
+ (OptionHandler_AddOption(result, SU_OPTION_X509_PRIVATE_KEY, tls_io_instance->x509privatekey) != 0)
+ )
+ {
+ LogError("unable to save x509privatekey option");
+ OptionHandler_Destroy(result);
+ result = NULL;
+ }
+ else if (
+ (tls_io_instance->x509privatekey != NULL) &&
+ (OptionHandler_AddOption(result, "TrustedCerts", tls_io_instance->certificate) != 0)
+ )
+ {
+ LogError("unable to save TrustedCerts option");
+ OptionHandler_Destroy(result);
+ result = NULL;
+ }
+ else
+ {
+ /*all is fine, all interesting options have been saved*/
+ /*return as is*/
+ }
+ }
}
+
return result;
}
@@ -205,6 +242,7 @@
if (open_result != IO_OPEN_OK)
{
+ LogError("Underlying IO open failed");
tls_io_instance->tlsio_state = TLSIO_STATE_ERROR;
indicate_open_complete(tls_io_instance, IO_OPEN_ERROR);
}
@@ -216,6 +254,7 @@
res = wolfSSL_connect(tls_io_instance->ssl);
if (res != SSL_SUCCESS)
{
+ LogError("WolfSSL connect failed");
indicate_open_complete(tls_io_instance, IO_OPEN_ERROR);
tls_io_instance->tlsio_state = TLSIO_STATE_ERROR;
}
@@ -229,6 +268,7 @@
unsigned char* new_socket_io_read_bytes = (unsigned char*)realloc(tls_io_instance->socket_io_read_bytes, tls_io_instance->socket_io_read_byte_count + size);
if (new_socket_io_read_bytes == NULL)
{
+ LogError("Failed allocating memory for received bytes");
tls_io_instance->tlsio_state = TLSIO_STATE_ERROR;
indicate_error(tls_io_instance);
}
@@ -247,6 +287,9 @@
switch (tls_io_instance->tlsio_state)
{
default:
+ LogError("Unknown TLS IO WolfSSL state: %d", (int)tls_io_instance->tlsio_state);
+ break;
+
case TLSIO_STATE_NOT_OPEN:
case TLSIO_STATE_ERROR:
break;
@@ -268,7 +311,11 @@
{
TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
- if (tls_io_instance->tlsio_state == TLSIO_STATE_CLOSING)
+ if (tls_io_instance->tlsio_state != TLSIO_STATE_CLOSING)
+ {
+ LogError("on_underlying_io_close_complete called when not in CLOSING state");
+ }
+ else
{
if (tls_io_instance->on_io_close_complete != NULL)
{
@@ -340,6 +387,7 @@
(void)ssl;
if (xio_send(tls_io_instance->socket_io, buf, sz, tls_io_instance->on_send_complete, tls_io_instance->on_send_complete_callback_context) != 0)
{
+ LogError("Failed sending bytes through underlying IO");
tls_io_instance->tlsio_state = TLSIO_STATE_ERROR;
indicate_error(tls_io_instance);
result = 0;
@@ -356,7 +404,11 @@
{
TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
(void)ssl;
- if (tls_io_instance->tlsio_state == TLSIO_STATE_IN_HANDSHAKE)
+ if (tls_io_instance->tlsio_state != TLSIO_STATE_IN_HANDSHAKE)
+ {
+ LogInfo("on_handshake_done called when not in IN_HANDSHAKE state");
+ }
+ else
{
tls_io_instance->tlsio_state = TLSIO_STATE_OPEN;
indicate_open_complete(tls_io_instance, IO_OPEN_OK);
@@ -373,6 +425,7 @@
int res = wolfSSL_CTX_load_verify_buffer(tls_io_instance->ssl_context, (const unsigned char*)tls_io_instance->certificate, strlen(tls_io_instance->certificate) + 1, SSL_FILETYPE_PEM);
if (res != SSL_SUCCESS)
{
+ LogError("wolfSSL_CTX_load_verify_buffer failed");
result = __LINE__;
}
else
@@ -402,7 +455,8 @@
result = __LINE__;
}
#ifdef HAVE_SECURE_RENEGOTIATION
- else if (wolfSSL_UseSecureRenegotiation(ssl) != SSL_SUCCESS) {
+ else if (wolfSSL_UseSecureRenegotiation(ssl) != SSL_SUCCESS)
+ {
LogError("unable to enable secure renegotiation");
result = __LINE__;
}
@@ -425,7 +479,7 @@
if (add_certificate_to_store(tls_io_instance) != 0)
{
- wolfSSL_CTX_free(tls_io_instance->ssl_context);
+ LogError("Failed to add certificates to store");
result = __LINE__;
}
else
@@ -433,7 +487,7 @@
tls_io_instance->ssl = wolfSSL_new(tls_io_instance->ssl_context);
if (tls_io_instance->ssl == NULL)
{
- wolfSSL_CTX_free(tls_io_instance->ssl_context);
+ LogError("Failed to add certificates to store");
result = __LINE__;
}
/*x509 authentication can only be build before underlying connection is realized*/
@@ -442,13 +496,9 @@
(x509_wolfssl_add_credentials(tls_io_instance->ssl, tls_io_instance->x509certificate, tls_io_instance->x509privatekey) != 0))
{
destroy_wolfssl_instance(tls_io_instance);
- tls_io_instance->ssl = NULL;
- wolfSSL_CTX_free(tls_io_instance->ssl_context);
- tls_io_instance->ssl_context = NULL;
LogError("unable to use x509 authentication");
result = __LINE__;
}
-
else
{
tls_io_instance->socket_io_read_bytes = NULL;
@@ -467,6 +517,7 @@
result = 0;
}
}
+
return result;
}
@@ -484,80 +535,91 @@
CONCRETE_IO_HANDLE tlsio_wolfssl_create(void* io_create_parameters)
{
- TLSIO_CONFIG* tls_io_config = io_create_parameters;
TLS_IO_INSTANCE* result;
- if (tls_io_config == NULL)
+ if (io_create_parameters == NULL)
{
+ LogError("NULL io_create_parameters");
result = NULL;
}
else
{
+ TLSIO_CONFIG* tls_io_config = io_create_parameters;
+
result = (TLS_IO_INSTANCE*)malloc(sizeof(TLS_IO_INSTANCE));
if (result != NULL)
{
memset(result, 0, sizeof(TLS_IO_INSTANCE));
- mallocAndStrcpy_s(&result->hostname, tls_io_config->hostname);
- result->port = tls_io_config->port;
-
- result->socket_io_read_bytes = 0;
- result->socket_io_read_byte_count = 0;
- result->socket_io = NULL;
-
- result->ssl = NULL;
- result->ssl_context = NULL;
- result->certificate = NULL;
- result->x509certificate = NULL;
- result->x509privatekey = NULL;
-
- result->on_bytes_received = NULL;
- result->on_bytes_received_context = NULL;
-
- result->on_io_open_complete = NULL;
- result->on_io_open_complete_context = NULL;
-
- result->on_io_close_complete = NULL;
- result->on_io_close_complete_context = NULL;
-
- result->on_io_error = NULL;
- result->on_io_error_context = NULL;
-
- result->tlsio_state = TLSIO_STATE_NOT_OPEN;
-
- result->ssl_context = wolfSSL_CTX_new(wolfTLSv1_client_method());
- if (result->ssl_context == NULL)
+ if (mallocAndStrcpy_s(&result->hostname, tls_io_config->hostname) != 0)
{
+ LogError("Cannot copy the hostname");
free(result);
result = NULL;
}
else
{
- const IO_INTERFACE_DESCRIPTION* socket_io_interface = socketio_get_interface_description();
- if (socket_io_interface == NULL)
+ result->port = tls_io_config->port;
+
+ result->socket_io_read_bytes = 0;
+ result->socket_io_read_byte_count = 0;
+ result->socket_io = NULL;
+
+ result->ssl = NULL;
+ result->certificate = NULL;
+ result->x509certificate = NULL;
+ result->x509privatekey = NULL;
+
+ result->on_bytes_received = NULL;
+ result->on_bytes_received_context = NULL;
+
+ result->on_io_open_complete = NULL;
+ result->on_io_open_complete_context = NULL;
+
+ result->on_io_close_complete = NULL;
+ result->on_io_close_complete_context = NULL;
+
+ result->on_io_error = NULL;
+ result->on_io_error_context = NULL;
+
+ result->tlsio_state = TLSIO_STATE_NOT_OPEN;
+
+ result->ssl_context = wolfSSL_CTX_new(wolfTLSv1_client_method());
+ if (result->ssl_context == NULL)
{
- wolfSSL_CTX_free(result->ssl_context);
+ LogError("Cannot create the wolfSSL context");
+ free(result->hostname);
free(result);
result = NULL;
}
else
{
- SOCKETIO_CONFIG socketio_config;
- socketio_config.hostname = result->hostname;
- socketio_config.port = result->port;
- socketio_config.accepted_socket = NULL;
-
- result->socket_io = xio_create(socket_io_interface, &socketio_config);
- if (result->socket_io == NULL)
+ const IO_INTERFACE_DESCRIPTION* socket_io_interface = socketio_get_interface_description();
+ if (socket_io_interface == NULL)
{
- LogError("Failure connecting to underlying socket_io");
wolfSSL_CTX_free(result->ssl_context);
+ free(result->hostname);
free(result);
result = NULL;
}
+ else
+ {
+ SOCKETIO_CONFIG socketio_config;
+ socketio_config.hostname = result->hostname;
+ socketio_config.port = result->port;
+ socketio_config.accepted_socket = NULL;
+
+ result->socket_io = xio_create(socket_io_interface, &socketio_config);
+ if (result->socket_io == NULL)
+ {
+ LogError("Failure connecting to underlying socket_io");
+ wolfSSL_CTX_free(result->ssl_context);
+ free(result->hostname);
+ free(result);
+ result = NULL;
+ }
+ }
}
}
-
-
}
}
@@ -577,18 +639,20 @@
if (tls_io_instance->certificate != NULL)
{
free(tls_io_instance->certificate);
- tls_io_instance->certificate = NULL;
}
if (tls_io_instance->x509certificate != NULL)
{
free(tls_io_instance->x509certificate);
- tls_io_instance->x509certificate = NULL;
}
if (tls_io_instance->x509privatekey != NULL)
{
free(tls_io_instance->x509privatekey);
- tls_io_instance->x509privatekey = NULL;
}
+ if (tls_io_instance->hostname != NULL)
+ {
+ free(tls_io_instance->hostname);
+ }
+
wolfSSL_CTX_free(tls_io_instance->ssl_context);
xio_destroy(tls_io_instance->socket_io);
free(tls_io);
@@ -601,6 +665,7 @@
if (tls_io == NULL)
{
+ LogError("NULL tls_io instance");
result = __LINE__;
}
else
@@ -627,11 +692,13 @@
if (create_wolfssl_instance(tls_io_instance) != 0)
{
+ LogError("Cannot create wolfssl instance.");
tls_io_instance->tlsio_state = TLSIO_STATE_NOT_OPEN;
result = __LINE__;
}
else if (xio_open(tls_io_instance->socket_io, on_underlying_io_open_complete, tls_io_instance, on_underlying_io_bytes_received, tls_io_instance, on_underlying_io_error, tls_io_instance) != 0)
{
+ LogError("Cannot open the underlying IO.");
tls_io_instance->tlsio_state = TLSIO_STATE_NOT_OPEN;
result = __LINE__;
}
@@ -660,6 +727,7 @@
if (tls_io == NULL)
{
+ LogError("NULL tls_io handle.");
result = __LINE__;
}
else
@@ -669,6 +737,7 @@
if ((tls_io_instance->tlsio_state == TLSIO_STATE_NOT_OPEN) ||
(tls_io_instance->tlsio_state == TLSIO_STATE_CLOSING))
{
+ LogError("Close called while not open.");
result = __LINE__;
}
else
@@ -679,6 +748,7 @@
if (xio_close(tls_io_instance->socket_io, on_underlying_io_close_complete, tls_io_instance) != 0)
{
+ LogError("xio_close failed.");
result = __LINE__;
}
else
@@ -698,6 +768,7 @@
if (tls_io == NULL)
{
+ LogError("NULL tls_io handle");
result = __LINE__;
}
else
@@ -706,6 +777,7 @@
if (tls_io_instance->tlsio_state != TLSIO_STATE_OPEN)
{
+ LogError("send called while not open");
result = __LINE__;
}
else
@@ -716,6 +788,7 @@
int res = wolfSSL_write(tls_io_instance->ssl, buffer, size);
if ((res < 0) || ((size_t)res != size)) // Best way I can think of to safely compare an int to a size_t
{
+ LogError("Error writing data through WolfSSL");
result = __LINE__;
}
else
@@ -730,7 +803,11 @@
void tlsio_wolfssl_dowork(CONCRETE_IO_HANDLE tls_io)
{
- if (tls_io != NULL)
+ if (tls_io == NULL)
+ {
+ LogError("NULL tls_io");
+ }
+ else
{
TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;
@@ -766,14 +843,15 @@
result = 0;
}
return result;
+}
-}
int tlsio_wolfssl_setoption(CONCRETE_IO_HANDLE tls_io, const char* optionName, const void* value)
{
int result;
if (tls_io == NULL || optionName == NULL)
{
+ LogError("Bad arguments, tls_io = %p, optionName = %p", tls_io, optionName);
result = __LINE__;
}
else
@@ -796,6 +874,7 @@
{
if (tls_io_instance->socket_io == NULL)
{
+ LogError("NULL underlying IO handle");
result = __LINE__;
}
else
--- a/urlencode.c Fri Jan 13 18:41:15 2017 -0800 +++ b/urlencode.c Sat Jan 28 09:35:22 2017 -0800 @@ -5,9 +5,6 @@ // PUT NO INCLUDES BEFORE HERE !!!! // #include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif #include "azure_c_shared_utility/gballoc.h" #include <stddef.h>
--- a/usha.c Fri Jan 13 18:41:15 2017 -0800 +++ b/usha.c Sat Jan 28 09:35:22 2017 -0800 @@ -8,12 +8,6 @@ * This file implements a unified interface to the SHA algorithms. */ -#include <stdlib.h> -#ifdef _CRTDBG_MAP_ALLOC -#include <crtdbg.h> -#endif -#include "azure_c_shared_utility/gballoc.h" - #include "azure_c_shared_utility/sha.h" /*
--- a/vector.c Fri Jan 13 18:41:15 2017 -0800
+++ b/vector.c Sat Jan 28 09:35:22 2017 -0800
@@ -2,84 +2,118 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdlib.h>
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
-
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/vector.h"
-
+#include "azure_c_shared_utility/xlogging.h"
-typedef struct VECTOR_TAG
-{
- void* storage;
- size_t count;
- size_t elementSize;
-} VECTOR;
+#include "azure_c_shared_utility/vector_types_internal.h"
VECTOR_HANDLE VECTOR_create(size_t elementSize)
{
VECTOR_HANDLE result;
- VECTOR* vec = (VECTOR*)malloc(sizeof(VECTOR));
- if (vec == NULL)
+ /* Codes_SRS_VECTOR_10_002: [VECTOR_create shall fail and return NULL if elementsize is 0.] */
+ if (elementSize == 0)
{
+ LogError("invalid elementSize(%zd).", elementSize);
result = NULL;
}
else
{
- vec->storage = NULL;
- vec->count = 0;
- vec->elementSize = elementSize;
- result = (VECTOR_HANDLE)vec;
+ result = (VECTOR*)malloc(sizeof(VECTOR));
+ /* Codes_SRS_VECTOR_10_002 : [VECTOR_create shall fail and return NULL if malloc fails.] */
+ if (result == NULL)
+ {
+ LogError("malloc failed.");
+ }
+ else
+ {
+ /* Codes_SRS_VECTOR_10_001: [VECTOR_create shall allocate a VECTOR_HANDLE that will contain an empty vector.The size of each element is given with the parameter elementSize.] */
+ result->storage = NULL;
+ result->count = 0;
+ result->elementSize = elementSize;
+ }
}
return result;
}
-static void internal_VECTOR_clear(VECTOR* vec)
-{
- if (vec->storage != NULL)
- {
- free(vec->storage);
- vec->storage = NULL;
- }
- vec->count = 0;
-}
-
void VECTOR_destroy(VECTOR_HANDLE handle)
{
- if (handle != NULL)
+ /* Codes_SRS_VECTOR_10_009: [VECTOR_destroy shall return if the given handle is NULL.] */
+ if (handle == NULL)
{
- VECTOR* vec = (VECTOR*)handle;
- internal_VECTOR_clear(vec);
- free(vec);
+ LogError("invalid argument handle(NULL).");
+ }
+ else
+ {
+ /* Codes_SRS_VECTOR_10_008: [VECTOR_destroy shall free the given handle and its internal storage.] */
+ free(handle->storage);
+ free(handle);
}
}
+VECTOR_HANDLE VECTOR_move(VECTOR_HANDLE handle)
+{
+ VECTOR_HANDLE result;
+ if (handle == NULL)
+ {
+ /* Codes_SRS_VECTOR_10_005: [VECTOR_move shall fail and return NULL if the given handle is NULL.] */
+ LogError("invalid argument - handle(NULL).");
+ result = NULL;
+ }
+ else
+ {
+ result = (VECTOR*)malloc(sizeof(VECTOR));
+ if (result == NULL)
+ {
+ /* Codes_SRS_VECTOR_10_006: [VECTOR_move shall fail and return NULL if malloc fails.] */
+ LogError("malloc failed.");
+ }
+ else
+ {
+ /* Codes_SRS_VECTOR_10_004: [VECTOR_move shall allocate a VECTOR_HANDLE and move the data to it from the given handle.] */
+ result->count = handle->count;
+ result->elementSize = handle->elementSize;
+ result->storage = handle->storage;
+
+ handle->storage = NULL;
+ handle->count = 0;
+ }
+ }
+ return result;
+}
+
/* insertion */
+
int VECTOR_push_back(VECTOR_HANDLE handle, const void* elements, size_t numElements)
{
int result;
if (handle == NULL || elements == NULL || numElements == 0)
{
+ /* Codes_SRS_VECTOR_10_011: [VECTOR_push_back shall fail and return non-zero if `handle` is NULL.] */
+ /* Codes_SRS_VECTOR_10_034: [VECTOR_push_back shall fail and return non-zero if `elements` is NULL.] */
+ /* Codes_SRS_VECTOR_10_035: [VECTOR_push_back shall fail and return non-zero if `numElements` is 0.] */
+ LogError("invalid argument - handle(%p), elements(%p), numElements(%zd).", handle, elements, numElements);
result = __LINE__;
}
else
{
- VECTOR* vec = (VECTOR*)handle;
- const size_t curSize = vec->elementSize * vec->count;
- const size_t appendSize = vec->elementSize * numElements;
+ size_t curSize = handle->elementSize * handle->count;
+ size_t appendSize = handle->elementSize * numElements;
- void* temp = realloc(vec->storage, curSize + appendSize);
+ void* temp = realloc(handle->storage, curSize + appendSize);
if (temp == NULL)
{
+ /* Codes_SRS_VECTOR_10_012: [VECTOR_push_back shall fail and return non-zero if memory allocation fails.] */
+ LogError("realloc failed.");
result = __LINE__;
}
else
{
- memcpy((unsigned char*)temp + curSize, elements, appendSize);
- vec->storage = temp;
- vec->count += numElements;
+ /* Codes_SRS_VECTOR_10_013: [VECTOR_push_back shall append the given elements and return 0 indicating success.] */
+ (void)memcpy((unsigned char*)temp + curSize, elements, appendSize);
+ handle->storage = temp;
+ handle->count += numElements;
result = 0;
}
}
@@ -87,103 +121,217 @@
}
/* removal */
+
void VECTOR_erase(VECTOR_HANDLE handle, void* elements, size_t numElements)
{
- if (handle != NULL && elements != NULL && numElements > 0)
+ if (handle == NULL || elements == NULL || numElements == 0)
{
- VECTOR* vec = (VECTOR*)handle;
- unsigned char* src = (unsigned char*)elements + (vec->elementSize * numElements);
- unsigned char* srcEnd = (unsigned char*)vec->storage + (vec->elementSize * vec->count);
- (void)memmove(elements, src, srcEnd - src);
- vec->count -= numElements;
- if (vec->count == 0)
+ /* Codes_SRS_VECTOR_10_015: [VECTOR_erase shall return if `handle` is NULL.] */
+ /* Codes_SRS_VECTOR_10_038: [VECTOR_erase shall return if `elements` is NULL.] */
+ /* Codes_SRS_VECTOR_10_039: [VECTOR_erase shall return if `numElements` is 0.] */
+ LogError("invalid argument - handle(%p), elements(%p), numElements(%zd).", handle, elements, numElements);
+ }
+ else
+ {
+ if (elements < handle->storage)
{
- free(vec->storage);
- vec->storage = NULL;
+ /* Codes_SRS_VECTOR_10_040: [VECTOR_erase shall return if `elements` is out of bound.] */
+ LogError("invalid argument elements(%p) is not a member of this object.", elements);
}
else
{
- vec->storage = realloc(vec->storage, (vec->elementSize * vec->count));
+ ptrdiff_t diff = ((unsigned char*)elements) - ((unsigned char*)handle->storage);
+ if ((diff % handle->elementSize) != 0)
+ {
+ /* Codes_SRS_VECTOR_10_041: [VECTOR_erase shall return if elements is misaligned.] */
+ LogError("invalid argument - elements(%p) is misaligned", elements);
+ }
+ else
+ {
+ /* Compute the arguments needed for memmove. */
+ unsigned char* src = (unsigned char*)elements + (handle->elementSize * numElements);
+ unsigned char* srcEnd = (unsigned char*)handle->storage + (handle->elementSize * handle->count);
+ if (src > srcEnd)
+ {
+ /* Codes_SRS_VECTOR_10_040: [VECTOR_erase shall return if `elements` is out of bound.] */
+ LogError("invalid argument - numElements(%zd) is out of bound.", numElements);
+ }
+ else
+ {
+ /* Codes_SRS_VECTOR_10_014: [VECTOR_erase shall remove the 'numElements' starting at 'elements' and reduce its internal storage.] */
+ handle->count -= numElements;
+ if (handle->count == 0)
+ {
+ free(handle->storage);
+ handle->storage = NULL;
+ }
+ else
+ {
+ void* tmp;
+ (void)memmove(elements, src, srcEnd - src);
+ tmp = realloc(handle->storage, (handle->elementSize * handle->count));
+ if (tmp == NULL)
+ {
+ LogInfo("realloc failed. Keeping original internal storage pointer.");
+ }
+ else
+ {
+ handle->storage = tmp;
+ }
+ }
+ }
+ }
}
}
}
void VECTOR_clear(VECTOR_HANDLE handle)
{
- if (handle != NULL)
+ /* Codes_SRS_VECTOR_10_017: [VECTOR_clear shall if the object is NULL or empty.] */
+ if (handle == NULL)
{
- VECTOR* vec = (VECTOR*)handle;
- internal_VECTOR_clear(vec);
+ LogError("invalid argument handle(NULL).");
+ }
+ else
+ {
+ /* Codes_SRS_VECTOR_10_016: [VECTOR_clear shall remove all elements from the object and release internal storage.] */
+ free(handle->storage);
+ handle->storage = NULL;
+ handle->count = 0;
}
}
/* access */
-void* VECTOR_element(const VECTOR_HANDLE handle, size_t index)
+void* VECTOR_element(VECTOR_HANDLE handle, size_t index)
{
- void* result = NULL;
- if (handle != NULL)
+ void* result;
+ if (handle == NULL)
+ {
+ /* Codes_SRS_VECTOR_10_019: [VECTOR_element shall fail and return NULL if handle is NULL.] */
+ LogError("invalid argument handle(NULL).");
+ result = NULL;
+ }
+ else
{
- const VECTOR* vec = (const VECTOR*)handle;
- if (index < vec->count)
+ if (index >= handle->count)
{
- result = (unsigned char*)vec->storage + (vec->elementSize * index);
+ /* Codes_SRS_VECTOR_10_020: [VECTOR_element shall fail and return NULL if the given index is out of range.] */
+ LogError("invalid argument - index(%zd); should be >= 0 and < %zd.", index, handle->count);
+ result = NULL;
+ }
+ else
+ {
+ /* Codes_SRS_VECTOR_10_018: [VECTOR_element shall return the element at the given index.] */
+ result = (unsigned char*)handle->storage + (handle->elementSize * index);
}
}
return result;
}
-void* VECTOR_front(const VECTOR_HANDLE handle)
+void* VECTOR_front(VECTOR_HANDLE handle)
{
- void* result = NULL;
- if (handle != NULL)
+ void* result;
+ if (handle == NULL)
+ {
+ /* Codes_SRS_VECTOR_10_022: [VECTOR_front shall fail and return NULL if handle is NULL.] */
+ LogError("invalid argument handle (NULL).");
+ result = NULL;
+ }
+ else
{
- const VECTOR* vec = (const VECTOR*)handle;
- result = vec->storage;
+ if (handle->count == 0)
+ {
+ /* Codes_SRS_VECTOR_10_028: [VECTOR_front shall return NULL if the vector is empty.] */
+ LogError("vector is empty.");
+ result = NULL;
+ }
+ else
+ {
+ /* Codes_SRS_VECTOR_10_021: [VECTOR_front shall return a pointer to the element at index 0.] */
+ result = handle->storage;
+ }
}
return result;
}
-void* VECTOR_back(const VECTOR_HANDLE handle)
+void* VECTOR_back(VECTOR_HANDLE handle)
{
- void* result = NULL;
- if (handle != NULL)
+ void* result;
+ if (handle == NULL)
+ {
+ /* Codes_SRS_VECTOR_10_024: [VECTOR_back shall fail and return NULL if handle is NULL.] */
+ LogError("invalid argument handle (NULL).");
+ result = NULL;
+ }
+ else
{
- const VECTOR* vec = (const VECTOR*)handle;
- result = (unsigned char*)vec->storage + (vec->elementSize * (vec->count - 1));
+ if (handle->count == 0)
+ {
+ /* Codes_SRS_VECTOR_10_029: [VECTOR_back shall return NULL if the vector is empty.] */
+ LogError("vector is empty.");
+ result = NULL;
+ }
+ else
+ {
+ /* Codes_SRS_VECTOR_10_023: [VECTOR_front shall return the last element of the vector.] */
+ result = (unsigned char*)handle->storage + (handle->elementSize * (handle->count - 1));
+ }
}
return result;
}
-void* VECTOR_find_if(const VECTOR_HANDLE handle, PREDICATE_FUNCTION pred, const void* value)
+void* VECTOR_find_if(VECTOR_HANDLE handle, PREDICATE_FUNCTION pred, const void* value)
{
- void* result = NULL;
- size_t i;
- VECTOR* handleData = (VECTOR*)handle;
- if (handle != NULL && pred != NULL && value != NULL)
+ void* result;
+ if (handle == NULL || pred == NULL)
{
- for (i = 0; i < handleData->count; ++i)
+ /* Codes_SRS_VECTOR_10_030: [VECTOR_find_if shall fail and return NULL if `handle` is NULL.] */
+ /* Codes_SRS_VECTOR_10_036: [VECTOR_find_if shall fail and return NULL if `pred` is NULL.] */
+ LogError("invalid argument - handle(%p), pred(%p)", handle, pred);
+ result = NULL;
+ }
+ else
+ {
+ size_t i;
+ for (i = 0; i < handle->count; ++i)
{
- void* elem = (unsigned char*)handleData->storage + (handleData->elementSize * i);
- if (!!pred(elem, value))
+ if (true == pred((unsigned char*)handle->storage + (handle->elementSize * i), value))
{
- result = elem;
+ /* Codes_SRS_VECTOR_10_031: [VECTOR_find_if shall return the first element in the vector that matches `pred`.] */
break;
}
}
+
+ if (i == handle->count)
+ {
+ /* Codes_SRS_VECTOR_10_032: [VECTOR_find_if shall return NULL if no matching element is found.] */
+ result = NULL;
+ }
+ else
+ {
+ /* Codes_SRS_VECTOR_10_031: [VECTOR_find_if shall return the first element in the vector that matches `pred`.]*/
+ result = (unsigned char*)handle->storage + (handle->elementSize * i);
+ }
}
return result;
}
/* capacity */
-size_t VECTOR_size(const VECTOR_HANDLE handle)
+size_t VECTOR_size(VECTOR_HANDLE handle)
{
- size_t result = 0;
- if (handle != NULL)
+ size_t result;
+ if (handle == NULL)
{
- const VECTOR* vec = (const VECTOR*)handle;
- result = vec->count;
+ /* Codes_SRS_VECTOR_10_026: [**VECTOR_size shall return 0 if the given handle is NULL.] */
+ LogError("invalid argument handle(NULL).");
+ result = 0;
+ }
+ else
+ {
+ /* Codes_SRS_VECTOR_10_025: [VECTOR_size shall return the number of elements stored with the given handle.] */
+ result = handle->count;
}
return result;
}
--- a/xio.c Fri Jan 13 18:41:15 2017 -0800
+++ b/xio.c Sat Jan 28 09:35:22 2017 -0800
@@ -2,9 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdlib.h>
-#ifdef _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
#include <stddef.h>
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/xio.h"
@@ -14,7 +11,7 @@
typedef struct XIO_INSTANCE_TAG
{
const IO_INTERFACE_DESCRIPTION* io_interface_description;
- XIO_HANDLE concrete_xio_handle;
+ CONCRETE_IO_HANDLE concrete_xio_handle;
} XIO_INSTANCE;
XIO_HANDLE xio_create(const IO_INTERFACE_DESCRIPTION* io_interface_description, const void* xio_create_parameters)
