22 | #define NOSTACKTRACE 1
23 |
24 | #if defined(NOSTACKTRACE)
25 | #define FUNC_ENTRY
26 | #define FUNC_ENTRY_NOLOG
27 | #define FUNC_ENTRY_MED
28 | #define FUNC_ENTRY_MAX
29 | #define FUNC_EXIT
30 | #define FUNC_EXIT_NOLOG
31 | #define FUNC_EXIT_MED
32 | #define FUNC_EXIT_MAX
33 | #define FUNC_EXIT_RC(x)
34 | #define FUNC_EXIT_MED_RC(x)
35 | #define FUNC_EXIT_MAX_RC(x)
36 |
37 | #else
38 |
39 | #if defined(WIN32)
40 | #define inline __inline
41 | #define FUNC_ENTRY StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MINIMUM)
42 | #define FUNC_ENTRY_NOLOG StackTrace_entry(__FUNCTION__, __LINE__, -1)
43 | #define FUNC_ENTRY_MED StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MEDIUM)
44 | #define FUNC_ENTRY_MAX StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MAXIMUM)
45 | #define FUNC_EXIT StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MINIMUM)
46 | #define FUNC_EXIT_NOLOG StackTrace_exit(__FUNCTION__, __LINE__, -1)
47 | #define FUNC_EXIT_MED StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MEDIUM)
48 | #define FUNC_EXIT_MAX StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MAXIMUM)
49 | #define FUNC_EXIT_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MINIMUM)
50 | #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MEDIUM)
51 | #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MAXIMUM)
52 | #else
53 | #define FUNC_ENTRY StackTrace_entry(__func__, __LINE__, TRACE_MINIMUM)
54 | #define FUNC_ENTRY_NOLOG StackTrace_entry(__func__, __LINE__, -1)
55 | #define FUNC_ENTRY_MED StackTrace_entry(__func__, __LINE__, TRACE_MEDIUM)
56 | #define FUNC_ENTRY_MAX StackTrace_entry(__func__, __LINE__, TRACE_MAXIMUM)
57 | #define FUNC_EXIT StackTrace_exit(__func__, __LINE__, NULL, TRACE_MINIMUM)
58 | #define FUNC_EXIT_NOLOG StackTrace_exit(__func__, __LINE__, NULL, -1)
59 | #define FUNC_EXIT_MED StackTrace_exit(__func__, __LINE__, NULL, TRACE_MEDIUM)
60 | #define FUNC_EXIT_MAX StackTrace_exit(__func__, __LINE__, NULL, TRACE_MAXIMUM)
61 | #define FUNC_EXIT_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MINIMUM)
62 | #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MEDIUM)
63 | #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MAXIMUM)
64 |
65 | void StackTrace_entry(const char* name, int line, int trace);
66 | void StackTrace_exit(const char* name, int line, void* return_value, int trace);
67 |
68 | void StackTrace_printStack(FILE* dest);
69 | char* StackTrace_get(unsigned long);
70 |
71 | #endif
72 |
73 | #endif
74 |
75 |
76 |
77 |
78 | #endif /* STACKTRACE_H_ */
79 |
--------------------------------------------------------------------------------
/MQTTPacket/test/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | PROJECT(mqttpacket-tests)
2 |
3 | IF (WIN32)
4 | SET(MQTT_TEST_BROKER "tcp://mqtt.iotree.co.uk:1883" CACHE STRING "Hostname of a test MQTT broker to use")
5 | SET(MQTT_TEST_PROXY "tcp://localhost:1883" CACHE STRING "Hostname of the test proxy to use")
6 | SET(MQTT_SSL_HOSTNAME "mqtt.iotree.co.uk" CACHE STRING "Hostname of a test SSL MQTT broker to use")
7 | SET(CERTDIR $ENV{APPVEYOR_BUILD_FOLDER}/test/ssl)
8 | ELSE ()
9 | SET(MQTT_TEST_BROKER "tcp://localhost:1883" CACHE STRING "Hostname of a test MQTT broker to use")
10 | SET(MQTT_TEST_PROXY "tcp://localhost:1884" CACHE STRING "Hostname of the test proxy to use")
11 | SET(MQTT_SSL_HOSTNAME "localhost" CACHE STRING "Hostname of a test SSL MQTT broker to use")
12 | SET(CERTDIR $ENV{TRAVIS_BUILD_DIR}/test/ssl)
13 | ENDIF ()
14 |
15 | include_directories(../src)
16 |
17 | ADD_EXECUTABLE(
18 | test1
19 | test1.c
20 | )
21 |
22 | TARGET_LINK_LIBRARIES(
23 | test1
24 | paho-embed-mqtt3c
25 | )
26 |
27 | ADD_TEST(
28 | NAME test1
29 | COMMAND "test1" "--connection" ${MQTT_TEST_BROKER}
30 | )
31 |
32 | SET_TESTS_PROPERTIES(
33 | test1
34 | PROPERTIES TIMEOUT 540
35 | )
36 |
--------------------------------------------------------------------------------
/MQTTPacket/test/build_test:
--------------------------------------------------------------------------------
1 | gcc -Wall test1.c -o test1 -I../src ../src/MQTTConnectClient.c ../src/MQTTConnectServer.c ../src/MQTTPacket.c ../src/MQTTSerializePublish.c ../src/MQTTDeserializePublish.c ../src/MQTTSubscribeServer.c ../src/MQTTSubscribeClient.c ../src/MQTTUnsubscribeServer.c ../src/MQTTUnsubscribeClient.c
2 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | #*******************************************************************************
2 | # Copyright (c) 2009, 2014 IBM Corp.
3 | #
4 | # All rights reserved. This program and the accompanying materials
5 | # are made available under the terms of the Eclipse Public License v1.0
6 | # and Eclipse Distribution License v1.0 which accompany this distribution.
7 | #
8 | # The Eclipse Public License is available at
9 | # http://www.eclipse.org/legal/epl-v10.html
10 | # and the Eclipse Distribution License is available at
11 | # http://www.eclipse.org/org/documents/edl-v10.php.
12 | #
13 | # Contributors:
14 | # Xiang Rong - 442039 Add makefile to Embedded C client
15 | #*******************************************************************************/
16 |
17 | # Note: on OS X you should install XCode and the associated command-line tools
18 |
19 | SHELL = /bin/sh
20 | .PHONY: clean, mkdir, install, uninstall, html
21 |
22 | # assume this is normally run in the main Paho directory
23 | ifndef srcdir
24 | srcdir = MQTTPacket/src
25 | endif
26 |
27 | ifndef blddir
28 | blddir = build/output
29 | endif
30 |
31 | ifndef prefix
32 | prefix = /usr/local
33 | endif
34 |
35 | ifndef exec_prefix
36 | exec_prefix = ${prefix}
37 | endif
38 |
39 | bindir = $(exec_prefix)/bin
40 | includedir = $(prefix)/include
41 | libdir = $(exec_prefix)/lib
42 |
43 | SOURCE_FILES_C = $(srcdir)/*.c
44 |
45 | HEADERS = $(srcdir)/*.h
46 |
47 |
48 | SAMPLE_FILES_C = pub0sub1 qos0pub
49 | SYNC_SAMPLES = ${addprefix ${blddir}/samples/,${SAMPLE_FILES_C}}
50 |
51 |
52 | TEST_FILES_C = test1
53 | SYNC_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_C}}
54 |
55 |
56 | # The names of libraries to be built
57 | MQTT_EMBED_LIB_C = paho-embed-mqtt3c
58 |
59 |
60 | # determine current platform
61 | ifeq ($(OS),Windows_NT)
62 | OSTYPE = $(OS)
63 | else
64 | OSTYPE = $(shell uname -s)
65 | MACHINETYPE = $(shell uname -m)
66 | endif
67 |
68 | ifeq ($(OSTYPE),Linux)
69 |
70 | CC ?= gcc
71 |
72 | ifndef INSTALL
73 | INSTALL = install
74 | endif
75 | INSTALL_PROGRAM = $(INSTALL)
76 | INSTALL_DATA = $(INSTALL) -m 644
77 |
78 | MAJOR_VERSION = 1
79 | MINOR_VERSION = 0
80 | VERSION = ${MAJOR_VERSION}.${MINOR_VERSION}
81 |
82 | EMBED_MQTTLIB_C_TARGET = ${blddir}/lib${MQTT_EMBED_LIB_C}.so.${VERSION}
83 |
84 |
85 | CCFLAGS_SO = -g -fPIC -Os -Wall -fvisibility=hidden -DLINUX_SO
86 | FLAGS_EXE = -I ${srcdir} -L ${blddir}
87 |
88 | LDFLAGS_C = -shared -Wl,-soname,lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION}
89 |
90 | all: build
91 |
92 | build: | mkdir ${EMBED_MQTTLIB_C_TARGET} ${SYNC_SAMPLES} ${SYNC_TESTS}
93 |
94 | clean:
95 | rm -rf ${blddir}/*
96 |
97 | mkdir:
98 | -mkdir -p ${blddir}/samples
99 | -mkdir -p ${blddir}/test
100 |
101 | ${SYNC_TESTS}: ${blddir}/test/%: ${srcdir}/../test/%.c
102 | ${CC} -g -o ${blddir}/test/${basename ${+F}} $< -l${MQTT_EMBED_LIB_C} ${FLAGS_EXE}
103 |
104 |
105 | ${SYNC_SAMPLES}: ${blddir}/samples/%: ${srcdir}/../samples/%.c ${srcdir}/../samples/transport.o
106 | ${CC} -o $@ $^ -l${MQTT_EMBED_LIB_C} ${FLAGS_EXE}
107 |
108 |
109 |
110 | ${EMBED_MQTTLIB_C_TARGET}: ${SOURCE_FILES_C} ${HEADERS_C}
111 | ${CC} ${CCFLAGS_SO} -o $@ ${SOURCE_FILES_C} ${LDFLAGS_C}
112 | -ln -s lib$(MQTT_EMBED_LIB_C).so.${VERSION} ${blddir}/lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION}
113 | -ln -s lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} ${blddir}/lib$(MQTT_EMBED_LIB_C).so
114 |
115 |
116 | strip_options:
117 | $(eval INSTALL_OPTS := -s)
118 |
119 | install-strip: build strip_options install
120 |
121 | install: build
122 | $(INSTALL_DATA) ${INSTALL_OPTS} ${EMBED_MQTTLIB_C_TARGET} $(DESTDIR)${libdir}
123 |
124 |
125 | /sbin/ldconfig $(DESTDIR)${libdir}
126 | ln -s lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so
127 |
128 |
129 | uninstall:
130 | rm $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so.${VERSION}
131 |
132 | /sbin/ldconfig $(DESTDIR)${libdir}
133 | rm $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so
134 |
135 |
136 | html:
137 |
138 | ARDUINO_LIB_FILES = MQTTClient/src/*.h MQTTClient/src/arduino/*.h $(srcdir)/*
139 | ARDUINO_SAMPLES = MQTTClient/samples/arduino/*
140 | LEGAL_FILES = edl-v10 epl-v10 notice.html about.html CONTRIBUTING.md README.md library.properties
141 |
142 | arduino: mkdir
143 | -mkdir -p ${blddir}/arduino/MQTTClient/examples
144 | -mkdir -p ${blddir}/arduino/MQTTClient/src
145 | cp $(ARDUINO_LIB_FILES) ${blddir}/arduino/MQTTClient/src
146 | cp $(LEGAL_FILES) ${blddir}/arduino/MQTTClient
147 | cp -R $(ARDUINO_SAMPLES) ${blddir}/arduino/MQTTClient/examples
148 | cd ${blddir}/arduino && zip -r arduino MQTTClient
149 |
150 | endif
151 |
152 |
153 |
154 | ifeq ($(OSTYPE),Darwin)
155 |
156 | CC ?= gcc
157 |
158 | ifndef INSTALL
159 | INSTALL = install
160 | endif
161 | INSTALL_PROGRAM = $(INSTALL)
162 | INSTALL_DATA = $(INSTALL) -m 644
163 |
164 | MAJOR_VERSION = 1
165 | MINOR_VERSION = 0
166 | VERSION = ${MAJOR_VERSION}.${MINOR_VERSION}
167 |
168 | EMBED_MQTTLIB_C_TARGET = ${blddir}/lib${MQTT_EMBED_LIB_C}.so.${VERSION}
169 |
170 |
171 | CCFLAGS_SO = -g -fPIC -Os -Wall -fvisibility=hidden -Wno-deprecated-declarations -DUSE_NAMED_SEMAPHORES
172 | FLAGS_EXE = -I ${srcdir} -L ${blddir}
173 |
174 | LDFLAGS_C = -shared -Wl,-install_name,lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION}
175 |
176 | all: build
177 |
178 | build: | mkdir ${EMBED_MQTTLIB_C_TARGET} ${SYNC_SAMPLES} ${SYNC_TESTS}
179 |
180 | clean:
181 | rm -rf ${blddir}/*
182 |
183 | mkdir:
184 | -mkdir -p ${blddir}/samples
185 | -mkdir -p ${blddir}/test
186 |
187 | ${SYNC_TESTS}: ${blddir}/test/%: ${srcdir}/../test/%.c
188 | ${CC} -g -o ${blddir}/test/${basename ${+F}} $< -l${MQTT_EMBED_LIB_C} ${FLAGS_EXE}
189 |
190 | ${SYNC_SAMPLES}: ${blddir}/samples/%: ${srcdir}/../samples/%.c
191 | ${CC} -o ${blddir}/samples/${basename ${+F}} $< ${FLAGS_EXE} -l${MQTT_EMBED_LIB_C}
192 |
193 | ${EMBED_MQTTLIB_C_TARGET}: ${SOURCE_FILES_C} ${HEADERS_C}
194 | ${CC} ${CCFLAGS_SO} -o $@ ${SOURCE_FILES_C} ${LDFLAGS_C}
195 | -ln -s lib$(MQTT_EMBED_LIB_C).so.${VERSION} ${blddir}/lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION}
196 | -ln -s lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} ${blddir}/lib$(MQTT_EMBED_LIB_C).so
197 |
198 |
199 | strip_options:
200 | $(eval INSTALL_OPTS := -s)
201 |
202 | install-strip: build strip_options install
203 |
204 | install: build
205 | $(INSTALL_DATA) ${INSTALL_OPTS} ${EMBED_MQTTLIB_C_TARGET} $(DESTDIR)${libdir}
206 |
207 | /sbin/ldconfig $(DESTDIR)${libdir}
208 | ln -s lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so
209 |
210 |
211 | uninstall:
212 | rm $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so.${VERSION}
213 | /sbin/ldconfig $(DESTDIR)${libdir}
214 | rm $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so
215 |
216 |
217 | html:
218 |
219 |
220 | endif
221 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | # Notices for Eclipse Paho
2 |
3 | This content is produced and maintained by the Eclipse Paho project.
4 |
5 | * Project home: https://projects.eclipse.org/projects/iot.paho
6 |
7 | ## Trademarks
8 |
9 | Paho™ is a trademark of the Eclipse Foundation.
10 |
11 | ## Copyright
12 |
13 | All content is the property of the respective authors or their employers. For
14 | more information regarding authorship of content, please consult the listed
15 | source code repository logs.
16 |
17 | ## Declared Project Licenses
18 |
19 | This program and the accompanying materials are made available under the terms
20 | of the Eclipse Public License v2.0 which is available at
21 | https://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
22 | v1.0 which is available at https://www.eclipse.org/org/documents/edl-v10.php.
23 |
24 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
25 |
26 | ## Source Code
27 |
28 | The project maintains the following source code repositories:
29 |
30 | * https://github.com/eclipse/paho-website
31 | * https://github.com/eclipse/paho.golang
32 | * https://github.com/eclipse/paho.mqtt-sn.embedded-c
33 | * https://github.com/eclipse/paho.mqtt-spy
34 | * https://github.com/eclipse/paho.mqtt.android
35 | * https://github.com/eclipse/paho.mqtt.c
36 | * https://github.com/eclipse/paho.mqtt.cpp
37 | * https://github.com/eclipse/paho.mqtt.d
38 | * https://github.com/eclipse/paho.mqtt.embedded-c
39 | * https://github.com/eclipse/paho.mqtt.golang
40 | * https://github.com/eclipse/paho.mqtt.java
41 | * https://github.com/eclipse/paho.mqtt.javascript
42 | * https://github.com/eclipse/paho.mqtt.m2mqtt
43 | * https://github.com/eclipse/paho.mqtt.python
44 | * https://github.com/eclipse/paho.mqtt.ruby
45 | * https://github.com/eclipse/paho.mqtt.rust
46 | * https://github.com/eclipse/paho.mqtt.testing
47 |
48 | ## Cryptography
49 |
50 | Content may contain encryption software. The country in which you are currently
51 | may have restrictions on the import, possession, and use, and/or re-export to
52 | another country, of encryption software. BEFORE using any encryption software,
53 | please check the country's laws, regulations and policies concerning the import,
54 | possession, or use, and re-export of encryption software, to see if this is
55 | permitted.
56 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Eclipse Paho MQTT C/C++ client for Embedded platforms
2 |
3 | This repository contains the source code for the [Eclipse Paho](http://eclipse.org/paho) MQTT C/C++ client library for Embedded platorms.
4 |
5 | It is dual licensed under the EPL and EDL (see about.html and notice.html for more details). You can choose which of these licenses you want to use the code under. The EDL allows you to embed the code into your application, and distribute your application in binary or source form without contributing any of your code, or any changes you make back to Paho. See the EDL for the exact conditions.
6 |
7 | There are three sub-projects:
8 |
9 | 1. MQTTPacket - simple de/serialization of MQTT packets, plus helper functions
10 | 2. MQTTClient - high(er) level C++ client, plus
11 | 3. MQTTClient-C - high(er) level C client (pretty much a clone of the C++ client)
12 |
13 | The *MQTTPacket* directory contains the lowest level C library with the smallest requirements. This supplies simple serialization
14 | and deserialization routines. They serve as a base for the higher level libraries, but can also be used on their own
15 | It is mainly up to you to write and read to and from the network.
16 |
17 | The *MQTTClient* directory contains the next level C++ library. This networking code is contained in separate classes so that you can plugin the
18 | network of your choice. Currently there are implementations for Linux, Arduino and mbed. ARM mbed was the first platform for which this was written,
19 | where the conventional language choice is C++, which explains the language choice. I have written a starter [Porting Guide](http://modelbasedtesting.co.uk/2014/08/25/porting-a-paho-embedded-c-client/).
20 |
21 | The *MQTTClient-C* directory contains a C equivalent of MQTTClient, for those platforms where C++ is not supported or the convention. As far
22 | as possible it is a direct translation from *MQTTClient*.
23 |
24 | ## Build requirements / compilation
25 |
26 | CMake builds for the various packages have been introduced, along with Travis-CI configuration for automated build & testing. The basic
27 | method of building on Linux is:
28 |
29 | ```
30 | mkdir build.paho
31 | cd build.paho
32 | cmake ..
33 | make
34 | ```
35 |
36 | The travis-build.sh file has the full build and test sequence for Linux.
37 |
38 |
39 | ## Usage and API
40 |
41 | See the samples directories for examples of intended use. Doxygen config files for each package are available in the doc directory.
42 |
43 | ## Runtime tracing
44 |
45 | The *MQTTClient* API has debug tracing for MQTT packets sent and received - turn this on by setting the MQTT_DEBUG preprocessor definition.
46 |
47 |
48 | ## Reporting bugs
49 |
50 | This project uses GitHub Issues here: [github.com/eclipse/paho.mqtt.embedded-c/issues](https://github.com/eclipse/paho.mqtt.embedded-c/issues) to track ongoing development and issues.
51 |
52 | ## More information
53 |
54 | Discussion of the Paho clients takes place on the [Eclipse Mattermost Paho channel](https://mattermost.eclipse.org/eclipse/channels/paho) and the [Eclipse paho-dev mailing list](https://dev.eclipse.org/mailman/listinfo/paho-dev).
55 |
56 | General questions about the MQTT protocol are discussed in the [MQTT Google Group](https://groups.google.com/forum/?hl=en-US&fromgroups#!forum/mqtt).
57 |
58 | More information is available via the [MQTT community](http://mqtt.org).
59 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | This project follows the [Eclipse Vulnerability Reporting Policy](https://www.eclipse.org/security/policy.php).
4 | Vulnerabilities are tracked by the Eclipse security team, in cooperation with the project lead.
5 | Fixing vulnerabilities is taken care of by the project committers, with assistance and guidance of the security
6 | team.
7 |
8 | ## Supported Versions
9 |
10 | Eclipse Paho provides security updates for the most recent version only.
11 |
12 | ## Reporting a Vulnerability
13 |
14 | We recommend that in case of suspected vulnerabilities you do not create a GitHub issue, but instead contact the
15 | Eclipse Security Team directly sending an email to security@eclipse.org.
16 |
17 |
--------------------------------------------------------------------------------
/about.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | About
5 |
6 |
7 | About This Content
8 |
9 | December 9, 2013
10 | License
11 |
12 | The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
13 | indicated below, the Content is provided to you under the terms and conditions of the
14 | Eclipse Public License Version 1.0 ("EPL") and Eclipse Distribution License Version 1.0 ("EDL").
15 | A copy of the EPL is available at
16 | http://www.eclipse.org/legal/epl-v10.html
17 | and a copy of the EDL is available at
18 | http://www.eclipse.org/org/documents/edl-v10.php.
19 | For purposes of the EPL, "Program" will mean the Content.
20 |
21 | If you did not receive this Content directly from the Eclipse Foundation, the Content is
22 | being redistributed by another party ("Redistributor") and different terms and conditions may
23 | apply to your use of any object code in the Content. Check the Redistributor's license that was
24 | provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
25 | indicated below, the terms and conditions of the EPL still apply to any source code in the Content
26 | and such source code may be obtained at http://www.eclipse.org.
27 |
28 |
29 |
--------------------------------------------------------------------------------
/doc/pahologo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eclipse-paho/paho.mqtt.embedded-c/32ad8d0d19ac982e32f5f4358adc00e5511ecff5/doc/pahologo.png
--------------------------------------------------------------------------------
/edl-v10:
--------------------------------------------------------------------------------
1 |
2 | Eclipse Distribution License - v 1.0
3 |
4 | Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
5 |
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9 |
10 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11 | 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.
12 | Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER 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.
15 |
16 |
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=MQTTClient
2 | version=1.0.0
3 | author=Ian Craggs
4 | maintainer=Ian Craggs https://github.com/icraggs
5 | sentence=This is the lowest level library, the simplest and smallest, but hardest to use. It simply deals with serialization and deserialization of MQTT packets.
6 | paragraph=...
7 | category=Communication
8 | url=https://github.com/eclipse/paho.mqtt.embedded-c
9 | architectures=*
10 |
--------------------------------------------------------------------------------
/test/mqttsas.py:
--------------------------------------------------------------------------------
1 | """
2 | *******************************************************************
3 | Copyright (c) 2013, 2018 IBM Corp.
4 |
5 | All rights reserved. This program and the accompanying materials
6 | are made available under the terms of the Eclipse Public License v1.0
7 | and Eclipse Distribution License v1.0 which accompany this distribution.
8 |
9 | The Eclipse Public License is available at
10 | http://www.eclipse.org/legal/epl-v10.html
11 | and the Eclipse Distribution License is available at
12 | http://www.eclipse.org/org/documents/edl-v10.php.
13 |
14 | Contributors:
15 | Ian Craggs - initial implementation and/or documentation
16 | Ian Craggs - add MQTTV5 support
17 | *******************************************************************
18 | """
19 | from __future__ import print_function
20 |
21 | import socket, sys, select, traceback, datetime, os
22 | try:
23 | import socketserver
24 | import MQTTV311 # Trace MQTT traffic - Python 3 version
25 | import MQTTV5
26 | except:
27 | traceback.print_exc()
28 | import SocketServer as socketserver
29 | import MQTTV3112 as MQTTV311 # Trace MQTT traffic - Python 2 version
30 | import MQTTV5
31 |
32 | MQTT = MQTTV311
33 | logging = True
34 | myWindow = None
35 |
36 |
37 | def timestamp():
38 | now = datetime.datetime.now()
39 | return now.strftime('%Y%m%d %H%M%S')+str(float("."+str(now.microsecond)))[1:]
40 |
41 | suspended = []
42 |
43 | class MyHandler(socketserver.StreamRequestHandler):
44 |
45 | def handle(self):
46 | global MQTT
47 | if not hasattr(self, "ids"):
48 | self.ids = {}
49 | if not hasattr(self, "versions"):
50 | self.versions = {}
51 | inbuf = True
52 | i = o = e = None
53 | try:
54 | clients = self.request
55 | brokers = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
56 | brokers.connect((brokerhost, brokerport))
57 | terminated = False
58 | while inbuf != None and not terminated:
59 | (i, o, e) = select.select([clients, brokers], [], [])
60 | for s in i:
61 | if s in suspended:
62 | print("suspended")
63 | if s == clients and s not in suspended:
64 | inbuf = MQTT.getPacket(clients) # get one packet
65 | if inbuf == None:
66 | break
67 | try:
68 | # if connect, this could be MQTTV3 or MQTTV5
69 | if inbuf[0] >> 4 == 1: # connect packet
70 | protocol_string = b'MQTT'
71 | pos = inbuf.find(protocol_string)
72 | if pos != -1:
73 | version = inbuf[pos + len(protocol_string)]
74 | if version == 5:
75 | MQTT = MQTTV5
76 | else:
77 | MQTT = MQTTV311
78 | packet = MQTT.unpackPacket(inbuf)
79 | if hasattr(packet.fh, "MessageType"):
80 | packet_type = packet.fh.MessageType
81 | publish_type = MQTT.PUBLISH
82 | connect_type = MQTT.CONNECT
83 | else:
84 | packet_type = packet.fh.PacketType
85 | publish_type = MQTT.PacketTypes.PUBLISH
86 | connect_type = MQTT.PacketTypes.CONNECT
87 | if packet_type == publish_type and \
88 | packet.topicName == "MQTTSAS topic" and \
89 | packet.data == b"TERMINATE":
90 | print("Terminating client", self.ids[id(clients)])
91 | brokers.close()
92 | clients.close()
93 | terminated = True
94 | break
95 | elif packet_type == publish_type and \
96 | packet.topicName == "MQTTSAS topic" and \
97 | packet.data == b"TERMINATE_SERVER":
98 | print("Suspending client ", self.ids[id(clients)])
99 | suspended.append(clients)
100 | elif packet_type == connect_type:
101 | self.ids[id(clients)] = packet.ClientIdentifier
102 | self.versions[id(clients)] = 3
103 | print(timestamp() , "C to S", self.ids[id(clients)], str(packet))
104 | #print([hex(b) for b in inbuf])
105 | #print(inbuf)
106 | except:
107 | traceback.print_exc()
108 | brokers.send(inbuf) # pass it on
109 | elif s == brokers:
110 | inbuf = MQTT.getPacket(brokers) # get one packet
111 | if inbuf == None:
112 | break
113 | try:
114 | print(timestamp(), "S to C", self.ids[id(clients)], str(MQTT.unpackPacket(inbuf)))
115 | except:
116 | traceback.print_exc()
117 | clients.send(inbuf)
118 | print(timestamp()+" client "+self.ids[id(clients)]+" connection closing")
119 | except:
120 | print(repr((i, o, e)), repr(inbuf))
121 | traceback.print_exc()
122 | if id(clients) in self.ids.keys():
123 | del self.ids[id(clients)]
124 | elif id(clients) in self.versions.keys():
125 | del self.versions[id(clients)]
126 |
127 | class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
128 | pass
129 |
130 | def run():
131 | global brokerhost, brokerport
132 | myhost = '127.0.0.1'
133 | if len(sys.argv) > 1:
134 | brokerhost = sys.argv[1]
135 | else:
136 | brokerhost = '127.0.0.1'
137 |
138 | if len(sys.argv) > 2:
139 | brokerport = int(sys.argv[2])
140 | else:
141 | brokerport = 1883
142 |
143 | if len(sys.argv) > 3:
144 | myport = int(sys.argv[3])
145 | else:
146 | if brokerhost == myhost:
147 | myport = brokerport + 1
148 | else:
149 | myport = 1883
150 |
151 | print("Listening on port", str(myport)+", broker on port", brokerport)
152 | s = ThreadingTCPServer(("127.0.0.1", myport), MyHandler)
153 | s.serve_forever()
154 |
155 | if __name__ == "__main__":
156 | run()
157 |
--------------------------------------------------------------------------------
/test/mqttsas2.py:
--------------------------------------------------------------------------------
1 | """
2 | *******************************************************************
3 | Copyright (c) 2013, 2017 IBM Corp.
4 |
5 | All rights reserved. This program and the accompanying materials
6 | are made available under the terms of the Eclipse Public License v1.0
7 | and Eclipse Distribution License v1.0 which accompany this distribution.
8 |
9 | The Eclipse Public License is available at
10 | http://www.eclipse.org/legal/epl-v10.html
11 | and the Eclipse Distribution License is available at
12 | http://www.eclipse.org/org/documents/edl-v10.php.
13 |
14 | Contributors:
15 | Ian Craggs - initial implementation and/or documentation
16 | *******************************************************************
17 | """
18 | from __future__ import print_function
19 |
20 | # Trace MQTT traffic
21 | import MQTTV3112 as MQTTV3
22 |
23 | import socket, sys, select, traceback, datetime, os
24 | import SocketServer as socketserver
25 |
26 | logging = True
27 | myWindow = None
28 |
29 |
30 | def timestamp():
31 | now = datetime.datetime.now()
32 | return now.strftime('%Y%m%d %H%M%S')+str(float("."+str(now.microsecond)))[1:]
33 |
34 |
35 | class MyHandler(socketserver.StreamRequestHandler):
36 |
37 | def handle(self):
38 | if not hasattr(self, "ids"):
39 | self.ids = {}
40 | if not hasattr(self, "versions"):
41 | self.versions = {}
42 | inbuf = True
43 | i = o = e = None
44 | try:
45 | clients = self.request
46 | brokers = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
47 | brokers.connect((brokerhost, brokerport))
48 | terminated = False
49 | while inbuf != None and not terminated:
50 | (i, o, e) = select.select([clients, brokers], [], [])
51 | for s in i:
52 | if s == clients:
53 | inbuf = MQTTV3.getPacket(clients) # get one packet
54 | if inbuf == None:
55 | break
56 | try:
57 | packet = MQTTV3.unpackPacket(inbuf)
58 | if packet.fh.MessageType == MQTTV3.PUBLISH and \
59 | packet.topicName == "MQTTSAS topic" and \
60 | packet.data == b"TERMINATE":
61 | print("Terminating client", self.ids[id(clients)])
62 | brokers.close()
63 | clients.close()
64 | terminated = True
65 | break
66 | elif packet.fh.MessageType == MQTTV3.CONNECT:
67 | self.ids[id(clients)] = packet.ClientIdentifier
68 | self.versions[id(clients)] = 3
69 | print(timestamp() , "C to S", self.ids[id(clients)], repr(packet))
70 | #print([hex(b) for b in inbuf])
71 | #print(inbuf)
72 | except:
73 | traceback.print_exc()
74 | brokers.send(inbuf) # pass it on
75 | elif s == brokers:
76 | inbuf = MQTTV3.getPacket(brokers) # get one packet
77 | if inbuf == None:
78 | break
79 | try:
80 | print(timestamp(), "S to C", self.ids[id(clients)], repr(MQTTV3.unpackPacket(inbuf)))
81 | except:
82 | traceback.print_exc()
83 | clients.send(inbuf)
84 | print(timestamp()+" client "+self.ids[id(clients)]+" connection closing")
85 | except:
86 | print(repr((i, o, e)), repr(inbuf))
87 | traceback.print_exc()
88 | if id(clients) in self.ids.keys():
89 | del self.ids[id(clients)]
90 | elif id(clients) in self.versions.keys():
91 | del self.versions[id(clients)]
92 |
93 | class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
94 | pass
95 |
96 | def run():
97 | global brokerhost, brokerport
98 | myhost = '127.0.0.1'
99 | if len(sys.argv) > 1:
100 | brokerhost = sys.argv[1]
101 | else:
102 | brokerhost = '127.0.0.1'
103 |
104 | if len(sys.argv) > 2:
105 | brokerport = int(sys.argv[2])
106 | else:
107 | brokerport = 1883
108 |
109 | if len(sys.argv) > 3:
110 | myport = int(sys.argv[3])
111 | else:
112 | if brokerhost == myhost:
113 | myport = brokerport + 1
114 | else:
115 | myport = 1883
116 |
117 | print("Listening on port", str(myport)+", broker on port", brokerport)
118 | s = ThreadingTCPServer(("127.0.0.1", myport), MyHandler)
119 | s.serve_forever()
120 |
121 | if __name__ == "__main__":
122 | run()
123 |
--------------------------------------------------------------------------------
/travis-build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | rm -rf build.paho
6 | mkdir build.paho
7 | cd build.paho
8 | echo "travis build dir $TRAVIS_BUILD_DIR pwd $PWD"
9 | cmake ..
10 | make
11 | python3 ../test/mqttsas.py localhost 1883 1885 &
12 | ctest -VV --timeout 600
13 | kill %1
14 | #killall mosquitto
15 |
--------------------------------------------------------------------------------
/travis-env-vars:
--------------------------------------------------------------------------------
1 | export TRAVIS_OS_NAME=linux
2 | export TRAVIS_BUILD_DIR=/home/icraggs/git/paho.mqtt.embedded-c
3 |
--------------------------------------------------------------------------------
/travis-install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ "$TRAVIS_OS_NAME" == "linux" ]; then
4 | pwd
5 | sudo service mosquitto stop
6 | # Stop any mosquitto instance which may be still running from previous runs
7 | killall mosquitto
8 | mosquitto -h
9 | mosquitto &
10 | fi
11 |
12 | if [ "$TRAVIS_OS_NAME" == "osx" ]; then
13 | pwd
14 | brew update
15 | brew install openssl mosquitto
16 | brew services stop mosquitto
17 | /usr/local/sbin/mosquitto -h
18 | /usr/local/sbin/mosquitto &
19 | fi
20 |
--------------------------------------------------------------------------------