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 8:3db46d1e5471, committed 2016-08-12
- Comitter:
- AzureIoTClient
- Date:
- Fri Aug 12 10:04:46 2016 -0700
- Parent:
- 7:1af47e3a19b6
- Child:
- 9:079c39803432
- Commit message:
- 1.0.10
Changed in this revision
--- a/azure_c_shared_utility/agenttime.h Fri Jul 29 16:01:07 2016 -0700 +++ b/azure_c_shared_utility/agenttime.h Fri Aug 12 10:04:46 2016 -0700 @@ -34,6 +34,13 @@ */ MOCKABLE_FUNCTION(, struct tm*, get_gmtime, time_t*, currentTime); +/** @brief Get current time representation of the given calendar time. +* +* @details This function provides the same functionality as the +* standard C @c mktime() function. +*/ +MOCKABLE_FUNCTION(, time_t, get_mktime, struct tm*, cal_time); + /** @brief Gets a C-string representation of the given time. * * @details This function provides the same functionality as the
--- a/azure_c_shared_utility/consolelogger.h Fri Jul 29 16:01:07 2016 -0700 +++ b/azure_c_shared_utility/consolelogger.h Fri Aug 12 10:04:46 2016 -0700 @@ -10,7 +10,7 @@ #include "azure_c_shared_utility/xlogging.h" - extern void consolelogger_log(LOG_CATEGORY log_category, unsigned int options, const char* format, ...); + extern void consolelogger_log(LOG_CATEGORY log_category, const char* file, const char* func, const int line, unsigned int options, const char* format, ...); #ifdef __cplusplus }
--- a/azure_c_shared_utility/httpapi.h Fri Jul 29 16:01:07 2016 -0700 +++ b/azure_c_shared_utility/httpapi.h Fri Aug 12 10:04:46 2016 -0700 @@ -67,6 +67,8 @@ */ DEFINE_ENUM(HTTPAPI_REQUEST_TYPE, HTTPAPI_REQUEST_TYPE_VALUES); +#define MAX_HOSTNAME_LEN 65 + /** * @brief Global initialization for the HTTP API component. *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/azure_c_shared_utility/shared_util_options.h Fri Aug 12 10:04:46 2016 -0700
@@ -0,0 +1,36 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+#ifndef SHARED_UTIL_OPTIONS_H
+#define SHARED_UTIL_OPTIONS_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ typedef struct HTTP_PROXY_OPTIONS_TAG
+ {
+ const char* host_address;
+ int port;
+ const char* username;
+ const char* password;
+ } HTTP_PROXY_OPTIONS;
+
+ static const char* OPTION_HTTP_PROXY = "proxy_data";
+ static const char* OPTION_HTTP_TIMEOUT = "timeout";
+
+ static const char* SU_OPTION_X509_CERT = "x509certificate";
+ static const char* SU_OPTION_X509_PRIVATE_KEY = "x509privatekey";
+
+ static const char* OPTION_CURL_LOW_SPEED_LIMIT = "CURLOPT_LOW_SPEED_LIMIT";
+ static const char* OPTION_CURL_LOW_SPEED_TIME = "CURLOPT_LOW_SPEED_TIME";
+ static const char* OPTION_CURL_FRESH_CONNECT = "CURLOPT_FRESH_CONNECT";
+ static const char* OPTION_CURL_FORBID_REUSE = "CURLOPT_FORBID_REUSE";
+ static const char* OPTION_CURL_VERBOSE = "CURLOPT_VERBOSE";
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SHARED_UTIL_OPTIONS_H */
--- a/azure_c_shared_utility/strings.h Fri Jul 29 16:01:07 2016 -0700 +++ b/azure_c_shared_utility/strings.h Fri Aug 12 10:04:46 2016 -0700 @@ -35,6 +35,8 @@ MOCKABLE_FUNCTION(, size_t, STRING_length, STRING_HANDLE, handle); MOCKABLE_FUNCTION(, int, STRING_compare, STRING_HANDLE, s1, STRING_HANDLE, s2); +extern STRING_HANDLE STRING_construct_sprintf(const char* format, ...); +extern int STRING_sprintf(STRING_HANDLE s1, const char* format, ...); #ifdef __cplusplus }
--- a/azure_c_shared_utility/xlogging.h Fri Jul 29 16:01:07 2016 -0700
+++ b/azure_c_shared_utility/xlogging.h Fri Aug 12 10:04:46 2016 -0700
@@ -20,7 +20,13 @@
LOG_TRACE
} LOG_CATEGORY;
-typedef void(*LOGGER_LOG)(LOG_CATEGORY log_category, unsigned int options, const char* format, ...);
+#if defined _MSC_VER
+#define FUNC_NAME __FUNCDNAME__
+#else
+#define FUNC_NAME __func__
+#endif
+
+typedef void(*LOGGER_LOG)(LOG_CATEGORY log_category, const char* file, const char* func, const int line, unsigned int options, const char* format, ...);
#define LOG_NONE 0x00
#define LOG_LINE 0x01
@@ -31,6 +37,11 @@
#define LogInfo(...)
#define LogError(...)
#define xlogging_get_log_function() NULL
+#define xlogging_set_log_function(...)
+#define LogErrorWinHTTPWithGetLastErrorAsString(...)
+#define log_incoming_frame(...)
+#define log_outgoing_frame(...)
+#define UNUSED(x) (void)(x)
#elif defined(ARDUINO_ARCH_ESP8266)
/*
The ESP8266 compiler dont do a good job compiling this code, it do not understand that the format is
@@ -57,9 +68,9 @@
#else /* !ARDUINO_ARCH_ESP8266 */
#if defined _MSC_VER
-#define LOG(log_category, log_options, format, ...) { LOGGER_LOG l = xlogging_get_log_function(); if (l != NULL) l(log_category, log_options, format, __VA_ARGS__); }
+#define LOG(log_category, log_options, format, ...) { LOGGER_LOG l = xlogging_get_log_function(); if (l != NULL) l(log_category, __FILE__, FUNC_NAME, __LINE__, log_options, format, __VA_ARGS__); }
#else
-#define LOG(log_category, log_options, format, ...) { LOGGER_LOG l = xlogging_get_log_function(); if (l != NULL) l(log_category, log_options, format, ##__VA_ARGS__); }
+#define LOG(log_category, log_options, format, ...) { LOGGER_LOG l = xlogging_get_log_function(); if (l != NULL) l(log_category, __FILE__, FUNC_NAME, __LINE__, log_options, format, ##__VA_ARGS__); }
#endif
#if defined _MSC_VER
--- a/consolelogger.c Fri Jul 29 16:01:07 2016 -0700
+++ b/consolelogger.c Fri Aug 12 10:04:46 2016 -0700
@@ -15,10 +15,10 @@
#define FUNC_NAME __func__
#endif
-void consolelogger_log(LOG_CATEGORY log_category,unsigned int options, const char* format, ...)
+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;
- va_start(args, format);
+ va_list args;
+ va_start(args, format);
time_t t = time(NULL);
@@ -28,7 +28,7 @@
(void)printf("Info: ");
break;
case LOG_ERROR:
- (void)printf("Error: Time:%.24s File:%s Func:%s Line:%d ", ctime(&t), __FILE__, FUNC_NAME, __LINE__);
+ (void)printf("Error: Time:%.24s File:%s Func:%s Line:%d ", ctime(&t), file, func, line);
break;
default:
break;
--- a/strings.c Fri Jul 29 16:01:07 2016 -0700
+++ b/strings.c Fri Aug 12 10:04:46 2016 -0700
@@ -12,6 +12,9 @@
#include <stddef.h>
#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
//
// PUT NO CLIENT LIBRARY INCLUDES BEFORE HERE
//
@@ -119,6 +122,69 @@
return result;
}
+STRING_HANDLE STRING_construct_sprintf(const char* format, ...)
+{
+ STRING* result;
+ if (format != NULL)
+ {
+ va_list arg_list;
+ va_start(arg_list, format);
+
+ /* Codes_SRS_STRING_07_041: [STRING_construct_sprintf shall determine the size of the resulting string and allocate the necessary memory.] */
+ int length = vsnprintf(NULL, 0, format, arg_list);
+ va_end(arg_list);
+ if (length > 0)
+ {
+ result = (STRING*)malloc(sizeof(STRING));
+ if (result != NULL)
+ {
+ result->s = (char*)malloc(length+1);
+ if (result->s != NULL)
+ {
+ va_start(arg_list, format);
+ if (vsnprintf(result->s, length+1, format, arg_list) < 0)
+ {
+ /* Codes_SRS_STRING_07_040: [If any error is encountered STRING_construct_sprintf shall return NULL.] */
+ free(result->s);
+ free(result);
+ result = NULL;
+ LogError("Failure: vsnprintf formatting failed.");
+ }
+ va_end(arg_list);
+ }
+ else
+ {
+ /* Codes_SRS_STRING_07_040: [If any error is encountered STRING_construct_sprintf shall return NULL.] */
+ free(result);
+ result = NULL;
+ LogError("Failure: allocation failed.");
+ }
+ }
+ else
+ {
+ LogError("Failure: allocation failed.");
+ }
+ }
+ else if (length == 0)
+ {
+ result = (STRING*)STRING_new();
+ }
+ else
+ {
+ /* Codes_SRS_STRING_07_039: [If the parameter format is NULL then STRING_construct_sprintf shall return NULL.] */
+ result = NULL;
+ LogError("Failure: vsnprintf return 0 length");
+ }
+ }
+ else
+ {
+ LogError("Failure: invalid argument.");
+ result = NULL;
+ }
+ /* Codes_SRS_STRING_07_045: [STRING_construct_sprintf shall allocate a new string with the value of the specified printf formated const char. ] */
+ return (STRING_HANDLE)result;
+}
+
/*this function will return a new STRING with the memory for the actual string passed in as a parameter.*/
/*return NULL if it fails.*/
/* The supplied memory must have been allocated with malloc! */
@@ -434,6 +500,67 @@
return result;
}
+int STRING_sprintf(STRING_HANDLE handle, const char* format, ...)
+{
+ int result;
+ if (handle == NULL || format == NULL)
+ {
+ /* Codes_SRS_STRING_07_042: [if the parameters s1 or format are NULL then STRING_sprintf shall return non zero value.] */
+ result = __LINE__;
+ LogError("Invalid arg (NULL)");
+ }
+ else
+ {
+ va_list arg_list;
+ va_start(arg_list, format);
+
+ int s2Length = vsnprintf(NULL, 0, format, arg_list);
+ va_end(arg_list);
+ if (s2Length < 0)
+ {
+ /* Codes_SRS_STRING_07_043: [If any error is encountered STRING_sprintf shall return a non zero value.] */
+ result = __LINE__;
+ LogError("Failure vsnprintf return < 0");
+ }
+ else if (s2Length == 0)
+ {
+ // Don't need to reallocate and nothing should be added
+ result = 0;
+ }
+ else
+ {
+ STRING* s1 = (STRING*)handle;
+ size_t s1Length = strlen(s1->s);
+ char* temp = (char*)realloc(s1->s, s1Length + s2Length + 1);
+ if (temp != NULL)
+ {
+ s1->s = temp;
+ va_start(arg_list, format);
+ if (vsnprintf(s1->s + s1Length, s1Length + s2Length + 1, format, arg_list) < 0)
+ {
+ /* Codes_SRS_STRING_07_043: [If any error is encountered STRING_sprintf shall return a non zero value.] */
+ LogError("Failure vsnprintf formatting error");
+ s1->s[s1Length] = '\0';
+ result = __LINE__;
+ }
+ else
+ {
+ /* Codes_SRS_STRING_07_044: [On success STRING_sprintf shall return 0.]*/
+ result = 0;
+ }
+ va_end(arg_list);
+ }
+ else
+ {
+ /* Codes_SRS_STRING_07_043: [If any error is encountered STRING_sprintf shall return a non zero value.] */
+ LogError("Failure unable to reallocate memory");
+ result = __LINE__;
+ }
+ }
+ }
+ return result;
+}
+
/*this function will quote the string passed as argument string =>"string"*/
/*returns 0 if success*/ /*doesn't change the string otherwise*/
/*any other error code is failure*/
--- a/xlogging.c Fri Jul 29 16:01:07 2016 -0700
+++ b/xlogging.c Fri Aug 12 10:04:46 2016 -0700
@@ -9,13 +9,8 @@
#ifdef WINCE
#include <stdarg.h>
-#if defined _MSC_VER
-#define FUNC_NAME __FUNCDNAME__
-#else
-#define FUNC_NAME __func__
-#endif
-void consolelogger_log(LOG_CATEGORY log_category, unsigned int options, const char* format, ...)
+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;
va_start(args, format);
@@ -28,7 +23,7 @@
(void)printf("Info: ");
break;
case LOG_ERROR:
- (void)printf("Error: Time:%.24s File:%s Func:%s Line:%d ", ctime(&t), __FILE__, FUNC_NAME, __LINE__);
+ (void)printf("Error: Time:%.24s File:%s Func:%s Line:%d ", ctime(&t), file, func, line);
break;
default:
break;
