Update Iothub client with uMqtt

This commit is contained in:
Jelani 2016-01-22 13:46:24 -08:00
Родитель aab573ca13
Коммит 0a00bc27ee
38 изменённых файлов: 2097 добавлений и 5092 удалений

4
.gitmodules поставляемый
Просмотреть файл

@ -1,3 +1,7 @@
[submodule "c/azure-c-shared-utility"]
path = c/azure-c-shared-utility
url = https://github.com/Azure/azure-c-shared-utility.git
[submodule "c/azure-umqtt-c"]
path = c/azure-umqtt-c
url = https://github.com/Azure/azure-umqtt-c.git
branch = develop

Просмотреть файл

@ -25,6 +25,7 @@ if(IN_OPENWRT)
endif()
add_subdirectory(azure-c-shared-utility/c)
add_subdirectory(azure-umqtt-c)
enable_testing()
@ -68,21 +69,14 @@ function(linkProton whatExecutableIsBuilding)
endif()
endfunction(linkProton)
function(includePaho)
#function body to be similar to includeProton
endfunction(includePaho)
function(includeMqtt)
include_directories(${MQTT_INC_FOLDER})
endfunction(includeMqtt)
function(linkPaho whatExecutableIsBuilding)
includePaho()
if(WIN32)
target_link_libraries(${whatExecutableIsBuilding} "$ENV{paho_path}/org.eclipse.paho.mqtt.c/Windows Build/paho-mqtt3cs/Debug/paho-mqtt3cs.lib")
file(COPY "$ENV{paho_path}/org.eclipse.paho.mqtt.c/Windows Build/paho-mqtt3cs/Debug/paho-mqtt3cs.dll" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
file(COPY "$ENV{openssldir}/bin/libeay32.dll" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
file(COPY "$ENV{openssldir}/bin/ssleay32.dll" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
else()
target_link_libraries(${whatExecutableIsBuilding} paho-mqtt3cs)
endif()
endfunction(linkPaho)
function(linkMqttLibrary whatExecutableIsBuilding)
includeMqtt()
target_link_libraries(${whatExecutableIsBuilding} umqtt)
endfunction(linkMqttLibrary)
function(includeHttp)
#function body to be similar to includeProton
@ -240,7 +234,6 @@ function(build_test_artifacts whatIsBuilding use_gballoc)
windows_unittests_add_exe(${whatIsBuilding} ${ARGN})
endif()
endif()
endfunction(build_test_artifacts)
set(SHARED_UTIL_ADAPTER_FOLDER "${CMAKE_CURRENT_LIST_DIR}/azure-c-shared-utility/c/adapters")

1
c/azure-umqtt-c Submodule

@ -0,0 +1 @@
Subproject commit 8eee4032b64ce3de322571f24559b33e0cf3e408

Просмотреть файл

@ -1,86 +0,0 @@
#!/bin/bash
set -e
paho_repo="https://git.eclipse.org/r/paho/org.eclipse.paho.mqtt.c"
build_root=
push_dir ()
{
pushd $1 > /dev/null
echo "In ${PWD#$build_root/}"
}
pop_dir ()
{
popd > /dev/null
}
usage ()
{
echo 'build_paho.sh [options]'
echo 'options'
echo ' -s, --source destination directory for paho source'
echo ' (default: $HOME/org.eclipse.paho.mqtt.c)'
echo ' -i, --install destination root directory for paho installation'
echo ' (default: $HOME)'
exit 1
}
process_args ()
{
build_root="$HOME/org.eclipse.paho.mqtt.c"
install_root="$HOME"
while [ ! -z "$1" ] && [ ! -z "$2" ]
do
if [ "$1" == "-s" ] || [ "$1" == "--source" ]
then
build_root="$2"
elif [ "$1" == "-i" ] || [ "$1" == "--install" ]
then
install_root="$2"
else
usage
fi
shift
shift
done
if [ ! -z "$1" ] && [ -z "$2" ]
then #odd number of arguments
usage
fi
}
sync_paho ()
{
echo Azure IoT SDK has a dependency on eclipse paho mqtt c sdk
echo http://www.eclipse.org/legal/CLA.php
read -p "Do you want to install the component (y/n)?" input_var
if [ "$input_var" == "y" ] || [ "$input_var" == "Y" ]
then
echo "preparing qpid proton-c"
else
exit 1
fi
rm $build_root -r -f
mkdir $build_root
git clone $paho_repo $build_root
}
build ()
{
push_dir $build_root
make install
pop_dir
}
process_args $*
echo "Source: $build_root"
echo "Install: $install_root"
sync_paho
build

Просмотреть файл

@ -51,20 +51,6 @@ install_proton_from_source ()
[ $? -eq 0 ] || return $?
}
install_paho_from_source ()
{
#Skip if already installed
code_dir="$HOME/org.eclipse.paho.mqtt.c"
if [ -d $code_dir ] && [ -d "$code_dir/build/output" ]
then
echo "Paho already installed."
return 0
fi
sudo bash c/build_all/linux/build_paho.sh --install /usr
[ $? -eq 0 ] || return $?
}
deps_install
if repo_exists
@ -77,5 +63,4 @@ else
fi
install_proton_from_source || exit 1
install_paho_from_source || exit 1
pop_dir

Просмотреть файл

@ -85,18 +85,6 @@ install_proton_from_source ()
sudo bash c/build_all/linux/build_proton.sh --install /usr
}
install_paho_from_source ()
{
#Skip if already installed
code_dir="$HOME/org.eclipse.paho.mqtt.c"
if [ -d $code_dir ] && [ -d "$code_dir/build/output" ]
then
echo "Paho already installed."
return 0
fi
sudo bash c/build_all/linux/build_paho.sh --install /usr
}
if ! repo_exists
then
@ -117,5 +105,4 @@ else
fi
install_proton_from_source
install_paho_from_source
pop_dir

Просмотреть файл

@ -1,51 +0,0 @@
<?xml version="1.0"?><package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Eclipse.Paho-C.paho-mqtt3cs</id>
<version>1.0.3</version>
<title>Eclipse Paho-C mqtt3cs Library</title>
<authors>Eclipse Org, Microsoft Corp</authors>
<owners>Azure-IoT</owners>
<licenseUrl>https://github.com/eclipse/paho.mqtt.c/blob/master/notice.html</licenseUrl>
<projectUrl>https://www.eclipse.org/paho/clients/c/</projectUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>This package brings the Paho MQTT C Client, which is a fully fledged MQTT client written in ANSI standard C.</description>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</iconUrl>
<summary>
The Paho MQTT C Client library provides 2 set of APIs: "Synchronous" and "Asynchronous" Ones.
The API calls will start with MQTTClient for Synchronous APIs, and MQTT Async for Asynchronous ones.
This package only contains the Synchronous mqtt3cs with Security (Using Open SSL).
Microsoft's contribution to this package was only the packaging for NuGet itself. The library has been developed and is maintained by the Eclipse Foundation.
</summary>
<releaseNotes/>
<copyright>Copyright 2015</copyright>
<tags>MQTT Paho Eclipse Native x86 x64 package</tags>
<dependencies>
</dependencies>
</metadata>
<files>
<file src="Eclipse.Paho-C.paho-mqtt3cs_thirdpartynotice.txt" target="thirdpartynotice.txt"/>
<!-- these are files for x86 plaform -->
<file src="paho_outputs\Win32\Debug\paho-mqtt3cs.lib" target="lib\native\Win32\Debug"/>
<file src="paho_outputs\Win32\Debug\paho-mqtt3cs.dll" target="lib\native\Win32\Debug"/>
<file src="paho_outputs\Win32\Debug\paho-mqtt3cs.pdb" target="lib\native\Win32\Debug"/>
<file src="paho_outputs\Win32\Release\paho-mqtt3cs.lib" target="lib\native\Win32\Release"/>
<file src="paho_outputs\Win32\Release\paho-mqtt3cs.dll" target="lib\native\Win32\Release"/>
<file src="openssl_outputs\Win32\Debug\" target="lib\native\Win32\Debug"/>
<!-- these are files for x64 plaform -->
<file src="paho_outputs\x64\Debug\paho-mqtt3cs.lib" target="lib\native\x64\Debug"/>
<file src="paho_outputs\x64\Debug\paho-mqtt3cs.dll" target="lib\native\x64\Debug"/>
<file src="paho_outputs\x64\Debug\paho-mqtt3cs.pdb" target="lib\native\x64\Debug"/>
<file src="paho_outputs\x64\Release\paho-mqtt3cs.lib" target="lib\native\x64\Release"/>
<file src="paho_outputs\x64\Release\paho-mqtt3cs.dll" target="lib\native\x64\Release"/>
<file src="openssl_outputs\x64\Debug\" target="lib\native\x64\Debug"/>
<!-- Target File -->
<file src="Eclipse.Paho-C.paho-mqtt3cs.targets" target="build\native"/>
<!-- include files -->
<file src="paho_outputs\include\*.h" target="build\native\include\paho"/>
</files>
</package>

Просмотреть файл

@ -1,91 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="Eclipse_Paho_mqtt3cs_init">
<PropertyGroup Label="Default initializers for properties">
<Linkage-Eclipse_Paho_mqtt3cs Condition="'$(Linkage-Eclipse_Paho_mqtt3cs)' == ''">static</Linkage-Eclipse_Paho_mqtt3cs>
<CallingConvention-Eclipse_Paho_mqtt3cs Condition="'$(CallingConvention-Eclipse_Paho_mqtt3cs)' == ''">cdecl</CallingConvention-Eclipse_Paho_mqtt3cs>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)../../build/native/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ResourceCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)../../build/native/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="Win32Debug" Condition="(( $(Configuration.ToLower().IndexOf('debug')) &gt; -1 ) And ('$(Platform)' == 'Win32' ) )">
<Link>
<AdditionalDependencies>$(MSBuildThisFileDirectory)../../lib/native/Win32/Debug/paho-mqtt3cs.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="Win32Release" Condition="(( $(Configuration.ToLower().IndexOf('debug')) == -1 ) And ('$(Platform)' == 'Win32' ) )">
<Link>
<AdditionalDependencies>$(MSBuildThisFileDirectory)../../lib/native/Win32/Release/paho-mqtt3cs.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="Win64Debug" Condition="(( $(Configuration.ToLower().IndexOf('debug')) &gt; -1 ) And ('$(Platform)' == 'x64' ) )">
<Link>
<AdditionalDependencies>$(MSBuildThisFileDirectory)../../lib/native/x64/Debug/paho-mqtt3cs.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="Win64Release" Condition="(( $(Configuration.ToLower().IndexOf('debug')) == -1 ) And ('$(Platform)' == 'x64' ) )">
<Link>
<AdditionalDependencies>$(MSBuildThisFileDirectory)../../lib/native/x64/Release/paho-mqtt3cs.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<UsingTask TaskName="Eclipse_Paho_mqtt3cs_Contains" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" TaskFactory="CodeTaskFactory">
<ParameterGroup>
<Text Output="false" ParameterType="System.String" />
<Library Output="false" Required="true" ParameterType="System.String" />
<Value Output="false" Required="true" ParameterType="System.String" />
<Result Output="true" ParameterType="System.String" />
</ParameterGroup>
<Task>
<Code>Result = ((Text ?? "").Split(';').Contains(Library) ) ? Value : String.Empty;</Code>
</Task>
</UsingTask>
<Target Name="Eclipse_Paho_mqtt3cs_init">
<Eclipse_Paho_mqtt3cs_Contains Text="Linkage-dynamic" Library="Eclipse_Paho_mqtt3cs" Value="dynamic" Condition="'$(Linkage-Eclipse_Paho_mqtt3cs)'==''">
<Output TaskParameter="Result" PropertyName="Linkage-Eclipse_Paho_mqtt3cs" />
</Eclipse_Paho_mqtt3cs_Contains>
<Eclipse_Paho_mqtt3cs_Contains Text="Linkage-static" Library="Eclipse_Paho_mqtt3cs" Value="static" Condition="'$(Linkage-Eclipse_Paho_mqtt3cs)'==''">
<Output TaskParameter="Result" PropertyName="Linkage-Eclipse_Paho_mqtt3cs" />
</Eclipse_Paho_mqtt3cs_Contains>
<Eclipse_Paho_mqtt3cs_Contains Text="Linkage-ltcg" Library="Eclipse_Paho_mqtt3cs" Value="ltcg" Condition="'$(Linkage-Eclipse_Paho_mqtt3cs)'==''">
<Output TaskParameter="Result" PropertyName="Linkage-Eclipse_Paho_mqtt3cs" />
</Eclipse_Paho_mqtt3cs_Contains>
<Eclipse_Paho_mqtt3cs_Contains Text="Linkage-sxs" Library="Eclipse_Paho_mqtt3cs" Value="sxs" Condition="'$(Linkage-Eclipse_Paho_mqtt3cs)'==''">
<Output TaskParameter="Result" PropertyName="Linkage-Eclipse_Paho_mqtt3cs" />
</Eclipse_Paho_mqtt3cs_Contains>
<Eclipse_Paho_mqtt3cs_Contains Text="CallingConvention-cdecl" Library="Eclipse_Paho_mqtt3cs" Value="cdecl" Condition="'$(CallingConvention-Eclipse_Paho_mqtt3cs)'==''">
<Output TaskParameter="Result" PropertyName="CallingConvention-Eclipse_Paho_mqtt3cs" />
</Eclipse_Paho_mqtt3cs_Contains>
<Eclipse_Paho_mqtt3cs_Contains Text="CallingConvention-stdcall" Library="Eclipse_Paho_mqtt3cs" Value="stdcall" Condition="'$(CallingConvention-Eclipse_Paho_mqtt3cs)'==''">
<Output TaskParameter="Result" PropertyName="CallingConvention-Eclipse_Paho_mqtt3cs" />
</Eclipse_Paho_mqtt3cs_Contains>
<Eclipse_Paho_mqtt3cs_Contains Text="CallingConvention-fastcall" Library="Eclipse_Paho_mqtt3cs" Value="fastcall" Condition="'$(CallingConvention-Eclipse_Paho_mqtt3cs)'==''">
<Output TaskParameter="Result" PropertyName="CallingConvention-Eclipse_Paho_mqtt3cs" />
</Eclipse_Paho_mqtt3cs_Contains>
<Eclipse_Paho_mqtt3cs_Contains Text="CallingConvention-thiscall" Library="Eclipse_Paho_mqtt3cs" Value="thiscall" Condition="'$(CallingConvention-Eclipse_Paho_mqtt3cs)'==''">
<Output TaskParameter="Result" PropertyName="CallingConvention-Eclipse_Paho_mqtt3cs" />
</Eclipse_Paho_mqtt3cs_Contains>
<Eclipse_Paho_mqtt3cs_Contains Text="CallingConvention-clrcall" Library="Eclipse_Paho_mqtt3cs" Value="clrcall" Condition="'$(CallingConvention-Eclipse_Paho_mqtt3cs)'==''">
<Output TaskParameter="Result" PropertyName="CallingConvention-Eclipse_Paho_mqtt3cs" />
</Eclipse_Paho_mqtt3cs_Contains>
</Target>
<Target Name="Eclipse_Paho_mqtt3cs_redist_AfterBuild" AfterTargets="AfterBuild" />
<Target Name="Eclipse_Paho_mqtt3cs_redist_AfterBuild_Win32_and_Debug" Label="Win32 and Debug" Condition="'$(Platform.ToLower())' == 'win32' And ( $(Configuration.ToLower().IndexOf('debug')) &gt; -1 )" AfterTargets="Eclipse_Paho_mqtt3cs_redist_AfterBuild">
<Copy SourceFiles="$(MSBuildThisFileDirectory)../../lib/native/Win32/Debug/paho-mqtt3cs.dll" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="Eclipse_Paho_mqtt3cs_redist_AfterBuild_Win32_and_Release" Label="Win32 and Release" Condition="'$(Platform.ToLower())' == 'win32' And ( $(Configuration.ToLower().IndexOf('debug')) == -1 )" AfterTargets="Eclipse_Paho_mqtt3cs_redist_AfterBuild">
<Copy SourceFiles="$(MSBuildThisFileDirectory)../../lib/native/Win32/Release/paho-mqtt3cs.dll" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="Eclipse_Paho_mqtt3cs_redist_AfterBuild_Win64_and_Debug" Label="Win64 and Debug" Condition="'$(Platform.ToLower())' == 'x64' And ( $(Configuration.ToLower().IndexOf('debug')) &gt; -1 )" AfterTargets="Eclipse_Paho_mqtt3cs_redist_AfterBuild">
<Copy SourceFiles="$(MSBuildThisFileDirectory)../../lib/native/x64/Debug/paho-mqtt3cs.dll" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="Eclipse_Paho_mqtt3cs_redist_AfterBuild_Win64_and_Release" Label="Win64 and Release" Condition="'$(Platform.ToLower())' == 'x64' And ( $(Configuration.ToLower().IndexOf('debug')) == -1 )" AfterTargets="Eclipse_Paho_mqtt3cs_redist_AfterBuild">
<Copy SourceFiles="$(MSBuildThisFileDirectory)../../lib/native/x64/Release/paho-mqtt3cs.dll" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
</Target>
</Project>

Просмотреть файл

@ -1,245 +0,0 @@
Third Party Notices for Azure IoT SDKs project
This project incorporates material from the project(s) listed below (collectively, “Third Party Code”).
Microsoft Corporation is not the original author of the Third Party Code.
The original copyright notice and license, under which Microsoft Corporation received such Third Party Code,
are set out below. This Third Party Code is licensed to you under their original license terms set forth below.
Microsoft Corporation reserves all other rights not expressly granted, whether by implication, estoppel or otherwise.
1. Paho C v1.0.3, obtained from https://www.eclipse.org/paho/clients/c/
/*
Eclipse Public License - v 1.0
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
AGREEMENT.
1. DEFINITIONS
"Contribution" means:
a) in the case of the initial Contributor, the initial
code and documentation distributed under this Agreement, and
b) in the case of each subsequent Contributor:
i) changes to the Program, and
ii) additions to the Program;
where such changes and/or additions to the Program
originate from and are distributed by that particular Contributor. A
Contribution 'originates' from a Contributor if it was added to the
Program by such Contributor itself or anyone acting on such
Contributor's behalf. Contributions do not include additions to the
Program which: (i) are separate modules of software distributed in
conjunction with the Program under their own license agreement, and (ii)
are not derivative works of the Program.
"Contributor" means any person or entity that distributes
the Program.
"Licensed Patents" mean patent claims licensable by a
Contributor which are necessarily infringed by the use or sale of its
Contribution alone or when combined with the Program.
"Program" means the Contributions distributed in accordance
with this Agreement.
"Recipient" means anyone who receives the Program under
this Agreement, including all Contributors.
2. GRANT OF RIGHTS
a) Subject to the terms of this Agreement, each
Contributor hereby grants Recipient a non-exclusive, worldwide,
royalty-free copyright license to reproduce, prepare derivative works
of, publicly display, publicly perform, distribute and sublicense the
Contribution of such Contributor, if any, and such derivative works, in
source code and object code form.
b) Subject to the terms of this Agreement, each
Contributor hereby grants Recipient a non-exclusive, worldwide,
royalty-free patent license under Licensed Patents to make, use, sell,
offer to sell, import and otherwise transfer the Contribution of such
Contributor, if any, in source code and object code form. This patent
license shall apply to the combination of the Contribution and the
Program if, at the time the Contribution is added by the Contributor,
such addition of the Contribution causes such combination to be covered
by the Licensed Patents. The patent license shall not apply to any other
combinations which include the Contribution. No hardware per se is
licensed hereunder.
c) Recipient understands that although each Contributor
grants the licenses to its Contributions set forth herein, no assurances
are provided by any Contributor that the Program does not infringe the
patent or other intellectual property rights of any other entity. Each
Contributor disclaims any liability to Recipient for claims brought by
any other entity based on infringement of intellectual property rights
or otherwise. As a condition to exercising the rights and licenses
granted hereunder, each Recipient hereby assumes sole responsibility to
secure any other intellectual property rights needed, if any. For
example, if a third party patent license is required to allow Recipient
to distribute the Program, it is Recipient's responsibility to acquire
that license before distributing the Program.
d) Each Contributor represents that to its knowledge it
has sufficient copyright rights in its Contribution, if any, to grant
the copyright license set forth in this Agreement.
3. REQUIREMENTS
A Contributor may choose to distribute the Program in object code
form under its own license agreement, provided that:
a) it complies with the terms and conditions of this
Agreement; and
b) its license agreement:
i) effectively disclaims on behalf of all Contributors
all warranties and conditions, express and implied, including warranties
or conditions of title and non-infringement, and implied warranties or
conditions of merchantability and fitness for a particular purpose;
ii) effectively excludes on behalf of all Contributors
all liability for damages, including direct, indirect, special,
incidental and consequential damages, such as lost profits;
iii) states that any provisions which differ from this
Agreement are offered by that Contributor alone and not by any other
party; and
iv) states that source code for the Program is available
from such Contributor, and informs licensees how to obtain it in a
reasonable manner on or through a medium customarily used for software
exchange.
When the Program is made available in source code form:
a) it must be made available under this Agreement; and
b) a copy of this Agreement must be included with each
copy of the Program.
Contributors may not remove or alter any copyright notices contained
within the Program.
Each Contributor must identify itself as the originator of its
Contribution, if any, in a manner that reasonably allows subsequent
Recipients to identify the originator of the Contribution.
4. COMMERCIAL DISTRIBUTION
Commercial distributors of software may accept certain
responsibilities with respect to end users, business partners and the
like. While this license is intended to facilitate the commercial use of
the Program, the Contributor who includes the Program in a commercial
product offering should do so in a manner which does not create
potential liability for other Contributors. Therefore, if a Contributor
includes the Program in a commercial product offering, such Contributor
("Commercial Contributor") hereby agrees to defend and
indemnify every other Contributor ("Indemnified Contributor")
against any losses, damages and costs (collectively "Losses")
arising from claims, lawsuits and other legal actions brought by a third
party against the Indemnified Contributor to the extent caused by the
acts or omissions of such Commercial Contributor in connection with its
distribution of the Program in a commercial product offering. The
obligations in this section do not apply to any claims or Losses
relating to any actual or alleged intellectual property infringement. In
order to qualify, an Indemnified Contributor must: a) promptly notify
the Commercial Contributor in writing of such claim, and b) allow the
Commercial Contributor to control, and cooperate with the Commercial
Contributor in, the defense and any related settlement negotiations. The
Indemnified Contributor may participate in any such claim at its own
expense.
For example, a Contributor might include the Program in a commercial
product offering, Product X. That Contributor is then a Commercial
Contributor. If that Commercial Contributor then makes performance
claims, or offers warranties related to Product X, those performance
claims and warranties are such Commercial Contributor's responsibility
alone. Under this section, the Commercial Contributor would have to
defend claims against the other Contributors related to those
performance claims and warranties, and if a court requires any other
Contributor to pay any damages as a result, the Commercial Contributor
must pay those damages.
5. NO WARRANTY
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
responsible for determining the appropriateness of using and
distributing the Program and assumes all risks associated with its
exercise of rights under this Agreement , including but not limited to
the risks and costs of program errors, compliance with applicable laws,
damage to or loss of data, programs or equipment, and unavailability or
interruption of operations.
6. DISCLAIMER OF LIABILITY
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
7. GENERAL
If any provision of this Agreement is invalid or unenforceable under
applicable law, it shall not affect the validity or enforceability of
the remainder of the terms of this Agreement, and without further action
by the parties hereto, such provision shall be reformed to the minimum
extent necessary to make such provision valid and enforceable.
If Recipient institutes patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that the
Program itself (excluding combinations of the Program with other
software or hardware) infringes such Recipient's patent(s), then such
Recipient's rights granted under Section 2(b) shall terminate as of the
date such litigation is filed.
All Recipient's rights under this Agreement shall terminate if it
fails to comply with any of the material terms or conditions of this
Agreement and does not cure such failure in a reasonable period of time
after becoming aware of such noncompliance. If all Recipient's rights
under this Agreement terminate, Recipient agrees to cease use and
distribution of the Program as soon as reasonably practicable. However,
Recipient's obligations under this Agreement and any licenses granted by
Recipient relating to the Program shall continue and survive.
Everyone is permitted to copy and distribute copies of this
Agreement, but in order to avoid inconsistency the Agreement is
copyrighted and may only be modified in the following manner. The
Agreement Steward reserves the right to publish new versions (including
revisions) of this Agreement from time to time. No one other than the
Agreement Steward has the right to modify this Agreement. The Eclipse
Foundation is the initial Agreement Steward. The Eclipse Foundation may
assign the responsibility to serve as the Agreement Steward to a
suitable separate entity. Each new version of the Agreement will be
given a distinguishing version number. The Program (including
Contributions) may always be distributed subject to the version of the
Agreement under which it was received. In addition, after a new version
of the Agreement is published, Contributor may elect to distribute the
Program (including its Contributions) under the new version. Except as
expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
rights or licenses to the intellectual property of any Contributor under
this Agreement, whether expressly, by implication, estoppel or
otherwise. All rights in the Program not expressly granted under this
Agreement are reserved.
This Agreement is governed by the laws of the State of New York and
the intellectual property laws of the United States of America. No party
to this Agreement will bring a legal action under this Agreement more
than one year after the cause of action arose. Each party waives its
rights to a jury trial in any resulting litigation.
*/

Просмотреть файл

@ -15,21 +15,15 @@
<copyright>Copyright 2015</copyright>
<tags>MQTT Microsoft Azure IoT Native x86 native package</tags>
<dependencies>
<dependency id="Microsoft.Azure.IoTHub.IoTHubClient" version="1.0.0-preview-011"/>
<dependency id="Microsoft.Azure.IoTHub.IoTHubClient" version="1.0.0-preview-011"/>
<dependency id="Microsoft.Azure.C.SharedUtility" version="1.0.0-preview-003"/>
</dependencies>
</metadata>
<files>
<file src="Microsoft.Azure.IoTHub.MqttTransport_thirdpartynotice.txt" target="thirdpartynotice.txt"/>
<file src="Microsoft.Azure.IoTHub.MqttTransport_thirdpartynotice.txt" target="thirdpartynotice.txt"/>
<!-- these are files for x86 plaform -->
<file src="..\..\..\..\build_output\c\win32\debug\iothub_client_mqtt_transport.lib" target="build\native\Win32\Debug"/>
<file src="..\..\..\..\build_output\c\win32\debug\iothub_client_mqtt_transport.pdb" target="build\native\Win32\Debug"/>
<file src="paho_outputs\Win32\Debug\paho-mqtt3cs.lib" target="build\native\Win32\Debug"/>
<file src="paho_outputs\Win32\Debug\paho-mqtt3cs.dll" target="build\native\Win32\Debug"/>
<file src="paho_outputs\Win32\Debug\paho-mqtt3cs.pdb" target="build\native\Win32\Debug"/>
<file src="openssl_outputs\Win32\Debug\" target="build\native\Win32\Debug"/>
<file src="Microsoft.Azure.IoTHub.MqttTransport.targets" target="build\native"/>
<file src="..\..\..\iothub_client\inc\iothubtransportmqtt.h" target="build\native\include"/>
</files>

Просмотреть файл

@ -14,7 +14,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="Win32Debug" Condition="(( $(Configuration.ToLower().IndexOf('debug')) &gt; -1 ) And ('$(Platform)' == 'Win32' ) )">
<Link>
<AdditionalDependencies>$(MSBuildThisFileDirectory)../../build/native/Win32/Debug/paho-mqtt3cs.lib;$(MSBuildThisFileDirectory)../../build/native/Win32/Debug/iothub_client_mqtt_transport.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>$(MSBuildThisFileDirectory)../../build/native/Win32/Debug/iothub_client_mqtt_transport.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<UsingTask TaskName="Microsoft_Azure_Mqtt_Transport_Contains" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" TaskFactory="CodeTaskFactory">
@ -57,14 +57,7 @@
<Output TaskParameter="Result" PropertyName="CallingConvention-Microsoft_Azure_Mqtt_Transport" />
</Microsoft_Azure_Mqtt_Transport_Contains>
</Target>
<Target Name="Microsoft_Azure_Mqtt_Transport_redist_AfterBuild" AfterTargets="AfterBuild" />
<Target Name="Microsoft_Azure_Mqtt_Transport_redist_AfterBuild" AfterTargets="AfterBuild" />
<Target Name="Microsoft_Azure_Mqtt_Transport_redist_AfterBuild_Win32_and_Debug" Label="Win32 and Debug" Condition="'$(Platform.ToLower())' == 'win32' And ( $(Configuration.ToLower().IndexOf('debug')) &gt; -1 )" AfterTargets="Microsoft_Azure_Mqtt_Transport_redist_AfterBuild">
<Copy SourceFiles="$(MSBuildThisFileDirectory)../../build/native/Win32/Debug/paho-mqtt3cs.pdb" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(MSBuildThisFileDirectory)../../build/native/Win32/Debug/paho-mqtt3cs.dll" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(MSBuildThisFileDirectory)../../build/native/Win32/Debug/libeay32.dll" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(MSBuildThisFileDirectory)../../build/native/Win32/Debug/libeay32.pdb" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(MSBuildThisFileDirectory)../../build/native/Win32/Debug/ssleay32.dll" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(MSBuildThisFileDirectory)../../build/native/Win32/Debug/ssleay32.pdb" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" />
</Target>
</Target>
</Project>

Просмотреть файл

@ -6,369 +6,3 @@ The original copyright notice and license, under which Microsoft Corporation rec
are set out below. This Third Party Code is licensed to you under their original license terms set forth below.
Microsoft Corporation reserves all other rights not expressly granted, whether by implication, estoppel or otherwise.
1. Paho C v1.0.3, obtained from https://www.eclipse.org/paho/clients/c/
/*
Eclipse Public License - v 1.0
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
AGREEMENT.
1. DEFINITIONS
"Contribution" means:
a) in the case of the initial Contributor, the initial
code and documentation distributed under this Agreement, and
b) in the case of each subsequent Contributor:
i) changes to the Program, and
ii) additions to the Program;
where such changes and/or additions to the Program
originate from and are distributed by that particular Contributor. A
Contribution 'originates' from a Contributor if it was added to the
Program by such Contributor itself or anyone acting on such
Contributor's behalf. Contributions do not include additions to the
Program which: (i) are separate modules of software distributed in
conjunction with the Program under their own license agreement, and (ii)
are not derivative works of the Program.
"Contributor" means any person or entity that distributes
the Program.
"Licensed Patents" mean patent claims licensable by a
Contributor which are necessarily infringed by the use or sale of its
Contribution alone or when combined with the Program.
"Program" means the Contributions distributed in accordance
with this Agreement.
"Recipient" means anyone who receives the Program under
this Agreement, including all Contributors.
2. GRANT OF RIGHTS
a) Subject to the terms of this Agreement, each
Contributor hereby grants Recipient a non-exclusive, worldwide,
royalty-free copyright license to reproduce, prepare derivative works
of, publicly display, publicly perform, distribute and sublicense the
Contribution of such Contributor, if any, and such derivative works, in
source code and object code form.
b) Subject to the terms of this Agreement, each
Contributor hereby grants Recipient a non-exclusive, worldwide,
royalty-free patent license under Licensed Patents to make, use, sell,
offer to sell, import and otherwise transfer the Contribution of such
Contributor, if any, in source code and object code form. This patent
license shall apply to the combination of the Contribution and the
Program if, at the time the Contribution is added by the Contributor,
such addition of the Contribution causes such combination to be covered
by the Licensed Patents. The patent license shall not apply to any other
combinations which include the Contribution. No hardware per se is
licensed hereunder.
c) Recipient understands that although each Contributor
grants the licenses to its Contributions set forth herein, no assurances
are provided by any Contributor that the Program does not infringe the
patent or other intellectual property rights of any other entity. Each
Contributor disclaims any liability to Recipient for claims brought by
any other entity based on infringement of intellectual property rights
or otherwise. As a condition to exercising the rights and licenses
granted hereunder, each Recipient hereby assumes sole responsibility to
secure any other intellectual property rights needed, if any. For
example, if a third party patent license is required to allow Recipient
to distribute the Program, it is Recipient's responsibility to acquire
that license before distributing the Program.
d) Each Contributor represents that to its knowledge it
has sufficient copyright rights in its Contribution, if any, to grant
the copyright license set forth in this Agreement.
3. REQUIREMENTS
A Contributor may choose to distribute the Program in object code
form under its own license agreement, provided that:
a) it complies with the terms and conditions of this
Agreement; and
b) its license agreement:
i) effectively disclaims on behalf of all Contributors
all warranties and conditions, express and implied, including warranties
or conditions of title and non-infringement, and implied warranties or
conditions of merchantability and fitness for a particular purpose;
ii) effectively excludes on behalf of all Contributors
all liability for damages, including direct, indirect, special,
incidental and consequential damages, such as lost profits;
iii) states that any provisions which differ from this
Agreement are offered by that Contributor alone and not by any other
party; and
iv) states that source code for the Program is available
from such Contributor, and informs licensees how to obtain it in a
reasonable manner on or through a medium customarily used for software
exchange.
When the Program is made available in source code form:
a) it must be made available under this Agreement; and
b) a copy of this Agreement must be included with each
copy of the Program.
Contributors may not remove or alter any copyright notices contained
within the Program.
Each Contributor must identify itself as the originator of its
Contribution, if any, in a manner that reasonably allows subsequent
Recipients to identify the originator of the Contribution.
4. COMMERCIAL DISTRIBUTION
Commercial distributors of software may accept certain
responsibilities with respect to end users, business partners and the
like. While this license is intended to facilitate the commercial use of
the Program, the Contributor who includes the Program in a commercial
product offering should do so in a manner which does not create
potential liability for other Contributors. Therefore, if a Contributor
includes the Program in a commercial product offering, such Contributor
("Commercial Contributor") hereby agrees to defend and
indemnify every other Contributor ("Indemnified Contributor")
against any losses, damages and costs (collectively "Losses")
arising from claims, lawsuits and other legal actions brought by a third
party against the Indemnified Contributor to the extent caused by the
acts or omissions of such Commercial Contributor in connection with its
distribution of the Program in a commercial product offering. The
obligations in this section do not apply to any claims or Losses
relating to any actual or alleged intellectual property infringement. In
order to qualify, an Indemnified Contributor must: a) promptly notify
the Commercial Contributor in writing of such claim, and b) allow the
Commercial Contributor to control, and cooperate with the Commercial
Contributor in, the defense and any related settlement negotiations. The
Indemnified Contributor may participate in any such claim at its own
expense.
For example, a Contributor might include the Program in a commercial
product offering, Product X. That Contributor is then a Commercial
Contributor. If that Commercial Contributor then makes performance
claims, or offers warranties related to Product X, those performance
claims and warranties are such Commercial Contributor's responsibility
alone. Under this section, the Commercial Contributor would have to
defend claims against the other Contributors related to those
performance claims and warranties, and if a court requires any other
Contributor to pay any damages as a result, the Commercial Contributor
must pay those damages.
5. NO WARRANTY
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
responsible for determining the appropriateness of using and
distributing the Program and assumes all risks associated with its
exercise of rights under this Agreement , including but not limited to
the risks and costs of program errors, compliance with applicable laws,
damage to or loss of data, programs or equipment, and unavailability or
interruption of operations.
6. DISCLAIMER OF LIABILITY
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
7. GENERAL
If any provision of this Agreement is invalid or unenforceable under
applicable law, it shall not affect the validity or enforceability of
the remainder of the terms of this Agreement, and without further action
by the parties hereto, such provision shall be reformed to the minimum
extent necessary to make such provision valid and enforceable.
If Recipient institutes patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that the
Program itself (excluding combinations of the Program with other
software or hardware) infringes such Recipient's patent(s), then such
Recipient's rights granted under Section 2(b) shall terminate as of the
date such litigation is filed.
All Recipient's rights under this Agreement shall terminate if it
fails to comply with any of the material terms or conditions of this
Agreement and does not cure such failure in a reasonable period of time
after becoming aware of such noncompliance. If all Recipient's rights
under this Agreement terminate, Recipient agrees to cease use and
distribution of the Program as soon as reasonably practicable. However,
Recipient's obligations under this Agreement and any licenses granted by
Recipient relating to the Program shall continue and survive.
Everyone is permitted to copy and distribute copies of this
Agreement, but in order to avoid inconsistency the Agreement is
copyrighted and may only be modified in the following manner. The
Agreement Steward reserves the right to publish new versions (including
revisions) of this Agreement from time to time. No one other than the
Agreement Steward has the right to modify this Agreement. The Eclipse
Foundation is the initial Agreement Steward. The Eclipse Foundation may
assign the responsibility to serve as the Agreement Steward to a
suitable separate entity. Each new version of the Agreement will be
given a distinguishing version number. The Program (including
Contributions) may always be distributed subject to the version of the
Agreement under which it was received. In addition, after a new version
of the Agreement is published, Contributor may elect to distribute the
Program (including its Contributions) under the new version. Except as
expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
rights or licenses to the intellectual property of any Contributor under
this Agreement, whether expressly, by implication, estoppel or
otherwise. All rights in the Program not expressly granted under this
Agreement are reserved.
This Agreement is governed by the laws of the State of New York and
the intellectual property laws of the United States of America. No party
to this Agreement will bring a legal action under this Agreement more
than one year after the cause of action arose. Each party waives its
rights to a jury trial in any resulting litigation.
*/
2. OpenSSL, obtained from https://github.com/openssl/openssl.git
LICENSE ISSUES
==============
The OpenSSL toolkit stays under a dual license, i.e. both the conditions of
the OpenSSL License and the original SSLeay license apply to the toolkit.
See below for the actual license texts. Actually both licenses are BSD-style
Open Source licenses. In case of any license issues related to OpenSSL
please contact openssl-core@openssl.org.
OpenSSL License
---------------
/* ====================================================================
* Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
Original SSLeay License
-----------------------
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/

Просмотреть файл

@ -61,80 +61,8 @@ nuget pack Microsoft.Azure.IoTHub.HttpTransport.nuspec
nuget pack Microsoft.Azure.IoTHub.AmqpTransport.nuspec
nuget pack Microsoft.Azure.IoTHub.IoTHubClient.nuspec
rem because nuget cannot access absolute files given by environment variables
mkdir paho_outputs
cd paho_outputs
mkdir Win32
mkdir x64
mkdir include
cd Win32
mkdir Release
mkdir Debug
cd ..
cd x64
mkdir Release
mkdir Debug
cd ..
cd ..
rem -- Copy Win32 Paho Files.
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\Debug\paho-mqtt3cs.lib" paho_outputs\Win32\Debug
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\Debug\paho-mqtt3cs.pdb" paho_outputs\Win32\Debug
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\Debug\paho-mqtt3cs.dll" paho_outputs\Win32\Debug
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\Windows Build\build\output\paho-mqtt3cs.lib" paho_outputs\Win32\Release
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\Windows Build\build\output\paho-mqtt3cs.dll" paho_outputs\Win32\Release
rem -- Copy 64 bits Paho Files.
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\x64\Debug\paho-mqtt3cs.lib" paho_outputs\x64\Debug
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\x64\Debug\paho-mqtt3cs.pdb" paho_outputs\x64\Debug
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\x64\Debug\paho-mqtt3cs.dll" paho_outputs\x64\Debug
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\x64\Release\paho-mqtt3cs.lib" paho_outputs\x64\Release
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\x64\Release\paho-mqtt3cs.dll" paho_outputs\x64\Release
rem -- Copy Header Files
copy "%PAHO_PATH%\org.eclipse.paho.mqtt.c\src\*.h" paho_outputs\include
mkdir openssl_outputs
cd openssl_outputs
mkdir Win32
cd Win32
mkdir Debug
cd ..
mkdir x64
cd x64
mkdir Debug
cd ..
cd ..
copy "%OpenSSLDir%\out32dllForNuget\libeay32.dll" openssl_outputs\Win32\Debug
copy "%OpenSSLDir%\out32dllForNuget\libeay32.lib" openssl_outputs\Win32\Debug
copy "%OpenSSLDir%\out32dllForNuget\libeay32.exp" openssl_outputs\Win32\Debug
copy "%OpenSSLDir%\out32dllForNuget\libeay32.pdb" openssl_outputs\Win32\Debug
copy "%OpenSSLDir%\out32dllForNuget\ssleay32.dll" openssl_outputs\Win32\Debug
copy "%OpenSSLDir%\out32dllForNuget\ssleay32.lib" openssl_outputs\Win32\Debug
copy "%OpenSSLDir%\out32dllForNuget\ssleay32.exp" openssl_outputs\Win32\Debug
copy "%OpenSSLDir%\out32dllForNuget\ssleay32.pdb" openssl_outputs\Win32\Debug
copy "%OpenSSLDir%\out64dll\libeay32.dll" openssl_outputs\x64\Debug
copy "%OpenSSLDir%\out64dll\libeay32.lib" openssl_outputs\x64\Debug
copy "%OpenSSLDir%\out64dll\libeay32.exp" openssl_outputs\x64\Debug
copy "%OpenSSLDir%\out64dll\libeay32.pdb" openssl_outputs\x64\Debug
copy "%OpenSSLDir%\out64dll\ssleay32.dll" openssl_outputs\x64\Debug
copy "%OpenSSLDir%\out64dll\ssleay32.lib" openssl_outputs\x64\Debug
copy "%OpenSSLDir%\out64dll\ssleay32.exp" openssl_outputs\x64\Debug
copy "%OpenSSLDir%\out64dll\ssleay32.pdb" openssl_outputs\x64\Debug
nuget pack Eclipse.Paho-C.paho-mqtt3cs.nuspec
nuget pack Microsoft.Azure.IoTHub.MqttTransport.nuspec
rmdir paho_outputs /S /Q
rmdir openssl_outputs /S /Q
nuget pack Microsoft.Azure.IoTHub.Serializer.nuspec
rmdir %client-root%\build_output /S /Q

Просмотреть файл

@ -1,172 +0,0 @@
@setlocal EnableExtensions EnableDelayedExpansion
@echo off
if not defined PAHO_PATH goto :errorPAHOPATHnotDefined
if not defined OpenSSLDir goto :errorOPenSSLDirnotDefined
goto :continueWithInstallation
:errorPAHOPATHnotDefined
@Echo PAHO_PATH not defined. Please, Define PAHO_PATH on Environment Variables, restart command prompt and the script.
goto :eof
:errorOPenSSLDirnotDefined
@Echo OpenSSLDir not defined. Please, Define OpenSSLDir on Environment Variables and restart the script.
goto :eof
:continueWithInstallation
rem -----------------------------------------------------------------------------
rem -- use OpenSSLDir
rem -----------------------------------------------------------------------------
set openSSL-root=%OpenSSLDir%
set openSSL-repo=https://github.com/openssl/openssl.git
set openSSL-build-root=%openSSL-root%
set openSSL-branch=OpenSSL_1_0_1-stable
rem -----------------------------------------------------------------------------
rem -- use PAHO_PATH
rem -----------------------------------------------------------------------------
set paho-root=%PAHO_PATH%
set paho-repo=https://git.eclipse.org/r/paho/org.eclipse.paho.mqtt.c.git
rem -- Move this to master as soon as the x64 bit configuration is on master.
set paho-branch=develop
set package-root=%~dp0\..\packaging\windows
set paho-build-root=%paho-root%\org.eclipse.paho.mqtt.c
rem -----------------------------------------------------------------------------
rem -- Make sure they know this is a third party component
rem -----------------------------------------------------------------------------
echo OpenSSL will be located at %openSSL-root%
echo.
echo Paho will be located at %paho-root%
echo.
@Echo Azure IoT SDK has a dependency on OpenSSL and Paho MQTT
@Echo https://github.com/openssl/openssl/blob/OpenSSL_1_0_1-stable/LICENSE
@Echo http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.c.git/tree/notice.html
choice /C yn /M "Do you want to install these components?"
if not %errorlevel%==1 goto :eof
rem -----------------------------------------------------------------------------
rem -Check Perl Version
@Echo This is your version of Perl. We require version 5.20 or higher.
perl -v
perl -v | findstr /i "(v5\.2*" > nul
IF %ERRORLEVEL% EQU 1 goto :wrongPerlVersion
goto :continueInstallingOpenSSL
:wrongPerlVersion
@Echo Seems like you have a wrong Perl Version.
@Echo Check your perl installation and make sure you install version 5.20 or higher and restart the script.
@Echo If you have multiple perl versions, make sure you set a supported one first on the PATH environment variable.
goto :eof
rem -----------------------------------------------------------------------------
rem -----------------------------------------------------------------------------
rem -- sync the OpenSSL source code
rem -----------------------------------------------------------------------------
:continueInstallingOpenSSL
if Exist %openSSL-root% rmdir %openSSL-root% /s /q
git clone -b %openSSL-branch% %openSSL-repo% %openSSL-build-root%
if not %errorlevel%==0 exit /b %errorlevel%
rem -----------------------------------------------------------------------------
rem -- build OpenSSL 32 bits
rem -----------------------------------------------------------------------------
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
if not %errorlevel%==0 exit /b %errorlevel%
pushd %openSSL-build-root%
perl Configure VC-WIN32 no-asm --prefix=%openSSL-build-root%
if not %errorlevel%==0 exit /b %errorlevel%
call ms\do_ms.bat
if not %errorlevel%==0 exit /b %errorlevel%
call nmake -f ms\ntdll.mak
if not %errorlevel%==0 exit /b %errorlevel%
call nmake -f ms\ntdll.mak install
if not %errorlevel%==0 exit /b %errorlevel%
mkdir out32dllForNuget
xcopy /q /y /R .\out32dll\*.* .\out32dllForNuget\*.*
if %errorlevel% neq 0 exit /b %errorlevel%
rem -----------------------------------------------------------------------------
rem -- sync the paho source code
rem -----------------------------------------------------------------------------
if Exist %paho-root% rmdir %paho-root% /s /q
git clone -b %paho-branch% %paho-repo% %paho-build-root%
if not %errorlevel%==0 exit /b %errorlevel%
rem -----------------------------------------------------------------------------
rem -- build paho 32 bits.
rem -----------------------------------------------------------------------------
pushd %paho-build-root%
if exist "%programfiles(x86)%\MSBuild\14.0\\." (
msbuild ".\Windows Build\paho-mqtt3cs\paho-mqtt3cs.vcxproj" /p:Configuration=Debug;PlatformToolset=v140
msbuild ".\Windows Build\paho-mqtt3cs\paho-mqtt3cs.vcxproj" /p:Configuration=Release;PlatformToolset=v140
goto paho_build_done
)
if exist "%programfiles(x86)%\MSBuild\12.0\\." (
msbuild ".\Windows Build\paho-mqtt3cs\paho-mqtt3cs.vcxproj" /p:Configuration=Debug
msbuild ".\Windows Build\paho-mqtt3cs\paho-mqtt3cs.vcxproj" /p:Configuration=Release
goto paho_build_done
)
@Echo Paho MQTT needs Visual Studio 2013 or higher in order to build.
exit /b 1
:paho_build_done
if not %errorlevel%==0 exit /b %errorlevel%
rem -----------------------------------------------------------------------------
rem -- build OpenSSL 64 bits
rem -----------------------------------------------------------------------------
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
if not %errorlevel%==0 exit /b %errorlevel%
pushd %openSSL-build-root%
perl Configure VC-WIN64A
if not %errorlevel%==0 exit /b %errorlevel%
call ms\do_win64a
if not %errorlevel%==0 exit /b %errorlevel%
call nmake -f ms\ntdll.mak clean
if not %errorlevel%==0 exit /b %errorlevel%
call nmake -f ms\ntdll.mak
if not %errorlevel%==0 exit /b %errorlevel%
mkdir out64dll
xcopy /q /y /R .\out32dll\*.* .\out64dll\*.*
if %errorlevel% neq 0 exit /b %errorlevel%
rem -----------------------------------------------------------------------------
rem -- build paho 64 bits.
rem -----------------------------------------------------------------------------
pushd %paho-build-root%
if exist "%programfiles(x86)%\MSBuild\14.0\\." (
msbuild ".\Windows Build\paho-mqtt3cs\paho-mqtt3cs.vcxproj" /p:Configuration=Debug;PlatformToolset=v140;Platform=x64
msbuild ".\Windows Build\paho-mqtt3cs\paho-mqtt3cs.vcxproj" /p:Configuration=Release;PlatformToolset=v140;Platform=x64
goto paho_build_done
)
if exist "%programfiles(x86)%\MSBuild\12.0\\." (
msbuild ".\Windows Build\paho-mqtt3cs\paho-mqtt3cs.vcxproj" /p:Configuration=Debug;Platform=x64
msbuild ".\Windows Build\paho-mqtt3cs\paho-mqtt3cs.vcxproj" /p:Configuration=Release;Platform=x64
goto paho_build_done
)
@Echo Paho MQTT needs Visual Studio 2013 or higher in order to build.
exit /b 1
:paho_build_done
if not %errorlevel%==0 exit /b %errorlevel%

Просмотреть файл

@ -64,9 +64,9 @@ You do *not* need to build the libraries in order to run the sample applications
The following instructions outline how you can build the libraries in Windows:
1. Create the folders **C:\\Proton**, **C:\\OpenSSL**, and **C:\\Paho** on your development machine in which to download the dependencies.
1. Create the folders **C:\\Proton** and **C:\\OpenSSL** on your development machine in which to download the dependencies.
2. Create the environment variables **PROTON\_PATH=C:\\Proton**, **OpenSSLDir=C:\\OpenSSL**, and **PAHO\_PATH=C:\\Paho**..
2. Create the environment variables **PROTON\_PATH=C:\\Proton** and **OpenSSLDir=C:\\OpenSSL**..
3. Install [cmake](http://www.cmake.org/) (make sure it is installed in your path, type "cmake -version" to verify).
@ -80,9 +80,7 @@ The following instructions outline how you can build the libraries in Windows:
7. Run the script **build\_proton.cmd** in the **c\\build_all\\windows** directory to build the proton libraries.
8. Run the script **build\_paho.cmd** in the **c\\build_all\\windows** directory.
9. Run the script **build\_client.cmd** in the **c\\build_all\\windows** directory.
8. Run the script **build\_client.cmd** in the **c\\build_all\\windows** directory.
> Note: In order to test MQTT End2End you must also deploy an [Azure IoT Protocol Gateway](https://github.com/Azure/azure-iot-protocol-gateway/blob/master/README.md).

Просмотреть файл

@ -101,11 +101,7 @@ you obtained in the "Connecting your device to an IoT hub" step above.
```
sudo ./c/build_all/linux/build_proton.sh --install /usr
```
- Build a few libraries upon which the samples depend:
```
sudo ~/azure-iot-sdks/c/build_all/linux/build_paho.sh
```
- Finally, build the sample applications:
```

Просмотреть файл

@ -86,12 +86,6 @@ you obtained in the "Connecting your device to an IoT hub" step above.
sudo ./c/build_all/linux/build_proton.sh --install /usr
```
- Build a few libraries upon which the samples depend:
```
sudo ~/azure-iot-sdks/c/build_all/linux/build_paho.sh
```
- Finally, build the sample applications:
```

Просмотреть файл

@ -227,11 +227,7 @@ To run this tool, you need connection and configuration information for your IoT
sudo ~/azure-iot-sdks/c/build_all/linux/build_proton.sh --install /usr
- This SDK sample depends on the presences of a few libraries. Run the following command to build them:
sudo ~/azure-iot-sdks/c/build_all/linux/build_paho.sh
- You can now build the SDK code using the following command, assuming everything went OK on build\_proton.sh and build\_paho.sh
- You can now build the SDK code using the following command, assuming everything went OK on build\_proton.sh
~/azure-iot-sdks/c/build_all/linux/build.sh

Просмотреть файл

@ -75,13 +75,7 @@ Before you begin you will need to create and configure an IoT hub to connect to.
sudo ~/azure-iot-sdks/c/build_all/linux/build_proton.sh --install
```
- This SDK sample depends on the presences of a few libraries. Run the following command to build them:
```
sudo ~/azure-iot-sdks/c/build_all/linux/build_paho.sh
```
- You can now build the SDK code using the following command, assuming everything went OK on build\_proton.sh and build\_paho.sh
- You can now build the SDK code using the following command, assuming everything went OK on build\_proton.sh
```
~/azure-iot-sdks/c/build_all/linux/build.sh

Просмотреть файл

@ -57,7 +57,6 @@ if(${use_mqtt})
set(iothub_client_mqtt_transport_c_files
${iothub_client_ll_transport_c_files}
./src/iothubtransportmqtt.c
./adapters/mqttapi_paho.c
)
set(iothub_client_mqtt_transport_h_files
@ -88,15 +87,33 @@ include_directories(${SHARED_UTIL_INC_FOLDER})
if(${use_http})
include_directories(${IOTHUB_CLIENT_HTTP_TRANSPORT_INC_FOLDER})
add_library(iothub_client_http_transport
${iothub_client_http_transport_c_files}
${iothub_client_http_transport_h_files}
)
linkSharedUtil(iothub_client_http_transport)
endif()
if(${use_amqp})
include_directories(${IOTHUB_CLIENT_AMQP_TRANSPORT_INC_FOLDER} ${PROTON_C_INCLUDES})
includeProton()
add_definitions(-Dqpid_proton_EXPORTS)
add_library(iothub_client_amqp_transport
${iothub_client_amqp_transport_c_files}
${iothub_client_amqp_transport_h_files}
)
linkSharedUtil(iothub_client_amqp_transport)
endif()
if(${use_mqtt})
include_directories(${IOTHUB_CLIENT_MQTT_TRANSPORT_INC_FOLDER} $ENV{paho_path}/org.eclipse.paho.mqtt.c/src)
include_directories(${IOTHUB_CLIENT_MQTT_TRANSPORT_INC_FOLDER} ${MQTT_INC_FOLDER})
add_library(iothub_client_mqtt_transport
${iothub_client_mqtt_transport_c_files}
${iothub_client_mqtt_transport_h_files}
)
linkSharedUtil(iothub_client_mqtt_transport)
linkMqttLibrary(iothub_client_mqtt_transport)
endif()
include_directories(${IOTHUB_CLIENT_INC_FOLDER})
@ -107,34 +124,6 @@ IF(WIN32)
add_definitions(-DGB_MEASURE_MEMORY_FOR_THIS -DGB_DEBUG_ALLOC)
ENDIF(WIN32)
if(${use_amqp})
add_definitions(-Dqpid_proton_EXPORTS)
endif()
if(${use_http})
add_library(iothub_client_http_transport
${iothub_client_http_transport_c_files}
${iothub_client_http_transport_h_files}
)
linkSharedUtil(iothub_client_http_transport)
endif()
if(${use_amqp})
add_library(iothub_client_amqp_transport
${iothub_client_amqp_transport_c_files}
${iothub_client_amqp_transport_h_files}
)
linkSharedUtil(iothub_client_amqp_transport)
endif()
if(${use_mqtt})
add_library(iothub_client_mqtt_transport
${iothub_client_mqtt_transport_c_files}
${iothub_client_mqtt_transport_h_files}
)
linkSharedUtil(iothub_client_mqtt_transport)
endif()
add_library(iothub_client
${iothub_client_c_files}
${iothub_client_h_files}

Просмотреть файл

@ -1,945 +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 <stdlib.h>
#ifdef _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#include "gballoc.h"
#include "mqttapi.h"
#include "iot_logging.h"
#include "strings.h"
#include "doublylinkedlist.h"
#include "lock.h"
#include "crt_abstractions.h"
#include "sastoken.h"
#include "MQTTClient.h"
#define SUBSCRIBEQOS 0
#define SENDMESSAGEQOS 1
#define EPOCH_TIME_T_VALUE (time_t)0
#define SAS_TOKEN_DEFAULT_LIFETIME (3600)
#define SAS_TOKEN_DEFAULT_REFRESH_LINE (600)
DEFINE_ENUM_STRINGS(MQTTAPI_RESULT, MQTTAPI_RESULT_VALUES);
typedef struct MQTTAPI_TOPIC_HANDLE_DATA_TAG
{
STRING_HANDLE topicName;
MQTTAPI_HANDLE mqttApiInstance;
} MQTTAPI_TOPIC_HANDLE_DATA, *PMQTTAPI_TOPIC_HANDLE_DATA;
typedef struct MQTTAPI_MESSAGE_RECEIVED_LIST_TAG
{
MQTTAPI_Message* messageReceived;
DLIST_ENTRY entry;
}MQTTAPI_MESSAGE_RECEIVED_LIST;
typedef struct MQTTAPI_MESSAGE_SEND_LIST_TAG
{
STRING_HANDLE topicName;
void* context;
MQTTClient_message* messageToSend;
DLIST_ENTRY entry;
MQTTClient_deliveryToken dt;
}MQTTAPI_MESSAGE_SEND_LIST;
typedef struct MQTTTAPI_HANDLE_DATA_TAG
{
STRING_HANDLE device_id;
STRING_HANDLE device_key;
STRING_HANDLE sasTokenSr;
// Holds the expiry (seconds since the epoch) that was last used for the SAS put to the CBS
size_t lastExpiryUsed;
// This will hold the amount of time (in seconds) that a SAS Token will have for it's expiration.
size_t sasTokenLifetime;
// This will hold how many seconds before the expiration of a SAS token we will try to start renewing
// it.
size_t sasRefreshLine;
bool connected;
bool subscribed;
PMQTTAPI_TOPIC_HANDLE_DATA subscribedTopicHandleData;
MQTTAPI_DeliveryComplete* dcCallback;
MQTTAPI_MessageArrived* maCallBack;
void* maCallbackContext;
MQTTClient client; //Saved instance
DLIST_ENTRY messagesReceived;
DLIST_ENTRY messagesToSend;
DLIST_ENTRY messagesSent;
LOCK_HANDLE LockHandle;
} MQTTTAPI_HANDLE_DATA, *PMQTTTAPI_HANDLE_DATA;
static bool connectToMQTTServer(MQTTClient client, const char* username, const char* password)
{
bool result;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
int rc;
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
conn_opts.MQTTVersion = 4;
conn_opts.username = username;
conn_opts.password = password;
conn_opts.ssl = &sslopts;
sslopts.enableServerCertAuth = 0;
/* Codes_SRS_MQTTAPI_04_024: [MQTTAPI_Create shall call underlying library connection functions to establish connection with the server.] */
if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
{
LogError("Failed to connect, MQTTClient_connect returned: %d\r\n", rc);
result = false;
}
else
{
result = true;
}
return result;
}
static bool checkAndTryToConnect(PMQTTTAPI_HANDLE_DATA mqttApiState)
{
bool result;
if (mqttApiState != NULL)
{
if (!mqttApiState->connected)
{
/* Codes_SRS_MQTTAPI_04_062: [MQTTAPI_create shall generate SAS Token with an expiring time of 1 hour.] */
size_t secondsSinceEpoch = (size_t)(difftime(get_time(NULL), EPOCH_TIME_T_VALUE) + 0);
size_t possibleNewExpiry = secondsSinceEpoch + mqttApiState->sasTokenLifetime;
STRING_HANDLE zeroLengthString;
if ((zeroLengthString = STRING_new()) == NULL)
{
LogError("Could not generate zeroLenghtString for skn. \r\n");
result = false;
}
else
{
STRING_HANDLE newSASToken = SASToken_Create(mqttApiState->device_key, mqttApiState->sasTokenSr, zeroLengthString, possibleNewExpiry);
if (newSASToken == NULL)
{
LogError("Could not generate a SAS Token\r\n");
result = false;
}
else
{
/* Codes_SRS_MQTTAPI_04_024: [MQTTAPI_Create shall call underlying library connection functions to establish connection with the server.] */
if (!connectToMQTTServer(mqttApiState->client, STRING_c_str(mqttApiState->device_id), STRING_c_str(newSASToken)))
{
/* Tests_SRS_MQTTAPI_04_025: [If connection fails MQTTAPI_Create shall return NULL. */
result = false;
}
else
{
mqttApiState->connected = true;
mqttApiState->lastExpiryUsed = possibleNewExpiry;
result = true;
}
STRING_delete(newSASToken);
}
STRING_delete(zeroLengthString);
}
}
else
{
//Here is the point that we need to check if we need to disconnect, generate a new SAS Token and Connect Again.
size_t secondsSinceEpoch;
int differenceWithLastExpiry;
secondsSinceEpoch = (size_t)(difftime(get_time(NULL), EPOCH_TIME_T_VALUE) + 0);
differenceWithLastExpiry = mqttApiState->lastExpiryUsed - secondsSinceEpoch;
/* Codes_SRS_MQTTAPI_04_063: [DoWork shall check the SAS Token Expiration time for the current connection. If the token is near to expire and there is no pending item, it shall disconnect, generate a new SAS Token with 1 hour expiration and connect again.] */
if ((differenceWithLastExpiry <= 0) ||
(((size_t)differenceWithLastExpiry) < mqttApiState->sasRefreshLine && DList_IsListEmpty(&(mqttApiState->messagesSent))
)
) // Within refresh minutes (or past if negative) of the expiration
{
/* First Disconnect */
/* Codes_SRS_MQTTAPI_04_064: [If the token is expired we shall disconnect, signal that all pending message are failed due to Token Expired.] */
if (MQTTClient_disconnect(mqttApiState->client, 0) != MQTTCLIENT_SUCCESS)
{
LogError("Token is Expired or about to be expired and Disconnect Failed. \r\n");
}
else
{
size_t possibleNewExpiry = secondsSinceEpoch + mqttApiState->sasTokenLifetime;
STRING_HANDLE zeroLengthString;
if ((zeroLengthString = STRING_new()) == NULL)
{
LogError("Could not generate zeroLenghtString for skn. \r\n");
result = false;
}
else
{
STRING_HANDLE newSASToken = SASToken_Create(mqttApiState->device_key, mqttApiState->sasTokenSr, zeroLengthString, possibleNewExpiry);
mqttApiState->connected = false;
if (newSASToken == NULL)
{
LogError("Could not generate a SAS Token\r\n");
result = false;
}
else
{
/* Codes_SRS_MQTTAPI_04_024: [MQTTAPI_Create shall call underlying library connection functions to establish connection with the server.] */
if (!connectToMQTTServer(mqttApiState->client, STRING_c_str(mqttApiState->device_id), STRING_c_str(newSASToken)))
{
/* Tests_SRS_MQTTAPI_04_025: [If connection fails MQTTAPI_Create shall return NULL. */
result = false;
}
else
{
mqttApiState->connected = true;
mqttApiState->lastExpiryUsed = possibleNewExpiry;
if (mqttApiState->subscribed)
{
int rc;
LogInfo("Trying to Subscribe after reconnect.\r\n");
if ((rc = MQTTClient_subscribe(mqttApiState->client, STRING_c_str(mqttApiState->subscribedTopicHandleData->topicName), SUBSCRIBEQOS)) != MQTTCLIENT_SUCCESS)
{
LogError("Could not subscribe again. Won't be able to receive messages. Error Code: %d.\r\n", rc);
}
else
{
LogInfo("Subscribed succesfully after reconnect..\r\n");
}
}
result = true;
}
STRING_delete(newSASToken);
}
STRING_delete(zeroLengthString);
}
}
}
result = true;
}
}
else
{
LogError("Invalid Arg. Handle is NULL. \r\n");
result = false;
}
return result;
}
static void connectionLost(void *context, char *cause)
{
PMQTTTAPI_HANDLE_DATA transportState = (PMQTTTAPI_HANDLE_DATA)context;
LogError("Lost Connection, reseting Connection State. Cause: %s \r\n", cause);
if (transportState != NULL)
{
transportState->connected = false;
}
LogInfo("Trying to connect again\r\n");
if (!checkAndTryToConnect(transportState))
{
LogError("Could not connect again. \r\n");
}
else
{
LogInfo("Connected.\r\n");
if (transportState->subscribed)
{
int rc;
LogInfo("Trying to Subscribe after reconnect.\r\n");
if ((rc = MQTTClient_subscribe(transportState->client, STRING_c_str(transportState->subscribedTopicHandleData->topicName), SUBSCRIBEQOS)) != MQTTCLIENT_SUCCESS)
{
LogError("Could not subscribe again. Won't be able to receive messages. Error Code: %d.\r\n", rc);
}
else
{
LogInfo("Subscribed succesfully after reconnect..\r\n");
}
}
}
if (cause != NULL)
{
MQTTClient_free(cause);
}
}
static void delivered(void *context, MQTTClient_deliveryToken dt)
{
PMQTTTAPI_HANDLE_DATA transportState = (PMQTTTAPI_HANDLE_DATA)context;
if (context != NULL)
{
//First try to find the message on the list.
PDLIST_ENTRY currentListEntry;
currentListEntry = transportState->messagesSent.Flink;
if (currentListEntry != NULL)
{
while (currentListEntry != &transportState->messagesSent)
{
MQTTAPI_MESSAGE_SEND_LIST *mqttMessageDetailEntry = containingRecord(currentListEntry, MQTTAPI_MESSAGE_SEND_LIST, entry);
//Identify here if the message is the one arrived.
if (mqttMessageDetailEntry->dt == dt)
{
(void)DList_RemoveEntryList(currentListEntry); //First remove the item from Waiting for Ack List.
if (transportState->dcCallback != NULL)
{
/* Codes_SRS_MQTTAPI_04_009: [The context parameter is a point to the original value passed by MQTTAPI_PublishMessage, which contains message-specific context.] */
/* Codes_SRS_MQTTAPI_04_052: [result contains the status of the message sent by publish.] */
transportState->dcCallback(mqttMessageDetailEntry->context, MQTTAPI_CONFIRMATION_OK);
}
STRING_delete(mqttMessageDetailEntry->topicName);
MQTTClient_freeMessage(&(mqttMessageDetailEntry->messageToSend));
free(mqttMessageDetailEntry);
break;
}
currentListEntry = currentListEntry->Flink;
}
}
else
{
LogError("Error trying to access items on messagesSEnt list. Possible not initialized List.\r\n");
}
}
}
/* Codes_SRS_MQTTAPI_04_006: [The MQTTAPI_Message parameter contains the structure for the received message, with message payload.] */
static int msgarrvd(void *context, char *topicName, int topicLen, MQTTClient_message *message)
{
MQTTAPI_MESSAGE_RECEIVED_LIST* mqttAPIMessgeEntryList;
int result;
PMQTTTAPI_HANDLE_DATA mqttApiHandleData = (PMQTTTAPI_HANDLE_DATA)context;
(void)(topicLen, topicName);
if (mqttApiHandleData == NULL)
{
LogError("Context parameter cannot be null. Ignoring message \r\n");
result = 1;
}
else if (mqttApiHandleData->maCallBack == NULL)
{
/* Codes_SRS_MQTTAPI_04_061: [If maCallBack is not set, MQTTAPI_MessageArrived shall return 0 to ignore received messages.] */
result = 1;
}
else if (message == NULL)
{
LogError("message parameter cannot be null. Returning error, so it can be sent again.\r\n");
result = 0;
}
else if ((mqttAPIMessgeEntryList = (MQTTAPI_MESSAGE_RECEIVED_LIST*)malloc(sizeof(MQTTAPI_MESSAGE_RECEIVED_LIST))) == NULL)
{
LogError("Memory Allocation Failure for MQTTAPI_Message entry list.\r\n");
result = 0;
}
else if ((mqttAPIMessgeEntryList->messageReceived = (MQTTAPI_Message*)malloc(sizeof(MQTTAPI_Message))) == NULL)
{
LogError("Memory Allocation Failure for MQTTAPI_Message.\r\n");
free(mqttAPIMessgeEntryList);
result = 0;
}
else
{
mqttAPIMessgeEntryList->messageReceived->payloadlen = message->payloadlen;
if ((mqttAPIMessgeEntryList->messageReceived->payload = (unsigned char*)malloc(mqttAPIMessgeEntryList->messageReceived->payloadlen)) == NULL)
{
LogError("Memory allocation error.\r\n");
free(mqttAPIMessgeEntryList->messageReceived);
free(mqttAPIMessgeEntryList);
result = 0;
}
else
{
(void)memcpy(mqttAPIMessgeEntryList->messageReceived->payload, message->payload, message->payloadlen);
if (Lock(mqttApiHandleData->LockHandle) == LOCK_OK)
{
DList_InsertHeadList(&(mqttApiHandleData->messagesReceived), &(mqttAPIMessgeEntryList->entry));
Unlock(mqttApiHandleData->LockHandle);
result = 1;
}
else
{
LogError("Problem Aquiring Lock to add message received on the list.\r\n");
free(mqttAPIMessgeEntryList->messageReceived->payload);
free(mqttAPIMessgeEntryList->messageReceived);
free(mqttAPIMessgeEntryList);
result = 0;
}
}
}
//We just free the MQTTClient Message if it was succesfully received, otherwise MQTTClient will call this with a corrupted message.
if (message != NULL && result == 1)
{
MQTTClient_freeMessage(&message);
}
return result;
}
MQTTAPI_HANDLE MQTTAPI_Create(const MQTTAPI_ConnectOptions* options)
{
PMQTTTAPI_HANDLE_DATA result;
/* Codes_SRS_MQTTAPI_04_011: [If any member of the parameter options is NULL or empty then MQTTAPI_Create shall return NULL.] */
if (options == NULL)
{
LogError("Invalid Argument. options cannot be NULL.\r\n")
result = NULL;
}
else if (options->deviceId == NULL || strlen(options->deviceId) <= 0)
{
LogError("Invalid Argument. Device Id cannot be NULL or Empty.\r\n")
result = NULL;
}
else if (options->deviceKey == NULL || strlen(options->deviceKey) <= 0)
{
LogError("Invalid Argument. Device Key cannot be NULL or Empty.\r\n")
result = NULL;
}
else if (options->serverURI == NULL || strlen(options->serverURI) <= 0)
{
LogError("Invalid Argument. Device Key cannot be NULL or Empty.\r\n")
result = NULL;
}
else if (options->sasTokenSr == NULL || strlen(options->sasTokenSr) <= 0)
{
LogError("Invalid Argument. sasTokenSr cannot be NULL or Empty.\r\n")
result = NULL;
}
/* Tests_SRS_MQTTAPI_04_014: [Otherwise, MQTTAPI_Create shall return a MQTTAPI_HANDLE suitable for further calls to the module.] */
else
{
result = (PMQTTTAPI_HANDLE_DATA)malloc(sizeof(MQTTTAPI_HANDLE_DATA));
if (result != NULL)
{
result->connected = false;
result->subscribed = false;
result->dcCallback = NULL;
result->maCallBack = NULL;
result->maCallbackContext = NULL;
result->subscribedTopicHandleData = NULL;
result->sasTokenLifetime = SAS_TOKEN_DEFAULT_LIFETIME;
result->sasRefreshLine = SAS_TOKEN_DEFAULT_REFRESH_LINE;
DList_InitializeListHead(&(result->messagesReceived));
DList_InitializeListHead(&(result->messagesToSend));
DList_InitializeListHead(&(result->messagesSent));
if ((result->LockHandle = Lock_Init()) == NULL)
{
LogError("Lock_Init failed\r\n");
free(result);
result = NULL;
}
/* Codes_SRS_MQTTAPI_04_012: [Parameters deviceId, deviceKey and sasTokenSr shall be saved.] */
else if ((result->device_id = STRING_construct(options->deviceId)) == NULL)
{
/* Codes_SRS_MQTTAPI_04_013: [If saving these parameters fail for any reason MQTTAPI_Create shall return NULL.] */
LogError("Could not create deviceId String.\r\n");
Lock_Deinit(result->LockHandle);
free(result);
result = NULL;
}
/* Codes_SRS_MQTTAPI_04_012: [Parameters deviceId, deviceKey and sasTokenSr shall be saved.] */
else if ((result->device_key = STRING_construct(options->deviceKey)) == NULL)
{
/* Codes_SRS_MQTTAPI_04_013: [If saving these parameters fail for any reason MQTTAPI_Create shall return NULL.] */
LogError("Could not create deviceId String.\r\n");
STRING_delete(result->device_id);
Lock_Deinit(result->LockHandle);
free(result);
result = NULL;
}
/* Codes_SRS_MQTTAPI_04_012: [Parameters deviceId, deviceKey and sasTokenSr shall be saved.] */
else if ((result->sasTokenSr = STRING_construct(options->sasTokenSr)) == NULL)
{
LogError("Could not create sasTokenSr String.\r\n");
STRING_delete(result->device_key);
STRING_delete(result->device_id);
Lock_Deinit(result->LockHandle);
free(result);
result = NULL;
}
else if (MQTTClient_create(&result->client, options->serverURI, STRING_c_str(result->device_id),
MQTTCLIENT_PERSISTENCE_NONE, NULL) != MQTTCLIENT_SUCCESS)
{
LogError("Could not create MQTT Client.\r\n");
STRING_delete(result->sasTokenSr);
STRING_delete(result->device_key);
STRING_delete(result->device_id);
Lock_Deinit(result->LockHandle);
free(result);
result = NULL;
}
/* Codes_SRS_MQTTAPI_04_004: [This function is registered when the user makes a call to MQTTAPI_SetCallbacks.] */
/* Codes_SRS_MQTTAPI_04_005: [The context parameter is a pointer to the original value passed by MQTTAPI_SetCallbacks, which contains application-specific context.] */
/* Codes_SRS_MQTTAPI_04_008: [This function is registered when the user makes a call to MQTTAPI_SetCallbacks.] */
else if (MQTTClient_setCallbacks(result->client, result, connectionLost, msgarrvd, delivered) != MQTTCLIENT_SUCCESS)
{
LogError("Could not set callbacks.\r\n");
STRING_delete(result->sasTokenSr);
STRING_delete(result->device_key);
STRING_delete(result->device_id);
MQTTClient_destroy(&result->client);
Lock_Deinit(result->LockHandle);
free(result);
result = NULL;
}
/* Codes_SRS_MQTTAPI_04_024: [MQTTAPI_Create shall call underlying library connection functions to establish connection with the server.] */
/* Codes_SRS_MQTTAPI_04_047: [Otherwise MQTTAPI_Create shall return a non-NULL MQTTAPI_HANDLE] */
else if (!checkAndTryToConnect(result))
{
/* Codes_SRS_MQTTAPI_04_025: [If connection fails MQTTAPI_Create shall return NULL. */
LogError("Could not Connect to MQTT Server.\r\n");
STRING_delete(result->sasTokenSr);
STRING_delete(result->device_key);
STRING_delete(result->device_id);
MQTTClient_destroy(&result->client);
Lock_Deinit(result->LockHandle);
free(result);
result = NULL;
}
}
else
{
/* Codes_SRS_MQTTAPI_04_015: [If creating instance fails for any reason, then MQTTAPI_Create shall return NULL.] */
LogError("Could not create MQTT API handle data. Memory allocation failed.\r\n");
result = NULL;
}
}
return (MQTTAPI_HANDLE)result;
}
MQTTAPI_RESULT MQTTAPI_SetMessageCallback(MQTTAPI_HANDLE instance, void* context, MQTTAPI_MessageArrived* ma)
{
MQTTAPI_RESULT result;
/* Codes_SRS_MQTTAPI_04_016: [If instance parameter is NULL, setMessageCallback shall return MQTTAPI_INVALID_ARG.] */
if (instance == NULL)
{
LogError("Invalid Argument. instance cannot be NULL.\r\n")
result = MQTTAPI_INVALID_ARG;
}
else
{
PMQTTTAPI_HANDLE_DATA mqttapi_handle_data = (PMQTTTAPI_HANDLE_DATA)instance;
/* Codes_SRS_MQTTAPI_04_020: [If while saving the callbacks fails setMessageCallback shall return MQTTAPI_ERROR, otherwise it shall return MQTTAPI_OK] */
/* Codes_SRS_MQTTAPI_04_019: [If any of the callback pointers are different than NULL it will be saved.] */
/* Codes_SRS_MQTTAPI_04_018: [If parameter context is not NULL, it will be saved and passed to the user when any of the callback is trigerred.] */
if (ma != NULL)
{
mqttapi_handle_data->maCallBack = ma;
mqttapi_handle_data->maCallbackContext = context;
result = MQTTAPI_OK;
}
else
{
LogError("Could not set because dc parameter cannot be NULL. \r\n");
result = MQTTAPI_ERROR;
}
}
return result;
}
MQTTAPI_RESULT MQTTAPI_SetDeliveryCompletedCallback(MQTTAPI_HANDLE instance, MQTTAPI_DeliveryComplete* dc)
{
MQTTAPI_RESULT result;
/* Codes_SRS_MQTTAPI_04_054: [If instance parameter is NULL, MQTTAPI_SetDeliveryCompletedCallback shall return MQTTAPI_INVALID_ARG.] */
if (instance == NULL)
{
LogError("Invalid Argument. instance cannot be NULL.\r\n")
result = MQTTAPI_INVALID_ARG;
}
else
{
PMQTTTAPI_HANDLE_DATA mqttapi_handle_data = (PMQTTTAPI_HANDLE_DATA)instance;
/* Codes_SRS_MQTTAPI_04_056: [If while saving the callbacks fails MQTTAPI_SetDeliveryCompletedCallback shall return MQTTAPI_ERROR] */
if (dc != NULL)
{
mqttapi_handle_data->dcCallback = dc;
result = MQTTAPI_OK;
}
else
{
/* Codes_SRS_MQTTAPI_04_057: [otherwise it shall return MQTTAPI_OK] */
LogError("Could not set because dc parameter cannot be NULL. \r\n");
result = MQTTAPI_ERROR;
}
}
return result;
}
void MQTTAPI_Destroy(MQTTAPI_HANDLE instance)
{
PMQTTTAPI_HANDLE_DATA mqttHandleData = (PMQTTTAPI_HANDLE_DATA)instance;
/* Codes_SRS_MQTTAPI_04_021: [If parameter instance is NULL then MQTTAPI_Destroy shall take no action.] */
if (mqttHandleData != NULL)
{
/* Codes_SRS_MQTTAPI_04_022: [MQTTAPI_Destroy shall free all resources used by MQTTAPI_HANDLE.] */
STRING_delete(mqttHandleData->device_id);
STRING_delete(mqttHandleData->device_key);
STRING_delete(mqttHandleData->sasTokenSr);
/* Codes_SRS_MQTTAPI_04_049: [If the instance is connected, MQTTAPI_Destroy shall disconnect the instance] */
if (mqttHandleData->subscribed)
{
MQTTAPI_Unsubscribe(mqttHandleData->subscribedTopicHandleData);
}
if (mqttHandleData->connected)
{
MQTTClient_disconnect(mqttHandleData->client, 0);
}
/* Codes_SRS_MQTTAPI_04_053: [If there are messages to be sent MQTTAPI_Destroy shall signal the user that the message couldnt be sent by reason of MQTTAPI_CONFIRMATION_BECAUSE_DESTROY] */
{
PDLIST_ENTRY received;
while ((received = DList_RemoveHeadList(&(mqttHandleData->messagesReceived))) != &(mqttHandleData->messagesReceived))
{
MQTTAPI_MESSAGE_RECEIVED_LIST* temp = containingRecord(received, MQTTAPI_MESSAGE_RECEIVED_LIST, entry);
if (mqttHandleData->maCallBack != NULL)
{
if (!mqttHandleData->maCallBack(mqttHandleData->maCallbackContext, temp->messageReceived))
{
LogError("Client could not handle message, dropping it.");
}
}
free(temp->messageReceived->payload);
free(temp->messageReceived);
free(temp);
}
}
{
PDLIST_ENTRY messageToSend;
while ((messageToSend = DList_RemoveHeadList(&(mqttHandleData->messagesToSend))) != &(mqttHandleData->messagesToSend))
{
MQTTAPI_MESSAGE_SEND_LIST* temp = containingRecord(messageToSend, MQTTAPI_MESSAGE_SEND_LIST, entry);
if (mqttHandleData->dcCallback != NULL)
{
mqttHandleData->dcCallback(temp->context, MQTTAPI_CONFIRMATION_BECAUSE_DESTROY);
MQTTClient_freeMessage(&(temp->messageToSend));
free(temp->messageToSend);
STRING_delete(temp->topicName);
free(temp);
}
}
}
{
PDLIST_ENTRY currentListEntry;
while ((currentListEntry = DList_RemoveHeadList(&(mqttHandleData->messagesSent))) != &(mqttHandleData->messagesSent))
{
MQTTAPI_MESSAGE_SEND_LIST* temp = containingRecord(currentListEntry, MQTTAPI_MESSAGE_SEND_LIST, entry);
if (mqttHandleData->dcCallback != NULL)
{
mqttHandleData->dcCallback(temp->context, MQTTAPI_CONFIRMATION_BECAUSE_DESTROY);
MQTTClient_freeMessage(&(temp->messageToSend));
free(temp->messageToSend);
STRING_delete(temp->topicName);
free(temp);
}
}
}
MQTTClient_destroy(&mqttHandleData->client);
Lock_Deinit(mqttHandleData->LockHandle);
free(mqttHandleData);
}
}
MQTTAPI_RESULT MQTTAPI_PublishMessage(MQTTAPI_HANDLE instance, const char* topicName, const MQTTAPI_Message* msg, void* context)
{
MQTTAPI_RESULT result;
PMQTTTAPI_HANDLE_DATA mqttApiHandleData = (PMQTTTAPI_HANDLE_DATA)instance;
/* Codes_SRS_MQTTAPI_04_038: [If any of the parameter is NULL, MQTTAPI_PublishMessage shall return MQTTAPI_INVALID_ARG.] */
if (instance == NULL)
{
LogError("Invalid Argument. instance can't be null.\r\n");
result = MQTTAPI_INVALID_ARG;
}
/* Codes_SRS_MQTTAPI_04_038: [If any of the parameter is NULL, MQTTAPI_PublishMessage shall return MQTTAPI_INVALID_ARG.] */
else if (topicName == NULL || strlen(topicName) <= 0)
{
LogError("Invalid Argument. topicName can't be null or empty.\r\n");
result = MQTTAPI_INVALID_ARG;
}
/* Codes_SRS_MQTTAPI_04_038: [If any of the parameter is NULL, MQTTAPI_PublishMessage shall return MQTTAPI_INVALID_ARG.] */
else if (msg == NULL)
{
LogError("Invalid Argument. msg can't be null.\r\n");
result = MQTTAPI_INVALID_ARG;
}
/* Codes_SRS_MQTTAPI_04_059: [If DeliveryCompleted callback is not set publishMessage shall return MQTTAPI_ERROR.] */
else if (mqttApiHandleData->dcCallback == NULL)
{
LogError("Error Sending data, missind Delivery Completed callback to be set.\r\n");
result = MQTTAPI_ERROR;
}
else
{
MQTTAPI_MESSAGE_SEND_LIST* mqttApiMessageEntryList;
/* Codes_SRS_MQTTAPI_04_039: [MQTTAPI_PublishMessage shall create structure needed to send a message to the topic described by the topicName parameter.] */
if ((mqttApiMessageEntryList = (MQTTAPI_MESSAGE_SEND_LIST*)malloc(sizeof(MQTTAPI_MESSAGE_SEND_LIST))) == NULL)
{
LogError("Memmory Allocation failure to create mqttApi Message.\r\n");
result = MQTTAPI_ERROR;
}
else if ((mqttApiMessageEntryList->topicName = STRING_construct(topicName)) == NULL)
{
LogError("Could not create topicName String.\r\n");
free(mqttApiMessageEntryList);
result = MQTTAPI_ERROR;
}
else
{
MQTTClient_message *pubmsg = (MQTTClient_message *)malloc(sizeof(MQTTClient_message));
if (pubmsg == NULL)
{
LogError("Memory Allocation Failure to create MQTTClient_message.\r\n");
STRING_delete(mqttApiMessageEntryList->topicName);
free(mqttApiMessageEntryList);
result = MQTTAPI_ERROR;
}
else
{
pubmsg->struct_id[0] = 'M';
pubmsg->struct_id[1] = 'Q';
pubmsg->struct_id[2] = 'T';
pubmsg->struct_id[3] = 'M';
pubmsg->struct_version = 0;
pubmsg->qos = SENDMESSAGEQOS;
pubmsg->retained = 0;
pubmsg->dup = 0;
pubmsg->msgid = 0;
pubmsg->payloadlen = msg->payloadlen;
/* Codes_SRS_MQTTAPI_04_043: [MQTTAPI_PublishMessage shall clone MQTTAPI_Message so the user can free it after calling publishMessage.] */
if ((pubmsg->payload = malloc(msg->payloadlen)) == NULL)
{
LogError("Memory Allocation Failure to create MQTTClient_message.\r\n");
free(pubmsg);
STRING_delete(mqttApiMessageEntryList->topicName);
free(mqttApiMessageEntryList);
result = MQTTAPI_ERROR;
}
else
{
(void)memcpy(pubmsg->payload, msg->payload, msg->payloadlen);
/* Codes_SRS_MQTTAPI_04_058: [If context is not NULL it shall be stored and passed to the user when received callback function is called.] */
mqttApiMessageEntryList->context = context;
mqttApiMessageEntryList->messageToSend = pubmsg;
DList_InsertHeadList(&(mqttApiHandleData->messagesToSend), &(mqttApiMessageEntryList->entry));
/* Codes_SRS_MQTTAPI_04_048: [If the message was correctly queued (on its on a queue on underlying library) MQTTAPI_PublishMessage shall return MQTTAPI_OK.] */
result = MQTTAPI_OK;
}
}
}
}
return result;
}
MQTTAPI_TOPIC_HANDLE MQTTAPI_Subscribe(MQTTAPI_HANDLE instance, const char* topic)
{
PMQTTTAPI_HANDLE_DATA handle = instance;
PMQTTAPI_TOPIC_HANDLE_DATA result;
/* Codes_SRS_MQTTAPI_04_029: [If any of the parameters instance or topic is NULL MQTTAPI_Subscribe shall return NULL.] */
if (instance == NULL || topic == NULL || strlen(topic) == 0)
{
result = NULL;
}
else
{
if ((result = (PMQTTAPI_TOPIC_HANDLE_DATA)malloc(sizeof(MQTTAPI_TOPIC_HANDLE_DATA))) == NULL)
{
LogError("Memory Allocation failure to store Topic Handle Data.\r\n");
handle->subscribed = false;
}
else if (checkAndTryToConnect(handle))
{
int rc;
/* Codes_SRS_MQTTAPI_04_031: [MQTTAPI_Subscribe shall call underlying library methods to subscribe to the topic on the topic parameter.] */
if ((rc = MQTTClient_subscribe(handle->client, topic, SUBSCRIBEQOS)) != MQTTCLIENT_SUCCESS)
{
/* Codes_SRS_MQTTAPI_04_032: [If the underlying library fails MQTTAPI_Subscribe shall return NULL] */
LogError("Error subscribing to topic. Code is:%d \r\n", rc);
free(result);
result = NULL;
handle->subscribed = false;
}
else
{
/* Codes_SRS_MQTTAPI_04_033: [Otherwise MQTTAPI_Subscribe shall return a non-NULL MQTTAPI_TOPIC_HANDLE] */
result->mqttApiInstance = handle;
if ((result->topicName = STRING_construct(topic)) == NULL)
{
LogError("Problem to save topic name.\r\n");
free(result);
result = NULL;
handle->subscribed = false;
}
else
{
handle->subscribedTopicHandleData = result;
handle->subscribed = true;
}
}
}
else
{
LogError("MQTT Client Not Connected. Error trying to reconect.\r\n");
free(result);
result = NULL;
}
}
return result;
}
void MQTTAPI_Unsubscribe(MQTTAPI_TOPIC_HANDLE topicInstance)
{
/* Codes_SRS_MQTTAPI_04_034: [If topicInstance is NULL MQTTAPI_Unsubscribe shall do nothing.] */
if (topicInstance != NULL)
{
PMQTTAPI_TOPIC_HANDLE_DATA topicHandleData = topicInstance;
PMQTTTAPI_HANDLE_DATA mqttApiInstance = topicHandleData->mqttApiInstance;
/* Codes_SRS_MQTTAPI_04_035: [MQTTAPI_Unsubscribe shall call underlying library methods to unsubscribe to the topic Instance.] */
if (MQTTClient_unsubscribe(mqttApiInstance->client, STRING_c_str(topicHandleData->topicName)) != MQTTCLIENT_SUCCESS)
{
LogError("Problems on Unsubscribing to Commands.\r\n");
}
else
{
mqttApiInstance->subscribed = false;
/* Codes_SRS_MQTTAPI_04_060: [MQTTAPI_Unsubscribe shall release all previously allocated resources pointed by topicInstance.] */
STRING_delete(mqttApiInstance->subscribedTopicHandleData->topicName);
free(mqttApiInstance->subscribedTopicHandleData);
}
}
}
void MQTTAPI_DoWork(MQTTAPI_HANDLE instance)
{
PMQTTTAPI_HANDLE_DATA handle = instance;
/* Codes_SRS_MQTTAPI_04_050: [if parameter instance is NULL then MQTTAPI_DoWork shall not perform any action.] */
if (handle != NULL)
{
if (!checkAndTryToConnect(handle))
{
LogError("Client Not Connected and could not connect.\r\n");
}
else
{
if (Lock(handle->LockHandle) == LOCK_OK)
{
//message
{
PDLIST_ENTRY received;
while ((received = DList_RemoveHeadList(&(handle->messagesReceived))) != &(handle->messagesReceived))
{
MQTTAPI_MESSAGE_RECEIVED_LIST* temp = containingRecord(received, MQTTAPI_MESSAGE_RECEIVED_LIST, entry);
if (handle->maCallBack != NULL)
{
if (!handle->maCallBack(handle->maCallbackContext, temp->messageReceived))
{
LogError("Client could not handle message, dropping it.");
}
}
free(temp->messageReceived->payload);
free(temp->messageReceived);
free(temp);
}
}
Unlock(handle->LockHandle);
}
else
{
LogError("Could not aquire lock for message.\r\n");
}
//Event
{
PDLIST_ENTRY messageToSend;
while ((messageToSend = DList_RemoveHeadList(&(handle->messagesToSend))) != &(handle->messagesToSend))
{
MQTTAPI_MESSAGE_SEND_LIST* temp = containingRecord(messageToSend, MQTTAPI_MESSAGE_SEND_LIST, entry);
if (MQTTClient_publishMessage(handle->client, STRING_c_str(temp->topicName), temp->messageToSend, &(temp->dt)) != MQTTCLIENT_SUCCESS)
{
handle->dcCallback(temp->context, MQTTAPI_CONFIRMATION_ERROR);
MQTTClient_freeMessage(&(temp->messageToSend));
free(temp->messageToSend);
STRING_delete(temp->topicName);
free(temp);
}
else
{
DList_InsertTailList(&(handle->messagesSent), &(temp->entry));
}
}
}
}
}
}

Двоичный файл не отображается.

Просмотреть файл

@ -20,3 +20,82 @@ extern IOTHUB_CLIENT_RESULT IoTHubTransportMqtt_SetOption(TRANSPORT_HANDLE handl
extern const void* MQTT_Protocol(void);
```
##IoTHubTransportMqtt_Create
```
TRANSPORT_HANDLE IoTHubTransportMqtt_Create(const IOTHUBTRANSPORT_CONFIG* config)
```
IoTHubTransportMqtt_Create shall create a TRANSPORT_HANDLE that can be further used in the calls to this modules APIS.
**SRS_IOTHUB_MQTT_TRANSPORT_07_001: [**If parameter config is NULL then IoTHubTransportMqtt_Create shall return NULL.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_002: [**If the parameter config's variables upperConfig or waitingToSend are NULL then IoTHubTransportMqtt_Create shall return NULL.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_003: [**If the upperConfig's variables deviceId, deviceKey, iotHubName, protocol, or iotHubSuffix are NULL then IoTHubTransportMqtt_Create shall return NULL.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_004: [**If the config's waitingToSend variable is NULL then IoTHubTransportMqtt_Create shall return NULL.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_005: [**If the upperConfig's variables deviceKey, iotHubName, or iotHubSuffix are empty strings then IoTHubTransportMqtt_Create shall return NULL.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_006: [**If the upperConfig's variables deviceId is an empty strings or length is greater then 128 then IoTHubTransportMqtt_Create shall return NULL.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_007: [**If the upperConfig's variables protocolGatewayHostName is non-Null and the length is an empty string then IoTHubTransportMqtt_Create shall return NULL.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_008: [**If the upperConfig contains a valid protocolGatewayHostName value the this shall be used for the hostname, otherwise the hostname shall be constructed using the iothubname and iothubSuffix.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_009: [**If any error is encountered then IoTHubTransportMqtt_Create shall return NULL.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_010: [**IoTHubTransportMqtt_Create shall allocate memory to save its internal state where all topics, hostname, device_id, device_key, sasTokenSr and client handle shall be saved.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_011: [**On Success IoTHubTransportMqtt_Create shall return a non-NULL value.**]**
##IoTHubTransportMqtt_Destroy
```
void IoTHubTransportMqtt_Destroy(TRANSPORT_HANDLE handle)
```
**SRS_IOTHUB_MQTT_TRANSPORT_07_012: [**IoTHubTransportMqtt_Destroy shall do nothing if parameter handle is NULL.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_013: [**If the parameter subscribe is true then IoTHubTransportMqtt_Destroy shall call IoTHubTransportMqtt_Unsubscribe.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_014: [**IoTHubTransportMqtt_Destroy shall free all the resources currently in use.**]**
##IoTHubTransportMqtt_Subscribe
```
int IoTHubTransportMqtt_Subscribe(TRANSPORT_HANDLE handle)
```
**SRS_IOTHUB_MQTT_TRANSPORT_07_015: [**If parameter handle is NULL than IoTHubTransportMqtt_Subscribe shall return a non-zero value.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_016: [**IoTHubTransportMqtt_Subscribe shall call mqtt_client_subscribe to subscribe to the Message Topic.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_017: [**Upon failure IoTHubTransportMqtt_Subscribe shall return a non-zero value.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_018: [**On success IoTHubTransportMqtt_Subscribe shall return 0.**]**
##IoTHubTransportMqtt_Unsubscribe
```
void IoTHubTransportMqtt_Unsubscribe(TRANSPORT_HANDLE handle)
```
**SRS_IOTHUB_MQTT_TRANSPORT_07_019: [**If parameter handle is NULL then IoTHubTransportMqtt_Unsubscribe shall do nothing.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_020: [**IoTHubTransportMqtt_Unsubscribe shall call mqtt_client_unsubscribe to unsubscribe the mqtt message topic.**]**
##IoTHubTransportMqtt_DoWork
```
void IoTHubTransportMqtt_DoWork(TRANSPORT_HANDLE handle, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle)
```
**SRS_IOTHUB_MQTT_TRANSPORT_07_026: [**IoTHubTransportMqtt_DoWork shall do nothing if parameter handle and/or iotHubClientHandle is NULL.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_027: [**IoTHubTransportMqtt_DoWork shall inspect the “waitingToSend” DLIST passed in config structure.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_028: [**IoTHubTransportMqtt_DoWork shall retrieve the payload message from the messageHandle parameter.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_029: [**IoTHubTransportMqtt_DoWork shall create a MQTT_MESSAGE_HANDLE and pass this to a call to mqtt_client_publish.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_030: [**IoTHubTransportMqtt_DoWork shall call mqtt_client_dowork everytime it is called if it is connected.**]**
##IoTHubTransportMqtt_GetSendStatus
```
IOTHUB_CLIENT_RESULT IoTHubTransportMqtt_GetSendStatus(TRANSPORT_HANDLE handle, IOTHUB_CLIENT_STATUS *iotHubClientStatus)
```
**SRS_IOTHUB_MQTT_TRANSPORT_07_023: [**IoTHubTransportMqtt_GetSendStatus shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_024: [**IoTHubTransportMqtt_GetSendStatus shall return IOTHUB_CLIENT_OK and status IOTHUB_CLIENT_SEND_STATUS_IDLE if there are currently no event items to be sent or being sent.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_025: [**IoTHubTransportMqtt_GetSendStatus shall return IOTHUB_CLIENT_OK and status IOTHUB_CLIENT_SEND_STATUS_BUSY if there are currently event items to be sent or being sent.**]**
##IoTHubTransportMqtt_SetOption
```
IOTHUB_CLIENT_RESULT IoTHubTransportMqtt_SetOption(TRANSPORT_HANDLE handle, const char* optionName, const void* value)
```
**SRS_IOTHUB_MQTT_TRANSPORT_07_021: [**If any parameter is NULL then IoTHubTransportMqtt_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_031: [**If the option parameter is set to "logtrace" then the value shall be a bool_ptr and the value will determine if the mqtt client log is on or off.**]**
**SRS_IOTHUB_MQTT_TRANSPORT_07_032: [**IoTHubTransportMqtt_SetOption shall return IOTHUB_CLIENT_INVALID_ARG if the option parameter is not a known option string.**]**
##MQTT_Protocol
```
const void* MQTT_Protocol(void)
```
**SRS_IOTHUB_MQTT_TRANSPORT_07_022: [**This function shall return a pointer to a structure of type TRANSPORT_PROVIDER having the following values for its fields:
IoTHubTransport_Create = IoTHubTransportMqtt_Create
IoTHubTransport_Destroy = IoTHubTransportMqtt_Destroy
IoTHubTransport_Subscribe = IoTHubTransportMqtt_Subscribe
IoTHubTransport_Unsubscribe = IoTHubTransportMqtt_Unsubscribe
IoTHubTransport_DoWork = IoTHubTransportMqtt_DoWork
IoTHubTransport_SetOption = IoTHubTransportMqtt_SetOption**]**

Просмотреть файл

@ -29,6 +29,8 @@
#include "iothub_message.h"
#include "xio.h"
#ifdef __cplusplus
extern "C"
{
@ -85,30 +87,34 @@ typedef void* IOTHUB_CLIENT_LL_HANDLE;
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 void*(*IOTHUB_CLIENT_TRANSPORT_PROVIDER)(void);
typedef const XIO_HANDLE (*IO_TRANSPORT_PROVIDER_CALLBACK)(const char* fqdn, int port);
/** @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, @c DeviceClientProvideAmqpResources,
* is defined in the include @c iothubtransportamqp.h. A function
* definition for HTTP, @c DeviceClientProvideHttpResources, is defined
* in the include @c iothubtransporthttp.h */
/** @brief A function pointer that is passed into the @c IoTHubClientCreate.
* A function definition for AMQP, @c DeviceClientProvideAmqpResources,
* is defined in the include @c iothubtransportamqp.h. A function
* definition for HTTP, @c DeviceClientProvideHttpResources, is defined
* in the include @c iothubtransporthttp.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. */
/** @brief The device key used to authenticate the device. */
const char* deviceKey;
/** @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. */
/** @brief IoT Hub suffix goes here, e.g., private.azure-devices-int.net. */
const char* iotHubSuffix;
const char* protocolGatewayHostName;
/** @brief A callback function to provide the IO transport instance, e.g. SChannel, OpenSSL or WebSockets. */
IO_TRANSPORT_PROVIDER_CALLBACK io_transport_provider_callback;
} IOTHUB_CLIENT_CONFIG;
/**

Просмотреть файл

@ -4,29 +4,29 @@
#this is CMakeLists.txt for iothub_client_sample_mqtt
if(NOT ${use_mqtt})
message(FATAL_ERROR "iothub_client_sample_mqtt being generated without mqtt support")
message(FATAL_ERROR "iothub_client_sample_mqtt being generated without mqtt support")
endif()
compileAsC99()
set(iothub_client_sample_mqtt_c_files
iothub_client_sample_mqtt.c
iothub_client_sample_mqtt.c
)
if(WIN32)
set(iothub_client_sample_mqtt_c_files ${iothub_client_sample_mqtt_c_files} ./windows/main.c)
set(iothub_client_sample_mqtt_c_files ${iothub_client_sample_mqtt_c_files} ./windows/main.c)
else()
set(iothub_client_sample_mqtt_c_files ${iothub_client_sample_mqtt_c_files} ./linux/main.c)
set(iothub_client_sample_mqtt_c_files ${iothub_client_sample_mqtt_c_files} ./linux/main.c)
endif()
set(iothub_client_sample_mqtt_h_files
iothub_client_sample_mqtt.h
iothub_client_sample_mqtt.h
)
IF(WIN32)
#windows needs this define
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DGB_MEASURE_MEMORY_FOR_THIS -DGB_DEBUG_ALLOC)
#windows needs this define
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DGB_MEASURE_MEMORY_FOR_THIS -DGB_DEBUG_ALLOC)
ENDIF(WIN32)
include_directories(.)
@ -34,10 +34,7 @@ include_directories(.)
add_executable(iothub_client_sample_mqtt ${iothub_client_sample_mqtt_c_files} ${iothub_client_sample_mqtt_h_files})
target_link_libraries(iothub_client_sample_mqtt
iothub_client_mqtt_transport
iothub_client
iothub_client_mqtt_transport
iothub_client_mqtt_transport
iothub_client
)
linkSharedUtil(iothub_client_sample_mqtt)
linkPaho(iothub_client_sample_mqtt)

Просмотреть файл

@ -9,11 +9,23 @@
#include "threadapi.h"
#include "crt_abstractions.h"
#include "iothubtransportmqtt.h"
#if _WIN32
#include "tlsio_schannel.h"
#else
#ifdef MBED_BUILD_TIMESTAMP
#include "tlsio_wolfssl.h"
#else
#include "tlsio_openssl.h"
#endif
#endif
#include "platform.h"
/*String containing Hostname, Device Id & Device Key in the format: */
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */
static const char* connectionString = "[device connection string]";
static int callbackCounter;
static char msgText[1024];
#define MESSAGE_COUNT 5
DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES);
@ -23,6 +35,25 @@ typedef struct EVENT_INSTANCE_TAG
int messageTrackingId; // For tracking the messages within the user callback.
} EVENT_INSTANCE;
const void* io_transport_provider(const char* fqdn, int port)
{
const IO_INTERFACE_DESCRIPTION* io_interface_description;
#ifdef _WIN32
TLSIO_SCHANNEL_CONFIG tls_io_config = { fqdn, port };
io_interface_description = tlsio_schannel_get_interface_description();
#else
#ifdef MBED_BUILD_TIMESTAMP
TLSIO_WOLFSSL_CONFIG tls_io_config = { fqdn, port };
io_interface_description = tlsio_wolfssl_get_interface_description();
#else
TLSIO_OPENSSL_CONFIG tls_io_config = { fqdn, port };
io_interface_description = tlsio_openssl_get_interface_description();
#endif
#endif
return (void*)xio_create(io_interface_description, &tls_io_config, NULL);
}
static IOTHUBMESSAGE_DISPOSITION_RESULT ReceiveMessageCallback(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback)
{
int* counter = (int*)userContextCallback;
@ -73,9 +104,6 @@ static void SendConfirmationCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, v
IoTHubMessage_Destroy(eventInstance->messageHandle);
}
static char msgText[1024];
#define MESSAGE_COUNT 5
void iothub_client_sample_mqtt_run(void)
{
IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle;
@ -90,54 +118,61 @@ void iothub_client_sample_mqtt_run(void)
(void)printf("Starting the IoTHub client sample MQTT...\r\n");
if ((iotHubClientHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, MQTT_Protocol)) == NULL)
if (platform_init() != 0)
{
(void)printf("ERROR: iotHubClientHandle is NULL!\r\n");
(void)printf("ERROR: platform_init fails!\r\n");
}
else
{
/* Setting Message call back, so we can receive Commands. */
if (IoTHubClient_LL_SetMessageCallback(iotHubClientHandle, ReceiveMessageCallback, &receiveContext) != IOTHUB_CLIENT_OK)
if ((iotHubClientHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, MQTT_Protocol)) == NULL)
{
(void)printf("ERROR: IoTHubClient_LL_SetMessageCallback..........FAILED!\r\n");
(void)printf("ERROR: iotHubClientHandle is NULL!\r\n");
}
else
{
(void)printf("IoTHubClient_LL_SetMessageCallback...successful.\r\n");
/* Now that we are ready to receive commands, let's send some messages */
for (int i = 0; i < MESSAGE_COUNT; i++)
/* Setting Message call back, so we can receive Commands. */
if (IoTHubClient_LL_SetMessageCallback(iotHubClientHandle, ReceiveMessageCallback, &receiveContext) != IOTHUB_CLIENT_OK)
{
sprintf_s(msgText, sizeof(msgText), "{\"deviceId\":\"myFirstDevice\",\"windSpeed\":%.2f}", avgWindSpeed + (rand() % 4 + 2));
if ((messages[i].messageHandle = IoTHubMessage_CreateFromByteArray((const unsigned char*)msgText, strlen(msgText))) == NULL)
{
(void)printf("ERROR: iotHubMessageHandle is NULL!\r\n");
}
else
{
messages[i].messageTrackingId = i;
(void)printf("ERROR: IoTHubClient_LL_SetMessageCallback..........FAILED!\r\n");
}
else
{
(void)printf("IoTHubClient_LL_SetMessageCallback...successful.\r\n");
if (IoTHubClient_LL_SendEventAsync(iotHubClientHandle, messages[i].messageHandle, SendConfirmationCallback, &messages[i]) != IOTHUB_CLIENT_OK)
/* Now that we are ready to receive commands, let's send some messages */
for (size_t i = 0; i < MESSAGE_COUNT; i++)
{
sprintf_s(msgText, sizeof(msgText), "{\"deviceId\":\"myFirstDevice\",\"windSpeed\":%.2f}", avgWindSpeed + (rand() % 4 + 2));
if ((messages[i].messageHandle = IoTHubMessage_CreateFromByteArray((const unsigned char*)msgText, strlen(msgText))) == NULL)
{
(void)printf("ERROR: IoTHubClient_LL_SendEventAsync..........FAILED!\r\n");
(void)printf("ERROR: iotHubMessageHandle is NULL!\r\n");
}
else
{
(void)printf("IoTHubClient_LL_SendEventAsync accepted message [%d] for transmission to IoT Hub.\r\n", i);
}
messages[i].messageTrackingId = i;
if (IoTHubClient_LL_SendEventAsync(iotHubClientHandle, messages[i].messageHandle, SendConfirmationCallback, &messages[i]) != IOTHUB_CLIENT_OK)
{
(void)printf("ERROR: IoTHubClient_LL_SendEventAsync..........FAILED!\r\n");
}
else
{
(void)printf("IoTHubClient_LL_SendEventAsync accepted message [%d] for transmission to IoT Hub.\r\n", (int)i);
}
}
}
}
}
/* Wait for Commands. */
while (1)
{
IoTHubClient_LL_DoWork(iotHubClientHandle);
ThreadAPI_Sleep(1);
}
/* Wait for Commands. */
while (1)
{
IoTHubClient_LL_DoWork(iotHubClientHandle);
ThreadAPI_Sleep(1);
}
IoTHubClient_LL_Destroy(iotHubClientHandle);
IoTHubClient_LL_Destroy(iotHubClientHandle);
}
platform_deinit();
}
}

Просмотреть файл

@ -81,8 +81,9 @@ IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* c
config->iotHubSuffix = NULL;
config->deviceId = NULL;
config->deviceKey = NULL;
/* Codes_SRS_IOTHUBCLIENT_LL_04_002: [If it does not, it shall pass the protocolGatewayHostName NULL.] */
config->protocolGatewayHostName = NULL;
/* Codes_SRS_IOTHUBCLIENT_LL_04_002: [If it does not, it shall pass the protocolGatewayHostName NULL.] */
config->protocolGatewayHostName = NULL;
config->io_transport_provider_callback = NULL;
if ((connString = STRING_construct(connectionString)) == NULL)
{
@ -125,7 +126,7 @@ IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* c
{
/* SRS_IOTHUBCLIENT_LL_12_010: [IoTHubClient_LL_CreateFromConnectionString shall fill up the IOTHUB_CLIENT_CONFIG structure using the following mapping: iotHubName = Name, iotHubSuffix = Suffix, deviceId = DeviceId, deviceKey = SharedAccessKey] */
const char* s_token = STRING_c_str(tokenString);
if (strcmp(s_token, HOSTNAME_TOKEN) == 0)
if (strcmp(s_token, HOSTNAME_TOKEN) == 0)
{
/* SRS_IOTHUBCLIENT_LL_12_009: [IoTHubClient_LL_CreateFromConnectionString shall split the value of HostName to Name and Suffix using the first "." as a separator] */
STRING_TOKENIZER_HANDLE tokenizer2 = NULL;
@ -176,7 +177,7 @@ IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* c
config->deviceKey = STRING_c_str(deviceKeyString);
}
}
/* Codes_SRS_IOTHUBCLIENT_LL_04_001: [IoTHubClient_LL_CreateFromConnectionString shall verify the existence of key/value pair GatewayHostName. If it does exist it shall pass the value to IoTHubClient_LL_Create API.] */
/* Codes_SRS_IOTHUBCLIENT_LL_04_001: [IoTHubClient_LL_CreateFromConnectionString shall verify the existence of key/value pair GatewayHostName. If it does exist it shall pass the value to IoTHubClient_LL_Create API.] */
else if (strcmp(s_token, PROTOCOL_GATEWAY_HOST) == 0)
{
protocolGateway = STRING_clone(valueString);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -18,16 +18,16 @@ endif()
if(${use_http})
add_subdirectory(iothubtransporthttp_unittests)
if(${use_amqp})
add_subdirectory(iothubclient_http_e2etests)
endif()
add_subdirectory(iothubclient_http_e2etests)
endif()
endif()
if(${use_mqtt})
add_subdirectory(iothubtransportmqtt_unittests)
if(${use_amqp})
add_subdirectory(iothubclient_mqtt_e2etests)
add_subdirectory(iothubclient_mqtt_e2etests)
endif()
add_subdirectory(mqttapi_paho_unittests)
endif()
add_subdirectory(version_unittests)

Просмотреть файл

@ -35,7 +35,7 @@ if(WIN32)
iothub_client_mqtt_transport
)
linkProton(${theseTestsName}_dll)
linkPaho(${theseTestsName}_dll)
linkMqttLibrary(${theseTestsName}_dll)
endif()
if(TARGET ${theseTestsName}_exe)
@ -47,7 +47,7 @@ if(WIN32)
iothub_client_mqtt_transport
)
linkProton(${theseTestsName}_exe)
linkPaho(${theseTestsName}_exe)
linkMqttLibrary(${theseTestsName}_exe)
endif()
else()
if(TARGET ${theseTestsName}_exe)
@ -60,7 +60,6 @@ else()
)
target_link_libraries(${theseTestsName}_exe pthread)
linkProton(${theseTestsName}_exe)
linkPaho(${theseTestsName}_exe)
linkMqttLibrary(${theseTestsName}_exe)
endif()
endif()

Просмотреть файл

@ -20,6 +20,16 @@
#include "buffer_.h"
#include "threadapi.h"
#if _WIN32
#include "tlsio_schannel.h"
#else
#ifdef MBED_BUILD_TIMESTAMP
#include "tlsio_wolfssl.h"
#else
#include "tlsio_openssl.h"
#endif
#endif
static MICROMOCK_GLOBAL_SEMAPHORE_HANDLE g_dllByDll;
static bool g_callbackRecv = false;
@ -28,9 +38,10 @@ const char* TEST_MESSAGE_DATA_FMT = "{\"notifyData\":\"%.24s\",\"id\":\"%d\"}";
static size_t g_iotHubTestId = 0;
#define IOTHUB_COUNTER_MAX 10
#define IOTHUB_TIMEOUT_SEC 1000
#define MAX_CLOUD_TRAVEL_TIME 60.0
#define IOTHUB_COUNTER_MAX 10
#define IOTHUB_TIMEOUT_SEC 1000
#define MAX_CLOUD_TRAVEL_TIME 60.0
#define TEMP_BUFFER_SIZE 1024
DEFINE_MICROMOCK_ENUM_TO_STRING(IOTHUB_TEST_CLIENT_RESULT, IOTHUB_TEST_CLIENT_RESULT_VALUES);
DEFINE_MICROMOCK_ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_RESULT_VALUES);
@ -55,6 +66,23 @@ typedef struct EXPECTED_RECEIVE_DATA_TAG
BEGIN_TEST_SUITE(iothubclient_mqtt_e2etests)
static XIO_HANDLE CreateXioConnection(const char* hostname, int portNum)
{
#if _WIN32
TLSIO_SCHANNEL_CONFIG tls_io_config = { hostname, portNum };
const IO_INTERFACE_DESCRIPTION* tlsio_interface = tlsio_schannel_get_interface_description();
#else
#ifdef MBED_BUILD_TIMESTAMP
TLSIO_WOLFSSL_CONFIG tls_io_config = { hostname, portNum };
const IO_INTERFACE_DESCRIPTION* tlsio_interface = tlsio_wolfssl_get_interface_description();
#else
TLSIO_OPENSSL_CONFIG tls_io_config = { hostname, portNum };
const IO_INTERFACE_DESCRIPTION* tlsio_interface = tlsio_openssl_get_interface_description();
#endif
#endif
return xio_create(tlsio_interface, &tls_io_config, NULL);
}
static int IoTHubCallback(void* context, const char* data, size_t size)
{
size;
@ -132,10 +160,10 @@ BEGIN_TEST_SUITE(iothubclient_mqtt_e2etests)
EXPECTED_RECEIVE_DATA* result = (EXPECTED_RECEIVE_DATA*)malloc(sizeof(EXPECTED_RECEIVE_DATA));
if (result != NULL)
{
char temp[1000];
char temp[TEMP_BUFFER_SIZE];
char* tempString;
time_t t = time(NULL);
sprintf(temp, TEST_MESSAGE_DATA_FMT, ctime(&t), g_iotHubTestId);
(void)snprintf(temp, TEMP_BUFFER_SIZE, TEST_MESSAGE_DATA_FMT, ctime(&t), g_iotHubTestId);
if ( (tempString = (char*)malloc(strlen(temp) + 1) ) == NULL)
{
free(result);
@ -184,10 +212,10 @@ BEGIN_TEST_SUITE(iothubclient_mqtt_e2etests)
EXPECTED_SEND_DATA* result = (EXPECTED_SEND_DATA*)malloc(sizeof(EXPECTED_SEND_DATA));
if (result != NULL)
{
char temp[1000];
char temp[TEMP_BUFFER_SIZE];
char* tempString;
time_t t = time(NULL);
sprintf(temp, TEST_EVENT_DATA_FMT, ctime(&t), g_iotHubTestId);
(void)snprintf(temp, TEMP_BUFFER_SIZE, TEST_EVENT_DATA_FMT, ctime(&t), g_iotHubTestId);
if ( (tempString = (char*)malloc(strlen(temp) + 1) ) == NULL)
{
free(result);
@ -235,123 +263,122 @@ BEGIN_TEST_SUITE(iothubclient_mqtt_e2etests)
{
}
//Disabling MQTT e2e tests, pending fix of Bug 480363 - MQTT- C Client not cleaning Open SSL Properly, causing crashes
//TEST_FUNCTION(IoTHub_MQTT_SendEvent_E2ETests)
//{
// // arrange
// IOTHUB_CLIENT_CONFIG iotHubConfig;
// IOTHUB_CLIENT_HANDLE iotHubClientHandle;
// IOTHUB_MESSAGE_HANDLE msgHandle;
// Will enable as soon as it's ready
TEST_FUNCTION(IoTHub_MQTT_SendEvent_E2ETests)
{
// arrange
IOTHUB_CLIENT_CONFIG iotHubConfig;
IOTHUB_CLIENT_HANDLE iotHubClientHandle;
IOTHUB_MESSAGE_HANDLE msgHandle;
// iotHubConfig.iotHubName = IoTHubAccount_GetIoTHubName();
// iotHubConfig.iotHubSuffix = IoTHubAccount_GetIoTHubSuffix();
// iotHubConfig.deviceId = IoTHubAccount_GetDeviceId();
// iotHubConfig.deviceKey = IoTHubAccount_GetDeviceKey();
// iotHubConfig.protocolGatewayHostName = IoTHubAccount_GetProtocolGatewayHostName();
// iotHubConfig.protocol = MQTT_Protocol;
iotHubConfig.iotHubName = IoTHubAccount_GetIoTHubName();
iotHubConfig.iotHubSuffix = IoTHubAccount_GetIoTHubSuffix();
iotHubConfig.deviceId = IoTHubAccount_GetDeviceId();
iotHubConfig.deviceKey = IoTHubAccount_GetDeviceKey();
iotHubConfig.protocolGatewayHostName = IoTHubAccount_GetProtocolGatewayHostName();
iotHubConfig.protocol = MQTT_Protocol;
// EXPECTED_SEND_DATA* sendData = EventData_Create();
// ASSERT_IS_NOT_NULL(sendData);
EXPECTED_SEND_DATA* sendData = EventData_Create();
ASSERT_IS_NOT_NULL(sendData);
// // Send the Event
// {
// IOTHUB_CLIENT_RESULT result;
// // Create the IoT Hub Data
// iotHubClientHandle = IoTHubClient_Create(&iotHubConfig);
// ASSERT_IS_NOT_NULL_WITH_MSG(iotHubClientHandle,"Could not create IoTHubClient.");
// Send the Event
{
IOTHUB_CLIENT_RESULT result;
// Create the IoT Hub Data
iotHubClientHandle = IoTHubClient_Create(&iotHubConfig);
ASSERT_IS_NOT_NULL_WITH_MSG(iotHubClientHandle,"Could not create IoTHubClient.");
// msgHandle = IoTHubMessage_CreateFromByteArray((const unsigned char*)sendData->expectedString, strlen(sendData->expectedString));
// ASSERT_IS_NOT_NULL_WITH_MSG(msgHandle, "Error Creating IoTHubMEssage From Byte Array.");
msgHandle = IoTHubMessage_CreateFromByteArray((const unsigned char*)sendData->expectedString, strlen(sendData->expectedString));
ASSERT_IS_NOT_NULL_WITH_MSG(msgHandle, "Error Creating IoTHubMEssage From Byte Array.");
// // act
// result = IoTHubClient_SendEventAsync(iotHubClientHandle, msgHandle, ReceiveConfirmationCallback, sendData);
// ASSERT_ARE_EQUAL(int, IOTHUB_CLIENT_OK, result);
// }
// act
result = IoTHubClient_SendEventAsync(iotHubClientHandle, msgHandle, ReceiveConfirmationCallback, sendData);
ASSERT_ARE_EQUAL(int, IOTHUB_CLIENT_OK, result);
}
// time_t beginOperation, nowTime;
// beginOperation = time(NULL);
// while (
// (
// (nowTime = time(NULL)),
// (difftime(nowTime, beginOperation) < MAX_CLOUD_TRAVEL_TIME) // time box
// ) &&
// (!sendData->dataWasRecv) // Condition box
// )
// {
// // Just go on here
// }
// ASSERT_IS_TRUE(sendData->dataWasRecv); // was found is written by the callback...
// IoTHubClient_Destroy(iotHubClientHandle);
time_t beginOperation, nowTime;
beginOperation = time(NULL);
while (
(
(nowTime = time(NULL)),
(difftime(nowTime, beginOperation) < MAX_CLOUD_TRAVEL_TIME) // time box
) &&
(!sendData->dataWasRecv) // Condition box
)
{
// Just go on here
}
ASSERT_IS_TRUE(sendData->dataWasRecv); // was found is written by the callback...
IoTHubClient_Destroy(iotHubClientHandle);
// {
// IOTHUB_TEST_HANDLE iotHubTestHandle = IoTHubTest_Initialize(IoTHubAccount_GetEventHubConnectionString(), IoTHubAccount_GetIoTHubConnString(), IoTHubAccount_GetDeviceId(), IoTHubAccount_GetDeviceKey(), IoTHubAccount_GetEventhubListenName(), IoTHubAccount_GetEventhubAccessKey(), IoTHubAccount_GetSharedAccessSignature(), IoTHubAccount_GetEventhubConsumerGroup());
// ASSERT_IS_NOT_NULL_WITH_MSG(iotHubTestHandle, "Problem Initializing IoTHub Test.");
{
IOTHUB_TEST_HANDLE iotHubTestHandle = IoTHubTest_Initialize(IoTHubAccount_GetEventHubConnectionString(), IoTHubAccount_GetIoTHubConnString(), IoTHubAccount_GetDeviceId(), IoTHubAccount_GetDeviceKey(), IoTHubAccount_GetEventhubListenName(), IoTHubAccount_GetEventhubAccessKey(), IoTHubAccount_GetSharedAccessSignature(), IoTHubAccount_GetEventhubConsumerGroup());
ASSERT_IS_NOT_NULL_WITH_MSG(iotHubTestHandle, "Problem Initializing IoTHub Test.");
// IOTHUB_TEST_CLIENT_RESULT result = IoTHubTest_ListenForEventForMaxDrainTime(iotHubTestHandle, IoTHubCallback, IoTHubAccount_GetIoTHubPartitionCount(), sendData);
// ASSERT_ARE_EQUAL(IOTHUB_TEST_CLIENT_RESULT, IOTHUB_TEST_CLIENT_OK, result);
IOTHUB_TEST_CLIENT_RESULT result = IoTHubTest_ListenForEventForMaxDrainTime(iotHubTestHandle, IoTHubCallback, IoTHubAccount_GetIoTHubPartitionCount(), sendData);
ASSERT_ARE_EQUAL(IOTHUB_TEST_CLIENT_RESULT, IOTHUB_TEST_CLIENT_OK, result);
// IoTHubTest_Deinit(iotHubTestHandle);
// }
IoTHubTest_Deinit(iotHubTestHandle);
}
// // assert
// ASSERT_IS_TRUE(sendData->wasFound); // was found is written by the callback...
// assert
ASSERT_IS_TRUE(sendData->wasFound); // was found is written by the callback...
// // cleanup
// IoTHubMessage_Destroy(msgHandle);
// EventData_Destroy(sendData);
//}
// cleanup
IoTHubMessage_Destroy(msgHandle);
EventData_Destroy(sendData);
}
//TEST_FUNCTION(IoTHub_MQTT_RecvMessage_E2ETest)
//{
// // arrange
// IOTHUB_CLIENT_CONFIG iotHubConfig;
// IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle;
TEST_FUNCTION(IoTHub_MQTT_RecvMessage_E2ETest)
{
// arrange
IOTHUB_CLIENT_CONFIG iotHubConfig;
IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle;
// EXPECTED_RECEIVE_DATA* notifyData = MessageData_Create();
// ASSERT_IS_NOT_NULL_WITH_MSG(notifyData, "Error creating Notify Data.");
EXPECTED_RECEIVE_DATA* notifyData = MessageData_Create();
ASSERT_IS_NOT_NULL_WITH_MSG(notifyData, "Error creating Notify Data.");
// // act
// iotHubConfig.iotHubName = IoTHubAccount_GetIoTHubName();
// iotHubConfig.iotHubSuffix = IoTHubAccount_GetIoTHubSuffix();
// iotHubConfig.deviceId = IoTHubAccount_GetDeviceId();
// iotHubConfig.deviceKey = IoTHubAccount_GetDeviceKey();
// iotHubConfig.protocolGatewayHostName = IoTHubAccount_GetProtocolGatewayHostName();
// iotHubConfig.protocol = MQTT_Protocol;
// act
iotHubConfig.iotHubName = IoTHubAccount_GetIoTHubName();
iotHubConfig.iotHubSuffix = IoTHubAccount_GetIoTHubSuffix();
iotHubConfig.deviceId = IoTHubAccount_GetDeviceId();
iotHubConfig.deviceKey = IoTHubAccount_GetDeviceKey();
iotHubConfig.protocolGatewayHostName = IoTHubAccount_GetProtocolGatewayHostName();
iotHubConfig.protocol = MQTT_Protocol;
iotHubClientHandle = IoTHubClient_Create(&iotHubConfig);
ASSERT_IS_NOT_NULL_WITH_MSG(iotHubClientHandle, "Error creating IoTHubClient.");
// iotHubClientHandle = IoTHubClient_Create(&iotHubConfig);
// ASSERT_IS_NOT_NULL_WITH_MSG(iotHubClientHandle, "Error creating IoTHubClient.");
IOTHUB_CLIENT_RESULT result = IoTHubClient_SetMessageCallback(iotHubClientHandle, ReceiveMessageCallback, notifyData);
ASSERT_ARE_EQUAL(int, IOTHUB_CLIENT_OK, result);
// IOTHUB_CLIENT_RESULT result = IoTHubClient_SetMessageCallback(iotHubClientHandle, ReceiveMessageCallback, notifyData);
// ASSERT_ARE_EQUAL(int, IOTHUB_CLIENT_OK, result);
IOTHUB_TEST_HANDLE iotHubTestHandle = IoTHubTest_Initialize(IoTHubAccount_GetEventHubConnectionString(), IoTHubAccount_GetIoTHubConnString(), IoTHubAccount_GetDeviceId(), IoTHubAccount_GetDeviceKey(), IoTHubAccount_GetEventhubListenName(), IoTHubAccount_GetEventhubAccessKey(), IoTHubAccount_GetSharedAccessSignature(), IoTHubAccount_GetEventhubConsumerGroup());
ASSERT_IS_NOT_NULL_WITH_MSG(iotHubTestHandle, "Error Creating IotHubTest.");
// IOTHUB_TEST_HANDLE iotHubTestHandle = IoTHubTest_Initialize(IoTHubAccount_GetEventHubConnectionString(), IoTHubAccount_GetIoTHubConnString(), IoTHubAccount_GetDeviceId(), IoTHubAccount_GetDeviceKey(), IoTHubAccount_GetEventhubListenName(), IoTHubAccount_GetEventhubAccessKey(), IoTHubAccount_GetSharedAccessSignature(), IoTHubAccount_GetEventhubConsumerGroup());
// ASSERT_IS_NOT_NULL_WITH_MSG(iotHubTestHandle, "Error Creating IotHubTest.");
IOTHUB_TEST_CLIENT_RESULT testResult = IoTHubTest_SendMessage(iotHubTestHandle, notifyData->toBeSend, notifyData->toBeSendSize);
ASSERT_ARE_EQUAL(IOTHUB_TEST_CLIENT_RESULT, IOTHUB_TEST_CLIENT_OK, testResult);
// IOTHUB_TEST_CLIENT_RESULT testResult = IoTHubTest_SendMessage(iotHubTestHandle, notifyData->toBeSend, notifyData->toBeSendSize);
// ASSERT_ARE_EQUAL(IOTHUB_TEST_CLIENT_RESULT, IOTHUB_TEST_CLIENT_OK, testResult);
IoTHubTest_Deinit(iotHubTestHandle);
// IoTHubTest_Deinit(iotHubTestHandle);
time_t beginOperation, nowTime;
beginOperation = time(NULL);
while (
(
(nowTime = time(NULL)),
(difftime(nowTime, beginOperation) < MAX_CLOUD_TRAVEL_TIME) //time box
) &&
(!notifyData->wasFound) //condition box
)
{
//just go on;
}
// time_t beginOperation, nowTime;
// beginOperation = time(NULL);
// while (
// (
// (nowTime = time(NULL)),
// (difftime(nowTime, beginOperation) < MAX_CLOUD_TRAVEL_TIME) //time box
// ) &&
// (!notifyData->wasFound) //condition box
// )
// {
// //just go on;
// }
// // assert
// ASSERT_IS_TRUE(notifyData->wasFound); // was found is written by the callback...
// // cleanup
// MessageData_Destroy(notifyData);
// IoTHubClient_Destroy(iotHubClientHandle);
//}
// assert
ASSERT_IS_TRUE(notifyData->wasFound); // was found is written by the callback...
// cleanup
MessageData_Destroy(notifyData);
IoTHubClient_Destroy(iotHubClientHandle);
}
END_TEST_SUITE(iothubclient_mqtt_e2etests)

Просмотреть файл

@ -22,4 +22,4 @@ set(${theseTestsName}_c_files
set(${theseTestsName}_h_files
)
build_test_artifacts(${theseTestsName} ON)
build_test_artifacts(${theseTestsName} ON)

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -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.
#this is CMakeLists.txt for mqttapi_paho_unittests
cmake_minimum_required(VERSION 2.8.11)
if(NOT ${use_mqtt})
message(FATAL_ERROR "mqttapi_paho_unittests being generated without mqtt support")
endif()
compileAsC99()
set(theseTestsName mqttapi_paho_unittests)
set(${theseTestsName}_cpp_files
${theseTestsName}.cpp
)
set(${theseTestsName}_c_files
../../adapters/mqttapi_paho.c
)
set(${theseTestsName}_h_files
)
build_test_artifacts(${theseTestsName} ON)

Просмотреть файл

@ -1,28 +0,0 @@
/*
Microsoft Azure IoT Client Libraries
Copyright (c) Microsoft Corporation
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the Software), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#include "testrunnerswitcher.h"
int main(void)
{
size_t failedTestCount = 0;
RUN_TEST_SUITE(mqttapi_paho_unittests, failedTestCount);
return failedTestCount;
}

Просмотреть файл

@ -1,888 +0,0 @@
/*
Microsoft Azure IoT Client Libraries
Copyright (c) Microsoft Corporation
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the Software), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#include <cstdlib>
#ifdef _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#include "testrunnerswitcher.h"
#include "micromock.h"
#include "micromockcharstararenullterminatedstrings.h"
/*the below is a horrible hack*/
#include "macro_utils.h"
#undef DEFINE_ENUM
#define DEFINE_ENUM(enumName, ...) typedef enum C2(enumName, _TAG) { FOR_EACH_1(DEFINE_ENUMERATION_CONSTANT, __VA_ARGS__)} enumName;
#include "map.h"
#include "mqttapi.h"
#include "lock.h"
#include "strings.h"
#include "crt_abstractions.h"
#include "vector.h"
#include "MQTTClient.h"
#include "doublylinkedlist.h"
#include "sastoken.h"
#include "agenttime.h"
DEFINE_MICROMOCK_ENUM_TO_STRING(MQTTAPI_RESULT, MQTTAPI_RESULT_VALUES);
#define GBALLOC_H
extern "C" int gballoc_init(void);
extern "C" void gballoc_deinit(void);
extern "C" void* gballoc_malloc(size_t size);
extern "C" void* gballoc_calloc(size_t nmemb, size_t size);
extern "C" void* gballoc_realloc(void* ptr, size_t size);
extern "C" void gballoc_free(void* ptr);
namespace BASEIMPLEMENTATION
{
/*if malloc is defined as gballoc_malloc at this moment, there'd be serious trouble*/
#define Lock(x) (LOCK_OK + gballocState - gballocState) /*compiler warning about constant in if condition*/
#define Unlock(x) (LOCK_OK + gballocState - gballocState)
#define Lock_Init() (LOCK_HANDLE)0x42
#define Lock_Deinit(x) (LOCK_OK + gballocState - gballocState)
#include "gballoc.c"
#undef Lock
#undef Unlock
#undef Lock_Init
#undef Lock_Deinit
#include "strings.c"
#include "buffer.c"
#include "vector.c"
#include "doublylinkedlist.c"
};
static size_t currentmalloc_call;
static size_t whenShallmalloc_fail;
static size_t currentrealloc_call;
static size_t whenShallrealloc_fail;
/*different STRING constructors*/
static size_t currentSTRING_new_call;
static size_t whenShallSTRING_new_fail;
static size_t currentSTRING_clone_call;
static size_t whenShallSTRING_clone_fail;
static size_t currentSTRING_construct_call;
static size_t whenShallSTRING_construct_fail;
static size_t currentSTRING_concat_call;
static size_t whenShallSTRING_concat_fail;
static size_t currentSTRING_empty_call;
static size_t whenShallSTRING_empty_fail;
static size_t currentSTRING_concat_with_STRING_call;
static size_t whenShallSTRING_concat_with_STRING_fail;
//CONSTANTS
#define TEST_DEVICE_ID "thisIsDeviceId"
#define TEST_DEVICE_KEY "thisIsDeviceKey"
#define TEST_SASTOKEN_SR "thisIsIotHubName.thisIsIoTHubNameSuffix\\Devices\\thisIsDeviceId"
#define TEST_IOTHUB_NAME "thisIsIotHubName"
#define TEST_LOCK_HANDLE (LOCK_HANDLE)0x4443
//Configuration Variations
static const MQTTAPI_ConnectOptions TEST_CONFIG_MQTTAPIconnectionOptions =
{
TEST_DEVICE_ID,/*const char* deviceId; */
TEST_DEVICE_KEY,/*const char* deviceKey; */
TEST_SASTOKEN_SR, /*const char* sasTokenSr; */
TEST_IOTHUB_NAME,/*const char* serverURI; */
};
//DEFINE HERE ALL OUR CONSTANTS
TYPED_MOCK_CLASS(CMQTTAPIMocks, CGlobalMock)
{
public:
/* Lock mocks */
MOCK_STATIC_METHOD_0(, LOCK_HANDLE, Lock_Init)
MOCK_METHOD_END(LOCK_HANDLE, TEST_LOCK_HANDLE)
MOCK_STATIC_METHOD_1(, LOCK_RESULT, Lock, LOCK_HANDLE, handle)
MOCK_METHOD_END(LOCK_RESULT, LOCK_OK)
MOCK_STATIC_METHOD_1(, LOCK_RESULT, Unlock, LOCK_HANDLE, handle)
MOCK_METHOD_END(LOCK_RESULT, LOCK_OK)
MOCK_STATIC_METHOD_1(, LOCK_RESULT, Lock_Deinit, LOCK_HANDLE, handle)
MOCK_METHOD_END(LOCK_RESULT, LOCK_OK)
MOCK_STATIC_METHOD_1(, void*, gballoc_malloc, size_t, size)
void* result2;
currentmalloc_call++;
if (whenShallmalloc_fail>0)
{
if (currentmalloc_call == whenShallmalloc_fail)
{
result2 = (STRING_HANDLE)NULL;
}
else
{
result2 = BASEIMPLEMENTATION::gballoc_malloc(size);
}
}
else
{
result2 = BASEIMPLEMENTATION::gballoc_malloc(size);
}
MOCK_METHOD_END(void*, result2);
MOCK_STATIC_METHOD_2(, void*, gballoc_realloc, void*, ptr, size_t, size)
void* result2;
currentrealloc_call++;
if (whenShallrealloc_fail>0)
{
if (currentrealloc_call == whenShallrealloc_fail)
{
result2 = (STRING_HANDLE)NULL;
}
else
{
result2 = BASEIMPLEMENTATION::gballoc_realloc(ptr,size);
}
}
else
{
result2 = BASEIMPLEMENTATION::gballoc_realloc(ptr, size);
}
MOCK_METHOD_END(void*,result2);
MOCK_STATIC_METHOD_1(, void, gballoc_free, void*, ptr)
BASEIMPLEMENTATION::gballoc_free(ptr);
MOCK_VOID_METHOD_END()
/*Strings*/
MOCK_STATIC_METHOD_0(, STRING_HANDLE, STRING_new)
STRING_HANDLE result2;
currentSTRING_new_call++;
if (whenShallSTRING_new_fail > 0)
{
if (currentSTRING_new_call == whenShallSTRING_new_fail)
{
result2 = (STRING_HANDLE)NULL;
}
else
{
result2 = BASEIMPLEMENTATION::STRING_new();
}
}
else
{
result2 = BASEIMPLEMENTATION::STRING_new();
}
MOCK_METHOD_END(STRING_HANDLE, result2)
MOCK_STATIC_METHOD_1(, STRING_HANDLE, STRING_clone, STRING_HANDLE, handle)
STRING_HANDLE result2;
currentSTRING_clone_call++;
if (whenShallSTRING_clone_fail > 0)
{
if (currentSTRING_clone_call == whenShallSTRING_clone_fail)
{
result2 = (STRING_HANDLE)NULL;
}
else
{
result2 = BASEIMPLEMENTATION::STRING_clone(handle);
}
}
else
{
result2 = BASEIMPLEMENTATION::STRING_clone(handle);
}
MOCK_METHOD_END(STRING_HANDLE, result2)
MOCK_STATIC_METHOD_1(, STRING_HANDLE, STRING_construct, const char*, source)
STRING_HANDLE result2;
currentSTRING_construct_call++;
if (whenShallSTRING_construct_fail > 0)
{
if (currentSTRING_construct_call == whenShallSTRING_construct_fail)
{
result2 = (STRING_HANDLE)NULL;
}
else
{
result2 = BASEIMPLEMENTATION::STRING_construct(source);
}
}
else
{
result2 = BASEIMPLEMENTATION::STRING_construct(source);
}
MOCK_METHOD_END(STRING_HANDLE, result2)
MOCK_STATIC_METHOD_1(, void, STRING_delete, STRING_HANDLE, s)
BASEIMPLEMENTATION::STRING_delete(s);
MOCK_VOID_METHOD_END()
MOCK_STATIC_METHOD_2(, int, STRING_concat, STRING_HANDLE, s1, const char*, s2)
currentSTRING_concat_call++;
MOCK_METHOD_END(int, (((whenShallSTRING_concat_fail > 0) && (currentSTRING_concat_call == whenShallSTRING_concat_fail)) ? __LINE__ : BASEIMPLEMENTATION::STRING_concat(s1, s2)));
MOCK_STATIC_METHOD_2(, int, STRING_concat_with_STRING, STRING_HANDLE, s1, STRING_HANDLE, s2)
currentSTRING_concat_with_STRING_call++;
MOCK_METHOD_END(int, (((currentSTRING_concat_with_STRING_call > 0) && (currentSTRING_concat_with_STRING_call == whenShallSTRING_concat_with_STRING_fail)) ? __LINE__ : BASEIMPLEMENTATION::STRING_concat_with_STRING(s1, s2)));
MOCK_STATIC_METHOD_1(, int, STRING_empty, STRING_HANDLE, s)
currentSTRING_concat_call++;
MOCK_METHOD_END(int, BASEIMPLEMENTATION::STRING_empty(s));
MOCK_STATIC_METHOD_1(, const char*, STRING_c_str, STRING_HANDLE, s)
MOCK_METHOD_END(const char*, BASEIMPLEMENTATION::STRING_c_str(s))
//MQTTClient STubs
MOCK_STATIC_METHOD_5(, int, MQTTClient_setCallbacks, MQTTClient, handle, void*, context, MQTTClient_connectionLost*, cl, MQTTClient_messageArrived*, ma, MQTTClient_deliveryComplete*, dc)
MOCK_METHOD_END(int, MQTTCLIENT_SUCCESS)
MOCK_STATIC_METHOD_5(, int, MQTTClient_create,MQTTClient*, handle, const char*, serverURI, const char*, clientId, int, persistence_type, void*, persistence_context)
MOCK_METHOD_END(int, MQTTCLIENT_SUCCESS)
MOCK_STATIC_METHOD_2(, int, MQTTClient_connect, MQTTClient, handle, MQTTClient_connectOptions*, options)
MOCK_METHOD_END(int, MQTTCLIENT_SUCCESS)
MOCK_STATIC_METHOD_1(, void, MQTTClient_free, void*, ptr)
MOCK_VOID_METHOD_END()
MOCK_STATIC_METHOD_2(, int, MQTTClient_disconnect, MQTTClient, handle, int, timeout)
MOCK_METHOD_END(int, MQTTCLIENT_SUCCESS)
MOCK_STATIC_METHOD_1(, void, MQTTClient_destroy, MQTTClient*, handle)
MOCK_VOID_METHOD_END()
MOCK_STATIC_METHOD_3(, int, MQTTClient_subscribe,MQTTClient, handle, const char*, topic, int, qos)
MOCK_METHOD_END(int, MQTTCLIENT_SUCCESS)
MOCK_STATIC_METHOD_2(, int, MQTTClient_unsubscribe,MQTTClient, handle, const char*, topic)
MOCK_METHOD_END(int, MQTTCLIENT_SUCCESS)
MOCK_STATIC_METHOD_1(, void, MQTTClient_freeMessage, MQTTClient_message**, msg)
MOCK_VOID_METHOD_END()
MOCK_STATIC_METHOD_4(, int, MQTTClient_publishMessage,MQTTClient, handle, const char*, topicName, MQTTClient_message*, msg, MQTTClient_deliveryToken*, dt)
MOCK_METHOD_END(int, MQTTCLIENT_SUCCESS)
/* DoublyLinkedList mocks */
MOCK_STATIC_METHOD_1(, void, DList_InitializeListHead, PDLIST_ENTRY, listHead)
BASEIMPLEMENTATION::DList_InitializeListHead(listHead);
MOCK_VOID_METHOD_END()
MOCK_STATIC_METHOD_1(, int, DList_IsListEmpty, PDLIST_ENTRY, listHead)
int result2 = BASEIMPLEMENTATION::DList_IsListEmpty(listHead);
MOCK_METHOD_END(int, result2)
MOCK_STATIC_METHOD_2(, void, DList_InsertTailList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, listEntry)
BASEIMPLEMENTATION::DList_InsertTailList(listHead, listEntry);
MOCK_VOID_METHOD_END()
MOCK_STATIC_METHOD_2(, void, DList_InsertHeadList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, listEntry)
BASEIMPLEMENTATION::DList_InsertHeadList(listHead, listEntry);
MOCK_VOID_METHOD_END()
MOCK_STATIC_METHOD_2(, void, DList_AppendTailList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, ListToAppend)
BASEIMPLEMENTATION::DList_AppendTailList(listHead, ListToAppend);
MOCK_VOID_METHOD_END()
MOCK_STATIC_METHOD_1(, int, DList_RemoveEntryList, PDLIST_ENTRY, listEntry)
int result2 = BASEIMPLEMENTATION::DList_RemoveEntryList(listEntry);
MOCK_METHOD_END(int, result2)
MOCK_STATIC_METHOD_1(, PDLIST_ENTRY, DList_RemoveHeadList, PDLIST_ENTRY, listHead)
PDLIST_ENTRY entry = BASEIMPLEMENTATION::DList_RemoveHeadList(listHead);
MOCK_METHOD_END(PDLIST_ENTRY, entry)
MOCK_STATIC_METHOD_1(, time_t, get_time, time_t*, t)
MOCK_METHOD_END(time_t, 0);
MOCK_STATIC_METHOD_4(, STRING_HANDLE, SASToken_Create, STRING_HANDLE, key, STRING_HANDLE, scope, STRING_HANDLE, keyName, size_t, expiry)
STRING_HANDLE tokenResult = BASEIMPLEMENTATION::STRING_new();
MOCK_METHOD_END(STRING_HANDLE, tokenResult);
};
DECLARE_GLOBAL_MOCK_METHOD_0(CMQTTAPIMocks, , LOCK_HANDLE, Lock_Init);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , LOCK_RESULT, Lock, LOCK_HANDLE, handle);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , LOCK_RESULT, Unlock, LOCK_HANDLE, handle);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , LOCK_RESULT, Lock_Deinit, LOCK_HANDLE, handle);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , void*, gballoc_malloc, size_t, size);
DECLARE_GLOBAL_MOCK_METHOD_2(CMQTTAPIMocks, , void*, gballoc_realloc, void*, ptr, size_t, size);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , void, gballoc_free, void*, ptr);
DECLARE_GLOBAL_MOCK_METHOD_0(CMQTTAPIMocks, , STRING_HANDLE, STRING_new);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , STRING_HANDLE, STRING_clone, STRING_HANDLE, handle);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , STRING_HANDLE, STRING_construct, const char*, s);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , void, STRING_delete, STRING_HANDLE, s);
DECLARE_GLOBAL_MOCK_METHOD_2(CMQTTAPIMocks, , int, STRING_concat, STRING_HANDLE, s1, const char*, s2);
DECLARE_GLOBAL_MOCK_METHOD_2(CMQTTAPIMocks, , int, STRING_concat_with_STRING, STRING_HANDLE, s1, STRING_HANDLE, s2);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , int, STRING_empty, STRING_HANDLE, s1);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , const char*, STRING_c_str, STRING_HANDLE, s);
DECLARE_GLOBAL_MOCK_METHOD_5(CMQTTAPIMocks, , int, MQTTClient_setCallbacks,MQTTClient, handle, void*, context, MQTTClient_connectionLost* ,cl, MQTTClient_messageArrived*, ma, MQTTClient_deliveryComplete*, dc);
DECLARE_GLOBAL_MOCK_METHOD_5(CMQTTAPIMocks, , int, MQTTClient_create, MQTTClient*, handle, const char*, serverURI, const char*, clientId, int, persistence_type, void*, persistence_context);
DECLARE_GLOBAL_MOCK_METHOD_2(CMQTTAPIMocks, , int, MQTTClient_connect, MQTTClient, handle, MQTTClient_connectOptions*, options);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , void, MQTTClient_free, void*, ptr);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , void, MQTTClient_destroy, MQTTClient*, handle);
DECLARE_GLOBAL_MOCK_METHOD_2(CMQTTAPIMocks, , int, MQTTClient_disconnect, MQTTClient, handle, int, timeout);
DECLARE_GLOBAL_MOCK_METHOD_3(CMQTTAPIMocks, , int, MQTTClient_subscribe, MQTTClient, handle, const char*, topic, int, qos);
DECLARE_GLOBAL_MOCK_METHOD_2(CMQTTAPIMocks, , int, MQTTClient_unsubscribe, MQTTClient, handle, const char*, topic);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, ,void, MQTTClient_freeMessage,MQTTClient_message**, msg);
DECLARE_GLOBAL_MOCK_METHOD_4(CMQTTAPIMocks, , int, MQTTClient_publishMessage, MQTTClient, handle, const char*, topicName, MQTTClient_message*, msg, MQTTClient_deliveryToken*, dt);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , void, DList_InitializeListHead, PDLIST_ENTRY, listHead);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , int, DList_IsListEmpty, PDLIST_ENTRY, listHead);
DECLARE_GLOBAL_MOCK_METHOD_2(CMQTTAPIMocks, , void, DList_InsertTailList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, listEntry);
DECLARE_GLOBAL_MOCK_METHOD_2(CMQTTAPIMocks, , void, DList_InsertHeadList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, listEntry);
DECLARE_GLOBAL_MOCK_METHOD_2(CMQTTAPIMocks, , void, DList_AppendTailList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, ListToAppend);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , int, DList_RemoveEntryList, PDLIST_ENTRY, listEntry);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , PDLIST_ENTRY, DList_RemoveHeadList, PDLIST_ENTRY, listHead);
DECLARE_GLOBAL_MOCK_METHOD_1(CMQTTAPIMocks, , time_t, get_time, time_t*, t)
DECLARE_GLOBAL_MOCK_METHOD_4(CMQTTAPIMocks, , STRING_HANDLE, SASToken_Create, STRING_HANDLE, key, STRING_HANDLE, scope, STRING_HANDLE, keyName, size_t, expiry)
static MICROMOCK_MUTEX_HANDLE g_testByTest;
static MICROMOCK_GLOBAL_SEMAPHORE_HANDLE g_dllByDll;
BEGIN_TEST_SUITE(mqttapi_paho_unittests)
TEST_SUITE_INITIALIZE(TestClassInitialize)
{
INITIALIZE_MEMORY_DEBUG(g_dllByDll);
g_testByTest = MicroMockCreateMutex();
ASSERT_IS_NOT_NULL(g_testByTest);
}
TEST_SUITE_CLEANUP(TestClassCleanup)
{
MicroMockDestroyMutex(g_testByTest);
DEINITIALIZE_MEMORY_DEBUG(g_dllByDll);
}
TEST_FUNCTION_INITIALIZE(TestMethodInitialize)
{
if (!MicroMockAcquireMutex(g_testByTest))
{
ASSERT_FAIL("our mutex is ABANDONED. Failure in test framework");
}
currentmalloc_call = 0;
whenShallmalloc_fail = 0;
currentrealloc_call = 0;
whenShallrealloc_fail = 0;
currentSTRING_new_call = 0;
whenShallSTRING_new_fail = 0;
currentSTRING_clone_call = 0;
whenShallSTRING_clone_fail = 0;
currentSTRING_construct_call = 0;
whenShallSTRING_construct_fail = 0;
currentSTRING_concat_call = 0;
whenShallSTRING_concat_fail = 0;
currentSTRING_empty_call = 0;
whenShallSTRING_empty_fail = 0;
currentSTRING_concat_with_STRING_call = 0;
whenShallSTRING_concat_with_STRING_fail = 0;
}
TEST_FUNCTION_CLEANUP(TestMethodCleanup)
{
if (!MicroMockReleaseMutex(g_testByTest))
{
ASSERT_FAIL("failure in test framework at ReleaseMutex");
}
}
/* Tests_SRS_MQTTAPI_04_011: [If any member of the parameter options is NULL or empty then MQTTAPI_Create shall return NULL.] */
TEST_FUNCTION(MQTTAPI_Create_with_NULL_options_fails)
{
/// arrange
CMQTTAPIMocks mocks;
/// act
auto result = MQTTAPI_Create(NULL);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
}
/* Tests_SRS_MQTTAPI_04_011: [If any member of the parameter options is NULL or empty then MQTTAPI_Create shall return NULL.] */
TEST_FUNCTION(MQTTAPI_Create_with_NULL_deviceId_fails)
{
/// arrange
CMQTTAPIMocks mocks;
const MQTTAPI_ConnectOptions TEST_CONFIG_MQTTAPIconnectionOptions_NULL_DEVICEID =
{
NULL,/*const char* deviceId; */
TEST_DEVICE_KEY,/*const char* deviceKey; */
TEST_IOTHUB_NAME,/*const char* serverURI; */
};
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions_NULL_DEVICEID);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
}
/* Tests_SRS_MQTTAPI_04_011: [If any member of the parameter options is NULL or empty then MQTTAPI_Create shall return NULL.] */
TEST_FUNCTION(MQTTAPI_Create_with_Empty_deviceId_fails)
{
/// arrange
CMQTTAPIMocks mocks;
const MQTTAPI_ConnectOptions TEST_CONFIG_MQTTAPIconnectionOptions_EMPTY_DEVICEID =
{
"",/*const char* deviceId; */
TEST_DEVICE_KEY,/*const char* deviceKey; */
TEST_IOTHUB_NAME,/*const char* serverURI; */
};
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions_EMPTY_DEVICEID);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
}
/* Tests_SRS_MQTTAPI_04_011: [If any member of the parameter options is NULL or empty then MQTTAPI_Create shall return NULL.] */
TEST_FUNCTION(MQTTAPI_Create_with_NULL_deviceKey_fails)
{
/// arrange
CMQTTAPIMocks mocks;
const MQTTAPI_ConnectOptions TEST_CONFIG_MQTTAPIconnectionOptions_NULL_DEVICEKEY =
{
TEST_DEVICE_ID,/*const char* deviceId; */
NULL,/*const char* deviceKey; */
TEST_IOTHUB_NAME,/*const char* serverURI; */
};
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions_NULL_DEVICEKEY);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
}
/* Tests_SRS_MQTTAPI_04_011: [If any member of the parameter options is NULL or empty then MQTTAPI_Create shall return NULL.] */
TEST_FUNCTION(MQTTAPI_Create_with_EMPTY_deviceKey_fails)
{
/// arrange
CMQTTAPIMocks mocks;
const MQTTAPI_ConnectOptions TEST_CONFIG_MQTTAPIconnectionOptions_EMPTY_DEVICEKEY =
{
TEST_DEVICE_ID,/*const char* deviceId; */
NULL,/*const char* deviceKey; */
TEST_IOTHUB_NAME,/*const char* serverURI; */
};
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions_EMPTY_DEVICEKEY);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
}
/* Tests_SRS_MQTTAPI_04_011: [If any member of the parameter options is NULL or empty then MQTTAPI_Create shall return NULL.] */
TEST_FUNCTION(MQTTAPI_Create_with_NULL_serverURI_fails)
{
/// arrange
CMQTTAPIMocks mocks;
const MQTTAPI_ConnectOptions TEST_CONFIG_MQTTAPIconnectionOptions_NULL_SERVERURI =
{
TEST_DEVICE_ID,/*const char* deviceId; */
TEST_DEVICE_KEY,/*const char* deviceKey; */
NULL,/*const char* serverURI; */
};
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions_NULL_SERVERURI);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
}
/* Tests_SRS_MQTTAPI_04_011: [If any member of the parameter options is NULL or empty then MQTTAPI_Create shall return NULL.] */
TEST_FUNCTION(MQTTAPI_Create_with_EMPTY_serverURI_fails)
{
/// arrange
CMQTTAPIMocks mocks;
const MQTTAPI_ConnectOptions TEST_CONFIG_MQTTAPIconnectionOptions_EMPTY_SERVERURI =
{
TEST_DEVICE_ID,/*const char* deviceId; */
TEST_DEVICE_KEY,/*const char* deviceKey; */
"",/*const char* serverURI; */
};
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions_EMPTY_SERVERURI);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
}
/* Tests_SRS_MQTTAPI_04_012: [Parameters deviceId, deviceKey and sasTokenSr shall be saved.] */
/* Tests_SRS_MQTTAPI_04_014: [Otherwise, MQTTAPI_Create shall return a MQTTAPI_HANDLE suitable for further calls to the module.] */
/* Tests_SRS_MQTTAPI_04_024: [MQTTAPI_Create shall call underlying library connection functions to establish connection with the server.] */
/* Tests_SRS_MQTTAPI_04_047: [Otherwise MQTTAPI_Create shall return a non-NULL MQTTAPI_HANDLE] */
TEST_FUNCTION(MQTTAPI_Create_with_valid_connectionOptions_succeed)
{
/// arrange
CMQTTAPIMocks mocks;
STRICT_EXPECTED_CALL(mocks, gballoc_malloc(IGNORED_NUM_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONFIG_MQTTAPIconnectionOptions.deviceId));
STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONFIG_MQTTAPIconnectionOptions.deviceKey));
STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONFIG_MQTTAPIconnectionOptions.sasTokenSr));
STRICT_EXPECTED_CALL(mocks, get_time(IGNORED_PTR_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, STRING_new());
STRICT_EXPECTED_CALL(mocks, SASToken_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, MQTTClient_create(IGNORED_PTR_ARG, TEST_CONFIG_MQTTAPIconnectionOptions.serverURI, TEST_CONFIG_MQTTAPIconnectionOptions.deviceId, MQTTCLIENT_PERSISTENCE_NONE, NULL))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, STRING_c_str(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, MQTTClient_setCallbacks(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_c_str(IGNORED_PTR_ARG))
.IgnoreAllArguments(); //UserName for connect.
STRICT_EXPECTED_CALL(mocks, STRING_c_str(IGNORED_PTR_ARG))
.IgnoreAllArguments(); //Password for connect.
STRICT_EXPECTED_CALL(mocks, MQTTClient_connect(IGNORED_PTR_ARG, IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, Lock_Init());
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions);
/// assert
ASSERT_IS_NOT_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
MQTTAPI_Destroy(result);
}
/* Tests_SRS_MQTTAPI_04_025: [If connection fails MQTTAPI_Create shall return NULL. */
TEST_FUNCTION(MQTTAPI_Create_MQTTClient_connect_fail_fails)
{
/// arrange
CMQTTAPIMocks mocks;
STRICT_EXPECTED_CALL(mocks, gballoc_malloc(IGNORED_NUM_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONFIG_MQTTAPIconnectionOptions.deviceId));
STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONFIG_MQTTAPIconnectionOptions.deviceKey));
STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONFIG_MQTTAPIconnectionOptions.sasTokenSr));
STRICT_EXPECTED_CALL(mocks, MQTTClient_create(IGNORED_PTR_ARG, TEST_CONFIG_MQTTAPIconnectionOptions.serverURI, TEST_CONFIG_MQTTAPIconnectionOptions.deviceId, MQTTCLIENT_PERSISTENCE_NONE, NULL))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, STRING_c_str(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, MQTTClient_setCallbacks(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_new());
STRICT_EXPECTED_CALL(mocks, get_time(IGNORED_PTR_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, SASToken_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_c_str(IGNORED_PTR_ARG))
.IgnoreAllArguments(); //UserName for connect.
STRICT_EXPECTED_CALL(mocks, STRING_c_str(IGNORED_PTR_ARG))
.IgnoreAllArguments(); //Password for connect.
STRICT_EXPECTED_CALL(mocks, MQTTClient_connect(IGNORED_PTR_ARG, IGNORED_PTR_ARG))
.IgnoreAllArguments()
.SetReturn(__LINE__);
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, MQTTClient_destroy(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, gballoc_free(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, Lock_Init());
STRICT_EXPECTED_CALL(mocks, Lock_Deinit(TEST_LOCK_HANDLE));
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
MQTTAPI_Destroy(result);
}
/* Tests_SRS_MQTTAPI_04_015: [If creating instance fails for any reason, then MQTTAPI_Create shall return NULL.] */
TEST_FUNCTION(MQTTAPI_Create_allocation_of_handledata_fails_fail)
{
/// arrange
CMQTTAPIMocks mocks;
whenShallmalloc_fail = 1;
STRICT_EXPECTED_CALL(mocks, gballoc_malloc(IGNORED_NUM_ARG))
.IgnoreArgument(1);
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
MQTTAPI_Destroy(result);
}
/* Tests_SRS_MQTTAPI_04_013: [If saving these parameters fail for any reason MQTTAPI_Create shall return NULL.] */
TEST_FUNCTION(MQTTAPI_Create_construct_deviceId_fail_fail)
{
/// arrange
CMQTTAPIMocks mocks;
STRICT_EXPECTED_CALL(mocks, gballoc_malloc(IGNORED_NUM_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, Lock_Init());
STRICT_EXPECTED_CALL(mocks, Lock_Deinit(TEST_LOCK_HANDLE));
whenShallSTRING_construct_fail = 1;
STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONFIG_MQTTAPIconnectionOptions.deviceId));
STRICT_EXPECTED_CALL(mocks, gballoc_free(IGNORED_PTR_ARG))
.IgnoreArgument(1);;
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
MQTTAPI_Destroy(result);
}
/* Tests_SRS_MQTTAPI_04_013: [If saving these parameters fail for any reason MQTTAPI_Create shall return NULL.] */
TEST_FUNCTION(MQTTAPI_Create_construct_deviceKey_fail_fail)
{
/// arrange
CMQTTAPIMocks mocks;
STRICT_EXPECTED_CALL(mocks, gballoc_malloc(IGNORED_NUM_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_InitializeListHead(IGNORED_PTR_ARG)).IgnoreArgument(1);
whenShallSTRING_construct_fail = 2;
STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONFIG_MQTTAPIconnectionOptions.deviceId));
STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONFIG_MQTTAPIconnectionOptions.deviceKey));
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, gballoc_free(IGNORED_PTR_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, Lock_Init());
STRICT_EXPECTED_CALL(mocks, Lock_Deinit(TEST_LOCK_HANDLE));
/// act
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions);
/// assert
ASSERT_IS_NULL(result);
mocks.AssertActualAndExpectedCalls();
///clenup
MQTTAPI_Destroy(result);
}
/* Tests_SRS_MQTTAPI_04_021: [If parameter instance is NULL then MQTTAPI_Destroy shall take no action.] */
TEST_FUNCTION(MQTTAPI_Destroy_with_NULL_instance_shall_do_nothing)
{
/// arrange
CMQTTAPIMocks mocks;
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions);
mocks.ResetAllCalls();
/// act
MQTTAPI_Destroy(NULL);
/// assert
mocks.AssertActualAndExpectedCalls();
///clenup
MQTTAPI_Destroy(result);
}
/* Tests_SRS_MQTTAPI_04_022: [MQTTAPI_Destroy shall free all resources used by MQTTAPI_HANDLE.] */
/* Tests_SRS_MQTTAPI_04_049: [If the instance is connected, MQTTAPI_Destroy shall disconnect the instance] */
TEST_FUNCTION(MQTTAPI_Destroy_shall_release_all_mqttapihandle_resources)
{
/// arrange
CMQTTAPIMocks mocks;
auto result = MQTTAPI_Create(&TEST_CONFIG_MQTTAPIconnectionOptions);
mocks.ResetAllCalls();
/// act
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, MQTTClient_disconnect(IGNORED_PTR_ARG, 0))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, MQTTClient_destroy(IGNORED_PTR_ARG))
.IgnoreAllArguments();
STRICT_EXPECTED_CALL(mocks, gballoc_free(IGNORED_PTR_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, Lock_Deinit(TEST_LOCK_HANDLE));
STRICT_EXPECTED_CALL(mocks, DList_RemoveHeadList(IGNORED_PTR_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_RemoveHeadList(IGNORED_PTR_ARG))
.IgnoreArgument(1);
STRICT_EXPECTED_CALL(mocks, DList_RemoveHeadList(IGNORED_PTR_ARG))
.IgnoreArgument(1);
MQTTAPI_Destroy(result);
/// assert
mocks.AssertActualAndExpectedCalls();
///clenup
}
END_TEST_SUITE(mqttapi_paho_unittests)

Просмотреть файл

@ -29,15 +29,12 @@ IF(WIN32)
ENDIF(WIN32)
include_directories(. ${SHARED_UTIL_INC_FOLDER} ${IOTHUB_CLIENT_INC_FOLDER})
link_directories(${whatIsBuilding}_dll ${SHARED_UTIL_LIB_DIR})
#link_directories(${whatIsBuilding}_dll ${SHARED_UTIL_LIB_DIR})
add_executable(simplesample_mqtt ${simplesample_mqtt_c_files} ${simplesample_mqtt_h_files})
target_link_libraries(simplesample_mqtt
iothub_client_mqtt_transport
serializer
iothub_client
iothub_client_mqtt_transport
)
linkSharedUtil(simplesample_mqtt)
linkPaho(simplesample_mqtt)

Просмотреть файл

@ -113,7 +113,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(PAHO_PATH)\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\$(Configuration)\paho-mqtt3cs.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>
@ -133,7 +133,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(PAHO_PATH)\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\$(Platform)\$(Configuration)\paho-mqtt3cs.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -153,7 +153,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>$(PAHO_PATH)\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\$(Configuration)\paho-mqtt3cs.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>
@ -177,7 +177,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>$(PAHO_PATH)\org.eclipse.paho.mqtt.c\Windows Build\paho-mqtt3cs\$(Platform)\$(Configuration)\paho-mqtt3cs.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />