Nigel Rantor / azure_c_shared_utility

Fork of azure_c_shared_utility by Azure IoT

Files at this revision

API Documentation at this revision

Comitter:
AzureIoTClient
Date:
Fri Apr 21 14:51:10 2017 -0700
Parent:
24:96ae4d5375ef
Child:
26:b38c66e3e45e
Commit message:
1.1.13

Changed in this revision

azure_c_shared_utility/base64.h Show annotated file Show diff for this revision Revisions of this file
azure_c_shared_utility/platform.h Show annotated file Show diff for this revision Revisions of this file
azure_c_shared_utility/refcount.h Show annotated file Show diff for this revision Revisions of this file
azure_c_shared_utility/xlogging.h Show annotated file Show diff for this revision Revisions of this file
base64.c Show annotated file Show diff for this revision Revisions of this file
consolelogger.c Show annotated file Show diff for this revision Revisions of this file
gballoc.c Show annotated file Show diff for this revision Revisions of this file
hmac.c Show annotated file Show diff for this revision Revisions of this file
httpapiex.c Show annotated file Show diff for this revision Revisions of this file
httpapiexsas.c Show annotated file Show diff for this revision Revisions of this file
httpheaders.c Show annotated file Show diff for this revision Revisions of this file
platform_mbed.cpp Show annotated file Show diff for this revision Revisions of this file
sastoken.c Show annotated file Show diff for this revision Revisions of this file
string_tokenizer.c Show annotated file Show diff for this revision Revisions of this file
strings.c Show annotated file Show diff for this revision Revisions of this file
urlencode.c Show annotated file Show diff for this revision Revisions of this file
xlogging.c Show annotated file Show diff for this revision Revisions of this file
--- a/azure_c_shared_utility/base64.h	Thu Apr 06 14:12:06 2017 -0700
+++ b/azure_c_shared_utility/base64.h	Fri Apr 21 14:51:10 2017 -0700
@@ -27,17 +27,17 @@
  *
  * @param	input	The buffer that needs to be base64 encoded.
  *
- * 			Base64_Encode takes as a parameter a pointer to a BUFFER. If @p input is @c NULL then
- * 			@c Base64_Encode returns @c NULL. The size of the BUFFER pointed to by @p input may
+ * 			Base64_Encoder takes as a parameter a pointer to a BUFFER. If @p input is @c NULL then
+ * 			@c Base64_Encoder returns @c NULL. The size of the BUFFER pointed to by @p input may
  * 			be zero. If when allocating memory to produce the encoding a failure occurs, then @c
- * 			Base64_Encode returns @c NULL. Otherwise
- * 			@c Base64_Encode returns a pointer to a STRING. That string contains the
+ * 			Base64_Encoder returns @c NULL. Otherwise
+ * 			@c Base64_Encoder returns a pointer to a STRING. That string contains the
  * 			base 64 encoding of the @p input. This encoding of @p input will not contain embedded
  * 			line feeds.
  *
  * @return	A @c STRING_HANDLE containing the base64 encoding of @p input.
  */
-MOCKABLE_FUNCTION(, STRING_HANDLE, Base64_Encode, BUFFER_HANDLE, input);
+MOCKABLE_FUNCTION(, STRING_HANDLE, Base64_Encoder, BUFFER_HANDLE, input);
 
 /**
  * @brief	Base64 encodes the buffer pointed to by @p source and returns the resulting string.
--- a/azure_c_shared_utility/platform.h	Thu Apr 06 14:12:06 2017 -0700
+++ b/azure_c_shared_utility/platform.h	Fri Apr 21 14:51:10 2017 -0700
@@ -8,12 +8,14 @@
 extern "C" {
 #endif /* __cplusplus */
 
+#include "azure_c_shared_utility/strings.h"
 #include "azure_c_shared_utility/xio.h"
 #include "azure_c_shared_utility/umock_c_prod.h"
 
     MOCKABLE_FUNCTION(, int, platform_init);
     MOCKABLE_FUNCTION(, void, platform_deinit);
     MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, platform_get_default_tlsio);
+    MOCKABLE_FUNCTION(, STRING_HANDLE, platform_get_platform_info);
 
 #ifdef __cplusplus
 }
--- a/azure_c_shared_utility/refcount.h	Thu Apr 06 14:12:06 2017 -0700
+++ b/azure_c_shared_utility/refcount.h	Fri Apr 21 14:51:10 2017 -0700
@@ -35,6 +35,12 @@
 #undef  REFCOUNT_USE_STD_ATOMIC
 #endif
 
+#if defined(FREERTOS_ARCH_ESP8266)
+#undef  REFCOUNT_USE_STD_ATOMIC  
+#define REFCOUNT_ATOMIC_DONTCARE 1
+#undef __GNUC__    
+#endif
+
 #define REFCOUNT_TYPE(type) \
 struct C2(C2(REFCOUNT_, type), _TAG)
 
--- a/azure_c_shared_utility/xlogging.h	Thu Apr 06 14:12:06 2017 -0700
+++ b/azure_c_shared_utility/xlogging.h	Fri Apr 21 14:51:10 2017 -0700
@@ -52,18 +52,33 @@
 #define xlogging_set_log_function(...)
 #define LogErrorWinHTTPWithGetLastErrorAsString(...)
 #define UNUSED(x) (void)(x)
+
+#elif defined(ESP8266_RTOS)
+#include "c_types.h"
+#define LogInfo(FORMAT, ...) do {    \
+        static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = FORMAT;  \
+        printf(flash_str, ##__VA_ARGS__);   \
+        printf("\n");\
+    } while(0)
+    
+#define LogError LogInfo
+#define LOG(log_category, log_options, FORMAT, ...)  { \
+        static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = (FORMAT); \
+        printf(flash_str, ##__VA_ARGS__); \
+        printf("\r\n"); \
+}
+
+
 #elif defined(ARDUINO_ARCH_ESP8266)
 /*
 The ESP8266 compiler doesn't do a good job compiling this code; it doesn't understand that the 'format' is
 a 'const char*' and moves it to RAM as a global variable, increasing the .bss size. So we create a
 specific LogInfo that explicitly pins the 'format' on the PROGMEM (flash) using a _localFORMAT variable
 with the macro PSTR.
-
 #define ICACHE_FLASH_ATTR   __attribute__((section(".irom0.text")))
 #define PROGMEM     ICACHE_RODATA_ATTR
 #define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
 const char* __localFORMAT = PSTR(FORMAT);
-
 On the other hand, vsprintf does not support the pinned 'format' and os_printf does not work with va_list,
 so we compacted the log in the macro LogInfo.
 */
--- a/base64.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/base64.c	Fri Apr 21 14:51:10 2017 -0700
@@ -241,12 +241,12 @@
     size_t currentPosition = 0;
     neededSize += (size == 0) ? (0) : ((((size - 1) / 3) + 1) * 4);
     neededSize += 1; /*+1 because \0 at the end of the string*/
-    /*Codes_SRS_BASE64_06_006: [If when allocating memory to produce the encoding a failure occurs then Base64_Encode shall return NULL.]*/
+    /*Codes_SRS_BASE64_06_006: [If when allocating memory to produce the encoding a failure occurs then Base64_Encoder shall return NULL.]*/
     encoded = (char*)malloc(neededSize);
     if (encoded == NULL)
     {
         result = NULL;
-        LogError("Base64_Encode:: Allocation failed.");
+        LogError("Base64_Encoder:: Allocation failed.");
     }
     else
     {
@@ -302,12 +302,12 @@
 
         /*null terminating the string*/
         encoded[destinationPosition] = '\0';
-        /*Codes_SRS_BASE64_06_007: [Otherwise Base64_Encode shall return a pointer to STRING, that string contains the base 64 encoding of input.]*/
+        /*Codes_SRS_BASE64_06_007: [Otherwise Base64_Encoder shall return a pointer to STRING, that string contains the base 64 encoding of input.]*/
         result = STRING_new_with_memory(encoded);
         if (result == NULL)
         {
             free(encoded);
-            LogError("Base64_Encode:: Allocation failed for return value.");
+            LogError("Base64_Encoder:: Allocation failed for return value.");
         }
     }
     return result;
@@ -333,7 +333,7 @@
     return result;
 }
 
-STRING_HANDLE Base64_Encode(BUFFER_HANDLE input)
+STRING_HANDLE Base64_Encoder(BUFFER_HANDLE input)
 {
     STRING_HANDLE result;
     /*the following will happen*/
@@ -343,11 +343,11 @@
     /*the encoding will use the optional [=] or [==] at the end of the encoded string, so that other less standard aware libraries can do their work*/
     /*these are the bits of the 3 normal bytes to be encoded*/
 
-    /*Codes_SRS_BASE64_06_001: [If input is NULL then Base64_Encode shall return NULL.]*/
+    /*Codes_SRS_BASE64_06_001: [If input is NULL then Base64_Encoder shall return NULL.]*/
     if (input == NULL)
     {
         result = NULL;
-        LogError("Base64_Encode:: NULL input");
+        LogError("Base64_Encoder:: NULL input");
     }
     else
     {
@@ -357,7 +357,7 @@
             (BUFFER_size(input, &inputSize) != 0))
         {
             result = NULL;
-            LogError("Base64_Encode:: BUFFER_routines failure.");
+            LogError("Base64_Encoder:: BUFFER_routines failure.");
         }
         else
         {
--- a/consolelogger.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/consolelogger.c	Fri Apr 21 14:51:10 2017 -0700
@@ -5,7 +5,11 @@
 #include <stdio.h>
 #include <time.h>
 #include "azure_c_shared_utility/xlogging.h"
+#include "azure_c_shared_utility/consolelogger.h"
 
+#if defined(__GNUC__)
+__attribute__ ((format (printf, 6, 7)))
+#endif
 void consolelogger_log(LOG_CATEGORY log_category, const char* file, const char* func, const int line, unsigned int options, const char* format, ...)
 {
     va_list args;
--- a/gballoc.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/gballoc.c	Fri Apr 21 14:51:10 2017 -0700
@@ -350,10 +350,10 @@
     }
     else
     {
-    /* Codes_SRS_GBALLOC_01_010: [gballoc_getMaximumMemoryUsed shall return the maximum amount of total memory used recorded since the module initialization.] */
+        /* Codes_SRS_GBALLOC_01_010: [gballoc_getMaximumMemoryUsed shall return the maximum amount of total memory used recorded since the module initialization.] */
         result = maxSize;
-        Unlock(gballocThreadSafeLock);
-}
+        (void)Unlock(gballocThreadSafeLock);
+    }
 
     return result;
 }
@@ -377,9 +377,9 @@
     }
     else
     {
-    /*Codes_SRS_GBALLOC_02_001: [gballoc_getCurrentMemoryUsed shall return the currently used memory size.] */
+        /*Codes_SRS_GBALLOC_02_001: [gballoc_getCurrentMemoryUsed shall return the currently used memory size.] */
         result = totalSize;
-        Unlock(gballocThreadSafeLock);
+        (void)Unlock(gballocThreadSafeLock);
     }
 
     return result;
--- a/hmac.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/hmac.c	Fri Apr 21 14:51:10 2017 -0700
@@ -218,7 +218,7 @@
 
         /* perform outer SHA */
         /* init context for 2nd pass */
-        USHAReset(&ctx->shaContext, ctx->whichSha) ||
+        USHAReset(&ctx->shaContext, (SHAversion)ctx->whichSha) ||
 
         /* start with outer pad */
         USHAInput(&ctx->shaContext, ctx->k_opad, ctx->blockSize) ||
--- a/httpapiex.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/httpapiex.c	Fri Apr 21 14:51:10 2017 -0700
@@ -394,7 +394,7 @@
                                 {
                                     /*Codes_SRS_HTTPAPIEX_02_035: [HTTPAPIEX_ExecuteRequest shall pass all the saved options (see HTTPAPIEX_SetOption) to the newly create HTTPAPI_HANDLE in step 2 by calling HTTPAPI_SetOption.]*/
                                     /*Codes_SRS_HTTPAPIEX_02_036: [If setting the option fails, then the failure shall be ignored.] */
-                                    HTTPAPIEX_SAVED_OPTION* option = VECTOR_element(handleData->savedOptions, i);
+                                    HTTPAPIEX_SAVED_OPTION* option = (HTTPAPIEX_SAVED_OPTION*)VECTOR_element(handleData->savedOptions, i);
                                     if (HTTPAPI_SetOption(handleData->httpHandle, option->optionName, option->value) != HTTPAPI_OK)
                                     {
                                         LogError("HTTPAPI_SetOption failed when called for option %s", option->optionName);
@@ -517,7 +517,7 @@
         vectorSize = VECTOR_size(handleData->savedOptions);
         for (i = 0; i < vectorSize; i++)
         {
-            HTTPAPIEX_SAVED_OPTION*savedOption = VECTOR_element(handleData->savedOptions, i);
+            HTTPAPIEX_SAVED_OPTION* savedOption = (HTTPAPIEX_SAVED_OPTION*)VECTOR_element(handleData->savedOptions, i);
             free((void*)savedOption->optionName);
             free((void*)savedOption->value);
         }
@@ -533,7 +533,7 @@
 
 static bool sameName(const void* element, const void* value)
 {
-    return (strcmp(((HTTPAPIEX_SAVED_OPTION*)element)->optionName, value) == 0) ? true : false;
+    return (strcmp(((HTTPAPIEX_SAVED_OPTION*)element)->optionName, (const char*)value) == 0) ? true : false;
 }
 
 /*return 0 on success, any other value is error*/
@@ -544,7 +544,7 @@
     int result;
     
     /*decide bwtween update or create*/
-    HTTPAPIEX_SAVED_OPTION* whereIsIt = VECTOR_find_if(handleData->savedOptions, sameName, optionName);
+    HTTPAPIEX_SAVED_OPTION* whereIsIt = (HTTPAPIEX_SAVED_OPTION*)VECTOR_find_if(handleData->savedOptions, sameName, optionName);
     if (whereIsIt != NULL)
     {
         free((void*)(whereIsIt->value));
--- a/httpapiexsas.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/httpapiexsas.c	Fri Apr 21 14:51:10 2017 -0700
@@ -43,7 +43,7 @@
     else
     {
         /*Codes_SRS_HTTPAPIEXSAS_01_001: [ HTTPAPIEX_SAS_Create shall create a new instance of HTTPAPIEX_SAS and return a non-NULL handle to it. ]*/
-        HTTPAPIEX_SAS_STATE* state = malloc(sizeof(HTTPAPIEX_SAS_STATE));
+        HTTPAPIEX_SAS_STATE* state = (HTTPAPIEX_SAS_STATE*)malloc(sizeof(HTTPAPIEX_SAS_STATE));
         /*Codes_SRS_HTTPAPIEXSAS_06_004: [If there are any other errors in the instantiation of this handle then HTTPAPIEX_SAS_Create shall return NULL.]*/
         if (state != NULL)
         {
--- a/httpheaders.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/httpheaders.c	Fri Apr 21 14:51:10 2017 -0700
@@ -310,7 +310,7 @@
     else
     {
         /*Codes_SRS_HTTP_HEADERS_02_004: [Otherwise HTTPHeaders_Clone shall clone the content of handle to a new handle.] */
-        result = malloc(sizeof(HTTP_HEADERS_HANDLE_DATA));
+        result = (HTTP_HEADERS_HANDLE_DATA*)malloc(sizeof(HTTP_HEADERS_HANDLE_DATA));
         if (result == NULL)
         {
             /*Codes_SRS_HTTP_HEADERS_02_005: [If cloning fails for any reason, then HTTPHeaders_Clone shall return NULL.] */
--- a/platform_mbed.cpp	Thu Apr 06 14:12:06 2017 -0700
+++ b/platform_mbed.cpp	Fri Apr 21 14:51:10 2017 -0700
@@ -62,6 +62,11 @@
     return tlsio_wolfssl_get_interface_description();
 }
 
+STRING_HANDLE platform_get_platform_info(void)
+{
+    return STRING_construct("(mbed)");
+}
+
 void platform_deinit(void)
 {
     EthernetInterface::disconnect();
--- a/sastoken.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/sastoken.c	Fri Apr 21 14:51:10 2017 -0700
@@ -152,7 +152,7 @@
             }
             else
             {
-                char* expiryASCII = malloc(seStop - seStart + 1);
+                char* expiryASCII = (char*)malloc(seStop - seStart + 1);
                 /*Codes_SRS_SASTOKEN_25_031: [**If malloc fails during validation then SASToken_Validate shall return false.**]***/
                 if (expiryASCII == NULL)
                 {
@@ -265,7 +265,7 @@
                     /*Codes_SRS_SASTOKEN_06_022: [The string "&skn=" is appended to result.]*/
                     /*Codes_SRS_SASTOKEN_06_023: [The argument keyName is appended to result.]*/
                     if ((HMACSHA256_ComputeHash(outBuf, outLen, inBuf, inLen, hash) != HMACSHA256_OK) ||
-                        ((base64Signature = Base64_Encode(hash)) == NULL) ||
+                        ((base64Signature = Base64_Encoder(hash)) == NULL) ||
                         ((urlEncodedSignature = URL_Encode(base64Signature)) == NULL) ||
                         (STRING_copy(result, "SharedAccessSignature sr=") != 0) ||
                         (STRING_concat(result, scope) != 0) ||
--- a/string_tokenizer.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/string_tokenizer.c	Fri Apr 21 14:51:10 2017 -0700
@@ -132,7 +132,7 @@
             else
             {
                 bool foundDelimitter = false;
-                char* endOfTokenPosition=NULL;
+                const char* endOfTokenPosition=NULL;
                 size_t amountOfCharactersToCopy;
                 size_t j;
                 //At this point the Current Pos is pointing to a character that is point to a nonDelimiter. So, now search for a Delimiter, till the end of the String. 
--- a/strings.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/strings.c	Fri Apr 21 14:51:10 2017 -0700
@@ -119,6 +119,9 @@
     return result;
 }
 
+#if defined(__GNUC__)
+__attribute__ ((format (printf, 1, 2)))
+#endif
 STRING_HANDLE STRING_construct_sprintf(const char* format, ...)
 {
     STRING* result;
@@ -507,6 +510,9 @@
     return result;
 }
 
+#if defined(__GNUC__)
+__attribute__ ((format (printf, 2, 3)))
+#endif
 int STRING_sprintf(STRING_HANDLE handle, const char* format, ...)
 {
     int result;
--- a/urlencode.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/urlencode.c	Fri Apr 21 14:51:10 2017 -0700
@@ -139,7 +139,7 @@
             currentUnsignedChar = (unsigned char)(*currentInput++);
             lengthOfResult += URL_PrintableCharSize(currentUnsignedChar);
         } while (currentUnsignedChar != 0);
-        if ((encodedURL = malloc(lengthOfResult)) == NULL)
+        if ((encodedURL = (char*)malloc(lengthOfResult)) == NULL)
         {
             /*Codes_SRS_URL_ENCODE_06_002: [If an error occurs during the encoding of input then URL_Encode will return NULL.]*/
             result = NULL;
--- a/xlogging.c	Thu Apr 06 14:12:06 2017 -0700
+++ b/xlogging.c	Fri Apr 21 14:51:10 2017 -0700
@@ -71,7 +71,8 @@
     const unsigned char* startPos = bufAsChar;
     
     /* Print the whole buffer. */
-    for (size_t i = 0; i < size; i++)
+    size_t i = 0;
+    for (i = 0; i < size; i++)
     {
         /* Store the printable value of the char in the charBuf to print. */
         charBuf[countbuf] = PRINTABLE(*bufAsChar);