Remove the C simulator
Considering the C# simulator is stable, we are going to retire the C simulator now.
This commit is contained in:
Родитель
9e1b8ed0e7
Коммит
dd838b2946
|
@ -12,9 +12,6 @@ EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventProcessor.WebJob", "EventProcessor\EventProcessor.WebJob\EventProcessor.WebJob.csproj", "{588C29C8-3BF8-4CF6-89A7-33D611388E0E}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventProcessor.WebJob", "EventProcessor\EventProcessor.WebJob\EventProcessor.WebJob.csproj", "{588C29C8-3BF8-4CF6-89A7-33D611388E0E}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simulator.WebJob", "Simulator\Simulator.WebJob\Simulator.WebJob.csproj", "{8F0FF371-2306-4210-9C22-0D0657B595DC}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simulator.WebJob", "Simulator\Simulator.WebJob\Simulator.WebJob.csproj", "{8F0FF371-2306-4210-9C22-0D0657B595DC}"
|
||||||
ProjectSection(ProjectDependencies) = postProject
|
|
||||||
{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533} = {88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}
|
|
||||||
EndProjectSection
|
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{3E3CB1FA-112D-49FB-A60A-71085BF01992}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{3E3CB1FA-112D-49FB-A60A-71085BF01992}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
@ -36,8 +33,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||||
WebEssentials-Settings.json = WebEssentials-Settings.json
|
WebEssentials-Settings.json = WebEssentials-Settings.json
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "iothub_client_sample_device_method", "Simulator\DMSimulator\iothub_client_sample_device_method.vcxproj", "{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -102,14 +97,6 @@ Global
|
||||||
{350C5961-0778-45F8-9A59-D309FCD653DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
{350C5961-0778-45F8-9A59-D309FCD653DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{350C5961-0778-45F8-9A59-D309FCD653DD}.Release|x86.ActiveCfg = Release|Any CPU
|
{350C5961-0778-45F8-9A59-D309FCD653DD}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{350C5961-0778-45F8-9A59-D309FCD653DD}.Release|x86.Build.0 = Release|Any CPU
|
{350C5961-0778-45F8-9A59-D309FCD653DD}.Release|x86.Build.0 = Release|Any CPU
|
||||||
{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
|
||||||
{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}.Debug|Any CPU.Build.0 = Debug|Win32
|
|
||||||
{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}.Debug|x86.ActiveCfg = Debug|Win32
|
|
||||||
{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}.Debug|x86.Build.0 = Debug|Win32
|
|
||||||
{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}.Release|Any CPU.ActiveCfg = Release|Win32
|
|
||||||
{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}.Release|Any CPU.Build.0 = Release|Win32
|
|
||||||
{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}.Release|x86.ActiveCfg = Release|Win32
|
|
||||||
{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}.Release|x86.Build.0 = Release|Win32
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -1,160 +0,0 @@
|
||||||
#include "../SendReport.h"
|
|
||||||
#include "../Utilities.h"
|
|
||||||
#include "ConfigurationUpdate.h"
|
|
||||||
|
|
||||||
// State switch graph: pending -> downloading -> applying -> idle
|
|
||||||
static DMTaskStep _steps[] =
|
|
||||||
{
|
|
||||||
{ CU_PENDING, 0, CU_DOWNLOADING },
|
|
||||||
{ CU_DOWNLOADING, 10, CU_APPLYING },
|
|
||||||
{ CU_APPLYING, 10, DM_IDLE },
|
|
||||||
{ DM_NULL, 0, DM_NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
static char* _version;
|
|
||||||
static time_t _downloadStartTime = 0;
|
|
||||||
static time_t _applyStartTime = 0;
|
|
||||||
|
|
||||||
static BOOL OnEnterState(DMTaskState state, time_t now)
|
|
||||||
{
|
|
||||||
BOOL succeeded = TRUE;
|
|
||||||
|
|
||||||
unsigned char* report = NULL;
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case CU_PENDING:
|
|
||||||
// No report for entering pending state
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CU_DOWNLOADING:
|
|
||||||
_downloadStartTime = now;
|
|
||||||
|
|
||||||
if (strcmp(_version, "downloadFail") == 0)
|
|
||||||
{
|
|
||||||
succeeded = FALSE;
|
|
||||||
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'configurationUpdate': { 'status': 'download failed', 'log': 'download failed' } } }");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'configurationUpdate': { 'status': 'downloading', 'log': 'downloading' } } }");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CU_APPLYING:
|
|
||||||
_applyStartTime = 0;
|
|
||||||
|
|
||||||
if (strcmp(_version, "applyFail") == 0)
|
|
||||||
{
|
|
||||||
succeeded = FALSE;
|
|
||||||
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'configurationUpdate': { 'status': 'apply failed', 'log': 'downloaded(%I64ds) -> apply failed' } } }",
|
|
||||||
now - _downloadStartTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'configurationUpdate': { 'status': 'applying', 'log': 'downloaded(%I64ds) -> applying' } } }",
|
|
||||||
now - _downloadStartTime);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DM_IDLE:
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'configurationUpdate': { 'status': 'updated to %s', 'log': 'downloaded(%I64ds) -> applied(%I64ds)' } }, 'ConfigurationVersion': '%s' }",
|
|
||||||
_version,
|
|
||||||
_applyStartTime - _downloadStartTime,
|
|
||||||
now - _applyStartTime,
|
|
||||||
_version);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
printf("Unknown ConfigurationUpdateState %d", state);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (report != NULL)
|
|
||||||
{
|
|
||||||
SendReport(report, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return succeeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnLeaveState(DMTaskState state, time_t now)
|
|
||||||
{
|
|
||||||
unsigned char* report = NULL;
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case DM_IDLE:
|
|
||||||
// No report for leaving idle state
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CU_PENDING:
|
|
||||||
// No report for leaving pending state
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CU_DOWNLOADING:
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'configurationUpdate': { 'status': 'download completed', 'log': 'downloaded(%I64ds)' } } }",
|
|
||||||
now - _downloadStartTime);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CU_APPLYING:
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'configurationUpdate': { 'status': 'apply completed', 'log': 'downloaded(%I64ds) -> applied(%I64ds)' } } }",
|
|
||||||
_applyStartTime - _downloadStartTime,
|
|
||||||
now - _applyStartTime);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
printf("Unknown ConfigurationUpdateState %d", state);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (report != NULL)
|
|
||||||
{
|
|
||||||
SendReport(report, size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL BeginConfigurationUpdate(const char* uri, DMTaskStep** steps, OnEnterStateProc* onEnterStateProc, OnLeaveStateProc* onLeaveStateProc)
|
|
||||||
{
|
|
||||||
// [WORKAROUND] Directly pick the version from the URI
|
|
||||||
const char* prefix = "/configuration/";
|
|
||||||
char* p = strstr(uri, prefix);
|
|
||||||
if (p == NULL)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
p += strlen(prefix);
|
|
||||||
|
|
||||||
free(_version);
|
|
||||||
_version = _strdup(p);
|
|
||||||
|
|
||||||
*steps = _steps;
|
|
||||||
*onEnterStateProc = OnEnterState;
|
|
||||||
*onLeaveStateProc = OnLeaveState;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "DMTaskBase.h"
|
|
||||||
|
|
||||||
BOOL BeginConfigurationUpdate(const char* uri, DMTaskStep** steps, OnEnterStateProc* onEnterStateProc, OnLeaveStateProc* onLeaveStateProc);
|
|
|
@ -1,28 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
typedef enum _DMTaskState
|
|
||||||
{
|
|
||||||
DM_NULL,
|
|
||||||
DM_IDLE,
|
|
||||||
|
|
||||||
FU_PENDING,
|
|
||||||
FU_DOWNLOADING,
|
|
||||||
FU_APPLYING,
|
|
||||||
FU_REBOOTING,
|
|
||||||
|
|
||||||
CU_PENDING,
|
|
||||||
CU_DOWNLOADING,
|
|
||||||
CU_APPLYING
|
|
||||||
} DMTaskState;
|
|
||||||
|
|
||||||
typedef struct _DMTaskStep
|
|
||||||
{
|
|
||||||
DMTaskState CurrentState;
|
|
||||||
time_t ExecuteTimeInSeconds;
|
|
||||||
DMTaskState NextState;
|
|
||||||
} DMTaskStep;
|
|
||||||
|
|
||||||
typedef BOOL(*OnEnterStateProc)(DMTaskState, time_t);
|
|
||||||
typedef void(*OnLeaveStateProc)(DMTaskState, time_t);
|
|
|
@ -1,138 +0,0 @@
|
||||||
#include "..\Utilities.h"
|
|
||||||
#include "FirmwareUpdate.h"
|
|
||||||
#include "ConfigurationUpdate.h"
|
|
||||||
#include "DMTaskBase.h"
|
|
||||||
#include "DMTaskEngine.h"
|
|
||||||
|
|
||||||
static DMTaskState _currentState = DM_IDLE;
|
|
||||||
static time_t _lastStateUpdateTime = 0;
|
|
||||||
static DMTaskStep* _steps = NULL;
|
|
||||||
static OnEnterStateProc _onEnterStateProc = NULL;
|
|
||||||
static OnLeaveStateProc _onLeaveStateProc = NULL;
|
|
||||||
|
|
||||||
// Method: firmwareUpdate(fwPackageUri)
|
|
||||||
static int OnMethodFirmwareUpdate(const unsigned char* payload, size_t size, unsigned char** response, size_t* resp_size)
|
|
||||||
{
|
|
||||||
if (_currentState != DM_IDLE)
|
|
||||||
{
|
|
||||||
AllocAndPrintf(response, resp_size, "Device is busy", size, payload);
|
|
||||||
return 409;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* uri = GetTopLevelNodeValue((const char*)payload, size, "FwPackageUri");
|
|
||||||
|
|
||||||
int status;
|
|
||||||
if (uri == NULL || !BeginFirmwareUpdate(uri, &_steps, &_onEnterStateProc, &_onLeaveStateProc))
|
|
||||||
{
|
|
||||||
_currentState = DM_IDLE;
|
|
||||||
AllocAndPrintf(response, resp_size, "Bad parameter: %.*s", size, payload);
|
|
||||||
status = 400;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_currentState = _steps->CurrentState;
|
|
||||||
time(&_lastStateUpdateTime);
|
|
||||||
AllocAndPrintf(response, resp_size, "Firmware updating accepted, uri = %s", uri);
|
|
||||||
status = 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(uri);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method: configurationUpdate(configUri)
|
|
||||||
static int OnMethodConfigurationUpdate(const unsigned char* payload, size_t size, unsigned char** response, size_t* resp_size)
|
|
||||||
{
|
|
||||||
if (_currentState != DM_IDLE)
|
|
||||||
{
|
|
||||||
AllocAndPrintf(response, resp_size, "Device is busy", size, payload);
|
|
||||||
return 409;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* uri = GetTopLevelNodeValue((const char*)payload, size, "ConfigUri");
|
|
||||||
|
|
||||||
int status;
|
|
||||||
if (uri == NULL || !BeginConfigurationUpdate(uri, &_steps, &_onEnterStateProc, &_onLeaveStateProc))
|
|
||||||
{
|
|
||||||
_currentState = DM_IDLE;
|
|
||||||
AllocAndPrintf(response, resp_size, "Bad parameter: %.*s", size, payload);
|
|
||||||
status = 400;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_currentState = _steps->CurrentState;
|
|
||||||
time(&_lastStateUpdateTime);
|
|
||||||
AllocAndPrintf(response, resp_size, "Configuration updating accepted, uri = %s", uri);
|
|
||||||
status = 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(uri);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method: ChangeDeviceState(...)
|
|
||||||
static int OnMethodChangeDeviceState(const unsigned char* payload, size_t size, unsigned char** response, size_t* resp_size)
|
|
||||||
{
|
|
||||||
// Return the whole parameter as output
|
|
||||||
*resp_size = size;
|
|
||||||
*response = malloc(*resp_size);
|
|
||||||
memcpy(*response, payload, size);
|
|
||||||
|
|
||||||
_steps = NULL;
|
|
||||||
_currentState = DM_IDLE;
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
int OnDeviceMethod(const char* method_name, const unsigned char* payload, size_t size, unsigned char** response, size_t* resp_size)
|
|
||||||
{
|
|
||||||
if (strcmp(method_name, "FirmwareUpdate") == 0)
|
|
||||||
{
|
|
||||||
return OnMethodFirmwareUpdate(payload, size, response, resp_size);
|
|
||||||
}
|
|
||||||
else if (strcmp(method_name, "ConfigurationUpdate") == 0)
|
|
||||||
{
|
|
||||||
return OnMethodConfigurationUpdate(payload, size, response, resp_size);
|
|
||||||
}
|
|
||||||
else if (strcmp(method_name, "ChangeDeviceState") == 0)
|
|
||||||
{
|
|
||||||
return OnMethodChangeDeviceState(payload, size, response, resp_size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void StepDMTask()
|
|
||||||
{
|
|
||||||
if (_currentState == DM_IDLE)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
time_t now;
|
|
||||||
time(&now);
|
|
||||||
|
|
||||||
for (DMTaskStep* p = _steps; p->CurrentState != DM_NULL; p++)
|
|
||||||
{
|
|
||||||
if (p->CurrentState == _currentState)
|
|
||||||
{
|
|
||||||
if (now >= _lastStateUpdateTime + p->ExecuteTimeInSeconds)
|
|
||||||
{
|
|
||||||
// Switch state according to the graph
|
|
||||||
_onLeaveStateProc(_currentState, now);
|
|
||||||
|
|
||||||
_currentState = p->NextState;
|
|
||||||
_lastStateUpdateTime = now;
|
|
||||||
|
|
||||||
BOOL succeeded = _onEnterStateProc(_currentState, now);
|
|
||||||
if (!succeeded)
|
|
||||||
{
|
|
||||||
_currentState = DM_IDLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
Find matching device method, then kick-off the asynchornize task
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
method_name: device method name
|
|
||||||
payload: device method parameters in JSON
|
|
||||||
size: length of the payload
|
|
||||||
response: device method returned message
|
|
||||||
resp_size: length of the message
|
|
||||||
|
|
||||||
Return
|
|
||||||
The status code if matching method found, otherwise -1
|
|
||||||
*/
|
|
||||||
int OnDeviceMethod(const char* method_name, const unsigned char* payload, size_t size, unsigned char** response, size_t* resp_size);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Run single step of the current task
|
|
||||||
*/
|
|
||||||
void StepDMTask();
|
|
|
@ -1,198 +0,0 @@
|
||||||
#include "../Utilities.h"
|
|
||||||
#include "../SendReport.h"
|
|
||||||
#include "FirmwareUpdate.h"
|
|
||||||
|
|
||||||
// State switch graph: pending -> downloading -> applying -> rebooting -> idle
|
|
||||||
static DMTaskStep _steps[] =
|
|
||||||
{
|
|
||||||
{ FU_PENDING, 0, FU_DOWNLOADING },
|
|
||||||
{ FU_DOWNLOADING, 10, FU_APPLYING },
|
|
||||||
{ FU_APPLYING, 10, FU_REBOOTING },
|
|
||||||
{ FU_REBOOTING, 10, DM_IDLE },
|
|
||||||
{ DM_NULL, 0, DM_NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
static char* _version = NULL;
|
|
||||||
static time_t _downloadStartTime = 0;
|
|
||||||
static time_t _applyStartTime = 0;
|
|
||||||
static time_t _rebootStartTime = 0;
|
|
||||||
|
|
||||||
static BOOL OnEnterState(DMTaskState state, time_t now)
|
|
||||||
{
|
|
||||||
BOOL succeeded = TRUE;
|
|
||||||
|
|
||||||
unsigned char* report = NULL;
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case FU_PENDING:
|
|
||||||
// No report for entering pending state
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FU_DOWNLOADING:
|
|
||||||
_downloadStartTime = now;
|
|
||||||
|
|
||||||
if (strcmp(_version, "downloadFail") == 0)
|
|
||||||
{
|
|
||||||
succeeded = FALSE;
|
|
||||||
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'firmwareUpdate': { 'status': 'download failed', 'log': 'download failed' } } }");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'firmwareUpdate': { 'status': 'downloading', 'log' : 'downloading' } } }");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FU_APPLYING:
|
|
||||||
_applyStartTime = now;
|
|
||||||
|
|
||||||
if (strcmp(_version, "applyFail") == 0)
|
|
||||||
{
|
|
||||||
succeeded = FALSE;
|
|
||||||
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'firmwareUpdate': { 'status': 'apply failed', 'log': 'downloaded(%I64ds) -> apply failed' } } }",
|
|
||||||
now - _downloadStartTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'firmwareUpdate': { 'status': 'applying', 'log': 'downloaded(%I64ds) -> applying' } } }",
|
|
||||||
now - _downloadStartTime);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FU_REBOOTING:
|
|
||||||
_rebootStartTime = now;
|
|
||||||
|
|
||||||
if (strcmp(_version, "rebootFail") == 0)
|
|
||||||
{
|
|
||||||
succeeded = FALSE;
|
|
||||||
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'firmwareUpdate': { 'status': 'reboot failed', 'log': 'downloaded(%I64ds) -> applied(%I64ds) -> reboot failed' } } }",
|
|
||||||
_applyStartTime - _downloadStartTime,
|
|
||||||
now - _applyStartTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'firmwareUpdate': { 'status': 'rebooting', 'log': 'downloaded(%I64ds) -> applied(%I64ds) -> rebooting' } } }",
|
|
||||||
_applyStartTime - _downloadStartTime,
|
|
||||||
now - _applyStartTime);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DM_IDLE:
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'firmwareUpdate': { 'status': 'updated to %s', 'log' : 'downloaded(%I64ds) -> applied(%I64ds) -> rebooted(%I64ds)' } }, 'FirmwareVersion' : '%s' }",
|
|
||||||
_version,
|
|
||||||
_applyStartTime - _downloadStartTime,
|
|
||||||
_rebootStartTime - _applyStartTime,
|
|
||||||
now - _rebootStartTime,
|
|
||||||
_version);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
printf("Unknown FirmwareUpdateState %d", state);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (report != NULL)
|
|
||||||
{
|
|
||||||
SendReport(report, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return succeeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnLeaveState(DMTaskState state, time_t now)
|
|
||||||
{
|
|
||||||
unsigned char* report = NULL;
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case DM_IDLE:
|
|
||||||
// No report for leaving idle state
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FU_PENDING:
|
|
||||||
// No report for leaving pending state
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FU_DOWNLOADING:
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'firmwareUpdate': { 'status': 'download completed', 'log': 'downloaded(%I64ds)' } } }",
|
|
||||||
now - _downloadStartTime);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FU_APPLYING:
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'firmwareUpdate': { 'status': 'apply completed', 'log': 'downloaded(%I64ds) -> applied(%I64ds)' } } }",
|
|
||||||
_applyStartTime - _downloadStartTime,
|
|
||||||
now - _applyStartTime);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FU_REBOOTING:
|
|
||||||
AllocAndPrintf(
|
|
||||||
&report,
|
|
||||||
&size,
|
|
||||||
"{ 'iothubDM': { 'firmwareUpdate': { 'status': 'reboot completed', 'log': 'downloaded(%I64ds) -> applied(%I64ds) -> rebooted(%I64ds)' } } }",
|
|
||||||
_applyStartTime - _downloadStartTime,
|
|
||||||
_rebootStartTime - _applyStartTime,
|
|
||||||
now - _rebootStartTime);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
printf("Unknown FirmwareUpdateState %d", state);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (report != NULL)
|
|
||||||
{
|
|
||||||
SendReport(report, size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL BeginFirmwareUpdate(const char* uri, DMTaskStep** steps, OnEnterStateProc* onEnterStateProc, OnLeaveStateProc* onLeaveStateProc)
|
|
||||||
{
|
|
||||||
// [WORKAROUND] Directly pick the version from the URI
|
|
||||||
const char* prefix = "/firmware/";
|
|
||||||
char* p = strstr(uri, prefix);
|
|
||||||
if (p == NULL)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
p += strlen(prefix);
|
|
||||||
|
|
||||||
free(_version);
|
|
||||||
_version = _strdup(p);
|
|
||||||
|
|
||||||
*steps = _steps;
|
|
||||||
*onEnterStateProc = OnEnterState;
|
|
||||||
*onLeaveStateProc = OnLeaveState;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "DMTaskBase.h"
|
|
||||||
|
|
||||||
BOOL BeginFirmwareUpdate(const char* uri, DMTaskStep** steps, OnEnterStateProc* onEnterStateProc, OnLeaveStateProc* onLeaveStateProc);
|
|
|
@ -1,28 +0,0 @@
|
||||||
#include "SendReport.h"
|
|
||||||
|
|
||||||
static IOTHUB_CLIENT_LL_HANDLE _iotHubClientHandle = NULL;
|
|
||||||
|
|
||||||
static void ReportedStateCallback(int status_code, void* userContextCallback)
|
|
||||||
{
|
|
||||||
(void)userContextCallback;
|
|
||||||
|
|
||||||
printf("\r\nReported state changed\r\n");
|
|
||||||
printf("Status code: %d\r\n", status_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetupSendReport(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle)
|
|
||||||
{
|
|
||||||
_iotHubClientHandle = iotHubClientHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SendReport(unsigned char* report, size_t size)
|
|
||||||
{
|
|
||||||
if (_iotHubClientHandle == NULL)
|
|
||||||
{
|
|
||||||
printf("Failed to send report. IotHubClientHandle has not been set");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
IoTHubClient_LL_SendReportedState(_iotHubClientHandle, report, size, ReportedStateCallback, NULL);
|
|
||||||
printf("Sent report: %.*s\r\n", size, report);
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "iothub_client.h"
|
|
||||||
|
|
||||||
void SetupSendReport(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle);
|
|
||||||
void SendReport(unsigned char* report, size_t size);
|
|
|
@ -1,79 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "jsmn/jsmn.h"
|
|
||||||
#include "Utilities.h"
|
|
||||||
|
|
||||||
#define MAX_TOKENS 32
|
|
||||||
|
|
||||||
char* GetTopLevelNodeValue(const char* json, size_t jsonLen, const char* name)
|
|
||||||
{
|
|
||||||
jsmn_parser parser;
|
|
||||||
jsmntok_t tokens[MAX_TOKENS];
|
|
||||||
|
|
||||||
jsmn_init(&parser);
|
|
||||||
int rst = jsmn_parse(&parser, (char*)json, jsonLen, tokens, MAX_TOKENS);
|
|
||||||
|
|
||||||
int startMin = 0;
|
|
||||||
for (jsmntok_t* t = tokens + 1; t < tokens + rst; t++)
|
|
||||||
{
|
|
||||||
if (t->start <= startMin)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t->type != JSMN_STRING)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
t++;
|
|
||||||
if (t >= tokens + rst)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t->type == JSMN_STRING && strncmp(json + t->start, name, t->size) == 0)
|
|
||||||
{
|
|
||||||
int tokenLen = t->end - t->start;
|
|
||||||
char* buffer = malloc(tokenLen + 1);
|
|
||||||
memcpy(buffer, json + t->start, tokenLen);
|
|
||||||
buffer[tokenLen] = 0;
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
startMin = t->end;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AllocAndPrintf(unsigned char** buffer, size_t* size, const char* format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
*size = vsnprintf(NULL, 0, format, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
*buffer = malloc(*size + 1);
|
|
||||||
va_start(args, format);
|
|
||||||
vsprintf((char*)*buffer, format, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
char* FormatTime(time_t* time)
|
|
||||||
{
|
|
||||||
static char buffer[128];
|
|
||||||
|
|
||||||
struct tm* p = gmtime(time);
|
|
||||||
|
|
||||||
sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02dZ",
|
|
||||||
p->tm_year + 1900,
|
|
||||||
p->tm_mon + 1,
|
|
||||||
p->tm_mday,
|
|
||||||
p->tm_hour,
|
|
||||||
p->tm_min,
|
|
||||||
p->tm_sec);
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
char* GetTopLevelNodeValue(const char* json, size_t jsonLen, const char* name);
|
|
||||||
|
|
||||||
void AllocAndPrintf(unsigned char** buffer, size_t* size, const char* format, ...);
|
|
||||||
|
|
||||||
char* FormatTime(time_t* time);
|
|
|
@ -1,63 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file agenttime.h
|
|
||||||
* @brief Function prototypes for time related functions.
|
|
||||||
*
|
|
||||||
* @details These functions are implemented with C standard functions,
|
|
||||||
* and therefore they are platform independent. But then a platform
|
|
||||||
* can replace these functions with its own implementation as necessary.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef AGENTTIME_H
|
|
||||||
#define AGENTTIME_H
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** @brief Get current calendar time.
|
|
||||||
*
|
|
||||||
* @details This function provides the same functionality as the
|
|
||||||
* standard C @c time() function.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, time_t, get_time, time_t*, currentTime);
|
|
||||||
|
|
||||||
/** @brief Get UTC in @c tm struct.
|
|
||||||
*
|
|
||||||
* @details This function provides the same functionality as the
|
|
||||||
* standard C @c gmtime() function.
|
|
||||||
*/
|
|
||||||
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
|
|
||||||
* standard C @c ctime() function.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, char*, get_ctime, time_t*, timeToGet);
|
|
||||||
|
|
||||||
/** @brief Gets the difference in seconds between @c stopTime and
|
|
||||||
* @c startTime.
|
|
||||||
*
|
|
||||||
* @details This function provides the same functionality as the
|
|
||||||
* standard C @c difftime() function.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, double, get_difftime, time_t, stopTime, time_t, startTime);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // AGENTTIME_H
|
|
|
@ -1,86 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file base64.h
|
|
||||||
* @brief Prototypes for functions related to encoding/decoding
|
|
||||||
* a @c buffer using standard base64 encoding.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BASE64_H
|
|
||||||
#define BASE64_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/strings.h"
|
|
||||||
#include "azure_c_shared_utility/buffer_.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C" {
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
extern const char base64char[64];
|
|
||||||
extern const char base64b16[16];
|
|
||||||
extern const char base64b8[4];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Base64 encodes a buffer and returns the resulting string.
|
|
||||||
*
|
|
||||||
* @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
|
|
||||||
* 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
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Base64 encodes the buffer pointed to by @p source and returns the resulting string.
|
|
||||||
*
|
|
||||||
* @param source The buffer that needs to be base64 encoded.
|
|
||||||
* @param size The size.
|
|
||||||
*
|
|
||||||
* This function produces a @c STRING_HANDLE containing the base64 encoding of the
|
|
||||||
* buffer pointed to by @p source, having the size as given by
|
|
||||||
* @p size. If @p source is @c NULL then @c Base64_Encode_Bytes returns @c NULL
|
|
||||||
* If @p source is not @c NULL and @p size is zero, then @c Base64_Encode_Bytes produces
|
|
||||||
* an empty @c STRING_HANDLE. Otherwise, @c Base64_Encode_Bytes produces a
|
|
||||||
* @c STRING_HANDLE containing the Base64 representation of the buffer. In case of
|
|
||||||
* any errors, @c Base64_Encode_Bytes returns @c NULL.].
|
|
||||||
*
|
|
||||||
* @return @c NULL in case an error occurs or a @c STRING_HANDLE containing the base64 encoding
|
|
||||||
* of @p input.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, Base64_Encode_Bytes, const unsigned char*, source, size_t, size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Base64 decodes the buffer pointed to by @p source and returns the resulting buffer.
|
|
||||||
*
|
|
||||||
* @param source A base64 encoded string buffer.
|
|
||||||
*
|
|
||||||
* This function decodes the string pointed at by @p source using base64 decoding and
|
|
||||||
* returns the resulting buffer. If @p source is @c NULL then
|
|
||||||
* @c Base64_Decoder returns NULL. If the string pointed to by @p source is zero
|
|
||||||
* length then the handle returned refers to a zero length buffer. If there is any
|
|
||||||
* memory allocation failure during the decode or if the source string has an invalid
|
|
||||||
* length for a base 64 encoded string then @c Base64_Decoder returns @c NULL.
|
|
||||||
*
|
|
||||||
* @return A @c BUFFER_HANDLE pointing to a buffer containing the result of base64 decoding @p
|
|
||||||
* source.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, BUFFER_HANDLE, Base64_Decoder, const char*, source);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* BASE64_H */
|
|
|
@ -1,39 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef BUFFER_H
|
|
||||||
#define BUFFER_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
typedef struct BUFFER_TAG* BUFFER_HANDLE;
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_new);
|
|
||||||
MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_create, const unsigned char*, source, size_t, size);
|
|
||||||
MOCKABLE_FUNCTION(, void, BUFFER_delete, BUFFER_HANDLE, handle);
|
|
||||||
MOCKABLE_FUNCTION(, int, BUFFER_pre_build, BUFFER_HANDLE, handle, size_t, size);
|
|
||||||
MOCKABLE_FUNCTION(, int, BUFFER_build, BUFFER_HANDLE, handle, const unsigned char*, source, size_t, size);
|
|
||||||
MOCKABLE_FUNCTION(, int, BUFFER_unbuild, BUFFER_HANDLE, handle);
|
|
||||||
MOCKABLE_FUNCTION(, int, BUFFER_enlarge, BUFFER_HANDLE, handle, size_t, enlargeSize);
|
|
||||||
MOCKABLE_FUNCTION(, int, BUFFER_content, BUFFER_HANDLE, handle, const unsigned char**, content);
|
|
||||||
MOCKABLE_FUNCTION(, int, BUFFER_size, BUFFER_HANDLE, handle, size_t*, size);
|
|
||||||
MOCKABLE_FUNCTION(, int, BUFFER_append, BUFFER_HANDLE, handle1, BUFFER_HANDLE, handle2);
|
|
||||||
MOCKABLE_FUNCTION(, int, BUFFER_prepend, BUFFER_HANDLE, handle1, BUFFER_HANDLE, handle2);
|
|
||||||
MOCKABLE_FUNCTION(, unsigned char*, BUFFER_u_char, BUFFER_HANDLE, handle);
|
|
||||||
MOCKABLE_FUNCTION(, size_t, BUFFER_length, BUFFER_HANDLE, handle);
|
|
||||||
MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_clone, BUFFER_HANDLE, handle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* BUFFER_H */
|
|
|
@ -1,72 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef CONDITION_H
|
|
||||||
#define CONDITION_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/lock.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef void* COND_HANDLE;
|
|
||||||
|
|
||||||
#define COND_RESULT_VALUES \
|
|
||||||
COND_OK, \
|
|
||||||
COND_INVALID_ARG, \
|
|
||||||
COND_ERROR, \
|
|
||||||
COND_TIMEOUT \
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Enumeration specifying the lock status.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(COND_RESULT, COND_RESULT_VALUES);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API creates and returns a valid condition handle.
|
|
||||||
*
|
|
||||||
* @return A valid @c COND_HANDLE when successful or @c NULL otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, COND_HANDLE, Condition_Init);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief unblock all currently working condition.
|
|
||||||
*
|
|
||||||
* @param handle A valid handle to the lock.
|
|
||||||
*
|
|
||||||
* @return Returns @c COND_OK when the condition object has been
|
|
||||||
* destroyed and @c COND_ERROR when an error occurs
|
|
||||||
* and @c COND_TIMEOUT when the handle times out.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, COND_RESULT, Condition_Post, COND_HANDLE, handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief block on the condition handle unti the thread is signalled
|
|
||||||
* or until the timeout_milliseconds is reached.
|
|
||||||
*
|
|
||||||
* @param handle A valid handle to the lock.
|
|
||||||
*
|
|
||||||
* @return Returns @c COND_OK when the condition object has been
|
|
||||||
* destroyed and @c COND_ERROR when an error occurs
|
|
||||||
* and @c COND_TIMEOUT when the handle times out.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, COND_RESULT, Condition_Wait, COND_HANDLE, handle, LOCK_HANDLE, lock, int, timeout_milliseconds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The condition instance is deinitialized.
|
|
||||||
*
|
|
||||||
* @param handle A valid handle to the condition.
|
|
||||||
*
|
|
||||||
* @return Returns @c COND_OK when the condition object has been
|
|
||||||
* destroyed and @c COND_ERROR when an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, Condition_Deinit, COND_HANDLE, handle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* CONDITION_H */
|
|
|
@ -1,19 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef CONSOLELOGGER_H
|
|
||||||
#define CONSOLELOGGER_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/xlogging.h"
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* CONSOLELOGGER_H */
|
|
|
@ -1,45 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef CONSTBUFFER_H
|
|
||||||
#define CONSTBUFFER_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/buffer_.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
/*this is the handle*/
|
|
||||||
typedef struct CONSTBUFFER_HANDLE_DATA_TAG* CONSTBUFFER_HANDLE;
|
|
||||||
|
|
||||||
/*this is what is returned when the content of the buffer needs access*/
|
|
||||||
typedef struct CONSTBUFFER_TAG
|
|
||||||
{
|
|
||||||
const unsigned char* buffer;
|
|
||||||
size_t size;
|
|
||||||
} CONSTBUFFER;
|
|
||||||
|
|
||||||
/*this creates a new constbuffer from a memory area*/
|
|
||||||
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_Create, const unsigned char*, source, size_t, size);
|
|
||||||
|
|
||||||
/*this creates a new constbuffer from an existing BUFFER_HANDLE*/
|
|
||||||
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromBuffer, BUFFER_HANDLE, buffer);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_Clone, CONSTBUFFER_HANDLE, constbufferHandle);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, const CONSTBUFFER*, CONSTBUFFER_GetContent, CONSTBUFFER_HANDLE, constbufferHandle);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, void, CONSTBUFFER_Destroy, CONSTBUFFER_HANDLE, constbufferHandle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* CONSTBUFFER_H */
|
|
|
@ -1,132 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file constmap.h
|
|
||||||
* @brief ConstMap is a module that implements a read-only dictionary
|
|
||||||
* of @c const char* keys to @c const char* values.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONSTMAP_H
|
|
||||||
#define CONSTMAP_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/crt_abstractions.h"
|
|
||||||
#include "azure_c_shared_utility/map.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#define CONSTMAP_RESULT_VALUES \
|
|
||||||
CONSTMAP_OK, \
|
|
||||||
CONSTMAP_ERROR, \
|
|
||||||
CONSTMAP_INVALIDARG, \
|
|
||||||
CONSTMAP_KEYNOTFOUND
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the status of calls to various APIs in this
|
|
||||||
* module.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(CONSTMAP_RESULT, CONSTMAP_RESULT_VALUES);
|
|
||||||
|
|
||||||
typedef struct CONSTMAP_HANDLE_DATA_TAG* CONSTMAP_HANDLE;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a new read-only map from a map handle.
|
|
||||||
*
|
|
||||||
* @param sourceMap The map from which we will populate key,value
|
|
||||||
* into the read-only map.
|
|
||||||
*
|
|
||||||
* @return A valid @c CONSTMAP_HANDLE or @c NULL in case an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, CONSTMAP_HANDLE, ConstMap_Create, MAP_HANDLE, sourceMap);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Destroy a read-only map. Deallocate memory associated with handle.
|
|
||||||
* @param handle Handle to a read-only map.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, ConstMap_Destroy, CONSTMAP_HANDLE, handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Clone a read-only map from another read-only map.
|
|
||||||
* @param handle Handle to a read-only map.
|
|
||||||
* @return A valid @c CONSTMAP_HANDLE or @c NULL in case an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, CONSTMAP_HANDLE, ConstMap_Clone, CONSTMAP_HANDLE, handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create a map handle populated from the read-only map.
|
|
||||||
* @param handle Handle to a read-only map.
|
|
||||||
* @return A valid @c MAP_HANDLE or @c NULL in case an error occurs.
|
|
||||||
*
|
|
||||||
* The new MAP_HANDLE needs to be destroyed when it is no longer needed.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, MAP_HANDLE, ConstMap_CloneWriteable, CONSTMAP_HANDLE, handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function returns a true if the map contains a key
|
|
||||||
* with the same value the parameter @p key.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param key The key that the caller wants checked.
|
|
||||||
*
|
|
||||||
* @return The function returns @c true if the key exists
|
|
||||||
* in the map and @c false if key is not found or
|
|
||||||
* parameters are invalid.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, bool, ConstMap_ContainsKey, CONSTMAP_HANDLE, handle, const char*, key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function returns @c true if at least one <key,value> pair
|
|
||||||
* exists in the map where the entry's value is equal to the
|
|
||||||
* parameter @c value.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param value The value that the caller wants checked.
|
|
||||||
*
|
|
||||||
* @return The function returns @c true if the value exists
|
|
||||||
* in the map and @c false if value is not found or
|
|
||||||
* parameters are invalid.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, bool, ConstMap_ContainsValue, CONSTMAP_HANDLE, handle, const char*, value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Retrieves the value of a stored key.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param key The key to be looked up in the map.
|
|
||||||
*
|
|
||||||
* @return Returns @c NULL in case the input arguments are @c NULL or if the
|
|
||||||
* requested key is not found in the map. Returns a pointer to the
|
|
||||||
* key's value otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, const char*, ConstMap_GetValue, CONSTMAP_HANDLE, handle, const char*, key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Retrieves the complete list of keys and values from the map
|
|
||||||
* in @p values and @p keys. Also writes the size of the list
|
|
||||||
* in @p count.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param keys The location where the list of keys is to be written.
|
|
||||||
* @param values The location where the list of values is to be written.
|
|
||||||
* @param count The number of stored keys and values is written at the
|
|
||||||
* location indicated by this pointer.
|
|
||||||
*
|
|
||||||
* @return Returns @c CONSTMAP_OK if the keys and values are retrieved
|
|
||||||
* and written successfully or an error code otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, CONSTMAP_RESULT, ConstMap_GetInternals, CONSTMAP_HANDLE, handle, const char*const**, keys, const char*const**, values, size_t*, count);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* CONSTMAP_H */
|
|
|
@ -1,161 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef CRT_ABSTRACTIONS_H
|
|
||||||
#define CRT_ABSTRACTIONS_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
|
||||||
#include <cerrno>
|
|
||||||
#include <cmath>
|
|
||||||
extern "C" {
|
|
||||||
#else
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
|
|
||||||
#ifdef QUARKGALILEO
|
|
||||||
#define HAS_STDBOOL
|
|
||||||
#ifdef __cplusplus
|
|
||||||
typedef bool _Bool;
|
|
||||||
#else
|
|
||||||
/*galileo apparently has _Bool and bool as built in types*/
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN32_WCE
|
|
||||||
#define HAS_STDBOOL
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstdbool>
|
|
||||||
/*because C++ doesn't do anything about _Bool... */
|
|
||||||
#define _Bool bool
|
|
||||||
#else
|
|
||||||
#include <stdbool.h>
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
/* WINCE does not support bool as C datatype */
|
|
||||||
#define __bool_true_false_are_defined 1
|
|
||||||
|
|
||||||
#define HAS_STDBOOL
|
|
||||||
|
|
||||||
#define _Bool bool
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define _CSTDBOOL_
|
|
||||||
#else
|
|
||||||
typedef unsigned char bool;
|
|
||||||
|
|
||||||
#define false 0
|
|
||||||
#define true 1
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if defined __STDC_VERSION__
|
|
||||||
#if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
|
|
||||||
/*C99 compiler or C11*/
|
|
||||||
#define HAS_STDBOOL
|
|
||||||
#include <stdbool.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef HAS_STDBOOL
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define _Bool bool
|
|
||||||
#else
|
|
||||||
typedef unsigned char _Bool;
|
|
||||||
typedef unsigned char bool;
|
|
||||||
#define false 0
|
|
||||||
#define true 1
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Codes_SRS_CRT_ABSTRACTIONS_99_001:[The module shall not redefine the secure functions implemented by Microsoft CRT.] */
|
|
||||||
/* Codes_SRS_CRT_ABSTRACTIONS_99_040 : [The module shall still compile when building on a Microsoft platform.] */
|
|
||||||
/* Codes_SRS_CRT_ABSTRACTIONS_99_002: [CRTAbstractions module shall expose the following API]*/
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#else
|
|
||||||
#include "inttypes.h"
|
|
||||||
|
|
||||||
/* Adding definitions from errno.h & crtdefs.h */
|
|
||||||
#if !defined (_TRUNCATE)
|
|
||||||
#define _TRUNCATE ((size_t)-1)
|
|
||||||
#endif /* !defined (_TRUNCATE) */
|
|
||||||
|
|
||||||
#if !defined STRUNCATE
|
|
||||||
#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);
|
|
||||||
extern int sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...);
|
|
||||||
#endif
|
|
||||||
extern unsigned long long strtoull_s(const char* nptr, char** endPtr, int base);
|
|
||||||
extern float strtof_s(const char* nptr, char** endPtr);
|
|
||||||
extern long double strtold_s(const char* nptr, char** endPtr);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, int, mallocAndStrcpy_s, char**, destination, const char*, source);
|
|
||||||
MOCKABLE_FUNCTION(, int, unsignedIntToString, char*, destination, size_t, destinationSize, unsigned int, value);
|
|
||||||
MOCKABLE_FUNCTION(, int, size_tToString, char*, destination, size_t, destinationSize, size_t, value);
|
|
||||||
/*following logic shall define the ISNAN macro*/
|
|
||||||
/*if runing on Microsoft Visual C compiler, than ISNAN shall be _isnan*/
|
|
||||||
/*else if running on C99 or C11, ISNAN shall be isnan*/
|
|
||||||
/*else if running on C89 ... #error and inform user*/
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define ISNAN _isnan
|
|
||||||
#else
|
|
||||||
#if defined __STDC_VERSION__
|
|
||||||
#if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
|
|
||||||
/*C99 compiler or C11*/
|
|
||||||
#define ISNAN isnan
|
|
||||||
#else
|
|
||||||
#error update this file to contain the latest C standard.
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#ifdef __cplusplus
|
|
||||||
/*C++ defines isnan... in C11*/
|
|
||||||
extern "C++" {
|
|
||||||
#define ISNAN std::isnan
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#error unknown (or C89) compiler, provide ISNAN with the same meaning as isnan in C99 standard
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define INT64_PRINTF "%I64d"
|
|
||||||
#else
|
|
||||||
#if defined __STDC_VERSION__
|
|
||||||
#if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
|
|
||||||
/*C99 compiler or C11*/
|
|
||||||
#define INT64_PRINTF "%" PRId64 ""
|
|
||||||
#else
|
|
||||||
#error update this file to contain the latest C standard.
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define INT64_PRINTF "%" PRId64 ""
|
|
||||||
#else
|
|
||||||
#error unknown (or C89) compiler, provide INT64_PRINTF with the same meaning as PRIdN in C99 standard
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* CRT_ABSTRACTIONS_H */
|
|
|
@ -1,43 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef DOUBLYLINKEDLIST_H
|
|
||||||
#define DOUBLYLINKEDLIST_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
typedef struct DLIST_ENTRY_TAG
|
|
||||||
{
|
|
||||||
struct DLIST_ENTRY_TAG *Flink;
|
|
||||||
struct DLIST_ENTRY_TAG *Blink;
|
|
||||||
} DLIST_ENTRY, *PDLIST_ENTRY;
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, void, DList_InitializeListHead, PDLIST_ENTRY, listHead);
|
|
||||||
MOCKABLE_FUNCTION(, int, DList_IsListEmpty, const PDLIST_ENTRY, listHead);
|
|
||||||
MOCKABLE_FUNCTION(, void, DList_InsertTailList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, listEntry);
|
|
||||||
MOCKABLE_FUNCTION(, void, DList_InsertHeadList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, listEntry);
|
|
||||||
MOCKABLE_FUNCTION(, void, DList_AppendTailList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, ListToAppend);
|
|
||||||
MOCKABLE_FUNCTION(, int, DList_RemoveEntryList, PDLIST_ENTRY, listEntry);
|
|
||||||
MOCKABLE_FUNCTION(, PDLIST_ENTRY, DList_RemoveHeadList, PDLIST_ENTRY, listHead);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate the address of the base of the structure given its type, and an
|
|
||||||
// address of a field within the structure.
|
|
||||||
//
|
|
||||||
#define containingRecord(address, type, field) ((type *)((uintptr_t)(address) - offsetof(type,field)))
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* DOUBLYLINKEDLIST_H */
|
|
|
@ -1,69 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef GB_STDIO_H
|
|
||||||
#define GB_STDIO_H
|
|
||||||
|
|
||||||
/*this file, if included instead of <stdio.h> has the following functionality:
|
|
||||||
1) if GB_STDIO_INTERCEPT is defined then
|
|
||||||
a) some of the stdio.h symbols shall be redefined, for example: fopen => gb_fopen
|
|
||||||
b) all "code" using the fopen will actually (because of the preprocessor) call to gb_fopen
|
|
||||||
c) gb_fopen shall blindly call into fopen, thus realizing a passthrough
|
|
||||||
|
|
||||||
reason is: unittesting. fopen is comes with the C Run Time and cannot be mocked (that is, in the global namespace cannot exist a function called fopen
|
|
||||||
|
|
||||||
2) if GB_STDIO_INTERCEPT is not defined then
|
|
||||||
a) it shall include <stdio.h> => no passthrough, just direct linking.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GB_STDIO_INTERCEPT
|
|
||||||
#include <stdio.h>
|
|
||||||
#else
|
|
||||||
|
|
||||||
/*source level intercepting of function calls*/
|
|
||||||
#define fopen fopen_never_called_never_implemented_always_forgotten
|
|
||||||
#define fclose fclose_never_called_never_implemented_always_forgotten
|
|
||||||
#define fseek fseek_never_called_never_implemented_always_forgotten
|
|
||||||
#define ftell ftell_never_called_never_implemented_always_forgotten
|
|
||||||
#define fprintf fprintf_never_called_never_implemented_always_forgotten
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstdio.h>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stdio.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef fopen
|
|
||||||
#define fopen gb_fopen
|
|
||||||
MOCKABLE_FUNCTION(, FILE*, gb_fopen, const char*, filename, const char*, mode);
|
|
||||||
|
|
||||||
|
|
||||||
#undef fclose
|
|
||||||
#define fclose gb_fclose
|
|
||||||
MOCKABLE_FUNCTION(, int, fclose, FILE *, stream);
|
|
||||||
|
|
||||||
#undef fseek
|
|
||||||
#define fseek gb_fseek
|
|
||||||
MOCKABLE_FUNCTION(, int, fseek, FILE *,stream, long int, offset, int, whence);
|
|
||||||
|
|
||||||
#undef ftell
|
|
||||||
#define ftell gb_ftell
|
|
||||||
MOCKABLE_FUNCTION(, long int, ftell, FILE *, stream);
|
|
||||||
|
|
||||||
#undef fprintf
|
|
||||||
#define fprintf gb_fprintf
|
|
||||||
extern int fprintf(FILE * stream, const char * format, ...);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*GB_STDIO_INTERCEPT*/
|
|
||||||
|
|
||||||
#endif /* GB_STDIO_H */
|
|
|
@ -1,57 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef GB_TIME_H
|
|
||||||
#define GB_TIME_H
|
|
||||||
|
|
||||||
/*this file, if included instead of <stdio.h> has the following functionality:
|
|
||||||
1) if GB_TIME_INTERCEPT is defined then
|
|
||||||
a) some of the time.h symbols shall be redefined, for example: time => gb_time
|
|
||||||
b) all "code" using the time will actually (because of the preprocessor) call to gb_time
|
|
||||||
c) gb_time shall blindly call into time, thus realizing a passthrough
|
|
||||||
|
|
||||||
reason is: unittesting. time comes with the C Run Time and cannot be mocked (that is, in the global namespace cannot exist a function called time
|
|
||||||
|
|
||||||
2) if GB_TIME_INTERCEPT is not defined then
|
|
||||||
a) it shall include <time.h> => no passthrough, just direct linking.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GB_TIME_INTERCEPT
|
|
||||||
#include <time.h>
|
|
||||||
#else
|
|
||||||
|
|
||||||
/*source level intercepting of function calls*/
|
|
||||||
#define time time_never_called_never_implemented_always_forgotten
|
|
||||||
#define localtime localtime_never_called_never_implemented_always_forgotten
|
|
||||||
#define strftime strftime_never_called_never_implemented_always_forgotten
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <ctime.h>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#undef time
|
|
||||||
#define time gb_time
|
|
||||||
MOCKABLE_FUNCTION(, time_t, time, time_t *, timer);
|
|
||||||
|
|
||||||
#undef localtime
|
|
||||||
#define localtime gb_localtime
|
|
||||||
MOCKABLE_FUNCTION(, struct tm *, localtime, const time_t *, timer);
|
|
||||||
|
|
||||||
#undef strftime
|
|
||||||
#define strftime gb_strftime
|
|
||||||
MOCKABLE_FUNCTION(, size_t, strftime, char *, s, size_t, maxsize, const char *, format, const struct tm *, timeptr);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*GB_TIME_INTERCEPT*/
|
|
||||||
|
|
||||||
#endif /* GB_TIME_H */
|
|
|
@ -1,68 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef GBALLOC_H
|
|
||||||
#define GBALLOC_H
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstdlib>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
#ifdef _CRTDBG_MAP_ALLOC
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
/* all translation units that need memory measurement need to have GB_MEASURE_MEMORY_FOR_THIS defined */
|
|
||||||
/* GB_DEBUG_ALLOC is the switch that turns the measurement on/off, so that it is not on always */
|
|
||||||
#if defined(GB_DEBUG_ALLOC)
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, int, gballoc_init);
|
|
||||||
MOCKABLE_FUNCTION(, void, gballoc_deinit);
|
|
||||||
MOCKABLE_FUNCTION(, void*, gballoc_malloc, size_t, size);
|
|
||||||
MOCKABLE_FUNCTION(, void*, gballoc_calloc, size_t, nmemb, size_t, size);
|
|
||||||
MOCKABLE_FUNCTION(, void*, gballoc_realloc, void*, ptr, size_t, size);
|
|
||||||
MOCKABLE_FUNCTION(, void, gballoc_free, void*, ptr);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, size_t, gballoc_getMaximumMemoryUsed);
|
|
||||||
MOCKABLE_FUNCTION(, size_t, gballoc_getCurrentMemoryUsed);
|
|
||||||
|
|
||||||
/* 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
|
|
||||||
#if defined(_CRTDBG_MAP_ALLOC) && defined(_DEBUG)
|
|
||||||
#undef _malloc_dbg
|
|
||||||
#undef _calloc_dbg
|
|
||||||
#undef _realloc_dbg
|
|
||||||
#undef _free_dbg
|
|
||||||
#define _malloc_dbg(size, ...) gballoc_malloc(size)
|
|
||||||
#define _calloc_dbg(nmemb, size, ...) gballoc_calloc(nmemb, size)
|
|
||||||
#define _realloc_dbg(ptr, size, ...) gballoc_realloc(ptr, size)
|
|
||||||
#define _free_dbg(ptr, ...) gballoc_free(ptr)
|
|
||||||
#else
|
|
||||||
#define malloc gballoc_malloc
|
|
||||||
#define calloc gballoc_calloc
|
|
||||||
#define realloc gballoc_realloc
|
|
||||||
#define free gballoc_free
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else /* GB_DEBUG_ALLOC */
|
|
||||||
|
|
||||||
#define gballoc_init() 0
|
|
||||||
#define gballoc_deinit() ((void)0)
|
|
||||||
|
|
||||||
#define gballoc_getMaximumMemoryUsed() SIZE_MAX
|
|
||||||
#define gballoc_getCurrentMemoryUsed() SIZE_MAX
|
|
||||||
|
|
||||||
#endif /* GB_DEBUG_ALLOC */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* GBALLOC_H */
|
|
|
@ -1,22 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef HMAC_H
|
|
||||||
#define HMAC_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/sha.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, int, hmac, SHAversion, whichSha, const unsigned char *, text, int, text_len,
|
|
||||||
const unsigned char *, key, int, key_len,
|
|
||||||
uint8_t, digest[USHAMaxHashSize]);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* HMAC_H */
|
|
|
@ -1,28 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef HMACSHA256_H
|
|
||||||
#define HMACSHA256_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/buffer_.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define HMACSHA256_RESULT_VALUES \
|
|
||||||
HMACSHA256_OK, \
|
|
||||||
HMACSHA256_INVALID_ARG, \
|
|
||||||
HMACSHA256_ERROR
|
|
||||||
|
|
||||||
DEFINE_ENUM(HMACSHA256_RESULT, HMACSHA256_RESULT_VALUES)
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, HMACSHA256_RESULT, HMACSHA256_ComputeHash, const unsigned char*, key, size_t, keyLen, const unsigned char*, payload, size_t, payloadLen, BUFFER_HANDLE, hash);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* HMACSHA256_H */
|
|
|
@ -1,198 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file httpapi.h
|
|
||||||
* @brief This module implements the standard HTTP API used by the C IoT client
|
|
||||||
* library.
|
|
||||||
*
|
|
||||||
* @details For example, on the Windows platform the HTTP API code uses
|
|
||||||
* WinHTTP and for Linux it uses curl and so forth. HTTPAPI must support
|
|
||||||
* HTTPs (HTTP+SSL).
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef HTTPAPI_H
|
|
||||||
#define HTTPAPI_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/httpheaders.h"
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/buffer_.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C" {
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct HTTP_HANDLE_DATA_TAG* HTTP_HANDLE;
|
|
||||||
|
|
||||||
#define AMBIGUOUS_STATUS_CODE (300)
|
|
||||||
|
|
||||||
#define HTTPAPI_RESULT_VALUES \
|
|
||||||
HTTPAPI_OK, \
|
|
||||||
HTTPAPI_INVALID_ARG, \
|
|
||||||
HTTPAPI_ERROR, \
|
|
||||||
HTTPAPI_OPEN_REQUEST_FAILED, \
|
|
||||||
HTTPAPI_SET_OPTION_FAILED, \
|
|
||||||
HTTPAPI_SEND_REQUEST_FAILED, \
|
|
||||||
HTTPAPI_RECEIVE_RESPONSE_FAILED, \
|
|
||||||
HTTPAPI_QUERY_HEADERS_FAILED, \
|
|
||||||
HTTPAPI_QUERY_DATA_AVAILABLE_FAILED, \
|
|
||||||
HTTPAPI_READ_DATA_FAILED, \
|
|
||||||
HTTPAPI_ALREADY_INIT, \
|
|
||||||
HTTPAPI_NOT_INIT, \
|
|
||||||
HTTPAPI_HTTP_HEADERS_FAILED, \
|
|
||||||
HTTPAPI_STRING_PROCESSING_ERROR, \
|
|
||||||
HTTPAPI_ALLOC_FAILED, \
|
|
||||||
HTTPAPI_INIT_FAILED, \
|
|
||||||
HTTPAPI_INSUFFICIENT_RESPONSE_BUFFER, \
|
|
||||||
HTTPAPI_SET_X509_FAILURE, \
|
|
||||||
HTTPAPI_SET_TIMEOUTS_FAILED \
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the possible return values for the APIs in
|
|
||||||
* this module.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(HTTPAPI_RESULT, HTTPAPI_RESULT_VALUES);
|
|
||||||
|
|
||||||
#define HTTPAPI_REQUEST_TYPE_VALUES\
|
|
||||||
HTTPAPI_REQUEST_GET, \
|
|
||||||
HTTPAPI_REQUEST_POST, \
|
|
||||||
HTTPAPI_REQUEST_PUT, \
|
|
||||||
HTTPAPI_REQUEST_DELETE, \
|
|
||||||
HTTPAPI_REQUEST_PATCH \
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the HTTP request verbs accepted by
|
|
||||||
* the HTTPAPI module.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(HTTPAPI_REQUEST_TYPE, HTTPAPI_REQUEST_TYPE_VALUES);
|
|
||||||
|
|
||||||
#define MAX_HOSTNAME_LEN 65
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Global initialization for the HTTP API component.
|
|
||||||
*
|
|
||||||
* Platform specific implementations are expected to initialize
|
|
||||||
* the underlying HTTP API stacks.
|
|
||||||
*
|
|
||||||
* @return @c HTTPAPI_OK if initialization is successful or an error
|
|
||||||
* code in case it fails.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTPAPI_RESULT, HTTPAPI_Init);
|
|
||||||
|
|
||||||
/** @brief Free resources allocated in ::HTTPAPI_Init. */
|
|
||||||
MOCKABLE_FUNCTION(, void, HTTPAPI_Deinit);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates an HTTPS connection to the host specified by the @p
|
|
||||||
* hostName parameter.
|
|
||||||
*
|
|
||||||
* @param hostName Name of the host.
|
|
||||||
*
|
|
||||||
* This function returns a handle to the newly created connection.
|
|
||||||
* You can use the handle in subsequent calls to execute specific
|
|
||||||
* HTTP calls using ::HTTPAPI_ExecuteRequest.
|
|
||||||
*
|
|
||||||
* @return A @c HTTP_HANDLE to the newly created connection or @c NULL in
|
|
||||||
* case an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTP_HANDLE, HTTPAPI_CreateConnection, const char*, hostName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Closes a connection created with ::HTTPAPI_CreateConnection.
|
|
||||||
*
|
|
||||||
* @param handle The handle to the HTTP connection created via ::HTTPAPI_CreateConnection.
|
|
||||||
*
|
|
||||||
* All resources allocated by ::HTTPAPI_CreateConnection should be
|
|
||||||
* freed in ::HTTPAPI_CloseConnection.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, HTTPAPI_CloseConnection, HTTP_HANDLE, handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sends the HTTP request to the host and handles the response for
|
|
||||||
* the HTTP call.
|
|
||||||
*
|
|
||||||
* @param handle The handle to the HTTP connection created
|
|
||||||
* via ::HTTPAPI_CreateConnection.
|
|
||||||
* @param requestType Specifies which HTTP method is used (GET,
|
|
||||||
* POST, DELETE, PUT, PATCH).
|
|
||||||
* @param relativePath Specifies the relative path of the URL
|
|
||||||
* excluding the host name.
|
|
||||||
* @param httpHeadersHandle Specifies a set of HTTP headers (name-value
|
|
||||||
* pairs) to be added to the
|
|
||||||
* HTTP request. The @p httpHeadersHandle
|
|
||||||
* handle can be created and setup with
|
|
||||||
* the proper name-value pairs by using the
|
|
||||||
* HTTPHeaders APIs available in @c
|
|
||||||
* HTTPHeaders.h.
|
|
||||||
* @param content Specifies a pointer to the request body.
|
|
||||||
* This value is optional and can be @c NULL.
|
|
||||||
* @param contentLength Specifies the request body size (this is
|
|
||||||
* typically added into the HTTP headers as
|
|
||||||
* the Content-Length header). This value is
|
|
||||||
* optional and can be 0.
|
|
||||||
* @param statusCode This is an out parameter, where
|
|
||||||
* ::HTTPAPI_ExecuteRequest returns the status
|
|
||||||
* code from the HTTP response (200, 201, 400,
|
|
||||||
* 401, etc.)
|
|
||||||
* @param responseHeadersHandle This is an HTTP headers handle to which
|
|
||||||
* ::HTTPAPI_ExecuteRequest must add all the
|
|
||||||
* HTTP response headers so that the caller of
|
|
||||||
* ::HTTPAPI_ExecuteRequest can inspect them.
|
|
||||||
* You can manipulate @p responseHeadersHandle
|
|
||||||
* by using the HTTPHeaders APIs available in
|
|
||||||
* @c HTTPHeaders.h
|
|
||||||
* @param responseContent This is a buffer that must be filled by
|
|
||||||
* ::HTTPAPI_ExecuteRequest with the contents
|
|
||||||
* of the HTTP response body. The buffer size
|
|
||||||
* must be increased by the
|
|
||||||
* ::HTTPAPI_ExecuteRequest implementation in
|
|
||||||
* order to fit the response body.
|
|
||||||
* ::HTTPAPI_ExecuteRequest must also handle
|
|
||||||
* chunked transfer encoding for HTTP responses.
|
|
||||||
* To manipulate the @p responseContent buffer,
|
|
||||||
* use the APIs available in @c Strings.h.
|
|
||||||
*
|
|
||||||
* @return @c HTTPAPI_OK if the API call is successful or an error
|
|
||||||
* code in case it fails.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTPAPI_RESULT, HTTPAPI_ExecuteRequest, HTTP_HANDLE, handle, HTTPAPI_REQUEST_TYPE, requestType, const char*, relativePath,
|
|
||||||
HTTP_HEADERS_HANDLE, httpHeadersHandle, const unsigned char*, content,
|
|
||||||
size_t, contentLength, unsigned int*, statusCode,
|
|
||||||
HTTP_HEADERS_HANDLE, responseHeadersHandle, BUFFER_HANDLE, responseContent);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the option named @p optionName bearing the value
|
|
||||||
* @p value for the HTTP_HANDLE @p handle.
|
|
||||||
*
|
|
||||||
* @param handle The handle to the HTTP connection created via
|
|
||||||
* ::HTTPAPI_CreateConnection.
|
|
||||||
* @param optionName A @c NULL terminated string representing the name
|
|
||||||
* of the option.
|
|
||||||
* @param value A pointer to the value for the option.
|
|
||||||
*
|
|
||||||
* @return @c HTTPAPI_OK if initialization is successful or an error
|
|
||||||
* code in case it fails.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTPAPI_RESULT, HTTPAPI_SetOption, HTTP_HANDLE, handle, const char*, optionName, const void*, value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Clones the option named @p optionName bearing the value @p value
|
|
||||||
* into the pointer @p savedValue.
|
|
||||||
*
|
|
||||||
* @param optionName A @c NULL terminated string representing the name of
|
|
||||||
* the option
|
|
||||||
* @param value A pointer to the value of the option.
|
|
||||||
* @param savedValue This pointer receives the copy of the value of the
|
|
||||||
* option. The copy needs to be free-able.
|
|
||||||
*
|
|
||||||
* @return @c HTTPAPI_OK if initialization is successful or an error
|
|
||||||
* code in case it fails.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTPAPI_RESULT, HTTPAPI_CloneOption, const char*, optionName, const void*, value, const void**, savedValue);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* HTTPAPI_H */
|
|
|
@ -1,106 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file httpapiex.h
|
|
||||||
* @brief This is a utility module that provides HTTP requests with
|
|
||||||
* build-in retry capabilities.
|
|
||||||
*
|
|
||||||
* @details HTTAPIEX is a utility module that provides HTTP requests with build-in
|
|
||||||
* retry capability to an HTTP server. Features over "regular" HTTPAPI include:
|
|
||||||
* - Optional parameters
|
|
||||||
* - Implementation independent
|
|
||||||
* - Retry mechanism
|
|
||||||
* - Persistent options
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef HTTPAPIEX_H
|
|
||||||
#define HTTPAPIEX_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/httpapi.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C" {
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct HTTPAPIEX_HANDLE_DATA_TAG* HTTPAPIEX_HANDLE;
|
|
||||||
|
|
||||||
#define HTTPAPIEX_RESULT_VALUES \
|
|
||||||
HTTPAPIEX_OK, \
|
|
||||||
HTTPAPIEX_ERROR, \
|
|
||||||
HTTPAPIEX_INVALID_ARG, \
|
|
||||||
HTTPAPIEX_RECOVERYFAILED
|
|
||||||
/*to be continued*/
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the status of calls to various APIs in this module.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(HTTPAPIEX_RESULT, HTTPAPIEX_RESULT_VALUES);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates an @c HTTPAPIEX_HANDLE that can be used in further calls.
|
|
||||||
*
|
|
||||||
* @param hostName Pointer to a null-terminated string that contains the host name
|
|
||||||
* of an HTTP server.
|
|
||||||
*
|
|
||||||
* If @p hostName is @c NULL then @c HTTPAPIEX_Create returns @c NULL. The @p
|
|
||||||
* hostName value is saved and associated with the returned handle. If creating
|
|
||||||
* the handle fails for any reason, then @c HTTAPIEX_Create returns @c NULL.
|
|
||||||
* Otherwise, @c HTTPAPIEX_Create returns an @c HTTAPIEX_HANDLE suitable for
|
|
||||||
* further calls to the module.
|
|
||||||
*
|
|
||||||
* @return An @c HTTAPIEX_HANDLE suitable for further calls to the module.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTPAPIEX_HANDLE, HTTPAPIEX_Create, const char*, hostName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Tries to execute an HTTP request.
|
|
||||||
*
|
|
||||||
* @param handle A valid @c HTTPAPIEX_HANDLE value.
|
|
||||||
* @param requestType A value from the ::HTTPAPI_REQUEST_TYPE enum.
|
|
||||||
* @param relativePath Relative path to send the request to on the server.
|
|
||||||
* @param requestHttpHeadersHandle Handle to the request HTTP headers.
|
|
||||||
* @param requestContent The request content.
|
|
||||||
* @param statusCode If non-null, the HTTP status code is written to this
|
|
||||||
* pointer.
|
|
||||||
* @param responseHttpHeadersHandle Handle to the response HTTP headers.
|
|
||||||
* @param responseContent The response content.
|
|
||||||
*
|
|
||||||
* @c HTTPAPIEX_ExecuteRequest tries to execute an HTTP request of type @p
|
|
||||||
* requestType, on the server's @p relativePath, pushing the request HTTP
|
|
||||||
* headers @p requestHttpHeadersHandle, having the content of the request
|
|
||||||
* as pointed to by @p requestContent. If successful, @c HTTAPIEX_ExecuteRequest
|
|
||||||
* writes in the out @p parameter statusCode the HTTP status, populates the @p
|
|
||||||
* responseHeadersHandle with the response headers and copies the response body
|
|
||||||
* to @p responseContent.
|
|
||||||
*
|
|
||||||
* @return An @c HTTAPIEX_HANDLE suitable for further calls to the module.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTPAPIEX_RESULT, HTTPAPIEX_ExecuteRequest, HTTPAPIEX_HANDLE, handle, HTTPAPI_REQUEST_TYPE, requestType, const char*, relativePath, HTTP_HEADERS_HANDLE, requestHttpHeadersHandle, BUFFER_HANDLE, requestContent, unsigned int*, statusCode, HTTP_HEADERS_HANDLE, responseHttpHeadersHandle, BUFFER_HANDLE, responseContent);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Frees all resources used by the @c HTTPAPIEX_HANDLE object.
|
|
||||||
*
|
|
||||||
* @param handle The @c HTTPAPIEX_HANDLE object to be freed.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, HTTPAPIEX_Destroy, HTTPAPIEX_HANDLE, handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the option @p optionName to the value pointed to by @p value.
|
|
||||||
*
|
|
||||||
* @param handle The @c HTTPAPIEX_HANDLE representing this session.
|
|
||||||
* @param optionName Name of the option.
|
|
||||||
* @param value The value to be set for the option.
|
|
||||||
*
|
|
||||||
* @return An @c HTTPAPIEX_RESULT indicating the status of the call.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTPAPIEX_RESULT, HTTPAPIEX_SetOption, HTTPAPIEX_HANDLE, handle, const char*, optionName, const void*, value);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* HTTPAPIEX_H */
|
|
|
@ -1,30 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef HTTPAPIEX_SAS_H
|
|
||||||
#define HTTPAPIEX_SAS_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/strings.h"
|
|
||||||
#include "azure_c_shared_utility/buffer_.h"
|
|
||||||
#include "azure_c_shared_utility/httpheaders.h"
|
|
||||||
#include "azure_c_shared_utility/httpapiex.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct HTTPAPIEX_SAS_STATE_TAG* HTTPAPIEX_SAS_HANDLE;
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, HTTPAPIEX_SAS_HANDLE, HTTPAPIEX_SAS_Create, STRING_HANDLE, key, STRING_HANDLE, uriResource, STRING_HANDLE, keyName);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, void, HTTPAPIEX_SAS_Destroy, HTTPAPIEX_SAS_HANDLE, handle);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, HTTPAPIEX_RESULT, HTTPAPIEX_SAS_ExecuteRequest, HTTPAPIEX_SAS_HANDLE, sasHandle, HTTPAPIEX_HANDLE, handle, HTTPAPI_REQUEST_TYPE, requestType, const char*, relativePath, HTTP_HEADERS_HANDLE, requestHttpHeadersHandle, BUFFER_HANDLE, requestContent, unsigned int*, statusCode, HTTP_HEADERS_HANDLE, responseHeadersHandle, BUFFER_HANDLE, responseContent);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* HTTPAPIEX_SAS_H */
|
|
|
@ -1,158 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file httpheaders.h
|
|
||||||
* @brief This is a utility module that handles HTTP message-headers.
|
|
||||||
*
|
|
||||||
* @details An application would use ::HTTPHeaders_Alloc to create a new set of HTTP headers.
|
|
||||||
* After getting the handle, the application would build in several headers by
|
|
||||||
* consecutive calls to ::HTTPHeaders_AddHeaderNameValuePair. When the headers are
|
|
||||||
* constructed, the application can retrieve the stored data by calling one of the
|
|
||||||
* following functions:
|
|
||||||
* - ::HTTPHeaders_FindHeaderValue - when the name of the header is known and it
|
|
||||||
* wants to know the value of that header
|
|
||||||
* - ::HTTPHeaders_GetHeaderCount - when the application needs to know the count
|
|
||||||
* of all the headers
|
|
||||||
* - ::HTTPHeaders_GetHeader - when the application needs to retrieve the
|
|
||||||
* <code>name + ": " + value</code> string based on an index.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef HTTPHEADERS_H
|
|
||||||
#define HTTPHEADERS_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C" {
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*Codes_SRS_HTTP_HEADERS_99_001:[ HttpHeaders shall have the following interface]*/
|
|
||||||
|
|
||||||
#define HTTP_HEADERS_RESULT_VALUES \
|
|
||||||
HTTP_HEADERS_OK, \
|
|
||||||
HTTP_HEADERS_INVALID_ARG, \
|
|
||||||
HTTP_HEADERS_ALLOC_FAILED, \
|
|
||||||
HTTP_HEADERS_INSUFFICIENT_BUFFER, \
|
|
||||||
HTTP_HEADERS_ERROR \
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the status of calls to various APIs in this module.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(HTTP_HEADERS_RESULT, HTTP_HEADERS_RESULT_VALUES);
|
|
||||||
typedef struct HTTP_HEADERS_HANDLE_DATA_TAG* HTTP_HEADERS_HANDLE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Produces a @c HTTP_HANDLE that can later be used in subsequent calls to the module.
|
|
||||||
*
|
|
||||||
* This function returns @c NULL in case an error occurs. After successful execution
|
|
||||||
* ::HTTPHeaders_GetHeaderCount will report @c 0 existing headers.
|
|
||||||
*
|
|
||||||
* @return A HTTP_HEADERS_HANDLE representing the newly created collection of HTTP headers.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTP_HEADERS_HANDLE, HTTPHeaders_Alloc);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief De-allocates the data structures allocated by previous API calls to the same handle.
|
|
||||||
*
|
|
||||||
* @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, HTTPHeaders_Free, HTTP_HEADERS_HANDLE, httpHeadersHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Adds a header record from the @p name and @p value parameters.
|
|
||||||
*
|
|
||||||
* @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value.
|
|
||||||
* @param name The name of the HTTP header to add. It is invalid for
|
|
||||||
* the name to include the ':' character or character codes
|
|
||||||
* outside the range 33-126.
|
|
||||||
* @param value The value to be assigned to the header.
|
|
||||||
*
|
|
||||||
* The function stores the @c name:value pair in such a way that when later
|
|
||||||
* retrieved by a call to ::HTTPHeaders_GetHeader it will return a string
|
|
||||||
* that is @c strcmp equal to @c name+": "+value. If the name already exists
|
|
||||||
* in the collection of headers, the function concatenates the new value
|
|
||||||
* after the existing value, separated by a comma and a space as in:
|
|
||||||
* <code>old-value+", "+new-value</code>.
|
|
||||||
*
|
|
||||||
* @return Returns @c HTTP_HEADERS_OK when execution is successful or an error code from
|
|
||||||
* the ::HTTPAPIEX_RESULT enum.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_AddHeaderNameValuePair, HTTP_HEADERS_HANDLE, httpHeadersHandle, const char*, name, const char*, value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API performs exactly the same as ::HTTPHeaders_AddHeaderNameValuePair
|
|
||||||
* except that if the header name already exists then the already existing value
|
|
||||||
* will be replaced as opposed to being concatenated to.
|
|
||||||
*
|
|
||||||
* @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value.
|
|
||||||
* @param name The name of the HTTP header to add/replace. It is invalid for
|
|
||||||
* the name to include the ':' character or character codes
|
|
||||||
* outside the range 33-126.
|
|
||||||
* @param value The value to be assigned to the header.
|
|
||||||
*
|
|
||||||
* @return Returns @c HTTP_HEADERS_OK when execution is successful or an error code from
|
|
||||||
* the ::HTTPAPIEX_RESULT enum.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_ReplaceHeaderNameValuePair, HTTP_HEADERS_HANDLE, httpHeadersHandle, const char*, name, const char*, value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Retrieves the value for a previously stored name.
|
|
||||||
*
|
|
||||||
* @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value.
|
|
||||||
* @param name The name of the HTTP header to find.
|
|
||||||
*
|
|
||||||
* @return The return value points to a string that shall be @c strcmp equal
|
|
||||||
* to the original stored string.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, const char*, HTTPHeaders_FindHeaderValue, HTTP_HEADERS_HANDLE, httpHeadersHandle, const char*, name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API retrieves the number of stored headers.
|
|
||||||
*
|
|
||||||
* @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value.
|
|
||||||
* @param headersCount If non-null, the API writes the number of
|
|
||||||
* into the memory pointed at by this parameter.
|
|
||||||
*
|
|
||||||
* @return Returns @c HTTP_HEADERS_OK when execution is successful or
|
|
||||||
* @c HTTP_HEADERS_ERROR when an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_GetHeaderCount, HTTP_HEADERS_HANDLE, httpHeadersHandle, size_t*, headersCount);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API retrieves the string name+": "+value for the header
|
|
||||||
* element at the given @p index.
|
|
||||||
*
|
|
||||||
* @param handle A valid @c HTTP_HEADERS_HANDLE value.
|
|
||||||
* @param index Zero-based index of the item in the
|
|
||||||
* headers collection.
|
|
||||||
* @param destination If non-null, the header value is written into a
|
|
||||||
* new string a pointer to which is written into this
|
|
||||||
* parameters. It is the caller's responsibility to free
|
|
||||||
* this memory.
|
|
||||||
*
|
|
||||||
* @return Returns @c HTTP_HEADERS_OK when execution is successful or
|
|
||||||
* @c HTTP_HEADERS_ERROR when an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_GetHeader, HTTP_HEADERS_HANDLE, handle, size_t, index, char**, destination);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API produces a clone of the @p handle parameter.
|
|
||||||
*
|
|
||||||
* @param handle A valid @c HTTP_HEADERS_HANDLE value.
|
|
||||||
*
|
|
||||||
* If @p handle is not @c NULL this function clones the content
|
|
||||||
* of the handle to a new handle and returns it.
|
|
||||||
*
|
|
||||||
* @return A @c HTTP_HEADERS_HANDLE containing a cloned copy of the
|
|
||||||
* contents of @p handle.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, HTTP_HEADERS_HANDLE, HTTPHeaders_Clone, HTTP_HEADERS_HANDLE, handle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* HTTPHEADERS_H */
|
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef LIST_H
|
|
||||||
#define LIST_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#include <cstdbool>
|
|
||||||
#else
|
|
||||||
#include "stdbool.h"
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
typedef struct LIST_INSTANCE_TAG* LIST_HANDLE;
|
|
||||||
typedef struct LIST_ITEM_INSTANCE_TAG* LIST_ITEM_HANDLE;
|
|
||||||
typedef bool (*LIST_MATCH_FUNCTION)(LIST_ITEM_HANDLE list_item, const void* match_context);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, LIST_HANDLE, list_create);
|
|
||||||
MOCKABLE_FUNCTION(, void, list_destroy, LIST_HANDLE, list);
|
|
||||||
MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, list_add, LIST_HANDLE, list, const void*, item);
|
|
||||||
MOCKABLE_FUNCTION(, int, list_remove, LIST_HANDLE, list, LIST_ITEM_HANDLE, item_handle);
|
|
||||||
MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, list_get_head_item, LIST_HANDLE, list);
|
|
||||||
MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, list_get_next_item, LIST_ITEM_HANDLE, item_handle);
|
|
||||||
MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, list_find, LIST_HANDLE, list, LIST_MATCH_FUNCTION, match_function, const void*, match_context);
|
|
||||||
MOCKABLE_FUNCTION(, const void*, list_item_get_value, LIST_ITEM_HANDLE, item_handle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* LIST_H */
|
|
|
@ -1,77 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file lock.h
|
|
||||||
* @brief A minimalistic platform agnostic lock abstraction for thread
|
|
||||||
* synchronization.
|
|
||||||
* @details The Lock component is implemented in order to achieve thread
|
|
||||||
* synchronization, as we may have a requirement to consume locks
|
|
||||||
* across different platforms. This component exposes some generic
|
|
||||||
* APIs so that it can be extended for platform specific
|
|
||||||
* implementations.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LOCK_H
|
|
||||||
#define LOCK_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef void* LOCK_HANDLE;
|
|
||||||
|
|
||||||
#define LOCK_RESULT_VALUES \
|
|
||||||
LOCK_OK, \
|
|
||||||
LOCK_ERROR \
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the lock status.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(LOCK_RESULT, LOCK_RESULT_VALUES);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API creates and returns a valid lock handle.
|
|
||||||
*
|
|
||||||
* @return A valid @c LOCK_HANDLE when successful or @c NULL otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, LOCK_HANDLE, Lock_Init);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Acquires a lock on the given lock handle. Uses platform
|
|
||||||
* specific mutex primitives in its implementation.
|
|
||||||
*
|
|
||||||
* @param handle A valid handle to the lock.
|
|
||||||
*
|
|
||||||
* @return Returns @c LOCK_OK when a lock has been acquired and
|
|
||||||
* @c LOCK_ERROR when an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, LOCK_RESULT, Lock, LOCK_HANDLE, handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Releases the lock on the given lock handle. Uses platform
|
|
||||||
* specific mutex primitives in its implementation.
|
|
||||||
*
|
|
||||||
* @param handle A valid handle to the lock.
|
|
||||||
*
|
|
||||||
* @return Returns @c LOCK_OK when the lock has been released and
|
|
||||||
* @c LOCK_ERROR when an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, LOCK_RESULT, Unlock, LOCK_HANDLE, handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The lock instance is destroyed.
|
|
||||||
*
|
|
||||||
* @param handle A valid handle to the lock.
|
|
||||||
*
|
|
||||||
* @return Returns @c LOCK_OK when the lock object has been
|
|
||||||
* destroyed and @c LOCK_ERROR when an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, LOCK_RESULT, Lock_Deinit, LOCK_HANDLE, handle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* LOCK_H */
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,202 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file map.h
|
|
||||||
* @brief Map is a module that implements a dictionary of @c STRING_HANDLE
|
|
||||||
* keys to @c STRING_HANDLE values.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MAP_H
|
|
||||||
#define MAP_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/strings.h"
|
|
||||||
#include "azure_c_shared_utility/crt_abstractions.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAP_RESULT_VALUES \
|
|
||||||
MAP_OK, \
|
|
||||||
MAP_ERROR, \
|
|
||||||
MAP_INVALIDARG, \
|
|
||||||
MAP_KEYEXISTS, \
|
|
||||||
MAP_KEYNOTFOUND, \
|
|
||||||
MAP_FILTER_REJECT
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the status of calls to various APIs in this
|
|
||||||
* module.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(MAP_RESULT, MAP_RESULT_VALUES);
|
|
||||||
|
|
||||||
typedef struct MAP_HANDLE_DATA_TAG* MAP_HANDLE;
|
|
||||||
|
|
||||||
typedef int (*MAP_FILTER_CALLBACK)(const char* mapProperty, const char* mapValue);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a new, empty map.
|
|
||||||
*
|
|
||||||
* @param mapFilterFunc A callback function supplied by the caller that is
|
|
||||||
* invoked during calls to ::Map_Add and
|
|
||||||
* ::Map_AddOrUpdate to provide the caller an
|
|
||||||
* opportunity to indicate whether the new entry or
|
|
||||||
* the update to an existing entry can be made or not.
|
|
||||||
* The callback function can request that the operation
|
|
||||||
* be canceled by returning a non-zero value from the
|
|
||||||
* callback.
|
|
||||||
*
|
|
||||||
* @return A valid @c MAP_HANDLE or @c NULL in case an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, MAP_HANDLE, Map_Create, MAP_FILTER_CALLBACK, mapFilterFunc);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Release all resources associated with the map.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, Map_Destroy, MAP_HANDLE, handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a copy of the map indicated by @p handle and returns a
|
|
||||||
* handle to it.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
*
|
|
||||||
* @return A valid @c MAP_HANDLE to the cloned copy of the map or @c NULL
|
|
||||||
* in case an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, MAP_HANDLE, Map_Clone, MAP_HANDLE, handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Adds a key/value pair to the map.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param key The @c key to be used for this map entry.
|
|
||||||
* @param value The @c value to be associated with @p key.
|
|
||||||
*
|
|
||||||
* If a non-NULL pointer to a callback function was supplied
|
|
||||||
* via the @c mapFilterFunc parameter when ::Map_Create was
|
|
||||||
* called then that callback is invoked when a new entry is
|
|
||||||
* added and if the callback returns a non-zero value then
|
|
||||||
* the function cancels the add operation and returns
|
|
||||||
* @c MAP_FILTER_REJECT.
|
|
||||||
*
|
|
||||||
* @return If any of the input parameters are @c NULL then this function
|
|
||||||
* returns @c MAP_INVALID_ARG. If the key already exists in the
|
|
||||||
* map then @c MAP_KEYEXISTS is returned. If the filter function
|
|
||||||
* associated with the map rejects the entry then
|
|
||||||
* @c MAP_FILTER_REJECT is returned. In case an error occurs when
|
|
||||||
* the new key is added to the map the function returns @c MAP_ERROR.
|
|
||||||
* If everything goes well then @c MAP_OK is returned.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_Add, MAP_HANDLE, handle, const char*, key, const char*, value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Adds/updates a key/value pair to the map.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param key The @c key to be used for this map entry.
|
|
||||||
* @param value The @c value to be associated with @p key.
|
|
||||||
*
|
|
||||||
* This function behaves exactly like ::Map_Add except that if the key
|
|
||||||
* already exists in the map then it overwrites the value with the
|
|
||||||
* supplied value instead of returning an error. If a non-NULL pointer
|
|
||||||
* to a callback function was supplied via the @c mapFilterFunc parameter
|
|
||||||
* when ::Map_Create was called then that callback is invoked when a new
|
|
||||||
* entry is added or when an existing entry is updated and if the
|
|
||||||
* callback returns a non-zero value then the function cancels the
|
|
||||||
* add/update operation and returns @c MAP_FILTER_REJECT.
|
|
||||||
*
|
|
||||||
* @return If any of the input parameters are @c NULL then this function
|
|
||||||
* returns @c MAP_INVALID_ARG. If the filter function associated
|
|
||||||
* with the map rejects the entry then @c MAP_FILTER_REJECT is
|
|
||||||
* returned. In case an error occurs when the new key is
|
|
||||||
* added/updated in the map the function returns @c MAP_ERROR. If
|
|
||||||
* everything goes well then @c MAP_OK is returned.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_AddOrUpdate, MAP_HANDLE, handle, const char*, key, const char*, value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Removes a key and its associated value from the map.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param key The @c key of the item to be deleted.
|
|
||||||
*
|
|
||||||
* @return Returns @c MAP_OK if the key was deleted successfully or an
|
|
||||||
* error code otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_Delete, MAP_HANDLE, handle, const char*, key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function returns a boolean value in @p keyExists if the map
|
|
||||||
* contains a key with the same value the parameter @p key.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param key The key that the caller wants checked.
|
|
||||||
* @param keyExists The function writes @c true at the address pointed at
|
|
||||||
* by this parameter if the key exists in the map and
|
|
||||||
* @c false otherwise.
|
|
||||||
*
|
|
||||||
* @return Returns @c MAP_OK if the check was performed successfully or an
|
|
||||||
* error code otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_ContainsKey, MAP_HANDLE, handle, const char*, key, bool*, keyExists);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function returns @c true in @p valueExists if at
|
|
||||||
* least one <key,value> pair exists in the map where the entry's
|
|
||||||
* value is equal to the parameter @c value.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param value The value that the caller wants checked.
|
|
||||||
* @param valueExists The function writes @c true at the address pointed at
|
|
||||||
* by this parameter if the value exists in the map and
|
|
||||||
* @c false otherwise.
|
|
||||||
*
|
|
||||||
* @return Returns @c MAP_OK if the check was performed successfully or an
|
|
||||||
* error code otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_ContainsValue, MAP_HANDLE, handle, const char*, value, bool*, valueExists);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Retrieves the value of a stored key.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param key The key to be looked up in the map.
|
|
||||||
*
|
|
||||||
* @return Returns @c NULL in case the input arguments are @c NULL or if the
|
|
||||||
* requested key is not found in the map. Returns a pointer to the
|
|
||||||
* key's value otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, const char*, Map_GetValueFromKey, MAP_HANDLE, handle, const char*, key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Retrieves the complete list of keys and values from the map
|
|
||||||
* in @p values and @p keys. Also writes the size of the list
|
|
||||||
* in @p count.
|
|
||||||
*
|
|
||||||
* @param handle The handle to an existing map.
|
|
||||||
* @param keys The location where the list of keys is to be written.
|
|
||||||
* @param values The location where the list of values is to be written.
|
|
||||||
* @param count The number of stored keys and values is written at the
|
|
||||||
* location indicated by this pointer.
|
|
||||||
*
|
|
||||||
* @return Returns @c MAP_OK if the keys and values are retrieved and written
|
|
||||||
* successfully or an error code otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_GetInternals, MAP_HANDLE, handle, const char*const**, keys, const char*const**, values, size_t*, count);
|
|
||||||
|
|
||||||
/*this API creates a JSON object from the content of the map*/
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, Map_ToJSON, MAP_HANDLE, handle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* MAP_H */
|
|
|
@ -1,47 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef OPTIONHANDLER_H
|
|
||||||
#define OPTIONHANDLER_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
|
|
||||||
#define OPTIONHANDLER_RESULT_VALUES \
|
|
||||||
OPTIONHANDLER_OK, \
|
|
||||||
OPTIONHANDLER_ERROR, \
|
|
||||||
OPTIONHANDLER_INVALIDARG
|
|
||||||
|
|
||||||
DEFINE_ENUM(OPTIONHANDLER_RESULT, OPTIONHANDLER_RESULT_VALUES)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
typedef struct OPTIONHANDLER_HANDLE_DATA_TAG* OPTIONHANDLER_HANDLE;
|
|
||||||
|
|
||||||
/*the following function pointer points to a function that produces a clone of the option specified by name and value (that is, a clone of void* value)*/
|
|
||||||
/*returns NULL if it failed to produce a clone, otherwise returns a non-NULL value*/
|
|
||||||
/*to be implemented by every module*/
|
|
||||||
typedef void* (*pfCloneOption)(const char* name, const void* value);
|
|
||||||
|
|
||||||
/*the following function pointer points to a function that frees resources allocated for an option*/
|
|
||||||
/*to be implemented by every module*/
|
|
||||||
typedef void (*pfDestroyOption)(const char* name, const void* value);
|
|
||||||
|
|
||||||
/*the following function pointer points to a function that sets an option for a module*/
|
|
||||||
/*to be implemented by every module*/
|
|
||||||
/*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);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /*OPTIONHANDLER*/
|
|
|
@ -1,22 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef PLATFORM_H
|
|
||||||
#define PLATFORM_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#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);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* PLATFORM_H */
|
|
|
@ -1,131 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
|
|
||||||
/*this header contains macros for ref_counting a variable.
|
|
||||||
|
|
||||||
There are no upper bound checks related to uint32_t overflow because we expect that bigger issues are in
|
|
||||||
the system when more than 4 billion references exist to the same variable. In the case when such an overflow
|
|
||||||
occurs, the object's ref count will reach zero (while still having 0xFFFFFFFF references) and likely the
|
|
||||||
controlling code will take the decision to free the object's resources. Then, any of the 0xFFFFFFFF references
|
|
||||||
will interact with deallocated memory / resources resulting in an undefined behavior.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef REFCOUNT_H
|
|
||||||
#define REFCOUNT_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstdint>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
|
|
||||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ == 201112) && (__STDC_NO_ATOMICS__!=1)
|
|
||||||
#define REFCOUNT_USE_STD_ATOMIC 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define REFCOUNT_TYPE(type) \
|
|
||||||
struct C2(C2(REFCOUNT_, type), _TAG)
|
|
||||||
|
|
||||||
#define REFCOUNT_SHORT_TYPE(type) \
|
|
||||||
C2(REFCOUNT_, type)
|
|
||||||
|
|
||||||
#define REFCOUNT_TYPE_DECLARE_CREATE(type) C2(REFCOUNT_SHORT_TYPE(type), _Create)
|
|
||||||
#define REFCOUNT_TYPE_CREATE(type) C2(REFCOUNT_SHORT_TYPE(type), _Create)()
|
|
||||||
|
|
||||||
/*this introduces a new refcount'd type based on another type */
|
|
||||||
/*and an initializer for that new type that also sets the ref count to 1. The type must not have a flexible array*/
|
|
||||||
/*the newly allocated memory shall be free'd by free()*/
|
|
||||||
/*and the ref counting is handled internally by the type in the _Create/ _Clone /_Destroy functions */
|
|
||||||
|
|
||||||
#if defined(REFCOUNT_USE_STD_ATOMIC)
|
|
||||||
#define COUNT_TYPE _Atomic uint32_t
|
|
||||||
#elif defined(WIN32)
|
|
||||||
#define COUNT_TYPE LONG
|
|
||||||
#else
|
|
||||||
#define COUNT_TYPE uint32_t
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define DEFINE_REFCOUNT_TYPE(type) \
|
|
||||||
REFCOUNT_TYPE(type) \
|
|
||||||
{ \
|
|
||||||
type counted; \
|
|
||||||
COUNT_TYPE count; \
|
|
||||||
}; \
|
|
||||||
static type* REFCOUNT_TYPE_DECLARE_CREATE(type) (void) \
|
|
||||||
{ \
|
|
||||||
REFCOUNT_TYPE(type)* result = (REFCOUNT_TYPE(type)*)malloc(sizeof(REFCOUNT_TYPE(type))); \
|
|
||||||
if (result != NULL) \
|
|
||||||
{ \
|
|
||||||
result->count = 1; \
|
|
||||||
} \
|
|
||||||
return (type*)result; \
|
|
||||||
} \
|
|
||||||
|
|
||||||
/*the following macros increment/decrement a ref count in an atomic way, depending on the platform*/
|
|
||||||
/*The following mechanisms are considered in this order
|
|
||||||
C11
|
|
||||||
- will result in #include <stdatomic.h>
|
|
||||||
- will use atomic_fetch_add/sub;
|
|
||||||
- about the return value: "Atomically, the value pointed to by object immediately before the effects"
|
|
||||||
windows
|
|
||||||
- will result in #include "windows.h"
|
|
||||||
- will use InterlockedIncrement/InterlockedDecrement;
|
|
||||||
- about the return value: https://msdn.microsoft.com/en-us/library/windows/desktop/ms683580(v=vs.85).aspx "The function returns the resulting decremented value"
|
|
||||||
gcc
|
|
||||||
- will result in no include (for gcc these are intrinsics build in)
|
|
||||||
- will use __sync_fetch_and_add/sub
|
|
||||||
- about the return value: "... returns the value that had previously been in memory." (https://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Atomic-Builtins.html#Atomic-Builtins)
|
|
||||||
other cases
|
|
||||||
- if REFCOUNT_ATOMIC_DONTCARE is defined, then
|
|
||||||
will result in ++/-- used for increment/decrement.
|
|
||||||
- if it is not defined, then error out
|
|
||||||
|
|
||||||
It seems windows is "one off" because it returns the value "after" the decrement, as opposed to C11 standard and gcc that return the value "before".
|
|
||||||
The macro DEC_RETURN_ZERO will be "0" on windows, and "1" on the other cases.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*if macro DEC_REF returns DEC_RETURN_ZERO that means the ref count has reached zero.*/
|
|
||||||
#if defined(REFCOUNT_USE_STD_ATOMIC)
|
|
||||||
#include <stdatomic.h>
|
|
||||||
#define DEC_RETURN_ZERO (1)
|
|
||||||
#define INC_REF(type, var) atomic_fetch_add((&((REFCOUNT_TYPE(type)*)var)->count), 1)
|
|
||||||
#define DEC_REF(type, var) atomic_fetch_sub((&((REFCOUNT_TYPE(type)*)var)->count), 1)
|
|
||||||
|
|
||||||
#elif defined(WIN32)
|
|
||||||
#include "windows.h"
|
|
||||||
#define DEC_RETURN_ZERO (0)
|
|
||||||
#define INC_REF(type, var) InterlockedIncrement(&(((REFCOUNT_TYPE(type)*)var)->count))
|
|
||||||
#define DEC_REF(type, var) InterlockedDecrement(&(((REFCOUNT_TYPE(type)*)var)->count))
|
|
||||||
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#define DEC_RETURN_ZERO (0)
|
|
||||||
#define INC_REF(type, var) __sync_add_and_fetch((&((REFCOUNT_TYPE(type)*)var)->count), 1)
|
|
||||||
#define DEC_REF(type, var) __sync_sub_and_fetch((&((REFCOUNT_TYPE(type)*)var)->count), 1)
|
|
||||||
|
|
||||||
#else
|
|
||||||
#if defined(REFCOUNT_ATOMIC_DONTCARE)
|
|
||||||
#define DEC_RETURN_ZERO (0)
|
|
||||||
#define INC_REF(type, var) ++((((REFCOUNT_TYPE(type)*)var)->count))
|
|
||||||
#define DEC_REF(type, var) --((((REFCOUNT_TYPE(type)*)var)->count))
|
|
||||||
#else
|
|
||||||
#error do not know how to atomically increment and decrement a uint32_t :(. Platform support needs to be extended to your platform.
|
|
||||||
#endif /*defined(REFCOUNT_ATOMIC_DONTCARE)*/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*REFCOUNT_H*/
|
|
||||||
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef SASTOKEN_H
|
|
||||||
#define SASTOKEN_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/strings.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, SASToken_Create, STRING_HANDLE, key, STRING_HANDLE, scope, STRING_HANDLE, keyName, size_t, expiry);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* SASTOKEN_H */
|
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/*************************** sha-private.h ***************************/
|
|
||||||
/********************** See RFC 4634 for details *********************/
|
|
||||||
#ifndef _SHA_PRIVATE__H
|
|
||||||
#define _SHA_PRIVATE__H
|
|
||||||
/*
|
|
||||||
* These definitions are defined in FIPS-180-2, section 4.1.
|
|
||||||
* Ch() and Maj() are defined identically in sections 4.1.1,
|
|
||||||
* 4.1.2 and 4.1.3.
|
|
||||||
*
|
|
||||||
* The definitions used in FIPS-180-2 are as follows:
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef USE_MODIFIED_MACROS
|
|
||||||
#define SHA_Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
|
|
||||||
#define SHA_Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
|
|
||||||
|
|
||||||
#else /* USE_MODIFIED_MACROS */
|
|
||||||
/*
|
|
||||||
* The following definitions are equivalent and potentially faster.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z))
|
|
||||||
#define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
|
|
||||||
|
|
||||||
#endif /* USE_MODIFIED_MACROS */
|
|
||||||
|
|
||||||
#define SHA_Parity(x, y, z) ((x) ^ (y) ^ (z))
|
|
||||||
|
|
||||||
#endif /* _SHA_PRIVATE__H */
|
|
||||||
|
|
|
@ -1,267 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/**************************** sha.h ****************************/
|
|
||||||
/******************* See RFC 4634 for details ******************/
|
|
||||||
#ifndef _SHA_H_
|
|
||||||
#define _SHA_H_
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Description:
|
|
||||||
* This file implements the Secure Hash Signature Standard
|
|
||||||
* algorithms as defined in the National Institute of Standards
|
|
||||||
* and Technology Federal Information Processing Standards
|
|
||||||
* Publication (FIPS PUB) 180-1 published on April 17, 1995, 180-2
|
|
||||||
* published on August 1, 2002, and the FIPS PUB 180-2 Change
|
|
||||||
* Notice published on February 28, 2004.
|
|
||||||
*
|
|
||||||
* A combined document showing all algorithms is available at
|
|
||||||
* http://csrc.nist.gov/publications/fips/
|
|
||||||
* fips180-2/fips180-2withchangenotice.pdf
|
|
||||||
*
|
|
||||||
* The five hashes are defined in these sizes:
|
|
||||||
* SHA-1 20 byte / 160 bit
|
|
||||||
* SHA-224 28 byte / 224 bit
|
|
||||||
* SHA-256 32 byte / 256 bit
|
|
||||||
* SHA-384 48 byte / 384 bit
|
|
||||||
* SHA-512 64 byte / 512 bit
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
/*
|
|
||||||
* If you do not have the ISO standard stdint.h header file, then you
|
|
||||||
* must typedef the following:
|
|
||||||
* name meaning
|
|
||||||
* uint64_t unsigned 64 bit integer
|
|
||||||
* uint32_t unsigned 32 bit integer
|
|
||||||
* uint8_t unsigned 8 bit integer (i.e., unsigned char)
|
|
||||||
* int_least16_t integer of >= 16 bits
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _SHA_enum_
|
|
||||||
#define _SHA_enum_
|
|
||||||
/*
|
|
||||||
* All SHA functions return one of these values.
|
|
||||||
*/
|
|
||||||
enum {
|
|
||||||
shaSuccess = 0,
|
|
||||||
shaNull, /* Null pointer parameter */
|
|
||||||
shaInputTooLong, /* input data too long */
|
|
||||||
shaStateError, /* called Input after FinalBits or Result */
|
|
||||||
shaBadParam /* passed a bad parameter */
|
|
||||||
};
|
|
||||||
#endif /* _SHA_enum_ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* These constants hold size information for each of the SHA
|
|
||||||
* hashing operations
|
|
||||||
*/
|
|
||||||
enum {
|
|
||||||
SHA1_Message_Block_Size = 64, SHA224_Message_Block_Size = 64,
|
|
||||||
SHA256_Message_Block_Size = 64, SHA384_Message_Block_Size = 128,
|
|
||||||
SHA512_Message_Block_Size = 128,
|
|
||||||
USHA_Max_Message_Block_Size = SHA512_Message_Block_Size,
|
|
||||||
|
|
||||||
SHA1HashSize = 20, SHA224HashSize = 28, SHA256HashSize = 32,
|
|
||||||
SHA384HashSize = 48, SHA512HashSize = 64,
|
|
||||||
USHAMaxHashSize = SHA512HashSize,
|
|
||||||
|
|
||||||
SHA1HashSizeBits = 160, SHA224HashSizeBits = 224,
|
|
||||||
SHA256HashSizeBits = 256, SHA384HashSizeBits = 384,
|
|
||||||
SHA512HashSizeBits = 512, USHAMaxHashSizeBits = SHA512HashSizeBits
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* These constants are used in the USHA (unified sha) functions.
|
|
||||||
*/
|
|
||||||
typedef enum SHAversion {
|
|
||||||
SHA1, SHA224, SHA256, SHA384, SHA512
|
|
||||||
} SHAversion;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This structure will hold context information for the SHA-1
|
|
||||||
* hashing operation.
|
|
||||||
*/
|
|
||||||
typedef struct SHA1Context {
|
|
||||||
uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */
|
|
||||||
|
|
||||||
uint32_t Length_Low; /* Message length in bits */
|
|
||||||
uint32_t Length_High; /* Message length in bits */
|
|
||||||
|
|
||||||
int_least16_t Message_Block_Index; /* Message_Block array index */
|
|
||||||
/* 512-bit message blocks */
|
|
||||||
uint8_t Message_Block[SHA1_Message_Block_Size];
|
|
||||||
|
|
||||||
int Computed; /* Is the digest computed? */
|
|
||||||
int Corrupted; /* Is the digest corrupted? */
|
|
||||||
} SHA1Context;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This structure will hold context information for the SHA-256
|
|
||||||
* hashing operation.
|
|
||||||
*/
|
|
||||||
typedef struct SHA256Context {
|
|
||||||
uint32_t Intermediate_Hash[SHA256HashSize/4]; /* Message Digest */
|
|
||||||
|
|
||||||
uint32_t Length_Low; /* Message length in bits */
|
|
||||||
uint32_t Length_High; /* Message length in bits */
|
|
||||||
|
|
||||||
int_least16_t Message_Block_Index; /* Message_Block array index */
|
|
||||||
/* 512-bit message blocks */
|
|
||||||
uint8_t Message_Block[SHA256_Message_Block_Size];
|
|
||||||
|
|
||||||
int Computed; /* Is the digest computed? */
|
|
||||||
int Corrupted; /* Is the digest corrupted? */
|
|
||||||
} SHA256Context;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This structure will hold context information for the SHA-512
|
|
||||||
* hashing operation.
|
|
||||||
*/
|
|
||||||
typedef struct SHA512Context {
|
|
||||||
#ifdef USE_32BIT_ONLY
|
|
||||||
uint32_t Intermediate_Hash[SHA512HashSize/4]; /* Message Digest */
|
|
||||||
uint32_t Length[4]; /* Message length in bits */
|
|
||||||
#else /* !USE_32BIT_ONLY */
|
|
||||||
uint64_t Intermediate_Hash[SHA512HashSize/8]; /* Message Digest */
|
|
||||||
uint64_t Length_Low, Length_High; /* Message length in bits */
|
|
||||||
#endif /* USE_32BIT_ONLY */
|
|
||||||
|
|
||||||
int_least16_t Message_Block_Index; /* Message_Block array index */
|
|
||||||
/* 1024-bit message blocks */
|
|
||||||
uint8_t Message_Block[SHA512_Message_Block_Size];
|
|
||||||
|
|
||||||
int Computed; /* Is the digest computed?*/
|
|
||||||
int Corrupted; /* Is the digest corrupted? */
|
|
||||||
} SHA512Context;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This structure will hold context information for the SHA-224
|
|
||||||
* hashing operation. It uses the SHA-256 structure for computation.
|
|
||||||
*/
|
|
||||||
typedef struct SHA256Context SHA224Context;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This structure will hold context information for the SHA-384
|
|
||||||
* hashing operation. It uses the SHA-512 structure for computation.
|
|
||||||
*/
|
|
||||||
typedef struct SHA512Context SHA384Context;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This structure holds context information for all SHA
|
|
||||||
* hashing operations.
|
|
||||||
*/
|
|
||||||
typedef struct USHAContext {
|
|
||||||
int whichSha; /* which SHA is being used */
|
|
||||||
union {
|
|
||||||
SHA1Context sha1Context;
|
|
||||||
SHA224Context sha224Context; SHA256Context sha256Context;
|
|
||||||
SHA384Context sha384Context; SHA512Context sha512Context;
|
|
||||||
} ctx;
|
|
||||||
} USHAContext;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This structure will hold context information for the HMAC
|
|
||||||
* keyed hashing operation.
|
|
||||||
*/
|
|
||||||
typedef struct HMACContext {
|
|
||||||
int whichSha; /* which SHA is being used */
|
|
||||||
int hashSize; /* hash size of SHA being used */
|
|
||||||
int blockSize; /* block size of SHA being used */
|
|
||||||
USHAContext shaContext; /* SHA context */
|
|
||||||
unsigned char k_opad[USHA_Max_Message_Block_Size];
|
|
||||||
/* outer padding - key XORd with opad */
|
|
||||||
} HMACContext;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Function Prototypes
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* SHA-1 */
|
|
||||||
extern int SHA1Reset(SHA1Context *);
|
|
||||||
extern int SHA1Input(SHA1Context *, const uint8_t *bytes,
|
|
||||||
unsigned int bytecount);
|
|
||||||
extern int SHA1FinalBits(SHA1Context *, const uint8_t bits,
|
|
||||||
unsigned int bitcount);
|
|
||||||
extern int SHA1Result(SHA1Context *,
|
|
||||||
uint8_t Message_Digest[SHA1HashSize]);
|
|
||||||
|
|
||||||
/* SHA-224 */
|
|
||||||
extern int SHA224Reset(SHA224Context *);
|
|
||||||
extern int SHA224Input(SHA224Context *, const uint8_t *bytes,
|
|
||||||
unsigned int bytecount);
|
|
||||||
extern int SHA224FinalBits(SHA224Context *, const uint8_t bits,
|
|
||||||
unsigned int bitcount);
|
|
||||||
extern int SHA224Result(SHA224Context *,
|
|
||||||
uint8_t Message_Digest[SHA224HashSize]);
|
|
||||||
|
|
||||||
/* SHA-256 */
|
|
||||||
extern int SHA256Reset(SHA256Context *);
|
|
||||||
extern int SHA256Input(SHA256Context *, const uint8_t *bytes,
|
|
||||||
unsigned int bytecount);
|
|
||||||
extern int SHA256FinalBits(SHA256Context *, const uint8_t bits,
|
|
||||||
unsigned int bitcount);
|
|
||||||
extern int SHA256Result(SHA256Context *,
|
|
||||||
uint8_t Message_Digest[SHA256HashSize]);
|
|
||||||
|
|
||||||
/* SHA-384 */
|
|
||||||
extern int SHA384Reset(SHA384Context *);
|
|
||||||
extern int SHA384Input(SHA384Context *, const uint8_t *bytes,
|
|
||||||
unsigned int bytecount);
|
|
||||||
extern int SHA384FinalBits(SHA384Context *, const uint8_t bits,
|
|
||||||
unsigned int bitcount);
|
|
||||||
extern int SHA384Result(SHA384Context *,
|
|
||||||
uint8_t Message_Digest[SHA384HashSize]);
|
|
||||||
|
|
||||||
/* SHA-512 */
|
|
||||||
extern int SHA512Reset(SHA512Context *);
|
|
||||||
extern int SHA512Input(SHA512Context *, const uint8_t *bytes,
|
|
||||||
unsigned int bytecount);
|
|
||||||
extern int SHA512FinalBits(SHA512Context *, const uint8_t bits,
|
|
||||||
unsigned int bitcount);
|
|
||||||
extern int SHA512Result(SHA512Context *,
|
|
||||||
uint8_t Message_Digest[SHA512HashSize]);
|
|
||||||
|
|
||||||
/* Unified SHA functions, chosen by whichSha */
|
|
||||||
extern int USHAReset(USHAContext *, SHAversion whichSha);
|
|
||||||
extern int USHAInput(USHAContext *,
|
|
||||||
const uint8_t *bytes, unsigned int bytecount);
|
|
||||||
extern int USHAFinalBits(USHAContext *,
|
|
||||||
const uint8_t bits, unsigned int bitcount);
|
|
||||||
extern int USHAResult(USHAContext *,
|
|
||||||
uint8_t Message_Digest[USHAMaxHashSize]);
|
|
||||||
extern int USHABlockSize(enum SHAversion whichSha);
|
|
||||||
extern int USHAHashSize(enum SHAversion whichSha);
|
|
||||||
extern int USHAHashSizeBits(enum SHAversion whichSha);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* HMAC Keyed-Hashing for Message Authentication, RFC2104,
|
|
||||||
* for all SHAs.
|
|
||||||
* This interface allows a fixed-length text input to be used.
|
|
||||||
*/
|
|
||||||
extern int hmac(SHAversion whichSha, /* which SHA algorithm to use */
|
|
||||||
const unsigned char *text, /* pointer to data stream */
|
|
||||||
int text_len, /* length of data stream */
|
|
||||||
const unsigned char *key, /* pointer to authentication key */
|
|
||||||
int key_len, /* length of authentication key */
|
|
||||||
uint8_t digest[USHAMaxHashSize]); /* caller digest to fill in */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* HMAC Keyed-Hashing for Message Authentication, RFC2104,
|
|
||||||
* for all SHAs.
|
|
||||||
* This interface allows any length of text input to be used.
|
|
||||||
*/
|
|
||||||
extern int hmacReset(HMACContext *ctx, enum SHAversion whichSha,
|
|
||||||
const unsigned char *key, int key_len);
|
|
||||||
extern int hmacInput(HMACContext *ctx, const unsigned char *text,
|
|
||||||
int text_len);
|
|
||||||
|
|
||||||
extern int hmacFinalBits(HMACContext *ctx, const uint8_t bits,
|
|
||||||
unsigned int bitcount);
|
|
||||||
extern int hmacResult(HMACContext *ctx,
|
|
||||||
uint8_t digest[USHAMaxHashSize]);
|
|
||||||
|
|
||||||
#endif /* _SHA_H_ */
|
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
// 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* OPTION_PROXY_ADDRESS = "proxy_address";
|
|
||||||
static const char* OPTION_PROXY_PORT = "proxy_port";
|
|
||||||
|
|
||||||
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 */
|
|
|
@ -1,41 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef SOCKETIO_H
|
|
||||||
#define SOCKETIO_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#include <cstddef>
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/xio.h"
|
|
||||||
#include "azure_c_shared_utility/xlogging.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
typedef struct SOCKETIO_CONFIG_TAG
|
|
||||||
{
|
|
||||||
const char* hostname;
|
|
||||||
int port;
|
|
||||||
void* accepted_socket;
|
|
||||||
} SOCKETIO_CONFIG;
|
|
||||||
|
|
||||||
#define RECEIVE_BYTES_VALUE 64
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, CONCRETE_IO_HANDLE, socketio_create, void*, io_create_parameters);
|
|
||||||
MOCKABLE_FUNCTION(, void, socketio_destroy, CONCRETE_IO_HANDLE, socket_io);
|
|
||||||
MOCKABLE_FUNCTION(, int, socketio_open, CONCRETE_IO_HANDLE, socket_io, ON_IO_OPEN_COMPLETE, on_io_open_complete, void*, on_io_open_complete_context, ON_BYTES_RECEIVED, on_bytes_received, void*, on_bytes_received_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, socketio_close, CONCRETE_IO_HANDLE, socket_io, ON_IO_CLOSE_COMPLETE, on_io_close_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, socketio_send, CONCRETE_IO_HANDLE, socket_io, const void*, buffer, size_t, size, ON_SEND_COMPLETE, on_send_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, void, socketio_dowork, CONCRETE_IO_HANDLE, socket_io);
|
|
||||||
MOCKABLE_FUNCTION(, int, socketio_setoption, CONCRETE_IO_HANDLE, socket_io, const char*, optionName, const void*, value);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, socketio_get_interface_description);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* SOCKETIO_H */
|
|
|
@ -1,11 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
typedef signed char int8_t;
|
|
||||||
typedef signed short int16_t;
|
|
||||||
typedef signed int int32_t;
|
|
||||||
typedef unsigned char uint8_t;
|
|
||||||
typedef unsigned short uint16_t;
|
|
||||||
typedef unsigned int uint32_t;
|
|
||||||
typedef signed __int64 int64_t;
|
|
||||||
typedef unsigned __int64 uint64_t;
|
|
|
@ -1,28 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef STRING_TOKENIZER_H
|
|
||||||
#define STRING_TOKENIZER_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/strings.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct STRING_TOKEN_TAG* STRING_TOKENIZER_HANDLE;
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, STRING_TOKENIZER_HANDLE, STRING_TOKENIZER_create, STRING_HANDLE, handle);
|
|
||||||
MOCKABLE_FUNCTION(, STRING_TOKENIZER_HANDLE, STRING_TOKENIZER_create_from_char, const char*, input);
|
|
||||||
MOCKABLE_FUNCTION(, int, STRING_TOKENIZER_get_next_token, STRING_TOKENIZER_HANDLE, t, STRING_HANDLE, output, const char*, delimiters);
|
|
||||||
MOCKABLE_FUNCTION(, void, STRING_TOKENIZER_destroy, STRING_TOKENIZER_HANDLE, t);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*STRING_TOKENIZER_H*/
|
|
|
@ -1,45 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef STRINGS_H
|
|
||||||
#define STRINGS_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
typedef struct STRING_TAG* STRING_HANDLE;
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new);
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_clone, STRING_HANDLE, handle);
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_construct, const char*, psz);
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_construct_n, const char*, psz, size_t, n);
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new_with_memory, const char*, memory);
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new_quoted, const char*, source);
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new_JSON, const char*, source);
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_from_byte_array, const unsigned char*, source, size_t, size);
|
|
||||||
MOCKABLE_FUNCTION(, void, STRING_delete, STRING_HANDLE, handle);
|
|
||||||
MOCKABLE_FUNCTION(, int, STRING_concat, STRING_HANDLE, handle, const char*, s2);
|
|
||||||
MOCKABLE_FUNCTION(, int, STRING_concat_with_STRING, STRING_HANDLE, s1, STRING_HANDLE, s2);
|
|
||||||
MOCKABLE_FUNCTION(, int, STRING_quote, STRING_HANDLE, handle);
|
|
||||||
MOCKABLE_FUNCTION(, int, STRING_copy, STRING_HANDLE, s1, const char*, s2);
|
|
||||||
MOCKABLE_FUNCTION(, int, STRING_copy_n, STRING_HANDLE, s1, const char*, s2, size_t, n);
|
|
||||||
MOCKABLE_FUNCTION(, const char*, STRING_c_str, STRING_HANDLE, handle);
|
|
||||||
MOCKABLE_FUNCTION(, int, STRING_empty, STRING_HANDLE, handle);
|
|
||||||
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
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*STRINGS_H*/
|
|
|
@ -1,90 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file threadapi.h
|
|
||||||
* @brief This module implements support for creating new threads,
|
|
||||||
* terminating threads and sleeping threads.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef THREADAPI_H
|
|
||||||
#define THREADAPI_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
typedef int(*THREAD_START_FUNC)(void *);
|
|
||||||
|
|
||||||
#define THREADAPI_RESULT_VALUES \
|
|
||||||
THREADAPI_OK, \
|
|
||||||
THREADAPI_INVALID_ARG, \
|
|
||||||
THREADAPI_NO_MEMORY, \
|
|
||||||
THREADAPI_ERROR
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the possible return values for the APIs in
|
|
||||||
* this module.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(THREADAPI_RESULT, THREADAPI_RESULT_VALUES);
|
|
||||||
|
|
||||||
typedef void* THREAD_HANDLE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a thread with the entry point specified by the @p func
|
|
||||||
* argument.
|
|
||||||
*
|
|
||||||
* @param threadHandle The handle to the new thread is returned in this
|
|
||||||
* pointer.
|
|
||||||
* @param func A function pointer that indicates the entry point
|
|
||||||
* to the new thread.
|
|
||||||
* @param arg A void pointer that must be passed to the function
|
|
||||||
* pointed to by @p func.
|
|
||||||
*
|
|
||||||
* @return @c THREADAPI_OK if the API call is successful or an error
|
|
||||||
* code in case it fails.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, THREADAPI_RESULT, ThreadAPI_Create, THREAD_HANDLE*, threadHandle, THREAD_START_FUNC, func, void*, arg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Blocks the calling thread by waiting on the thread identified by
|
|
||||||
* the @p threadHandle argument to complete.
|
|
||||||
*
|
|
||||||
* @param threadHandle The handle of the thread to wait for completion.
|
|
||||||
* @param res The result returned by the thread which is passed
|
|
||||||
* to the ::ThreadAPI_Exit function.
|
|
||||||
*
|
|
||||||
* When the @p threadHandle thread completes, all resources associated
|
|
||||||
* with the thread must be released and the thread handle will no
|
|
||||||
* longer be valid.
|
|
||||||
*
|
|
||||||
* @return @c THREADAPI_OK if the API call is successful or an error
|
|
||||||
* code in case it fails.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, THREADAPI_RESULT, ThreadAPI_Join, THREAD_HANDLE, threadHandle, int*, res);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is called by a thread when the thread exits.
|
|
||||||
*
|
|
||||||
* @param res An integer that represents the exit status of the thread.
|
|
||||||
*
|
|
||||||
* This function is called by a thread when the thread exits in order
|
|
||||||
* to return a result value to the caller of the ::ThreadAPI_Join
|
|
||||||
* function. The @p res value must be copied into the @p res out
|
|
||||||
* argument passed to the ::ThreadAPI_Join function.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, ThreadAPI_Exit, int, res);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sleeps the current thread for the given number of milliseconds.
|
|
||||||
*
|
|
||||||
* @param milliseconds The number of milliseconds to sleep.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, ThreadAPI_Sleep, unsigned int, milliseconds);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* THREADAPI_H */
|
|
|
@ -1,26 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef TICKCOUNTER_H
|
|
||||||
#define TICKCOUNTER_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#include <cstdint>
|
|
||||||
#else
|
|
||||||
#include <stdint.h>
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
typedef struct TICK_COUNTER_INSTANCE_TAG* TICK_COUNTER_HANDLE;
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, TICK_COUNTER_HANDLE, tickcounter_create);
|
|
||||||
MOCKABLE_FUNCTION(, void, tickcounter_destroy, TICK_COUNTER_HANDLE, tick_counter);
|
|
||||||
MOCKABLE_FUNCTION(, int, tickcounter_get_current_ms, TICK_COUNTER_HANDLE, tick_counter, uint64_t*, current_ms);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* TICKCOUNTER_H */
|
|
|
@ -1,22 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef TLSIO_H
|
|
||||||
#define TLSIO_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct TLSIO_CONFIG_TAG
|
|
||||||
{
|
|
||||||
const char* hostname;
|
|
||||||
int port;
|
|
||||||
} TLSIO_CONFIG;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* TLSIO_H */
|
|
|
@ -1,34 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef TLSIO_OPENSSL_H
|
|
||||||
#define TLSIO_OPENSSL_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#include <cstddef>
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/xio.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_openssl_init);
|
|
||||||
MOCKABLE_FUNCTION(, void, tlsio_openssl_deinit);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, CONCRETE_IO_HANDLE, tlsio_openssl_create, void*, io_create_parameters);
|
|
||||||
MOCKABLE_FUNCTION(, void, tlsio_openssl_destroy, CONCRETE_IO_HANDLE, tls_io);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_openssl_open, CONCRETE_IO_HANDLE, tls_io, ON_IO_OPEN_COMPLETE, on_io_open_complete, void*, on_io_open_complete_context, ON_BYTES_RECEIVED, on_bytes_received, void*, on_bytes_received_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_openssl_close, CONCRETE_IO_HANDLE, tls_io, ON_IO_CLOSE_COMPLETE, on_io_close_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_openssl_send, CONCRETE_IO_HANDLE, tls_io, const void*, buffer, size_t, size, ON_SEND_COMPLETE, on_send_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, void, tlsio_openssl_dowork, CONCRETE_IO_HANDLE, tls_io);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_openssl_setoption, CONCRETE_IO_HANDLE, tls_io, const char*, optionName, const void*, value);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, tlsio_openssl_get_interface_description);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* TLSIO_OPENSSL_H */
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef TLSIO_SCHANNEL_H
|
|
||||||
#define TLSIO_SCHANNEL_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#include <cstddef>
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/xio.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, CONCRETE_IO_HANDLE, tlsio_schannel_create, void*, io_create_parameters);
|
|
||||||
MOCKABLE_FUNCTION(, void, tlsio_schannel_destroy, CONCRETE_IO_HANDLE, tls_io);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_schannel_open, CONCRETE_IO_HANDLE, tls_io, ON_IO_OPEN_COMPLETE, on_io_open_complete, void*, on_io_open_complete_context, ON_BYTES_RECEIVED, on_bytes_received, void*, on_bytes_received_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_schannel_close, CONCRETE_IO_HANDLE, tls_io, ON_IO_CLOSE_COMPLETE, on_io_close_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_schannel_send, CONCRETE_IO_HANDLE, tls_io, const void*, buffer, size_t, size, ON_SEND_COMPLETE, on_send_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, void, tlsio_schannel_dowork, CONCRETE_IO_HANDLE, tls_io);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_schannel_setoption, CONCRETE_IO_HANDLE, tls_io, const char*, optionName, const void*, value);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, tlsio_schannel_get_interface_description);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* TLSIO_SCHANNEL_H */
|
|
|
@ -1,32 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef TLSIO_WOLFSSL_H
|
|
||||||
#define TLSIO_WOLFSSL_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#include <cstddef>
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/xio.h"
|
|
||||||
#include "azure_c_shared_utility/xlogging.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, CONCRETE_IO_HANDLE, tlsio_wolfssl_create, void*, io_create_parameters);
|
|
||||||
MOCKABLE_FUNCTION(, void, tlsio_wolfssl_destroy, CONCRETE_IO_HANDLE, tls_io);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_wolfssl_open, CONCRETE_IO_HANDLE, tls_io, ON_IO_OPEN_COMPLETE, on_io_open_complete, void*, on_io_open_complete_context, ON_BYTES_RECEIVED, on_bytes_received, void*, on_bytes_received_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_wolfssl_close, CONCRETE_IO_HANDLE, tls_io, ON_IO_CLOSE_COMPLETE, on_io_close_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_wolfssl_send, CONCRETE_IO_HANDLE, tls_io, const void*, buffer, size_t, size, ON_SEND_COMPLETE, on_send_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, void, tlsio_wolfssl_dowork, CONCRETE_IO_HANDLE, tls_io);
|
|
||||||
MOCKABLE_FUNCTION(, int, tlsio_wolfssl_setoption, CONCRETE_IO_HANDLE, tls_io, const char*, optionName, const void*, value);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, tlsio_wolfssl_get_interface_description);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* TLSIO_WOLFSSL_H */
|
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#undef MOCKABLE_FUNCTION
|
|
||||||
|
|
||||||
/* This header is meant to be included by production code headers, so that the MOCKABLE_FUNCTION gets enabled. */
|
|
||||||
/*
|
|
||||||
If you are porting to a new platform and do not want to build the tests, but only the production code,
|
|
||||||
simply make sure that this file is in the include path (either by copying it to your inc folder or
|
|
||||||
by adjusting the include paths).
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef ENABLE_MOCKS
|
|
||||||
|
|
||||||
/* Codes_SRS_UMOCK_C_LIB_01_001: [MOCKABLE_FUNCTION shall be used to wrap function definition allowing the user to declare a function that can be mocked.]*/
|
|
||||||
#define MOCKABLE_FUNCTION(modifiers, result, function, ...) \
|
|
||||||
MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK(modifiers, result, function, __VA_ARGS__)
|
|
||||||
|
|
||||||
#include "umock_c.h"
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
|
|
||||||
#define UMOCK_C_PROD_ARG_IN_SIGNATURE(count, arg_type, arg_name) arg_type arg_name IFCOMMA(count)
|
|
||||||
|
|
||||||
/* Codes_SRS_UMOCK_C_LIB_01_002: [The macro shall generate a function signature in case ENABLE_MOCKS is not defined.] */
|
|
||||||
/* Codes_SRS_UMOCK_C_LIB_01_005: [**If ENABLE_MOCKS is not defined, MOCKABLE_FUNCTION shall only generate a declaration for the function.] */
|
|
||||||
/* Codes_SRS_UMOCK_C_LIB_01_001: [MOCKABLE_FUNCTION shall be used to wrap function definition allowing the user to declare a function that can be mocked.]*/
|
|
||||||
#define MOCKABLE_FUNCTION(modifiers, result, function, ...) \
|
|
||||||
result modifiers function(IF(COUNT_ARG(__VA_ARGS__),,void) FOR_EACH_2_COUNTED(UMOCK_C_PROD_ARG_IN_SIGNATURE, __VA_ARGS__));
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef UNIQUEID_H
|
|
||||||
#define UNIQUEID_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C" {
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#define UNIQUEID_RESULT_VALUES \
|
|
||||||
UNIQUEID_OK, \
|
|
||||||
UNIQUEID_INVALID_ARG, \
|
|
||||||
UNIQUEID_ERROR
|
|
||||||
|
|
||||||
DEFINE_ENUM(UNIQUEID_RESULT, UNIQUEID_RESULT_VALUES)
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, UNIQUEID_RESULT, UniqueId_Generate, char*, uid, size_t, bufferSize);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* UNIQUEID_H */
|
|
|
@ -1,23 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef URLENCODE_H
|
|
||||||
#define URLENCODE_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/strings.h"
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, URL_EncodeString, const char*, textEncode);
|
|
||||||
MOCKABLE_FUNCTION(, STRING_HANDLE, URL_Encode, STRING_HANDLE, input);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* URLENCODE_H */
|
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef VECTOR_H
|
|
||||||
#define VECTOR_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/crt_abstractions.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdbool>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct VECTOR_TAG* VECTOR_HANDLE;
|
|
||||||
|
|
||||||
typedef bool(*PREDICATE_FUNCTION)(const void* element, const void* value);
|
|
||||||
|
|
||||||
/* creation */
|
|
||||||
MOCKABLE_FUNCTION(, VECTOR_HANDLE, VECTOR_create, size_t, elementSize);
|
|
||||||
MOCKABLE_FUNCTION(, void, VECTOR_destroy, VECTOR_HANDLE, handle);
|
|
||||||
|
|
||||||
/* insertion */
|
|
||||||
MOCKABLE_FUNCTION(, int, VECTOR_push_back, VECTOR_HANDLE, handle, const void*, elements, size_t, numElements);
|
|
||||||
|
|
||||||
/* removal */
|
|
||||||
MOCKABLE_FUNCTION(, void, VECTOR_erase, VECTOR_HANDLE, handle, void*, elements, size_t, numElements);
|
|
||||||
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);
|
|
||||||
|
|
||||||
/* capacity */
|
|
||||||
MOCKABLE_FUNCTION(, size_t, VECTOR_size, const VECTOR_HANDLE, handle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* VECTOR_H */
|
|
|
@ -1,13 +0,0 @@
|
||||||
// cstdbool standard header
|
|
||||||
#pragma once
|
|
||||||
#ifndef _CSTDBOOL_
|
|
||||||
#define _CSTDBOOL_
|
|
||||||
#include <yvals.h>
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#endif /* _CSTDBOOL_ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 1992-2013 by P.J. Plauger. ALL RIGHTS RESERVED.
|
|
||||||
* Consult your license regarding permissions and restrictions.
|
|
||||||
V6.40:0009 */
|
|
|
@ -1,18 +0,0 @@
|
||||||
#ifndef _WINCE_STDBOOL
|
|
||||||
#define _WINCE_STDBOOL
|
|
||||||
|
|
||||||
#define __bool_true_false_are_defined 1
|
|
||||||
|
|
||||||
#define HAS_STDBOOL
|
|
||||||
|
|
||||||
#ifndef __cplusplus
|
|
||||||
|
|
||||||
typedef unsigned char bool;
|
|
||||||
typedef bool _Bool;
|
|
||||||
|
|
||||||
#define false 0
|
|
||||||
#define true 1
|
|
||||||
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* _WINCE_STDBOOL */
|
|
|
@ -1,46 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef WSIO_H
|
|
||||||
#define WSIO_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdbool>
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/xio.h"
|
|
||||||
#include "azure_c_shared_utility/xlogging.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
typedef struct WSIO_CONFIG_TAG
|
|
||||||
{
|
|
||||||
const char* host;
|
|
||||||
int port;
|
|
||||||
const char* protocol_name;
|
|
||||||
const char* relative_path;
|
|
||||||
bool use_ssl;
|
|
||||||
} WSIO_CONFIG;
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, CONCRETE_IO_HANDLE, wsio_create, void*, io_create_parameters);
|
|
||||||
MOCKABLE_FUNCTION(, void, wsio_destroy, CONCRETE_IO_HANDLE, ws_io);
|
|
||||||
MOCKABLE_FUNCTION(, int, wsio_open, CONCRETE_IO_HANDLE, ws_io, ON_IO_OPEN_COMPLETE, on_io_open_complete, void*, on_io_open_complete_context, ON_BYTES_RECEIVED, on_bytes_received, void*, on_bytes_received_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, wsio_close, CONCRETE_IO_HANDLE, ws_io, ON_IO_CLOSE_COMPLETE, on_io_close_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, wsio_send, CONCRETE_IO_HANDLE, ws_io, const void*, buffer, size_t, size, ON_SEND_COMPLETE, on_send_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, void, wsio_dowork, CONCRETE_IO_HANDLE, ws_io);
|
|
||||||
MOCKABLE_FUNCTION(, int, wsio_setoption, CONCRETE_IO_HANDLE, socket_io, const char*, optionName, const void*, value);
|
|
||||||
MOCKABLE_FUNCTION(, void*, wsio_clone_option, const char*, name, const void*, value);
|
|
||||||
MOCKABLE_FUNCTION(, void, wsio_destroy_option, const char*, name, const void*, value);
|
|
||||||
MOCKABLE_FUNCTION(, OPTIONHANDLER_HANDLE, wsio_retrieveoptions, CONCRETE_IO_HANDLE, handle);
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, wsio_get_interface_description);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* WSIO_H */
|
|
|
@ -1,21 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef X509_OPENSSL_H
|
|
||||||
#define X509_OPENSSL_H
|
|
||||||
|
|
||||||
#include "openssl/ssl.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(,int, x509_openssl_add_credentials, SSL_CTX*, ssl_ctx, const char*, x509certificate, const char*, x509privatekey);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,26 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef X509_SCHANNEL_H
|
|
||||||
#define X509_SCHANNEL_H
|
|
||||||
|
|
||||||
#include "windows.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
typedef struct X509_SCHANNEL_HANDLE_DATA_TAG* X509_SCHANNEL_HANDLE;
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, X509_SCHANNEL_HANDLE, x509_schannel_create, const char*, x509certificate, const char*, x509privatekey);
|
|
||||||
MOCKABLE_FUNCTION(, void, x509_schannel_destroy, X509_SCHANNEL_HANDLE, x509_schannel_handle);
|
|
||||||
MOCKABLE_FUNCTION(, PCCERT_CONTEXT, x509_schannel_get_certificate_context, X509_SCHANNEL_HANDLE, x509_schannel_handle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,77 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef XIO_H
|
|
||||||
#define XIO_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/optionhandler.h"
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/xlogging.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C" {
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
typedef struct XIO_INSTANCE_TAG* XIO_HANDLE;
|
|
||||||
typedef void* CONCRETE_IO_HANDLE;
|
|
||||||
|
|
||||||
typedef enum IO_SEND_RESULT_TAG
|
|
||||||
{
|
|
||||||
IO_SEND_OK,
|
|
||||||
IO_SEND_ERROR,
|
|
||||||
IO_SEND_CANCELLED
|
|
||||||
} IO_SEND_RESULT;
|
|
||||||
|
|
||||||
typedef enum IO_OPEN_RESULT_TAG
|
|
||||||
{
|
|
||||||
IO_OPEN_OK,
|
|
||||||
IO_OPEN_ERROR,
|
|
||||||
IO_OPEN_CANCELLED
|
|
||||||
} IO_OPEN_RESULT;
|
|
||||||
|
|
||||||
typedef void(*ON_BYTES_RECEIVED)(void* context, const unsigned char* buffer, size_t size);
|
|
||||||
typedef void(*ON_SEND_COMPLETE)(void* context, IO_SEND_RESULT send_result);
|
|
||||||
typedef void(*ON_IO_OPEN_COMPLETE)(void* context, IO_OPEN_RESULT open_result);
|
|
||||||
typedef void(*ON_IO_CLOSE_COMPLETE)(void* context);
|
|
||||||
typedef void(*ON_IO_ERROR)(void* context);
|
|
||||||
|
|
||||||
typedef OPTIONHANDLER_HANDLE (*IO_RETRIEVEOPTIONS)(CONCRETE_IO_HANDLE concrete_io);
|
|
||||||
typedef CONCRETE_IO_HANDLE(*IO_CREATE)(void* io_create_parameters);
|
|
||||||
typedef void(*IO_DESTROY)(CONCRETE_IO_HANDLE concrete_io);
|
|
||||||
typedef int(*IO_OPEN)(CONCRETE_IO_HANDLE concrete_io, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context);
|
|
||||||
typedef int(*IO_CLOSE)(CONCRETE_IO_HANDLE concrete_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context);
|
|
||||||
typedef int(*IO_SEND)(CONCRETE_IO_HANDLE concrete_io, const void* buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void* callback_context);
|
|
||||||
typedef void(*IO_DOWORK)(CONCRETE_IO_HANDLE concrete_io);
|
|
||||||
typedef int(*IO_SETOPTION)(CONCRETE_IO_HANDLE concrete_io, const char* optionName, const void* value);
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct IO_INTERFACE_DESCRIPTION_TAG
|
|
||||||
{
|
|
||||||
IO_RETRIEVEOPTIONS concrete_io_retrieveoptions;
|
|
||||||
IO_CREATE concrete_io_create;
|
|
||||||
IO_DESTROY concrete_io_destroy;
|
|
||||||
IO_OPEN concrete_io_open;
|
|
||||||
IO_CLOSE concrete_io_close;
|
|
||||||
IO_SEND concrete_io_send;
|
|
||||||
IO_DOWORK concrete_io_dowork;
|
|
||||||
IO_SETOPTION concrete_io_setoption;
|
|
||||||
} IO_INTERFACE_DESCRIPTION;
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, XIO_HANDLE, xio_create, const IO_INTERFACE_DESCRIPTION*, io_interface_description, const void*, io_create_parameters);
|
|
||||||
MOCKABLE_FUNCTION(, void, xio_destroy, XIO_HANDLE, xio);
|
|
||||||
MOCKABLE_FUNCTION(, int, xio_open, XIO_HANDLE, xio, ON_IO_OPEN_COMPLETE, on_io_open_complete, void*, on_io_open_complete_context, ON_BYTES_RECEIVED, on_bytes_received, void*, on_bytes_received_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, xio_close, XIO_HANDLE, xio, ON_IO_CLOSE_COMPLETE, on_io_close_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, int, xio_send, XIO_HANDLE, xio, const void*, buffer, size_t, size, ON_SEND_COMPLETE, on_send_complete, void*, callback_context);
|
|
||||||
MOCKABLE_FUNCTION(, void, xio_dowork, XIO_HANDLE, xio);
|
|
||||||
MOCKABLE_FUNCTION(, int, xio_setoption, XIO_HANDLE, xio, const char*, optionName, const void*, value);
|
|
||||||
MOCKABLE_FUNCTION(, OPTIONHANDLER_HANDLE, xio_retrieveoptions, XIO_HANDLE, xio);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* XIO_H */
|
|
|
@ -1,130 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef XLOGGING_H
|
|
||||||
#define XLOGGING_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstdio>
|
|
||||||
#else
|
|
||||||
#include <stdio.h>
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/agenttime.h"
|
|
||||||
|
|
||||||
typedef enum LOG_CATEGORY_TAG
|
|
||||||
{
|
|
||||||
LOG_ERROR,
|
|
||||||
LOG_INFO,
|
|
||||||
LOG_TRACE
|
|
||||||
} LOG_CATEGORY;
|
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
/*no logging is useful when time and fprintf are mocked*/
|
|
||||||
#ifdef NO_LOGGING
|
|
||||||
#define LOG(...)
|
|
||||||
#define LogInfo(...)
|
|
||||||
#define LogError(...)
|
|
||||||
#define xlogging_get_log_function() NULL
|
|
||||||
#define xlogging_set_log_function(...)
|
|
||||||
#define LogErrorWinHTTPWithGetLastErrorAsString(...)
|
|
||||||
#define UNUSED(x) (void)(x)
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
/*
|
|
||||||
The ESP8266 compiler don’t do a good job compiling this code, it do not understand that the ‘format?is
|
|
||||||
a ‘cont char*?and moves it to the RAM as a global variable, increasing a lot the .bss. So, we create a
|
|
||||||
specific LogInfo that explicitly pin 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 do not support the pinned ‘format?and os_printf do not works with va_list,
|
|
||||||
so we compacted the log in the macro LogInfo.
|
|
||||||
*/
|
|
||||||
#include "esp8266/azcpgmspace.h"
|
|
||||||
#define LogInfo(FORMAT, ...) { \
|
|
||||||
const char* __localFORMAT = PSTR(FORMAT); \
|
|
||||||
os_printf(__localFORMAT, ##__VA_ARGS__); \
|
|
||||||
os_printf("\r\n"); \
|
|
||||||
}
|
|
||||||
#define LogError LogInfo
|
|
||||||
|
|
||||||
#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, __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, __FILE__, FUNC_NAME, __LINE__, log_options, format, ##__VA_ARGS__); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined _MSC_VER
|
|
||||||
#define LogInfo(FORMAT, ...) do{LOG(LOG_INFO, LOG_LINE, FORMAT, __VA_ARGS__); }while(0)
|
|
||||||
#else
|
|
||||||
#define LogInfo(FORMAT, ...) do{LOG(LOG_INFO, LOG_LINE, FORMAT, ##__VA_ARGS__); }while(0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined _MSC_VER
|
|
||||||
#define LogError(FORMAT, ...) do{ LOG(LOG_ERROR, LOG_LINE, FORMAT, __VA_ARGS__); }while(0)
|
|
||||||
#define TEMP_BUFFER_SIZE 1024
|
|
||||||
#define MESSAGE_BUFFER_SIZE 260
|
|
||||||
#define LogErrorWinHTTPWithGetLastErrorAsString(FORMAT, ...) do { \
|
|
||||||
DWORD errorMessageID = GetLastError(); \
|
|
||||||
LogError(FORMAT, __VA_ARGS__); \
|
|
||||||
CHAR messageBuffer[MESSAGE_BUFFER_SIZE]; \
|
|
||||||
if (errorMessageID == 0) \
|
|
||||||
{\
|
|
||||||
LogError("GetLastError() returned 0. Make sure you are calling this right after the code that failed. "); \
|
|
||||||
} \
|
|
||||||
else\
|
|
||||||
{\
|
|
||||||
int size = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, \
|
|
||||||
GetModuleHandle("WinHttp"), errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), messageBuffer, MESSAGE_BUFFER_SIZE, NULL); \
|
|
||||||
if (size == 0)\
|
|
||||||
{\
|
|
||||||
size = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), messageBuffer, MESSAGE_BUFFER_SIZE, NULL); \
|
|
||||||
if (size == 0)\
|
|
||||||
{\
|
|
||||||
LogError("GetLastError Code: %d. ", errorMessageID); \
|
|
||||||
}\
|
|
||||||
else\
|
|
||||||
{\
|
|
||||||
LogError("GetLastError: %s.", messageBuffer); \
|
|
||||||
}\
|
|
||||||
}\
|
|
||||||
else\
|
|
||||||
{\
|
|
||||||
LogError("GetLastError: %s.", messageBuffer); \
|
|
||||||
}\
|
|
||||||
}\
|
|
||||||
} while(0)
|
|
||||||
#else
|
|
||||||
#define LogError(FORMAT, ...) do{ LOG(LOG_ERROR, LOG_LINE, FORMAT, ##__VA_ARGS__); }while(0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
extern void xlogging_set_log_function(LOGGER_LOG log_function);
|
|
||||||
extern LOGGER_LOG xlogging_get_log_function(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* ARDUINO_ARCH_ESP8266 */
|
|
||||||
|
|
||||||
#endif /* XLOGGING_H */
|
|
|
@ -1,55 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file blob.h
|
|
||||||
* @brief Contains blob APIs needed for File Upload feature of IoTHub client.
|
|
||||||
*
|
|
||||||
* @details IoTHub client needs to upload a byte array by using blob storage API
|
|
||||||
* IoTHub service provides the complete SAS URI to execute a PUT request
|
|
||||||
* that will upload the data.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BLOB_H
|
|
||||||
#define BLOB_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/buffer_.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#define BLOB_RESULT_VALUES \
|
|
||||||
BLOB_OK, \
|
|
||||||
BLOB_ERROR, \
|
|
||||||
BLOB_NOT_IMPLEMENTED, \
|
|
||||||
BLOB_HTTP_ERROR, \
|
|
||||||
BLOB_INVALID_ARG
|
|
||||||
|
|
||||||
DEFINE_ENUM(BLOB_RESULT, BLOB_RESULT_VALUES)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Synchronously uploads a byte array to blob storage
|
|
||||||
*
|
|
||||||
* @param SASURI The URI to use to upload data
|
|
||||||
* @param size The size of the data to be uploaded (can be 0)
|
|
||||||
* @param source A pointer to the byte array to be uploaded (can be NULL, but then size needs to be zero)
|
|
||||||
* @param httpStatus A pointer to an out argument receiving the HTTP status (available only when the return value is BLOB_OK)
|
|
||||||
* @param httpResponse A BUFFER_HANDLE that receives the HTTP response from the server (available only when the return value is BLOB_OK)
|
|
||||||
*
|
|
||||||
* @return A @c BLOB_RESULT. BLOB_OK means the blob has been uploaded successfully. Any other value indicates an error
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, BLOB_RESULT, Blob_UploadFromSasUri,const char*, SASURI, const unsigned char*, source, size_t, size, unsigned int*, httpStatus, BUFFER_HANDLE, httpResponse)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* BLOB_H */
|
|
|
@ -1,269 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file iothub_client.h
|
|
||||||
* @brief Extends the IoTHubCLient_LL module with additional features.
|
|
||||||
*
|
|
||||||
* @details IoTHubClient is a module that extends the IoTHubCLient_LL
|
|
||||||
* module with 2 features:
|
|
||||||
* - scheduling the work for the IoTHubCLient from a
|
|
||||||
* thread, so that the user does not need to create their
|
|
||||||
* own thread
|
|
||||||
* - thread-safe APIs
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef IOTHUB_CLIENT_H
|
|
||||||
#define IOTHUB_CLIENT_H
|
|
||||||
|
|
||||||
typedef struct IOTHUB_CLIENT_INSTANCE_TAG* IOTHUB_CLIENT_HANDLE;
|
|
||||||
|
|
||||||
#include "iothub_client_ll.h"
|
|
||||||
#include "iothubtransport.h"
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define IOTHUB_CLIENT_FILE_UPLOAD_RESULT_VALUES \
|
|
||||||
FILE_UPLOAD_OK ,\
|
|
||||||
FILE_UPLOAD_ERROR
|
|
||||||
|
|
||||||
DEFINE_ENUM(IOTHUB_CLIENT_FILE_UPLOAD_RESULT, IOTHUB_CLIENT_FILE_UPLOAD_RESULT_VALUES)
|
|
||||||
typedef void(*IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK)(IOTHUB_CLIENT_FILE_UPLOAD_RESULT result, void* userContextCallback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a IoT Hub client for communication with an existing
|
|
||||||
* IoT Hub using the specified connection string parameter.
|
|
||||||
*
|
|
||||||
* @param connectionString Pointer to a character string
|
|
||||||
* @param protocol Function pointer for protocol implementation
|
|
||||||
*
|
|
||||||
* Sample connection string:
|
|
||||||
* <blockquote>
|
|
||||||
* <pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessKey=[Device key goes here];</pre>
|
|
||||||
* <pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessSignature=SharedAccessSignature sr=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net]/devices/[Device ID goes here]&sig=[SAS Token goes here]&se=[Expiry Time goes here];</pre>
|
|
||||||
* </blockquote>
|
|
||||||
*
|
|
||||||
* @return A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
|
|
||||||
* invoking other functions for IoT Hub client and @c NULL on failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_HANDLE, IoTHubClient_CreateFromConnectionString, const char*, connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a IoT Hub client for communication with an existing IoT
|
|
||||||
* Hub using the specified parameters.
|
|
||||||
*
|
|
||||||
* @param config Pointer to an @c IOTHUB_CLIENT_CONFIG structure
|
|
||||||
*
|
|
||||||
* The API does not allow sharing of a connection across multiple
|
|
||||||
* devices. This is a blocking call.
|
|
||||||
*
|
|
||||||
* @return A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
|
|
||||||
* invoking other functions for IoT Hub client and @c NULL on failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_HANDLE, IoTHubClient_Create, const IOTHUB_CLIENT_CONFIG*, config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a IoT Hub client for communication with an existing IoT
|
|
||||||
* Hub using the specified parameters.
|
|
||||||
*
|
|
||||||
* @param transportHandle TRANSPORT_HANDLE which represents a connection.
|
|
||||||
* @param config Pointer to an @c IOTHUB_CLIENT_CONFIG structure
|
|
||||||
*
|
|
||||||
* The API allows sharing of a connection across multiple
|
|
||||||
* devices. This is a blocking call.
|
|
||||||
*
|
|
||||||
* @return A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
|
|
||||||
* invoking other functions for IoT Hub client and @c NULL on failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_HANDLE, IoTHubClient_CreateWithTransport, TRANSPORT_HANDLE, transportHandle, const IOTHUB_CLIENT_CONFIG*, config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Disposes of resources allocated by the IoT Hub client. This is a
|
|
||||||
* blocking call.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, IoTHubClient_Destroy, IOTHUB_CLIENT_HANDLE, iotHubClientHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Asynchronous call to send the message specified by @p eventMessageHandle.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param eventMessageHandle The handle to an IoT Hub message.
|
|
||||||
* @param eventConfirmationCallback The callback specified by the device for receiving
|
|
||||||
* confirmation of the delivery of the IoT Hub message.
|
|
||||||
* This callback can be expected to invoke the
|
|
||||||
* ::IoTHubClient_SendEventAsync function for the
|
|
||||||
* same message in an attempt to retry sending a failing
|
|
||||||
* message. The user can specify a @c NULL value here to
|
|
||||||
* indicate that no callback is required.
|
|
||||||
* @param userContextCallback User specified context that will be provided to the
|
|
||||||
* callback. This can be @c NULL.
|
|
||||||
*
|
|
||||||
* @b NOTE: The application behavior is undefined if the user calls
|
|
||||||
* the ::IoTHubClient_Destroy function from within any callback.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SendEventAsync, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_MESSAGE_HANDLE, eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, eventConfirmationCallback, void*, userContextCallback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function returns the current sending status for IoTHubClient.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param iotHubClientStatus The sending state is populated at the address pointed
|
|
||||||
* at by this parameter. The value will be set to
|
|
||||||
* @c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
|
|
||||||
* no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
|
|
||||||
* if there are.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_GetSendStatus, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_STATUS*, iotHubClientStatus);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets up the message callback to be invoked when IoT Hub issues a
|
|
||||||
* message to the device. This is a blocking call.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param messageCallback The callback specified by the device for receiving
|
|
||||||
* messages from IoT Hub.
|
|
||||||
* @param userContextCallback User specified context that will be provided to the
|
|
||||||
* callback. This can be @c NULL.
|
|
||||||
*
|
|
||||||
* @b NOTE: The application behavior is undefined if the user calls
|
|
||||||
* the ::IoTHubClient_Destroy function from within any callback.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetMessageCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC, messageCallback, void*, userContextCallback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function returns in the out parameter @p lastMessageReceiveTime
|
|
||||||
* what was the value of the @c time function when the last message was
|
|
||||||
* received at the client.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param lastMessageReceiveTime Out parameter containing the value of @c time function
|
|
||||||
* when the last message was received.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_GetLastMessageReceiveTime, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, time_t*, lastMessageReceiveTime);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API sets a runtime option identified by parameter @p optionName
|
|
||||||
* to a value pointed to by @p value. @p optionName and the data type
|
|
||||||
* @p value is pointing to are specific for every option.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param optionName Name of the option.
|
|
||||||
* @param value The value.
|
|
||||||
*
|
|
||||||
* The options that can be set via this API are:
|
|
||||||
* - @b timeout - the maximum time in milliseconds a communication is
|
|
||||||
* allowed to use. @p value is a pointer to an @c unsigned @c int with
|
|
||||||
* the timeout value in milliseconds. This is only supported for the HTTP
|
|
||||||
* protocol as of now. When the HTTP protocol uses CURL, the meaning of
|
|
||||||
* the parameter is <em>total request time</em>. When the HTTP protocol uses
|
|
||||||
* winhttp, the meaning is the same as the @c dwSendTimeout and
|
|
||||||
* @c dwReceiveTimeout parameters of the
|
|
||||||
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
|
|
||||||
* WinHttpSetTimeouts</a> API.
|
|
||||||
* - @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
|
|
||||||
* when CURL is used. It has the same meaning as CURL's option with the same
|
|
||||||
* name. @p value is pointer to a long.
|
|
||||||
* - @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
|
|
||||||
* when CURL is used. It has the same meaning as CURL's option with the same
|
|
||||||
* name. @p value is pointer to a long.
|
|
||||||
* - @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
|
|
||||||
* when CURL is used. It has the same meaning as CURL's option with the same
|
|
||||||
* name. @p value is pointer to a long.
|
|
||||||
* - @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
|
|
||||||
* when CURL is used. It has the same meaning as CURL's option with the same
|
|
||||||
* name. @p value is pointer to a long.
|
|
||||||
* - @b CURLOPT_VERBOSE - only available for HTTP protocol and only
|
|
||||||
* when CURL is used. It has the same meaning as CURL's option with the same
|
|
||||||
* name. @p value is pointer to a long.
|
|
||||||
* - @b messageTimeout - the maximum time in milliseconds until a message
|
|
||||||
* is timeouted. The time starts at IoTHubClient_SendEventAsync. By default,
|
|
||||||
* messages do not expire. @p is a pointer to a uint64_t
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetOption, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const char*, optionName, const void*, value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API specifies a call back to be used when the device receives a state update.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param deviceTwinCallback The callback specified by the device client to be used for updating
|
|
||||||
* the desired state. The callback will be called in response to a
|
|
||||||
* request send by the IoTHub services. The payload will be passed to the
|
|
||||||
* callback, along with two version numbers:
|
|
||||||
* - Desired:
|
|
||||||
* - LastSeenReported:
|
|
||||||
* @param userContextCallback User specified context that will be provided to the
|
|
||||||
* callback. This can be @c NULL.
|
|
||||||
*
|
|
||||||
* @b NOTE: The application behavior is undefined if the user calls
|
|
||||||
* the ::IoTHubClient_Destroy function from within any callback.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetDeviceTwinCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK, deviceTwinCallback, void*, userContextCallback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API sends a report of the device's properties and their current values.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param reportedState The current device property values to be 'reported' to the IoTHub.
|
|
||||||
* @param reportedStateCallback The callback specified by the device client to be called with the
|
|
||||||
* result of the transaction.
|
|
||||||
* @param userContextCallback User specified context that will be provided to the
|
|
||||||
* callback. This can be @c NULL.
|
|
||||||
*
|
|
||||||
* @b NOTE: The application behavior is undefined if the user calls
|
|
||||||
* the ::IoTHubClient_Destroy function from within any callback.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SendReportedState, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const unsigned char*, reportedState, size_t, size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK, reportedStateCallback, void*, userContextCallback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API sets callback for cloud to device method call.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param deviceMethodCallback The callback which will be called by IoTHub.
|
|
||||||
* @param userContextCallback User specified context that will be provided to the
|
|
||||||
* callback. This can be @c NULL.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetDeviceMethodCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC, deviceMethodCallback, void*, userContextCallback);
|
|
||||||
|
|
||||||
#ifndef DONT_USE_UPLOADTOBLOB
|
|
||||||
/**
|
|
||||||
* @brief IoTHubClient_UploadToBlobAsync uploads data from memory to a file in Azure Blob Storage.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the IoTHubClient_Create function.
|
|
||||||
* @param destinationFileName The name of the file to be created in Azure Blob Storage.
|
|
||||||
* @param source The source of data.
|
|
||||||
* @param size The size of data.
|
|
||||||
* @param iotHubClientFileUploadCallback A callback to be invoked when the file upload operation has finished.
|
|
||||||
* @param context A user-provided context to be passed to the file upload callback.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_UploadToBlobAsync, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const char*, destinationFileName, const unsigned char*, source, size_t, size, IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK, iotHubClientFileUploadCallback, void*, context);
|
|
||||||
#endif
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* IOTHUB_CLIENT_H */
|
|
|
@ -1,435 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file iothub_client_ll.h
|
|
||||||
* @brief APIs that allow a user (usually a device) to communicate
|
|
||||||
* with an Azure IoTHub.
|
|
||||||
*
|
|
||||||
* @details IoTHubClient_LL is a module that allows a user (usually a
|
|
||||||
* device) to communicate with an Azure IoTHub. It can send events
|
|
||||||
* and receive messages. At any given moment in time there can only
|
|
||||||
* be at most 1 message callback function.
|
|
||||||
*
|
|
||||||
* This API surface contains a set of APIs that allows the user to
|
|
||||||
* interact with the lower layer portion of the IoTHubClient. These APIs
|
|
||||||
* contain @c _LL_ in their name, but retain the same functionality like the
|
|
||||||
* @c IoTHubClient_... APIs, with one difference. If the @c _LL_ APIs are
|
|
||||||
* used then the user is responsible for scheduling when the actual work done
|
|
||||||
* by the IoTHubClient happens (when the data is sent/received on/from the wire).
|
|
||||||
* This is useful for constrained devices where spinning a separate thread is
|
|
||||||
* often not desired.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef IOTHUB_CLIENT_LL_H
|
|
||||||
#define IOTHUB_CLIENT_LL_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#define IOTHUB_CLIENT_RESULT_VALUES \
|
|
||||||
IOTHUB_CLIENT_OK, \
|
|
||||||
IOTHUB_CLIENT_INVALID_ARG, \
|
|
||||||
IOTHUB_CLIENT_ERROR, \
|
|
||||||
IOTHUB_CLIENT_INVALID_SIZE, \
|
|
||||||
IOTHUB_CLIENT_INDEFINITE_TIME
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the status of calls to various APIs in this module.
|
|
||||||
*/
|
|
||||||
|
|
||||||
DEFINE_ENUM(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_RESULT_VALUES);
|
|
||||||
|
|
||||||
struct IOTHUBTRANSPORT_CONFIG_TAG;
|
|
||||||
typedef struct IOTHUBTRANSPORT_CONFIG_TAG IOTHUBTRANSPORT_CONFIG;
|
|
||||||
|
|
||||||
typedef struct IOTHUB_CLIENT_LL_HANDLE_DATA_TAG* IOTHUB_CLIENT_LL_HANDLE;
|
|
||||||
|
|
||||||
#define IOTHUB_CLIENT_STATUS_VALUES \
|
|
||||||
IOTHUB_CLIENT_SEND_STATUS_IDLE, \
|
|
||||||
IOTHUB_CLIENT_SEND_STATUS_BUSY
|
|
||||||
|
|
||||||
/** @brief Enumeration returned by the ::IoTHubClient_LL_GetSendStatus
|
|
||||||
* API to indicate the current sending status of the IoT Hub client.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(IOTHUB_CLIENT_STATUS, IOTHUB_CLIENT_STATUS_VALUES);
|
|
||||||
|
|
||||||
#define IOTHUB_IDENTITY_TYPE_VALUE \
|
|
||||||
IOTHUB_TYPE_TELEMETRY, \
|
|
||||||
IOTHUB_TYPE_DEVICE_TWIN, \
|
|
||||||
IOTHUB_TYPE_DEVICE_METHODS
|
|
||||||
DEFINE_ENUM(IOTHUB_IDENTITY_TYPE, IOTHUB_IDENTITY_TYPE_VALUE);
|
|
||||||
|
|
||||||
#define IOTHUB_PROCESS_ITEM_RESULT_VALUE \
|
|
||||||
IOTHUB_PROCESS_OK, \
|
|
||||||
IOTHUB_PROCESS_ERROR, \
|
|
||||||
IOTHUB_PROCESS_NOT_CONNECTED, \
|
|
||||||
IOTHUB_PROCESS_CONTINUE
|
|
||||||
DEFINE_ENUM(IOTHUB_PROCESS_ITEM_RESULT, IOTHUB_PROCESS_ITEM_RESULT_VALUE);
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/agenttime.h"
|
|
||||||
#include "azure_c_shared_utility/xio.h"
|
|
||||||
#include "azure_c_shared_utility/doublylinkedlist.h"
|
|
||||||
#include "iothub_message.h"
|
|
||||||
#include "iothub_transport_ll.h"
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_VALUES \
|
|
||||||
IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_SUCCESS, \
|
|
||||||
IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_ERROR \
|
|
||||||
|
|
||||||
/** @brief Enumeration returned by remotely executed functions
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(IOTHUB_CLIENT_IOTHUB_METHOD_STATUS, IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_VALUES);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES \
|
|
||||||
IOTHUB_CLIENT_CONFIRMATION_OK, \
|
|
||||||
IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY, \
|
|
||||||
IOTHUB_CLIENT_CONFIRMATION_MESSAGE_TIMEOUT, \
|
|
||||||
IOTHUB_CLIENT_CONFIRMATION_ERROR \
|
|
||||||
|
|
||||||
/** @brief Enumeration passed in by the IoT Hub when the event confirmation
|
|
||||||
* callback is invoked to indicate status of the event processing in
|
|
||||||
* the hub.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES);
|
|
||||||
|
|
||||||
#define TRANSPORT_TYPE_VALUES \
|
|
||||||
TRANSPORT_LL, /*LL comes from "LowLevel" */ \
|
|
||||||
TRANSPORT_THREADED
|
|
||||||
|
|
||||||
DEFINE_ENUM(TRANSPORT_TYPE, TRANSPORT_TYPE_VALUES);
|
|
||||||
|
|
||||||
#define IOTHUBMESSAGE_DISPOSITION_RESULT_VALUES \
|
|
||||||
IOTHUBMESSAGE_ACCEPTED, \
|
|
||||||
IOTHUBMESSAGE_REJECTED, \
|
|
||||||
IOTHUBMESSAGE_ABANDONED
|
|
||||||
|
|
||||||
/** @brief Enumeration returned by the callback which is invoked whenever the
|
|
||||||
* IoT Hub sends a message to the device.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(IOTHUBMESSAGE_DISPOSITION_RESULT, IOTHUBMESSAGE_DISPOSITION_RESULT_VALUES);
|
|
||||||
|
|
||||||
#define DEVICE_TWIN_UPDATE_STATE_VALUES \
|
|
||||||
DEVICE_TWIN_UPDATE_COMPLETE, \
|
|
||||||
DEVICE_TWIN_UPDATE_PARTIAL
|
|
||||||
|
|
||||||
DEFINE_ENUM(DEVICE_TWIN_UPDATE_STATE, DEVICE_TWIN_UPDATE_STATE_VALUES);
|
|
||||||
|
|
||||||
typedef void(*IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK)(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback);
|
|
||||||
typedef IOTHUBMESSAGE_DISPOSITION_RESULT (*IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC)(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback);
|
|
||||||
typedef const TRANSPORT_PROVIDER*(*IOTHUB_CLIENT_TRANSPORT_PROVIDER)(void);
|
|
||||||
|
|
||||||
typedef void(*IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK)(DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size, void* userContextCallback);
|
|
||||||
typedef void(*IOTHUB_CLIENT_REPORTED_STATE_CALLBACK)(int status_code, void* userContextCallback);
|
|
||||||
typedef int(*IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC)(const char* method_name, const unsigned char* payload, size_t size, unsigned char** response, size_t* resp_size, void* userContextCallback);
|
|
||||||
|
|
||||||
/** @brief This struct captures IoTHub client configuration. */
|
|
||||||
typedef struct IOTHUB_CLIENT_CONFIG_TAG
|
|
||||||
{
|
|
||||||
/** @brief A function pointer that is passed into the @c IoTHubClientCreate.
|
|
||||||
* A function definition for AMQP is defined in the include @c iothubtransportamqp.h.
|
|
||||||
* A function definition for HTTP is defined in the include @c iothubtransporthttp.h
|
|
||||||
* A function definition for MQTT is defined in the include @c iothubtransportmqtt.h */
|
|
||||||
IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol;
|
|
||||||
|
|
||||||
/** @brief A string that identifies the device. */
|
|
||||||
const char* deviceId;
|
|
||||||
|
|
||||||
/** @brief The device key used to authenticate the device.
|
|
||||||
If neither deviceSasToken nor deviceKey is present then the authentication is assumed x509.*/
|
|
||||||
const char* deviceKey;
|
|
||||||
|
|
||||||
/** @brief The device SAS Token used to authenticate the device in place of device key.
|
|
||||||
If neither deviceSasToken nor deviceKey is present then the authentication is assumed x509.*/
|
|
||||||
const char* deviceSasToken;
|
|
||||||
|
|
||||||
/** @brief The IoT Hub name to which the device is connecting. */
|
|
||||||
const char* iotHubName;
|
|
||||||
|
|
||||||
/** @brief IoT Hub suffix goes here, e.g., private.azure-devices-int.net. */
|
|
||||||
const char* iotHubSuffix;
|
|
||||||
|
|
||||||
const char* protocolGatewayHostName;
|
|
||||||
} IOTHUB_CLIENT_CONFIG;
|
|
||||||
|
|
||||||
/** @brief This struct captures IoTHub client device configuration. */
|
|
||||||
typedef struct IOTHUB_CLIENT_DEVICE_CONFIG_TAG
|
|
||||||
{
|
|
||||||
/** @brief A function pointer that is passed into the @c IoTHubClientCreate.
|
|
||||||
* A function definition for AMQP is defined in the include @c iothubtransportamqp.h.
|
|
||||||
* A function definition for HTTP is defined in the include @c iothubtransporthttp.h
|
|
||||||
* A function definition for MQTT is defined in the include @c iothubtransportmqtt.h */
|
|
||||||
IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol;
|
|
||||||
|
|
||||||
/** @brief a transport handle implementing the protocol */
|
|
||||||
void * transportHandle;
|
|
||||||
|
|
||||||
/** @brief A string that identifies the device. */
|
|
||||||
const char* deviceId;
|
|
||||||
|
|
||||||
/** @brief The device key used to authenticate the device.
|
|
||||||
x509 authentication is is not supported for multiplexed connections*/
|
|
||||||
const char* deviceKey;
|
|
||||||
|
|
||||||
/** @brief The device SAS Token used to authenticate the device in place of device key.
|
|
||||||
x509 authentication is is not supported for multiplexed connections.*/
|
|
||||||
const char* deviceSasToken;
|
|
||||||
} IOTHUB_CLIENT_DEVICE_CONFIG;
|
|
||||||
|
|
||||||
/** @brief This struct captures IoTHub transport configuration. */
|
|
||||||
struct IOTHUBTRANSPORT_CONFIG_TAG
|
|
||||||
{
|
|
||||||
const IOTHUB_CLIENT_CONFIG* upperConfig;
|
|
||||||
PDLIST_ENTRY waitingToSend;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a IoT Hub client for communication with an existing
|
|
||||||
* IoT Hub using the specified connection string parameter.
|
|
||||||
*
|
|
||||||
* @param connectionString Pointer to a character string
|
|
||||||
* @param protocol Function pointer for protocol implementation
|
|
||||||
*
|
|
||||||
* Sample connection string:
|
|
||||||
* <blockquote>
|
|
||||||
* <pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessKey=[Device key goes here];</pre>
|
|
||||||
* </blockquote>
|
|
||||||
*
|
|
||||||
* @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
|
|
||||||
* invoking other functions for IoT Hub client and @c NULL on failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_CreateFromConnectionString, const char*, connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a IoT Hub client for communication with an existing IoT
|
|
||||||
* Hub using the specified parameters.
|
|
||||||
*
|
|
||||||
* @param config Pointer to an @c IOTHUB_CLIENT_CONFIG structure
|
|
||||||
*
|
|
||||||
* The API does not allow sharing of a connection across multiple
|
|
||||||
* devices. This is a blocking call.
|
|
||||||
*
|
|
||||||
* @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
|
|
||||||
* invoking other functions for IoT Hub client and @c NULL on failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_Create, const IOTHUB_CLIENT_CONFIG*, config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a IoT Hub client for communication with an existing IoT
|
|
||||||
* Hub using an existing transport.
|
|
||||||
*
|
|
||||||
* @param config Pointer to an @c IOTHUB_CLIENT_DEVICE_CONFIG structure
|
|
||||||
*
|
|
||||||
* The API *allows* sharing of a connection across multiple
|
|
||||||
* devices. This is a blocking call.
|
|
||||||
*
|
|
||||||
* @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
|
|
||||||
* invoking other functions for IoT Hub client and @c NULL on failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_CreateWithTransport, const IOTHUB_CLIENT_DEVICE_CONFIG*, config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Disposes of resources allocated by the IoT Hub client. This is a
|
|
||||||
* blocking call.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, IoTHubClient_LL_Destroy, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Asynchronous call to send the message specified by @p eventMessageHandle.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param eventMessageHandle The handle to an IoT Hub message.
|
|
||||||
* @param eventConfirmationCallback The callback specified by the device for receiving
|
|
||||||
* confirmation of the delivery of the IoT Hub message.
|
|
||||||
* This callback can be expected to invoke the
|
|
||||||
* ::IoTHubClient_LL_SendEventAsync function for the
|
|
||||||
* same message in an attempt to retry sending a failing
|
|
||||||
* message. The user can specify a @c NULL value here to
|
|
||||||
* indicate that no callback is required.
|
|
||||||
* @param userContextCallback User specified context that will be provided to the
|
|
||||||
* callback. This can be @c NULL.
|
|
||||||
*
|
|
||||||
* @b NOTE: The application behavior is undefined if the user calls
|
|
||||||
* the ::IoTHubClient_LL_Destroy function from within any callback.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SendEventAsync, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_MESSAGE_HANDLE, eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, eventConfirmationCallback, void*, userContextCallback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function returns the current sending status for IoTHubClient.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param iotHubClientStatus The sending state is populated at the address pointed
|
|
||||||
* at by this parameter. The value will be set to
|
|
||||||
* @c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
|
|
||||||
* no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
|
|
||||||
* if there are.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetSendStatus, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_STATUS*, iotHubClientStatus);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets up the message callback to be invoked when IoT Hub issues a
|
|
||||||
* message to the device. This is a blocking call.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param messageCallback The callback specified by the device for receiving
|
|
||||||
* messages from IoT Hub.
|
|
||||||
* @param userContextCallback User specified context that will be provided to the
|
|
||||||
* callback. This can be @c NULL.
|
|
||||||
*
|
|
||||||
* @b NOTE: The application behavior is undefined if the user calls
|
|
||||||
* the ::IoTHubClient_LL_Destroy function from within any callback.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetMessageCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC, messageCallback, void*, userContextCallback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function returns in the out parameter @p lastMessageReceiveTime
|
|
||||||
* what was the value of the @c time function when the last message was
|
|
||||||
* received at the client.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param lastMessageReceiveTime Out parameter containing the value of @c time function
|
|
||||||
* when the last message was received.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetLastMessageReceiveTime, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, time_t*, lastMessageReceiveTime);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is meant to be called by the user when work
|
|
||||||
* (sending/receiving) can be done by the IoTHubClient.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
*
|
|
||||||
* All IoTHubClient interactions (in regards to network traffic
|
|
||||||
* and/or user level callbacks) are the effect of calling this
|
|
||||||
* function and they take place synchronously inside _DoWork.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, IoTHubClient_LL_DoWork, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API sets a runtime option identified by parameter @p optionName
|
|
||||||
* to a value pointed to by @p value. @p optionName and the data type
|
|
||||||
* @p value is pointing to are specific for every option.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param optionName Name of the option.
|
|
||||||
* @param value The value.
|
|
||||||
*
|
|
||||||
* The options that can be set via this API are:
|
|
||||||
* - @b timeout - the maximum time in milliseconds a communication is
|
|
||||||
* allowed to use. @p value is a pointer to an @c unsigned @c int with
|
|
||||||
* the timeout value in milliseconds. This is only supported for the HTTP
|
|
||||||
* protocol as of now. When the HTTP protocol uses CURL, the meaning of
|
|
||||||
* the parameter is <em>total request time</em>. When the HTTP protocol uses
|
|
||||||
* winhttp, the meaning is the same as the @c dwSendTimeout and
|
|
||||||
* @c dwReceiveTimeout parameters of the
|
|
||||||
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
|
|
||||||
* WinHttpSetTimeouts</a> API.
|
|
||||||
* - @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
|
|
||||||
* when CURL is used. It has the same meaning as CURL's option with the same
|
|
||||||
* name. @p value is pointer to a long.
|
|
||||||
* - @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
|
|
||||||
* when CURL is used. It has the same meaning as CURL's option with the same
|
|
||||||
* name. @p value is pointer to a long.
|
|
||||||
* - @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
|
|
||||||
* when CURL is used. It has the same meaning as CURL's option with the same
|
|
||||||
* name. @p value is pointer to a long.
|
|
||||||
* - @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
|
|
||||||
* when CURL is used. It has the same meaning as CURL's option with the same
|
|
||||||
* name. @p value is pointer to a long.
|
|
||||||
* - @b CURLOPT_VERBOSE - only available for HTTP protocol and only
|
|
||||||
* when CURL is used. It has the same meaning as CURL's option with the same
|
|
||||||
* name. @p value is pointer to a long.
|
|
||||||
* - @b keepalive - available for MQTT protocol. Integer value that sets the
|
|
||||||
* interval in seconds when pings are sent to the server.
|
|
||||||
* - @b logtrace - available for MQTT protocol. Boolean value that turns on and
|
|
||||||
* off the diagnostic logging.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetOption, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, optionName, const void*, value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API specifies a call back to be used when the device receives a desired state update.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param deviceTwinCallback The callback specified by the device client to be used for updating
|
|
||||||
* the desired state. The callback will be called in response to patch
|
|
||||||
* request send by the IoTHub services. The payload will be passed to the
|
|
||||||
* callback, along with two version numbers:
|
|
||||||
* - Desired:
|
|
||||||
* - LastSeenReported:
|
|
||||||
* @param userContextCallback User specified context that will be provided to the
|
|
||||||
* callback. This can be @c NULL.
|
|
||||||
*
|
|
||||||
* @b NOTE: The application behavior is undefined if the user calls
|
|
||||||
* the ::IoTHubClient_LL_Destroy function from within any callback.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetDeviceTwinCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK, deviceTwinCallback, void*, userContextCallback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API sneds a report of the device's properties and their current values.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param reportedState The current device property values to be 'reported' to the IoTHub.
|
|
||||||
* @param reportedStateCallback The callback specified by the device client to be called with the
|
|
||||||
* result of the transaction.
|
|
||||||
* @param userContextCallback User specified context that will be provided to the
|
|
||||||
* callback. This can be @c NULL.
|
|
||||||
*
|
|
||||||
* @b NOTE: The application behavior is undefined if the user calls
|
|
||||||
* the ::IoTHubClient_LL_Destroy function from within any callback.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SendReportedState, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const unsigned char*, reportedState, size_t, size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK, reportedStateCallback, void*, userContextCallback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This API sets callback for cloud to device method call.
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param deviceMethodCallback The callback which will be called by IoTHub.
|
|
||||||
* @param userContextCallback User specified context that will be provided to the
|
|
||||||
* callback. This can be @c NULL.
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetDeviceMethodCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC, deviceMethodCallback, void*, userContextCallback);
|
|
||||||
|
|
||||||
#ifndef DONT_USE_UPLOADTOBLOB
|
|
||||||
/**
|
|
||||||
* @brief This API uploads to Azure Storage the content pointed to by @p source having the size @p size
|
|
||||||
* under the blob name devicename/@pdestinationFileName
|
|
||||||
*
|
|
||||||
* @param iotHubClientHandle The handle created by a call to the create function.
|
|
||||||
* @param destinationFileName name of the file.
|
|
||||||
* @param source pointer to the source for file content (can be NULL)
|
|
||||||
* @param size the size of the source in memory (if @p source is NULL then size needs to be 0).
|
|
||||||
*
|
|
||||||
* @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, const unsigned char*, source, size_t, size);
|
|
||||||
|
|
||||||
#endif /*DONT_USE_UPLOADTOBLOB*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* IOTHUB_CLIENT_LL_H */
|
|
|
@ -1,53 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file iothub_client_ll.h
|
|
||||||
* @brief APIs that allow a user (usually a device) to communicate
|
|
||||||
* with an Azure IoTHub.
|
|
||||||
*
|
|
||||||
* @details IoTHubClient_LL is a module that allows a user (usually a
|
|
||||||
* device) to communicate with an Azure IoTHub. It can send events
|
|
||||||
* and receive messages. At any given moment in time there can only
|
|
||||||
* be at most 1 message callback function.
|
|
||||||
*
|
|
||||||
* This API surface contains a set of APIs that allows the user to
|
|
||||||
* interact with the lower layer portion of the IoTHubClient. These APIs
|
|
||||||
* contain @c _LL_ in their name, but retain the same functionality like the
|
|
||||||
* @c IoTHubClient_... APIs, with one difference. If the @c _LL_ APIs are
|
|
||||||
* used then the user is responsible for scheduling when the actual work done
|
|
||||||
* by the IoTHubClient happens (when the data is sent/received on/from the wire).
|
|
||||||
* This is useful for constrained devices where spinning a separate thread is
|
|
||||||
* often not desired.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DONT_USE_UPLOADTOBLOB
|
|
||||||
|
|
||||||
#ifndef IOTHUB_CLIENT_LL_UPLOADTOBLOB_H
|
|
||||||
#define IOTHUB_CLIENT_LL_UPLOADTOBLOB_H
|
|
||||||
|
|
||||||
#include "iothub_client_ll.h"
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE;
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, IoTHubClient_LL_UploadToBlob_Create, const IOTHUB_CLIENT_CONFIG*, config);
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob_Impl, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, handle, const char*, destinationFileName, const unsigned char*, source, size_t, size);
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob_SetOption, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, handle, const char*, optionName, const void*, value);
|
|
||||||
MOCKABLE_FUNCTION(, void, IoTHubClient_LL_UploadToBlob_Destroy, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, handle);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* IOTHUB_CLIENT_LL_UPLOADTOBLOB_H */
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error "trying to #include iothub_client_ll_uploadtoblob.h in the presence of #define DONT_USE_UPLOADTOBLOB"
|
|
||||||
#endif /*DONT_USE_UPLOADTOBLOB*/
|
|
|
@ -1,39 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef IOTHUB_CLIENT_OPTIONS_H
|
|
||||||
#define IOTHUB_CLIENT_OPTIONS_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct IOTHUB_PROXY_OPTIONS_TAG
|
|
||||||
{
|
|
||||||
const char* host_address;
|
|
||||||
const char* username;
|
|
||||||
const char* password;
|
|
||||||
} IOTHUB_PROXY_OPTIONS;
|
|
||||||
|
|
||||||
static const char* OPTION_LOG_TRACE = "logtrace";
|
|
||||||
static const char* OPTION_X509_CERT = "x509certificate";
|
|
||||||
static const char* OPTION_X509_PRIVATE_KEY = "x509privatekey";
|
|
||||||
static const char* OPTION_KEEP_ALIVE = "keepalive";
|
|
||||||
|
|
||||||
static const char* OPTION_PROXY_HOST = "proxy_address";
|
|
||||||
static const char* OPTION_PROXY_USERNAME = "proxy_username";
|
|
||||||
static const char* OPTION_PROXY_PASSWORD = "proxy_password";
|
|
||||||
|
|
||||||
static const char* OPTION_SAS_TOKEN_LIFETIME = "sas_token_lifetime";
|
|
||||||
static const char* OPTION_SAS_TOKEN_REFRESH_TIME = "sas_token_refresh_time";
|
|
||||||
static const char* OPTION_CBS_REQUEST_TIMEOUT = "cbs_request_timeout";
|
|
||||||
|
|
||||||
static const char* OPTION_MIN_POLLING_TIME = "MinimumPollingTime";
|
|
||||||
static const char* OPTION_BATCHING = "Batching";
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* IOTHUB_CLIENT_OPTIONS_H */
|
|
|
@ -1,70 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef IOTHUB_CLIENT_PRIVATE_H
|
|
||||||
#define IOTHUB_CLIENT_PRIVATE_H
|
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/crt_abstractions.h"
|
|
||||||
#include "azure_c_shared_utility/doublylinkedlist.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
#include "azure_c_shared_utility/constbuffer.h"
|
|
||||||
|
|
||||||
#include "iothub_message.h"
|
|
||||||
#include "iothub_client_ll.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define EVENT_ENDPOINT "/messages/events"
|
|
||||||
#define MESSAGE_ENDPOINT "/messages/devicebound"
|
|
||||||
#define MESSAGE_ENDPOINT_HTTP "/messages/devicebound"
|
|
||||||
#define MESSAGE_ENDPOINT_HTTP_ETAG "/messages/devicebound/"
|
|
||||||
#define CLIENT_DEVICE_TYPE_PREFIX "iothubclient"
|
|
||||||
#define CLIENT_DEVICE_BACKSLASH "/"
|
|
||||||
#define CBS_REPLY_TO "cbs"
|
|
||||||
#define CBS_ENDPOINT "/$" CBS_REPLY_TO
|
|
||||||
#define API_VERSION "?api-version=2016-02-03"
|
|
||||||
#define REJECT_QUERY_PARAMETER "&reject"
|
|
||||||
|
|
||||||
MOCKABLE_FUNCTION(, void, IoTHubClient_LL_SendComplete, IOTHUB_CLIENT_LL_HANDLE, handle, PDLIST_ENTRY, completed, IOTHUB_CLIENT_CONFIRMATION_RESULT, result);
|
|
||||||
MOCKABLE_FUNCTION(, void, IoTHubClient_LL_ReportedStateComplete, IOTHUB_CLIENT_LL_HANDLE, handle, uint32_t, item_id, int, status_code);
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUBMESSAGE_DISPOSITION_RESULT, IoTHubClient_LL_MessageCallback, IOTHUB_CLIENT_LL_HANDLE, handle, IOTHUB_MESSAGE_HANDLE, message);
|
|
||||||
MOCKABLE_FUNCTION(, void, IoTHubClient_LL_RetrievePropertyComplete, IOTHUB_CLIENT_LL_HANDLE, handle, DEVICE_TWIN_UPDATE_STATE, update_state, const unsigned char*, payLoad, size_t, size);
|
|
||||||
MOCKABLE_FUNCTION(, int, IoTHubClient_LL_DeviceMethodComplete, IOTHUB_CLIENT_LL_HANDLE, handle, const char*, method_name, const unsigned char*, payLoad, size_t, size, BUFFER_HANDLE, result_payload);
|
|
||||||
|
|
||||||
typedef struct IOTHUB_MESSAGE_LIST_TAG
|
|
||||||
{
|
|
||||||
IOTHUB_MESSAGE_HANDLE messageHandle;
|
|
||||||
IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK callback;
|
|
||||||
void* context;
|
|
||||||
DLIST_ENTRY entry;
|
|
||||||
uint64_t ms_timesOutAfter; /* a value of "0" means "no timeout", if the IOTHUBCLIENT_LL's handle tickcounter > msTimesOutAfer then the message shall timeout*/
|
|
||||||
}IOTHUB_MESSAGE_LIST;
|
|
||||||
|
|
||||||
typedef struct IOTHUB_DEVICE_TWIN_TAG
|
|
||||||
{
|
|
||||||
uint32_t item_id;
|
|
||||||
uint64_t ms_timesOutAfter; /* a value of "0" means "no timeout", if the IOTHUBCLIENT_LL's handle tickcounter > msTimesOutAfer then the message shall timeout*/
|
|
||||||
IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reported_state_callback;
|
|
||||||
CONSTBUFFER_HANDLE report_data_handle;
|
|
||||||
void* context;
|
|
||||||
DLIST_ENTRY entry;
|
|
||||||
} IOTHUB_DEVICE_TWIN;
|
|
||||||
|
|
||||||
union IOTHUB_IDENTITY_INFO_TAG
|
|
||||||
{
|
|
||||||
IOTHUB_DEVICE_TWIN* device_twin;
|
|
||||||
IOTHUB_MESSAGE_LIST* iothub_message;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* IOTHUB_CLIENT_PRIVATE_H */
|
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file iothub_client_version.h
|
|
||||||
* @brief Functions for managing the client SDK version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef IOTHUB_CLIENT_VERSION_H
|
|
||||||
#define IOTHUB_CLIENT_VERSION_H
|
|
||||||
|
|
||||||
#define IOTHUB_SDK_VERSION "1.0.16"
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns a pointer to a null terminated string containing the
|
|
||||||
* current IoT Hub Client SDK version.
|
|
||||||
*
|
|
||||||
* @return Pointer to a null terminated string containing the
|
|
||||||
* current IoT Hub Client SDK version.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, const char*, IoTHubClient_GetVersionString);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // IOTHUB_CLIENT_VERSION_H
|
|
|
@ -1,181 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
/** @file iothub_message.h
|
|
||||||
* @brief The @c IoTHub_Message component encapsulates one message that
|
|
||||||
* can be transferred by an IoT hub client.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef IOTHUB_MESSAGE_H
|
|
||||||
#define IOTHUB_MESSAGE_H
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/macro_utils.h"
|
|
||||||
#include "azure_c_shared_utility/map.h"
|
|
||||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstddef>
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define IOTHUB_MESSAGE_RESULT_VALUES \
|
|
||||||
IOTHUB_MESSAGE_OK, \
|
|
||||||
IOTHUB_MESSAGE_INVALID_ARG, \
|
|
||||||
IOTHUB_MESSAGE_INVALID_TYPE, \
|
|
||||||
IOTHUB_MESSAGE_ERROR \
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the status of calls to various
|
|
||||||
* APIs in this module.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(IOTHUB_MESSAGE_RESULT, IOTHUB_MESSAGE_RESULT_VALUES);
|
|
||||||
|
|
||||||
#define IOTHUBMESSAGE_CONTENT_TYPE_VALUES \
|
|
||||||
IOTHUBMESSAGE_BYTEARRAY, \
|
|
||||||
IOTHUBMESSAGE_STRING, \
|
|
||||||
IOTHUBMESSAGE_UNKNOWN \
|
|
||||||
|
|
||||||
/** @brief Enumeration specifying the content type of the a given
|
|
||||||
* message.
|
|
||||||
*/
|
|
||||||
DEFINE_ENUM(IOTHUBMESSAGE_CONTENT_TYPE, IOTHUBMESSAGE_CONTENT_TYPE_VALUES);
|
|
||||||
|
|
||||||
typedef struct IOTHUB_MESSAGE_HANDLE_DATA_TAG* IOTHUB_MESSAGE_HANDLE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a new IoT hub message from a byte array. The type of the
|
|
||||||
* message will be set to @c IOTHUBMESSAGE_BYTEARRAY.
|
|
||||||
*
|
|
||||||
* @param byteArray The byte array from which the message is to be created.
|
|
||||||
* @param size The size of the byte array.
|
|
||||||
*
|
|
||||||
* @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
|
|
||||||
* created or @c NULL in case an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_HANDLE, IoTHubMessage_CreateFromByteArray, const unsigned char*, byteArray, size_t, size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a new IoT hub message from a null terminated string. The
|
|
||||||
* type of the message will be set to @c IOTHUBMESSAGE_STRING.
|
|
||||||
*
|
|
||||||
* @param source The null terminated string from which the message is to be
|
|
||||||
* created.
|
|
||||||
*
|
|
||||||
* @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
|
|
||||||
* created or @c NULL in case an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_HANDLE, IoTHubMessage_CreateFromString, const char*, source);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a new IoT hub message with the content identical to that
|
|
||||||
* of the @p iotHubMessageHandle parameter.
|
|
||||||
*
|
|
||||||
* @param iotHubMessageHandle Handle to the message that is to be cloned.
|
|
||||||
*
|
|
||||||
* @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
|
|
||||||
* cloned or @c NULL in case an error occurs.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_HANDLE, IoTHubMessage_Clone, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Fetches a pointer and size for the data associated with the IoT
|
|
||||||
* hub message handle. If the content type of the message is not
|
|
||||||
* @c IOTHUBMESSAGE_BYTEARRAY then the function returns
|
|
||||||
* @c IOTHUB_MESSAGE_INVALID_ARG.
|
|
||||||
*
|
|
||||||
* @param iotHubMessageHandle Handle to the message.
|
|
||||||
* @param buffer Pointer to the memory location where the
|
|
||||||
* pointer to the buffer will be written.
|
|
||||||
* @param size The size of the buffer will be written to
|
|
||||||
* this address.
|
|
||||||
*
|
|
||||||
* @return Returns IOTHUB_MESSAGE_OK if the byte array was fetched successfully
|
|
||||||
* or an error code otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_GetByteArray, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const unsigned char**, buffer, size_t*, size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns the null terminated string stored in the message.
|
|
||||||
* If the content type of the message is not @c IOTHUBMESSAGE_STRING
|
|
||||||
* then the function returns @c NULL.
|
|
||||||
*
|
|
||||||
* @param iotHubMessageHandle Handle to the message.
|
|
||||||
*
|
|
||||||
* @return @c NULL if an error occurs or a pointer to the stored null
|
|
||||||
* terminated string otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetString, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns the content type of the message given by parameter
|
|
||||||
* @c iotHubMessageHandle.
|
|
||||||
*
|
|
||||||
* @param iotHubMessageHandle Handle to the message.
|
|
||||||
*
|
|
||||||
* @return An @c IOTHUBMESSAGE_CONTENT_TYPE value.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUBMESSAGE_CONTENT_TYPE, IoTHubMessage_GetContentType, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Gets a handle to the message's properties map.
|
|
||||||
*
|
|
||||||
* @param iotHubMessageHandle Handle to the message.
|
|
||||||
*
|
|
||||||
* @return A @c MAP_HANDLE pointing to the properties map for this message.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, MAP_HANDLE, IoTHubMessage_Properties, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Gets the MessageId from the IOTHUB_MESSAGE_HANDLE.
|
|
||||||
*
|
|
||||||
* @param iotHubMessageHandle Handle to the message.
|
|
||||||
*
|
|
||||||
* @return A const char* pointing to the Message Id.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetMessageId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the MessageId for the IOTHUB_MESSAGE_HANDLE.
|
|
||||||
*
|
|
||||||
* @param iotHubMessageHandle Handle to the message.
|
|
||||||
* @param messageId Pointer to the memory location of the messageId
|
|
||||||
*
|
|
||||||
* @return Returns IOTHUB_MESSAGE_OK if the messageId was set successfully
|
|
||||||
* or an error code otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetMessageId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, messageId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Gets the CorrelationId from the IOTHUB_MESSAGE_HANDLE.
|
|
||||||
*
|
|
||||||
* @param iotHubMessageHandle Handle to the message.
|
|
||||||
*
|
|
||||||
* @return A const char* pointing to the Correlation Id.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetCorrelationId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the CorrelationId for the IOTHUB_MESSAGE_HANDLE.
|
|
||||||
*
|
|
||||||
* @param iotHubMessageHandle Handle to the message.
|
|
||||||
* @param correlationId Pointer to the memory location of the messageId
|
|
||||||
*
|
|
||||||
* @return Returns IOTHUB_MESSAGE_OK if the messageId was set successfully
|
|
||||||
* or an error code otherwise.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetCorrelationId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, correlationId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Frees all resources associated with the given message handle.
|
|
||||||
*
|
|
||||||
* @param iotHubMessageHandle Handle to the message.
|
|
||||||
*/
|
|
||||||
MOCKABLE_FUNCTION(, void, IoTHubMessage_Destroy, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* IOTHUB_MESSAGE_H */
|
|
|
@ -1,82 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef IOTHUB_TRANSPORT_LL_H
|
|
||||||
#define IOTHUB_TRANSPORT_LL_H
|
|
||||||
|
|
||||||
typedef void* TRANSPORT_LL_HANDLE;
|
|
||||||
typedef void* IOTHUB_DEVICE_HANDLE;
|
|
||||||
|
|
||||||
struct TRANSPORT_PROVIDER_TAG;
|
|
||||||
typedef struct TRANSPORT_PROVIDER_TAG TRANSPORT_PROVIDER;
|
|
||||||
|
|
||||||
union IOTHUB_IDENTITY_INFO_TAG;
|
|
||||||
typedef union IOTHUB_IDENTITY_INFO_TAG IOTHUB_IDENTITY_INFO;
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/doublylinkedlist.h"
|
|
||||||
#include "azure_c_shared_utility/strings.h"
|
|
||||||
#include "iothub_message.h"
|
|
||||||
#include "iothub_client_ll.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** @brief This struct captures device configuration. */
|
|
||||||
typedef struct IOTHUB_DEVICE_CONFIG_TAG
|
|
||||||
{
|
|
||||||
/** @brief A string that identifies the device. */
|
|
||||||
const char* deviceId;
|
|
||||||
|
|
||||||
/** @brief The device key used to authenticate the device. */
|
|
||||||
const char* deviceKey;
|
|
||||||
|
|
||||||
/** @brief The device SAS used to authenticate the device in place of using the device key. */
|
|
||||||
const char* deviceSasToken;
|
|
||||||
|
|
||||||
} IOTHUB_DEVICE_CONFIG;
|
|
||||||
|
|
||||||
typedef STRING_HANDLE (*pfIoTHubTransport_GetHostname)(TRANSPORT_LL_HANDLE handle);
|
|
||||||
typedef IOTHUB_CLIENT_RESULT(*pfIoTHubTransport_SetOption)(TRANSPORT_LL_HANDLE handle, const char *optionName, const void* value);
|
|
||||||
typedef TRANSPORT_LL_HANDLE(*pfIoTHubTransport_Create)(const IOTHUBTRANSPORT_CONFIG* config);
|
|
||||||
typedef void (*pfIoTHubTransport_Destroy)(TRANSPORT_LL_HANDLE handle);
|
|
||||||
typedef IOTHUB_DEVICE_HANDLE(*pfIotHubTransport_Register)(TRANSPORT_LL_HANDLE handle, const IOTHUB_DEVICE_CONFIG* device, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, PDLIST_ENTRY waitingToSend);
|
|
||||||
typedef void(*pfIotHubTransport_Unregister)(IOTHUB_DEVICE_HANDLE deviceHandle);
|
|
||||||
typedef int (*pfIoTHubTransport_Subscribe)(IOTHUB_DEVICE_HANDLE handle);
|
|
||||||
typedef void (*pfIoTHubTransport_Unsubscribe)(IOTHUB_DEVICE_HANDLE handle);
|
|
||||||
typedef void (*pfIoTHubTransport_DoWork)(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle);
|
|
||||||
typedef IOTHUB_CLIENT_RESULT(*pfIoTHubTransport_GetSendStatus)(IOTHUB_DEVICE_HANDLE handle, IOTHUB_CLIENT_STATUS *iotHubClientStatus);
|
|
||||||
typedef int (*pfIoTHubTransport_Subscribe_DeviceTwin)(IOTHUB_DEVICE_HANDLE handle);
|
|
||||||
typedef void (*pfIoTHubTransport_Unsubscribe_DeviceTwin)(IOTHUB_DEVICE_HANDLE handle);
|
|
||||||
typedef IOTHUB_PROCESS_ITEM_RESULT(*pfIoTHubTransport_ProcessItem)(TRANSPORT_LL_HANDLE handle, IOTHUB_IDENTITY_TYPE item_type, IOTHUB_IDENTITY_INFO* iothub_item);
|
|
||||||
typedef int(*pfIoTHubTransport_Subscribe_DeviceMethod)(IOTHUB_DEVICE_HANDLE handle);
|
|
||||||
typedef void(*pfIoTHubTransport_Unsubscribe_DeviceMethod)(IOTHUB_DEVICE_HANDLE handle);
|
|
||||||
|
|
||||||
#define TRANSPORT_PROVIDER_FIELDS \
|
|
||||||
pfIoTHubTransport_Subscribe_DeviceMethod IoTHubTransport_Subscribe_DeviceMethod; \
|
|
||||||
pfIoTHubTransport_Unsubscribe_DeviceMethod IoTHubTransport_Unsubscribe_DeviceMethod;\
|
|
||||||
pfIoTHubTransport_Subscribe_DeviceTwin IoTHubTransport_Subscribe_DeviceTwin; \
|
|
||||||
pfIoTHubTransport_Unsubscribe_DeviceTwin IoTHubTransport_Unsubscribe_DeviceTwin; \
|
|
||||||
pfIoTHubTransport_ProcessItem IoTHubTransport_ProcessItem; \
|
|
||||||
pfIoTHubTransport_GetHostname IoTHubTransport_GetHostname; \
|
|
||||||
pfIoTHubTransport_SetOption IoTHubTransport_SetOption; \
|
|
||||||
pfIoTHubTransport_Create IoTHubTransport_Create; \
|
|
||||||
pfIoTHubTransport_Destroy IoTHubTransport_Destroy; \
|
|
||||||
pfIotHubTransport_Register IoTHubTransport_Register; \
|
|
||||||
pfIotHubTransport_Unregister IoTHubTransport_Unregister; \
|
|
||||||
pfIoTHubTransport_Subscribe IoTHubTransport_Subscribe; \
|
|
||||||
pfIoTHubTransport_Unsubscribe IoTHubTransport_Unsubscribe; \
|
|
||||||
pfIoTHubTransport_DoWork IoTHubTransport_DoWork; \
|
|
||||||
pfIoTHubTransport_GetSendStatus IoTHubTransport_GetSendStatus /*there's an intentional missing ; on this line*/
|
|
||||||
|
|
||||||
struct TRANSPORT_PROVIDER_TAG
|
|
||||||
{
|
|
||||||
TRANSPORT_PROVIDER_FIELDS;
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* IOTHUB_TRANSPORT_LL_H */
|
|
|
@ -1,32 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef IOTHUB_TRANSPORT_H
|
|
||||||
#define IOTHUB_TRANSPORT_H
|
|
||||||
|
|
||||||
typedef struct TRANSPORT_HANDLE_DATA_TAG* TRANSPORT_HANDLE;
|
|
||||||
|
|
||||||
#include "azure_c_shared_utility/lock.h"
|
|
||||||
#include "azure_c_shared_utility/crt_abstractions.h"
|
|
||||||
#include "iothub_client.h"
|
|
||||||
#include "iothub_client_private.h"
|
|
||||||
#include "iothub_transport_ll.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern TRANSPORT_HANDLE IoTHubTransport_Create(IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol, const char* iotHubName, const char* iotHubSuffix);
|
|
||||||
extern void IoTHubTransport_Destroy(TRANSPORT_HANDLE transportHandle);
|
|
||||||
extern LOCK_HANDLE IoTHubTransport_GetLock(TRANSPORT_HANDLE transportHandle);
|
|
||||||
extern TRANSPORT_LL_HANDLE IoTHubTransport_GetLLTransport(TRANSPORT_HANDLE transportHandle);
|
|
||||||
extern IOTHUB_CLIENT_RESULT IoTHubTransport_StartWorkerThread(TRANSPORT_HANDLE transportHandle, IOTHUB_CLIENT_HANDLE clientHandle);
|
|
||||||
extern bool IoTHubTransport_SignalEndWorkerThread(TRANSPORT_HANDLE transportHandle, IOTHUB_CLIENT_HANDLE clientHandle);
|
|
||||||
extern void IoTHubTransport_JoinWorkerThread(TRANSPORT_HANDLE transportHandle, IOTHUB_CLIENT_HANDLE clientHandle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* IOTHUB_TRANSPORT_H */
|
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef IOTHUBTRANSPORTAMQP_H
|
|
||||||
#define IOTHUBTRANSPORTAMQP_H
|
|
||||||
|
|
||||||
#include "iothub_transport_ll.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern const TRANSPORT_PROVIDER* AMQP_Protocol(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*IOTHUBTRANSPORTAMQP_H*/
|
|
|
@ -1,110 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef IOTHUBTRANSPORTAMQP_AUTH_H
|
|
||||||
#define IOTHUBTRANSPORTAMQP_AUTH_H
|
|
||||||
|
|
||||||
#include "azure-uamqp-c/cbs.h"
|
|
||||||
#include "azure_c_shared_utility/strings.h"
|
|
||||||
#include "iothub_transport_ll.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum AUTHENTICATION_STATUS_TAG
|
|
||||||
{
|
|
||||||
AUTHENTICATION_STATUS_IDLE,
|
|
||||||
AUTHENTICATION_STATUS_IN_PROGRESS,
|
|
||||||
AUTHENTICATION_STATUS_TIMEOUT,
|
|
||||||
AUTHENTICATION_STATUS_FAILURE,
|
|
||||||
AUTHENTICATION_STATUS_OK
|
|
||||||
} AUTHENTICATION_STATUS;
|
|
||||||
|
|
||||||
typedef enum AMQP_TRANSPORT_CREDENTIAL_TYPE_TAG
|
|
||||||
{
|
|
||||||
CREDENTIAL_NOT_BUILD,
|
|
||||||
X509,
|
|
||||||
DEVICE_KEY,
|
|
||||||
DEVICE_SAS_TOKEN,
|
|
||||||
} AMQP_TRANSPORT_CREDENTIAL_TYPE;
|
|
||||||
|
|
||||||
typedef struct X509_CREDENTIAL_TAG
|
|
||||||
{
|
|
||||||
const char* x509certificate;
|
|
||||||
const char* x509privatekey;
|
|
||||||
} X509_CREDENTIAL;
|
|
||||||
|
|
||||||
typedef union AMQP_TRANSPORT_CREDENTIAL_UNION_TAG
|
|
||||||
{
|
|
||||||
// Key associated to the device to be used.
|
|
||||||
STRING_HANDLE deviceKey;
|
|
||||||
|
|
||||||
// SAS associated to the device to be used.
|
|
||||||
STRING_HANDLE deviceSasToken;
|
|
||||||
|
|
||||||
// X509
|
|
||||||
X509_CREDENTIAL x509credential;
|
|
||||||
} AMQP_TRANSPORT_CREDENTIAL_UNION;
|
|
||||||
|
|
||||||
typedef struct AMQP_TRANSPORT_CREDENTIAL_TAG
|
|
||||||
{
|
|
||||||
AMQP_TRANSPORT_CREDENTIAL_TYPE credentialType;
|
|
||||||
AMQP_TRANSPORT_CREDENTIAL_UNION credential;
|
|
||||||
} AMQP_TRANSPORT_CREDENTIAL;
|
|
||||||
|
|
||||||
typedef AUTHENTICATION_STATE_HANDLE void*;
|
|
||||||
|
|
||||||
/** @brief Creates a state holder for all authentication-related information and connections.
|
|
||||||
*
|
|
||||||
* @returns an instance of the AUTHENTICATION_STATE_HANDLE if succeeds, NULL if any failure occurs.
|
|
||||||
*/
|
|
||||||
extern AUTHENTICATION_STATE_HANDLE authentication_create(const char* deviceId, AMQP_TRANSPORT_CREDENTIAL* credentials, TRANSPORT_LL_HANDLE transport);
|
|
||||||
|
|
||||||
/** @brief Establishes the first authentication for the device in the transport it is registered to.
|
|
||||||
*
|
|
||||||
* @details If SAS token or key are used, creates a cbs instance for the transport if it does not have one,
|
|
||||||
* and puts a SAS token in (creates one if key is used, or applies the SAS token if provided by user).
|
|
||||||
* If certificates are used, they are set on the tls_io instance of the transport.
|
|
||||||
*
|
|
||||||
* @returns 0 if it succeeds, non-zero if it fails.
|
|
||||||
*/
|
|
||||||
extern int authentication_authenticate(AUTHENTICATION_STATE_HANDLE authentication_state);
|
|
||||||
|
|
||||||
/** @brief Indicates if the device is authenticated successfuly, if authentication is in progress or completed with failure.
|
|
||||||
*
|
|
||||||
* @returns A flag indicating the current authentication status of the device.
|
|
||||||
*/
|
|
||||||
extern AUTHENTICATION_STATUS authentication_get_status(AUTHENTICATION_STATE_HANDLE authentication_state);
|
|
||||||
|
|
||||||
/** @brief Refreshes the authentication if needed.
|
|
||||||
*
|
|
||||||
* @details If SAS key is used, a new token is generated and put to cbs if the previous generated token is expired.
|
|
||||||
*
|
|
||||||
* @returns 0 if it succeeds, non-zero if it fails.
|
|
||||||
*/
|
|
||||||
extern int authentication_refresh(AUTHENTICATION_STATE_HANDLE authentication_state);
|
|
||||||
|
|
||||||
/** @brief Sets the common options related to certificates and cbs.
|
|
||||||
*
|
|
||||||
* @details The new options are only applied effectively to the transport on the next call to authenticate() or refresh().
|
|
||||||
*
|
|
||||||
* @returns 0 if it succeeds, non-zero if it fails.
|
|
||||||
*/
|
|
||||||
extern int authentication_set_option(AUTHENTICATION_STATE_HANDLE authentication_state, const char* name, const void* value);
|
|
||||||
|
|
||||||
/** @brief De-authenticates the device and destroy the state instance.
|
|
||||||
*
|
|
||||||
* @details Closes the subscription to cbs if in use, destroys the cbs instance if it is the last device registered.
|
|
||||||
* No action is taken if certificate-based authentication if used.
|
|
||||||
*
|
|
||||||
* @returns 0 if it succeeds, non-zero if it fails.
|
|
||||||
*/
|
|
||||||
extern int authentication_destroy(AUTHENTICATION_STATE_HANDLE authentication_state);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*IOTHUBTRANSPORTAMQP_AUTH_H*/
|
|
|
@ -1,21 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef IOTHUBTRANSPORTAMQP_WEBSOCKETS_H
|
|
||||||
#define IOTHUBTRANSPORTAMQP_WEBSOCKETS_H
|
|
||||||
|
|
||||||
#include "iothub_client_private.h"
|
|
||||||
#include "iothub_transport_ll.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern const TRANSPORT_PROVIDER* AMQP_Protocol_over_WebSocketsTls(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*IOTHUBTRANSPORTAMQP_WEBSOCKETS_H*/
|
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef IOTHUBTRANSPORTHTTP_H
|
|
||||||
#define IOTHUBTRANSPORTHTTP_H
|
|
||||||
|
|
||||||
#include "iothub_transport_ll.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern const TRANSPORT_PROVIDER* HTTP_Protocol(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*IOTHUBTRANSPORTHTTP_H*/
|
|
|
@ -1,19 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef IOTHUBTRANSPORTMQTT_H
|
|
||||||
#define IOTHUBTRANSPORTMQTT_H
|
|
||||||
|
|
||||||
#include "iothub_transport_ll.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
extern const TRANSPORT_PROVIDER* MQTT_Protocol(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*IOTHUBTRANSPORTMQTT_H*/
|
|
|
@ -1,22 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#ifndef UAMQP_MESSAGING_H
|
|
||||||
#define UAMQP_MESSAGING_H
|
|
||||||
|
|
||||||
#include "iothub_message.h"
|
|
||||||
#include "azure_uamqp_c/message.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern int IoTHubMessage_CreateFromUamqpMessage(MESSAGE_HANDLE uamqp_message, IOTHUB_MESSAGE_HANDLE* iothubclient_message);
|
|
||||||
extern int message_create_from_iothub_message(IOTHUB_MESSAGE_HANDLE iothub_message, MESSAGE_HANDLE* uamqp_message);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*UAMQP_MESSAGING_H*/
|
|
|
@ -1,247 +0,0 @@
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <windows.h>
|
|
||||||
#include <TlHelp32.h>
|
|
||||||
|
|
||||||
#include "iothub_client.h"
|
|
||||||
#include "iothub_message.h"
|
|
||||||
#include "azure_c_shared_utility/threadapi.h"
|
|
||||||
#include "azure_c_shared_utility/crt_abstractions.h"
|
|
||||||
#include "azure_c_shared_utility/platform.h"
|
|
||||||
#include "iothubtransportmqtt.h"
|
|
||||||
#include "SendReport.h"
|
|
||||||
#include "utilities.h"
|
|
||||||
#include "DMTasks/DMTaskEngine.h"
|
|
||||||
|
|
||||||
#ifdef MBED_BUILD_TIMESTAMP
|
|
||||||
#include "certs.h"
|
|
||||||
#endif // MBED_BUILD_TIMESTAMP
|
|
||||||
|
|
||||||
/*String containing Hostname, Device Id & Device Key in the format: */
|
|
||||||
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */
|
|
||||||
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessSignature=<device_sas_token>" */
|
|
||||||
|
|
||||||
static int callbackCounter;
|
|
||||||
static bool g_continueRunning;
|
|
||||||
#define MESSAGE_COUNT 5
|
|
||||||
#define DOWORK_LOOP_NUM 3
|
|
||||||
|
|
||||||
static char* connectionString;
|
|
||||||
static char* reportedProperties;
|
|
||||||
|
|
||||||
typedef struct EVENT_INSTANCE_TAG
|
|
||||||
{
|
|
||||||
IOTHUB_MESSAGE_HANDLE messageHandle;
|
|
||||||
size_t messageTrackingId; // For tracking the messages within the user callback.
|
|
||||||
} EVENT_INSTANCE;
|
|
||||||
|
|
||||||
static int DeviceMethodCallback(const char* method_name, const unsigned char* payload, size_t size, unsigned char** response, size_t* resp_size, void* userContextCallback)
|
|
||||||
{
|
|
||||||
(void)userContextCallback;
|
|
||||||
|
|
||||||
printf("\r\nDevice Method called\r\n");
|
|
||||||
printf("Device Method name: %s\r\n", method_name);
|
|
||||||
printf("Device Method payload: %.*s\r\n", (int)size, (const char*)payload);
|
|
||||||
|
|
||||||
int status = OnDeviceMethod(method_name, payload, size, response, resp_size);
|
|
||||||
|
|
||||||
if (status <= 0)
|
|
||||||
{
|
|
||||||
status = 200;
|
|
||||||
AllocAndPrintf(response, resp_size, "Response from %s with parameter %.*s", method_name, size, payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\r\nResponse status: %d\r\n", status);
|
|
||||||
printf("Response payload: %.*s\r\n\r\n", (int)*resp_size, *response);
|
|
||||||
|
|
||||||
callbackCounter++;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int DeviceTwinCallback(DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size, void* userContextCallback)
|
|
||||||
{
|
|
||||||
(void)userContextCallback;
|
|
||||||
|
|
||||||
printf("\r\nDevice Twin changed\r\n");
|
|
||||||
printf("Update state: %d\r\n", update_state);
|
|
||||||
printf("payLoad: %.*s\r\n", size, payLoad);
|
|
||||||
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ReportedStateCallback(int status_code, void* userContextCallback)
|
|
||||||
{
|
|
||||||
(void)userContextCallback;
|
|
||||||
|
|
||||||
printf("\r\nReported state changed\r\n");
|
|
||||||
printf("Status code: %d\r\n", status_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
void iothub_client_sample_device_method_run(void)
|
|
||||||
{
|
|
||||||
IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle;
|
|
||||||
|
|
||||||
g_continueRunning = true;
|
|
||||||
|
|
||||||
callbackCounter = 0;
|
|
||||||
int receiveContext = 0;
|
|
||||||
|
|
||||||
if (platform_init() != 0)
|
|
||||||
{
|
|
||||||
(void)printf("Failed to initialize the platform.\r\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((iotHubClientHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, MQTT_Protocol)) == NULL)
|
|
||||||
{
|
|
||||||
(void)printf("ERROR: iotHubClientHandle is NULL!\r\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool traceOn = true;
|
|
||||||
IoTHubClient_LL_SetOption(iotHubClientHandle, "logtrace", &traceOn);
|
|
||||||
|
|
||||||
#ifdef MBED_BUILD_TIMESTAMP
|
|
||||||
// For mbed add the certificate information
|
|
||||||
if (IoTHubClient_LL_SetOption(iotHubClientHandle, "TrustedCerts", certificates) != IOTHUB_CLIENT_OK)
|
|
||||||
{
|
|
||||||
printf("failure to set option \"TrustedCerts\"\r\n");
|
|
||||||
}
|
|
||||||
#endif // MBED_BUILD_TIMESTAMP
|
|
||||||
|
|
||||||
// Send reported properties as startup telemetry
|
|
||||||
SetupSendReport(iotHubClientHandle);
|
|
||||||
SendReport((unsigned char*)reportedProperties, strlen(reportedProperties));
|
|
||||||
|
|
||||||
if (IoTHubClient_LL_SetDeviceMethodCallback(iotHubClientHandle, DeviceMethodCallback, &receiveContext) != IOTHUB_CLIENT_OK)
|
|
||||||
{
|
|
||||||
(void)printf("ERROR: IoTHubClient_LL_SetDeviceMethodCallback..........FAILED!\r\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(void)printf("IoTHubClient_LL_SetDeviceMethodCallback...successful.\r\n");
|
|
||||||
|
|
||||||
if (IoTHubClient_LL_SetDeviceTwinCallback(iotHubClientHandle, DeviceTwinCallback, &receiveContext) != IOTHUB_CLIENT_OK)
|
|
||||||
{
|
|
||||||
(void)printf("ERROR: IoTHubClient_LL_SetDeviceTwinCallback..........FAILED!\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t iterator = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
IoTHubClient_LL_DoWork(iotHubClientHandle);
|
|
||||||
ThreadAPI_Sleep(1);
|
|
||||||
|
|
||||||
StepDMTask();
|
|
||||||
|
|
||||||
iterator++;
|
|
||||||
} while (g_continueRunning);
|
|
||||||
|
|
||||||
(void)printf("iothub_client_sample_device_method exited, call DoWork %d more time to complete final sending...\r\n", DOWORK_LOOP_NUM);
|
|
||||||
for (size_t index = 0; index < DOWORK_LOOP_NUM; index++)
|
|
||||||
{
|
|
||||||
IoTHubClient_LL_DoWork(iotHubClientHandle);
|
|
||||||
ThreadAPI_Sleep(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IoTHubClient_LL_Destroy(iotHubClientHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
platform_deinit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Usage(void)
|
|
||||||
{
|
|
||||||
printf("Usage: /d:<device connect string> /p:<reported properties in JSON>\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD WINAPI WatchDogThread(LPVOID lpThreadParameter)
|
|
||||||
{
|
|
||||||
(void)lpThreadParameter;
|
|
||||||
|
|
||||||
DWORD currentProcessID = GetCurrentProcessId();
|
|
||||||
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
||||||
|
|
||||||
DWORD parentProcessID = 0;
|
|
||||||
PROCESSENTRY32 processEntry;
|
|
||||||
processEntry.dwSize = sizeof(processEntry);
|
|
||||||
|
|
||||||
BOOL bContinue = Process32First(hSnapshot, &processEntry);
|
|
||||||
while (bContinue)
|
|
||||||
{
|
|
||||||
if (processEntry.th32ProcessID == currentProcessID)
|
|
||||||
{
|
|
||||||
parentProcessID = processEntry.th32ParentProcessID;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bContinue = Process32Next(hSnapshot, &processEntry);
|
|
||||||
}
|
|
||||||
CloseHandle(hSnapshot);
|
|
||||||
|
|
||||||
if (parentProcessID != 0)
|
|
||||||
{
|
|
||||||
printf("Parent process ID: %d\r\n", parentProcessID);
|
|
||||||
HANDLE hParent = OpenProcess(SYNCHRONIZE, FALSE, parentProcessID);
|
|
||||||
|
|
||||||
if (hParent != NULL)
|
|
||||||
{
|
|
||||||
printf("Opened parent process\r\n");
|
|
||||||
if (WaitForSingleObject(hParent, INFINITE) == WAIT_OBJECT_0)
|
|
||||||
{
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Failed to open parent process. GetLastError()=%d\r\n", GetLastError());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Failed to find parent process\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
|
||||||
{
|
|
||||||
for (int i = 1; i < argc; i++)
|
|
||||||
{
|
|
||||||
if (strncmp(argv[i], "/d:", 3) == 0)
|
|
||||||
{
|
|
||||||
connectionString = _strdup(argv[i] + 3);
|
|
||||||
}
|
|
||||||
else if (strncmp(argv[i], "/p:", 3) == 0)
|
|
||||||
{
|
|
||||||
reportedProperties = _strdup(argv[i] + 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(connectionString) == 0)
|
|
||||||
{
|
|
||||||
printf("Missing connection string\r\n");
|
|
||||||
Usage();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(reportedProperties) == 0)
|
|
||||||
{
|
|
||||||
printf("Missing connection string\r\n");
|
|
||||||
Usage();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetConsoleTitle(connectionString);
|
|
||||||
|
|
||||||
HANDLE hProcess = CreateThread(NULL, 0, WatchDogThread, NULL, 0, NULL);
|
|
||||||
CloseHandle(hProcess);
|
|
||||||
|
|
||||||
iothub_client_sample_device_method_run();
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,148 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
|
||||||
<ProjectConfiguration Include="Debug|Win32">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|Win32">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
</ItemGroup>
|
|
||||||
<PropertyGroup Label="Globals">
|
|
||||||
<ProjectGUID>{88C4CAFE-3DA8-4CDC-A7DC-1A8635DBE533}</ProjectGUID>
|
|
||||||
<Keyword>Win32Proj</Keyword>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
<ProjectName>iothub_client_sample_device_method</ProjectName>
|
|
||||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
|
||||||
<ImportGroup Label="ExtensionSettings">
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<PropertyGroup Label="UserMacros" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<_ProjectFileVersion>10.0.20506.1</_ProjectFileVersion>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</OutDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</IntDir>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">DMSimulator</TargetName>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.exe</TargetExt>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</GenerateManifest>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</OutDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</IntDir>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">DMSimulator</TargetName>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.exe</TargetExt>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</GenerateManifest>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>.\inc;.\inc\azure_c_shared_utility;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<AssemblerListingLocation>Debug/</AssemblerListingLocation>
|
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
|
||||||
<CompileAs>CompileAsC</CompileAs>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<DisableSpecificWarnings>4232</DisableSpecificWarnings>
|
|
||||||
<ExceptionHandling>
|
|
||||||
</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;ARCHITECTURE_x86=1;GB_MEASURE_MEMORY_FOR_THIS;GB_DEBUG_ALLOC;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions> /machine:X86 /debug %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;.\lib\iothub_client_mqtt_transport.lib;.\lib\iothub_client.lib;.\lib\umqtt.lib;.\lib\aziotsharedutil.lib;crypt32.lib;winhttp.lib;ws2_32.lib;secur32.lib;rpcrt4.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
|
|
||||||
<ImportLibrary>
|
|
||||||
</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>$(OutputPath)$(TargetName).pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>.\inc;.\inc\azure_c_shared_utility;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<AssemblerListingLocation>Release/</AssemblerListingLocation>
|
|
||||||
<CompileAs>CompileAsC</CompileAs>
|
|
||||||
<DisableSpecificWarnings>4232</DisableSpecificWarnings>
|
|
||||||
<ExceptionHandling>
|
|
||||||
</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
|
||||||
<Optimization>MaxSpeed</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;ARCHITECTURE_x86=1;GB_MEASURE_MEMORY_FOR_THIS;GB_DEBUG_ALLOC;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<DebugInformationFormat>
|
|
||||||
</DebugInformationFormat>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions> /machine:X86 %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;.\lib\iothub_client_mqtt_transport.lib;.\lib\iothub_client.lib;.\lib\umqtt.lib;.\lib\aziotsharedutil.lib;crypt32.lib;winhttp.lib;ws2_32.lib;secur32.lib;rpcrt4.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
|
|
||||||
<ImportLibrary>
|
|
||||||
</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>$(OutputPath)$(TargetName).pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include=".\iothub_client_sample_device_method.c" />
|
|
||||||
<ClCompile Include="DMTasks\ConfigurationUpdate.c" />
|
|
||||||
<ClCompile Include="DMTasks\DMTaskEngine.c" />
|
|
||||||
<ClCompile Include="DMTasks\FirmwareUpdate.c" />
|
|
||||||
<ClCompile Include="jsmn\jsmn.c" />
|
|
||||||
<ClCompile Include="SendReport.c" />
|
|
||||||
<ClCompile Include="Utilities.c" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="DMTasks\ConfigurationUpdate.h" />
|
|
||||||
<ClInclude Include="DMTasks\DMTaskBase.h" />
|
|
||||||
<ClInclude Include="DMTasks\DMTaskEngine.h" />
|
|
||||||
<ClInclude Include="DMTasks\FirmwareUpdate.h" />
|
|
||||||
<ClInclude Include="jsmn\jsmn.h" />
|
|
||||||
<ClInclude Include="SendReport.h" />
|
|
||||||
<ClInclude Include="Utilities.h" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
||||||
<ImportGroup Label="ExtensionTargets">
|
|
||||||
</ImportGroup>
|
|
||||||
</Project>
|
|
|
@ -1,47 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include=".\iothub_client_sample_device_method.c" />
|
|
||||||
<ClCompile Include="jsmn\jsmn.c">
|
|
||||||
<Filter>jsmn</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Utilities.c" />
|
|
||||||
<ClCompile Include="DMTasks\ConfigurationUpdate.c">
|
|
||||||
<Filter>DMTasks</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="DMTasks\FirmwareUpdate.c">
|
|
||||||
<Filter>DMTasks</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="SendReport.c" />
|
|
||||||
<ClCompile Include="DMTasks\DMTaskEngine.c">
|
|
||||||
<Filter>DMTasks</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Filter Include="jsmn">
|
|
||||||
<UniqueIdentifier>{1ddede64-4e94-4ce3-bea4-26cc96469b0f}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="DMTasks">
|
|
||||||
<UniqueIdentifier>{589290d6-4d16-422d-8157-10417af1237a}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="jsmn\jsmn.h">
|
|
||||||
<Filter>jsmn</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Utilities.h" />
|
|
||||||
<ClInclude Include="DMTasks\ConfigurationUpdate.h">
|
|
||||||
<Filter>DMTasks</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="DMTasks\FirmwareUpdate.h">
|
|
||||||
<Filter>DMTasks</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="SendReport.h" />
|
|
||||||
<ClInclude Include="DMTasks\DMTaskEngine.h">
|
|
||||||
<Filter>DMTasks</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="DMTasks\DMTaskBase.h">
|
|
||||||
<Filter>DMTasks</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
|
@ -1,314 +0,0 @@
|
||||||
#include "jsmn.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocates a fresh unused token from the token pull.
|
|
||||||
*/
|
|
||||||
static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser,
|
|
||||||
jsmntok_t *tokens, size_t num_tokens) {
|
|
||||||
jsmntok_t *tok;
|
|
||||||
if (parser->toknext >= num_tokens) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
tok = &tokens[parser->toknext++];
|
|
||||||
tok->start = tok->end = -1;
|
|
||||||
tok->size = 0;
|
|
||||||
#ifdef JSMN_PARENT_LINKS
|
|
||||||
tok->parent = -1;
|
|
||||||
#endif
|
|
||||||
return tok;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fills token type and boundaries.
|
|
||||||
*/
|
|
||||||
static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type,
|
|
||||||
int start, int end) {
|
|
||||||
token->type = type;
|
|
||||||
token->start = start;
|
|
||||||
token->end = end;
|
|
||||||
token->size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fills next available token with JSON primitive.
|
|
||||||
*/
|
|
||||||
static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
|
|
||||||
size_t len, jsmntok_t *tokens, size_t num_tokens) {
|
|
||||||
jsmntok_t *token;
|
|
||||||
int start;
|
|
||||||
|
|
||||||
start = parser->pos;
|
|
||||||
|
|
||||||
for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
|
|
||||||
switch (js[parser->pos]) {
|
|
||||||
#ifndef JSMN_STRICT
|
|
||||||
/* In strict mode primitive must be followed by "," or "}" or "]" */
|
|
||||||
case ':':
|
|
||||||
#endif
|
|
||||||
case '\t' : case '\r' : case '\n' : case ' ' :
|
|
||||||
case ',' : case ']' : case '}' :
|
|
||||||
goto found;
|
|
||||||
}
|
|
||||||
if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
|
|
||||||
parser->pos = start;
|
|
||||||
return JSMN_ERROR_INVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef JSMN_STRICT
|
|
||||||
/* In strict mode primitive must be followed by a comma/object/array */
|
|
||||||
parser->pos = start;
|
|
||||||
return JSMN_ERROR_PART;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
found:
|
|
||||||
if (tokens == NULL) {
|
|
||||||
parser->pos--;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
token = jsmn_alloc_token(parser, tokens, num_tokens);
|
|
||||||
if (token == NULL) {
|
|
||||||
parser->pos = start;
|
|
||||||
return JSMN_ERROR_NOMEM;
|
|
||||||
}
|
|
||||||
jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
|
|
||||||
#ifdef JSMN_PARENT_LINKS
|
|
||||||
token->parent = parser->toksuper;
|
|
||||||
#endif
|
|
||||||
parser->pos--;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fills next token with JSON string.
|
|
||||||
*/
|
|
||||||
static int jsmn_parse_string(jsmn_parser *parser, const char *js,
|
|
||||||
size_t len, jsmntok_t *tokens, size_t num_tokens) {
|
|
||||||
jsmntok_t *token;
|
|
||||||
|
|
||||||
int start = parser->pos;
|
|
||||||
|
|
||||||
parser->pos++;
|
|
||||||
|
|
||||||
/* Skip starting quote */
|
|
||||||
for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
|
|
||||||
char c = js[parser->pos];
|
|
||||||
|
|
||||||
/* Quote: end of string */
|
|
||||||
if (c == '\"') {
|
|
||||||
if (tokens == NULL) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
token = jsmn_alloc_token(parser, tokens, num_tokens);
|
|
||||||
if (token == NULL) {
|
|
||||||
parser->pos = start;
|
|
||||||
return JSMN_ERROR_NOMEM;
|
|
||||||
}
|
|
||||||
jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos);
|
|
||||||
#ifdef JSMN_PARENT_LINKS
|
|
||||||
token->parent = parser->toksuper;
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Backslash: Quoted symbol expected */
|
|
||||||
if (c == '\\' && parser->pos + 1 < len) {
|
|
||||||
int i;
|
|
||||||
parser->pos++;
|
|
||||||
switch (js[parser->pos]) {
|
|
||||||
/* Allowed escaped symbols */
|
|
||||||
case '\"': case '/' : case '\\' : case 'b' :
|
|
||||||
case 'f' : case 'r' : case 'n' : case 't' :
|
|
||||||
break;
|
|
||||||
/* Allows escaped symbol \uXXXX */
|
|
||||||
case 'u':
|
|
||||||
parser->pos++;
|
|
||||||
for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) {
|
|
||||||
/* If it isn't a hex character we have an error */
|
|
||||||
if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
|
|
||||||
(js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
|
|
||||||
(js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */
|
|
||||||
parser->pos = start;
|
|
||||||
return JSMN_ERROR_INVAL;
|
|
||||||
}
|
|
||||||
parser->pos++;
|
|
||||||
}
|
|
||||||
parser->pos--;
|
|
||||||
break;
|
|
||||||
/* Unexpected symbol */
|
|
||||||
default:
|
|
||||||
parser->pos = start;
|
|
||||||
return JSMN_ERROR_INVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parser->pos = start;
|
|
||||||
return JSMN_ERROR_PART;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse JSON string and fill tokens.
|
|
||||||
*/
|
|
||||||
int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
|
|
||||||
jsmntok_t *tokens, unsigned int num_tokens) {
|
|
||||||
int r;
|
|
||||||
int i;
|
|
||||||
jsmntok_t *token;
|
|
||||||
int count = parser->toknext;
|
|
||||||
|
|
||||||
for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
|
|
||||||
char c;
|
|
||||||
jsmntype_t type;
|
|
||||||
|
|
||||||
c = js[parser->pos];
|
|
||||||
switch (c) {
|
|
||||||
case '{': case '[':
|
|
||||||
count++;
|
|
||||||
if (tokens == NULL) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
token = jsmn_alloc_token(parser, tokens, num_tokens);
|
|
||||||
if (token == NULL)
|
|
||||||
return JSMN_ERROR_NOMEM;
|
|
||||||
if (parser->toksuper != -1) {
|
|
||||||
tokens[parser->toksuper].size++;
|
|
||||||
#ifdef JSMN_PARENT_LINKS
|
|
||||||
token->parent = parser->toksuper;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
|
|
||||||
token->start = parser->pos;
|
|
||||||
parser->toksuper = parser->toknext - 1;
|
|
||||||
break;
|
|
||||||
case '}': case ']':
|
|
||||||
if (tokens == NULL)
|
|
||||||
break;
|
|
||||||
type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
|
|
||||||
#ifdef JSMN_PARENT_LINKS
|
|
||||||
if (parser->toknext < 1) {
|
|
||||||
return JSMN_ERROR_INVAL;
|
|
||||||
}
|
|
||||||
token = &tokens[parser->toknext - 1];
|
|
||||||
for (;;) {
|
|
||||||
if (token->start != -1 && token->end == -1) {
|
|
||||||
if (token->type != type) {
|
|
||||||
return JSMN_ERROR_INVAL;
|
|
||||||
}
|
|
||||||
token->end = parser->pos + 1;
|
|
||||||
parser->toksuper = token->parent;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (token->parent == -1) {
|
|
||||||
if(token->type != type || parser->toksuper == -1) {
|
|
||||||
return JSMN_ERROR_INVAL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
token = &tokens[token->parent];
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
for (i = parser->toknext - 1; i >= 0; i--) {
|
|
||||||
token = &tokens[i];
|
|
||||||
if (token->start != -1 && token->end == -1) {
|
|
||||||
if (token->type != type) {
|
|
||||||
return JSMN_ERROR_INVAL;
|
|
||||||
}
|
|
||||||
parser->toksuper = -1;
|
|
||||||
token->end = parser->pos + 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Error if unmatched closing bracket */
|
|
||||||
if (i == -1) return JSMN_ERROR_INVAL;
|
|
||||||
for (; i >= 0; i--) {
|
|
||||||
token = &tokens[i];
|
|
||||||
if (token->start != -1 && token->end == -1) {
|
|
||||||
parser->toksuper = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
case '\"':
|
|
||||||
r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
|
|
||||||
if (r < 0) return r;
|
|
||||||
count++;
|
|
||||||
if (parser->toksuper != -1 && tokens != NULL)
|
|
||||||
tokens[parser->toksuper].size++;
|
|
||||||
break;
|
|
||||||
case '\t' : case '\r' : case '\n' : case ' ':
|
|
||||||
break;
|
|
||||||
case ':':
|
|
||||||
parser->toksuper = parser->toknext - 1;
|
|
||||||
break;
|
|
||||||
case ',':
|
|
||||||
if (tokens != NULL && parser->toksuper != -1 &&
|
|
||||||
tokens[parser->toksuper].type != JSMN_ARRAY &&
|
|
||||||
tokens[parser->toksuper].type != JSMN_OBJECT) {
|
|
||||||
#ifdef JSMN_PARENT_LINKS
|
|
||||||
parser->toksuper = tokens[parser->toksuper].parent;
|
|
||||||
#else
|
|
||||||
for (i = parser->toknext - 1; i >= 0; i--) {
|
|
||||||
if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) {
|
|
||||||
if (tokens[i].start != -1 && tokens[i].end == -1) {
|
|
||||||
parser->toksuper = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#ifdef JSMN_STRICT
|
|
||||||
/* In strict mode primitives are: numbers and booleans */
|
|
||||||
case '-': case '0': case '1' : case '2': case '3' : case '4':
|
|
||||||
case '5': case '6': case '7' : case '8': case '9':
|
|
||||||
case 't': case 'f': case 'n' :
|
|
||||||
/* And they must not be keys of the object */
|
|
||||||
if (tokens != NULL && parser->toksuper != -1) {
|
|
||||||
jsmntok_t *t = &tokens[parser->toksuper];
|
|
||||||
if (t->type == JSMN_OBJECT ||
|
|
||||||
(t->type == JSMN_STRING && t->size != 0)) {
|
|
||||||
return JSMN_ERROR_INVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
/* In non-strict mode every unquoted value is a primitive */
|
|
||||||
default:
|
|
||||||
#endif
|
|
||||||
r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
|
|
||||||
if (r < 0) return r;
|
|
||||||
count++;
|
|
||||||
if (parser->toksuper != -1 && tokens != NULL)
|
|
||||||
tokens[parser->toksuper].size++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
#ifdef JSMN_STRICT
|
|
||||||
/* Unexpected char in strict mode */
|
|
||||||
default:
|
|
||||||
return JSMN_ERROR_INVAL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tokens != NULL) {
|
|
||||||
for (i = parser->toknext - 1; i >= 0; i--) {
|
|
||||||
/* Unmatched opened object or array */
|
|
||||||
if (tokens[i].start != -1 && tokens[i].end == -1) {
|
|
||||||
return JSMN_ERROR_PART;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new parser based over a given buffer with an array of tokens
|
|
||||||
* available.
|
|
||||||
*/
|
|
||||||
void jsmn_init(jsmn_parser *parser) {
|
|
||||||
parser->pos = 0;
|
|
||||||
parser->toknext = 0;
|
|
||||||
parser->toksuper = -1;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
#ifndef __JSMN_H_
|
|
||||||
#define __JSMN_H_
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSON type identifier. Basic types are:
|
|
||||||
* o Object
|
|
||||||
* o Array
|
|
||||||
* o String
|
|
||||||
* o Other primitive: number, boolean (true/false) or null
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
JSMN_UNDEFINED = 0,
|
|
||||||
JSMN_OBJECT = 1,
|
|
||||||
JSMN_ARRAY = 2,
|
|
||||||
JSMN_STRING = 3,
|
|
||||||
JSMN_PRIMITIVE = 4
|
|
||||||
} jsmntype_t;
|
|
||||||
|
|
||||||
enum jsmnerr {
|
|
||||||
/* Not enough tokens were provided */
|
|
||||||
JSMN_ERROR_NOMEM = -1,
|
|
||||||
/* Invalid character inside JSON string */
|
|
||||||
JSMN_ERROR_INVAL = -2,
|
|
||||||
/* The string is not a full JSON packet, more bytes expected */
|
|
||||||
JSMN_ERROR_PART = -3
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSON token description.
|
|
||||||
* type type (object, array, string etc.)
|
|
||||||
* start start position in JSON data string
|
|
||||||
* end end position in JSON data string
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
jsmntype_t type;
|
|
||||||
int start;
|
|
||||||
int end;
|
|
||||||
int size;
|
|
||||||
#ifdef JSMN_PARENT_LINKS
|
|
||||||
int parent;
|
|
||||||
#endif
|
|
||||||
} jsmntok_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSON parser. Contains an array of token blocks available. Also stores
|
|
||||||
* the string being parsed now and current position in that string
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
unsigned int pos; /* offset in the JSON string */
|
|
||||||
unsigned int toknext; /* next token to allocate */
|
|
||||||
int toksuper; /* superior token node, e.g parent object or array */
|
|
||||||
} jsmn_parser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create JSON parser over an array of tokens
|
|
||||||
*/
|
|
||||||
void jsmn_init(jsmn_parser *parser);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run JSON parser. It parses a JSON data string into and array of tokens, each describing
|
|
||||||
* a single JSON object.
|
|
||||||
*/
|
|
||||||
int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
|
|
||||||
jsmntok_t *tokens, unsigned int num_tokens);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __JSMN_H_ */
|
|
Двоичные данные
Simulator/DMSimulator/lib/aziotsharedutil.lib
Двоичные данные
Simulator/DMSimulator/lib/aziotsharedutil.lib
Двоичный файл не отображается.
Двоичные данные
Simulator/DMSimulator/lib/iothub_client.lib
Двоичные данные
Simulator/DMSimulator/lib/iothub_client.lib
Двоичный файл не отображается.
Двоичные данные
Simulator/DMSimulator/lib/iothub_client_mqtt_transport.lib
Двоичные данные
Simulator/DMSimulator/lib/iothub_client_mqtt_transport.lib
Двоичный файл не отображается.
Двоичные данные
Simulator/DMSimulator/lib/umqtt.lib
Двоичные данные
Simulator/DMSimulator/lib/umqtt.lib
Двоичный файл не отображается.
Двоичные данные
Simulator/Simulator.WebJob/DMSimulator.exe
Двоичные данные
Simulator/Simulator.WebJob/DMSimulator.exe
Двоичный файл не отображается.
|
@ -258,11 +258,6 @@
|
||||||
<Install>false</Install>
|
<Install>false</Install>
|
||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="DMSimulator.exe">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
@ -273,7 +268,8 @@
|
||||||
</Target>
|
</Target>
|
||||||
<Import Project="..\..\packages\Microsoft.Web.WebJobs.Publish.1.0.11\tools\webjobs.targets" Condition="Exists('..\..\packages\Microsoft.Web.WebJobs.Publish.1.0.11\tools\webjobs.targets')" />
|
<Import Project="..\..\packages\Microsoft.Web.WebJobs.Publish.1.0.11\tools\webjobs.targets" Condition="Exists('..\..\packages\Microsoft.Web.WebJobs.Publish.1.0.11\tools\webjobs.targets')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PreBuildEvent>copy /y $(SolutionDir)\Simulator\DMSimulator\$(ConfigurationName)\DMSimulator.exe $(ProjectDir)</PreBuildEvent>
|
<PreBuildEvent>
|
||||||
|
</PreBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче