Skip to content

Commit

Permalink
Add Visual Studio project for Azure IoT Hub example. Replace sprintf …
Browse files Browse the repository at this point in the history
…with safe snprintf. Cleanup of the snprintf to use macro XSNPRINTF.
  • Loading branch information
dgarske committed Jun 13, 2016
1 parent 4b8c7cd commit 11625f9
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 5 deletions.
8 changes: 4 additions & 4 deletions examples/azure/azureiothub.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ static char* url_encode(char* table, unsigned char *s, char *enc)
{
for (; *s; s++){
if (table[*s]) {
sprintf(enc, "%c", table[*s]);
XSNPRINTF(enc, 2, "%c", table[*s]);
}
else {
sprintf(enc, "%%%02x", *s);
XSNPRINTF(enc, 4, "%%%02x", *s);
}
while (*++enc); /* locate end */
}
Expand Down Expand Up @@ -271,7 +271,7 @@ static int SasTokenCreate(char* sasToken, int sasTokenLen)
url_encode(mRfc3986, (byte*)AZURE_DEVICE_NAME, deviceName);

/* Build signature sting "uri \n expiration" */
snprintf(sigData, sizeof(sigData), AZURE_SIG_FMT, deviceName, lTime);
XSNPRINTF(sigData, sizeof(sigData), AZURE_SIG_FMT, deviceName, lTime);

/* HMAC-SHA256 Hash sigData using decoded key */
rc = wc_HmacSetKey(&hmac, SHA256, decodedKey, decodedKeyLen);
Expand Down Expand Up @@ -301,7 +301,7 @@ static int SasTokenCreate(char* sasToken, int sasTokenLen)
url_encode(mRfc3986, base64Sig, (char*)encodedSig);

/* Build sasToken */
snprintf(sasToken, sasTokenLen, AZURE_PASSWORD_FMT, deviceName, encodedSig, lTime);
XSNPRINTF(sasToken, sasTokenLen, AZURE_PASSWORD_FMT, deviceName, encodedSig, lTime);
PRINTF("%s", sasToken);

return 0;
Expand Down
145 changes: 145 additions & 0 deletions examples/azure/azureiothub.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?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>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{D6D64B80-7203-4E0D-B883-E126B823A96E}</ProjectGuid>
<RootNamespace>azureIotHub</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IntDir>$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;$(SolutionDir)wolfssl.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../;../../;../../../wolfssl/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;$(SolutionDir)wolfssl.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\mqttnet.c" />
<ClCompile Include="azureiothub.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\mqttexample.h" />
<ClInclude Include="..\mqttnet.h" />
<ClInclude Include="azureiothub.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\wolfmqtt.vcxproj">
<Project>{d42405ee-238f-4560-8b49-e70948ec9100}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
36 changes: 36 additions & 0 deletions examples/azure/azureiothub.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="azureiothub.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\mqttnet.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="azureiothub.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\mqttnet.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\mqttexample.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion examples/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ EXTRA_DIST+= examples/mqttuart.c \
examples/firmware/fwclient.vcxproj \
examples/firmware/fwclient.vcxproj.filters \
examples/firmware/fwpush.vcxproj \
examples/firmware/fwpush.vcxproj.filters
examples/firmware/fwpush.vcxproj.filters \
examples/azure/azureiothub.vcxproj \
examples/azure/azureiothub.vcxproj.filters
10 changes: 10 additions & 0 deletions wolfmqtt.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fwclient", "examples\firmwa
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fwpush", "examples\firmware\fwpush.vcxproj", "{AC340EE9-6612-4B96-8B64-D1FF64301D32}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "azureiothub", "examples\azure\azureiothub.vcxproj", "{D6D64B80-7203-4E0D-B883-E126B823A96E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -54,6 +56,14 @@ Global
{AC340EE9-6612-4B96-8B64-D1FF64301D32}.Release|x64.Build.0 = Release|x64
{AC340EE9-6612-4B96-8B64-D1FF64301D32}.Release|x86.ActiveCfg = Release|Win32
{AC340EE9-6612-4B96-8B64-D1FF64301D32}.Release|x86.Build.0 = Release|Win32
{D6D64B80-7203-4E0D-B883-E126B823A96E}.Debug|x64.ActiveCfg = Debug|x64
{D6D64B80-7203-4E0D-B883-E126B823A96E}.Debug|x64.Build.0 = Debug|x64
{D6D64B80-7203-4E0D-B883-E126B823A96E}.Debug|x86.ActiveCfg = Debug|Win32
{D6D64B80-7203-4E0D-B883-E126B823A96E}.Debug|x86.Build.0 = Debug|Win32
{D6D64B80-7203-4E0D-B883-E126B823A96E}.Release|x64.ActiveCfg = Release|x64
{D6D64B80-7203-4E0D-B883-E126B823A96E}.Release|x64.Build.0 = Release|x64
{D6D64B80-7203-4E0D-B883-E126B823A96E}.Release|x86.ActiveCfg = Release|Win32
{D6D64B80-7203-4E0D-B883-E126B823A96E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions wolfmqtt/mqtt_types.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ enum MqttPacketResponseCodes {
#ifndef XISALNUM
#define XISALNUM(c) isalnum((c))
#endif
#ifndef XSNPRINTF
#define XSNPRINTF snprintf
#endif
#endif

#ifndef WOLFMQTT_CUSTOM_MALLOC
Expand Down

0 comments on commit 11625f9

Please sign in to comment.