PubSub Mqtt: add mqtt-c deps

This commit is contained in:
Lukas M 2018-09-03 12:06:39 +02:00 committed by Julius Pfrommer
parent 0b2ae29dac
commit 96ac93d268
4 changed files with 3339 additions and 1 deletions

View File

@ -51,7 +51,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
option(UA_ENABLE_AMALGAMATION "Concatenate the library to a single file open62541.h/.c" OFF)
option(UA_ENABLE_AMALGAMATION "Concatenate the library to a single file open62541.h/.c" ON)
set(UA_AMALGAMATION_ARCHITECTURES "" CACHE STRING "List of architectures to include in amalgamation")
mark_as_advanced(UA_AMALGAMATION_ARCHITECTURES)
@ -492,6 +492,8 @@ set(internal_headers ${PROJECT_SOURCE_DIR}/deps/queue.h
${PROJECT_SOURCE_DIR}/deps/atoi.h
#${PROJECT_SOURCE_DIR}/deps/musl/floatscan.h
#${PROJECT_SOURCE_DIR}/deps/musl/vfprintf.h
${PROJECT_SOURCE_DIR}/deps/mqtt-c/mqtt_pal.h
${PROJECT_SOURCE_DIR}/deps/mqtt-c/mqtt.h
${PROJECT_SOURCE_DIR}/src/ua_util_internal.h
${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.h
${PROJECT_SOURCE_DIR}/src/ua_types_encoding_json.h

1693
deps/mqtt-c/mqtt.c vendored Normal file

File diff suppressed because it is too large Load Diff

1538
deps/mqtt-c/mqtt.h vendored Normal file

File diff suppressed because it is too large Load Diff

105
deps/mqtt-c/mqtt_pal.h vendored Normal file
View File

@ -0,0 +1,105 @@
#ifndef __MQTT_PAL_H__
#define __MQTT_PAL_H__
/**
* @file
* @brief Includes/supports the types/calls required by the MQTT-C client.
*
* @note This is the \em only file included in mqtt.h, and mqtt.c. It is therefore
* responsible for including/supporting all the required types and calls.
*
* @defgroup pal Platform abstraction layer
* @brief Documentation of the types and calls required to port MQTT-C to a new platform.
*
* mqtt_pal.h is the \em only header file included in mqtt.c. Therefore, to port MQTT-C to a
* new platform the following types, functions, constants, and macros must be defined in
* mqtt_pal.h:
* - Types:
* - \c size_t, \c ssize_t
* - \c uint8_t, \c uint16_t, \c uint32_t
* - \c va_list
* - \c mqtt_pal_time_t : return type of \c MQTT_PAL_TIME()
* - \c mqtt_pal_mutex_t : type of the argument that is passed to \c MQTT_PAL_MUTEX_LOCK and
* \c MQTT_PAL_MUTEX_RELEASE
* - Functions:
* - \c memcpy, \c strlen
* - \c va_start, \c va_arg, \c va_end
* - Constants:
* - \c INT_MIN
*
* Additionally, three macro's are required:
* - \c MQTT_PAL_HTONS(s) : host-to-network endian conversion for uint16_t.
* - \c MQTT_PAL_NTOHS(s) : network-to-host endian conversion for uint16_t.
* - \c MQTT_PAL_TIME() : returns [type: \c mqtt_pal_time_t] current time in seconds.
* - \c MQTT_PAL_MUTEX_LOCK(mtx_pointer) : macro that locks the mutex pointed to by \c mtx_pointer.
* - \c MQTT_PAL_MUTEX_RELEASE(mtx_pointer) : macro that unlocks the mutex pointed to by
* \c mtx_pointer.
*
* Lastly, \ref mqtt_pal_sendall and \ref mqtt_pal_recvall, must be implemented in mqtt_pal.c
* for sending and receiving data using the platforms socket calls.
*/
/* UNIX-like platform support */
#ifdef __unix__
#include <limits.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include <arpa/inet.h>
#include <pthread.h>
#define MQTT_PAL_HTONS(s) htons(s)
#define MQTT_PAL_NTOHS(s) ntohs(s)
#define MQTT_PAL_TIME() time(NULL)
typedef time_t mqtt_pal_time_t;
typedef pthread_mutex_t mqtt_pal_mutex_t;
#define MQTT_PAL_MUTEX_INIT(mtx_ptr) pthread_mutex_init(mtx_ptr, NULL)
#define MQTT_PAL_MUTEX_LOCK(mtx_ptr) pthread_mutex_lock(mtx_ptr)
#define MQTT_PAL_MUTEX_UNLOCK(mtx_ptr) pthread_mutex_unlock(mtx_ptr)
struct my_custom_socket_handle {
void* client;
void* connection;
};
typedef struct my_custom_socket_handle* mqtt_pal_socket_handle;
/*#ifdef MQTT_USE_BIO
#include <openssl/bio.h>
typedef BIO* mqtt_pal_socket_handle;
#else
typedef int mqtt_pal_socket_handle;
#endif*/
#endif
/**
* @brief Sends all the bytes in a buffer.
* @ingroup pal
*
* @param[in] fd The file-descriptor (or handle) of the socket.
* @param[in] buf A pointer to the first byte in the buffer to send.
* @param[in] len The number of bytes to send (starting at \p buf).
* @param[in] flags Flags which are passed to the underlying socket.
*
* @returns The number of bytes sent if successful, an \ref MQTTErrors otherwise.
*/
ssize_t mqtt_pal_sendall(mqtt_pal_socket_handle fd, const void* buf, size_t len, int flags);
/**
* @brief Non-blocking receive all the byte available.
* @ingroup pal
*
* @param[in] fd The file-descriptor (or handle) of the socket.
* @param[in] buf A pointer to the receive buffer.
* @param[in] bufsz The max number of bytes that can be put into \p buf.
* @param[in] flags Flags which are passed to the underlying socket.
*
* @returns The number of bytes received if successful, an \ref MQTTErrors otherwise.
*/
ssize_t mqtt_pal_recvall(mqtt_pal_socket_handle fd, void* buf, size_t bufsz, int flags);
#endif /* __MQTT_PAL_H__ */