Files
neuron/plugins/mqtt/mqttc_util.h
T
gc87 f28bdb8270 Refactor the MQTT driver
- Add default initialization of variables
- Rename source file
2021-11-08 15:16:04 +08:00

117 lines
3.1 KiB
C

/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#ifndef NEURON_PLUGIN_MQTTC_UTIL
#define NEURON_PLUGIN_MQTTC_UTIL
#ifdef __cplusplus
extern "C" {
#endif
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <neuron.h>
typedef struct {
/* debug app options */
int publisher; /* publisher app? */
int quiet;
int verbose;
int tracelevel;
char *delimiter;
int maxdatalen;
/* message options */
char *message;
char *filename;
int stdin_lines;
int stdlin_complete;
int null_message;
/* MQTT options */
int MQTT_version; // 3-3_1, 4-3_3_1, 5-5
char *topic;
char *respons_topic;
char *clientid;
int qos;
int retained;
char *username;
char *password;
char *host;
char *port;
char *connection; // tcp://, ssl://, ws://, wss://
int keepalive;
int keepalive_interval;
int clean_session;
/* will options */
char *will_topic;
char *will_payload;
int will_qos;
int will_retain;
/* TLS options */
int insecure;
char *capath;
char *cert;
char *cafile;
char *key;
char *keypass;
char *ciphers;
char *psk_identity;
char *psk;
/* MQTT V5 options */
int message_expiry;
struct {
char *name;
char *value;
} user_property;
/* websocket HTTP proxies */
char *http_proxy;
char *https_proxy;
} option_t;
typedef enum {
MQTTC_SUCCESS = 0,
MQTTC_NO_CERTFILESET,
MQTTC_CERTFILE_LOAD_FAILURE,
MQTTC_IS_NULL,
MQTTC_CONNECT_FAILURE,
MQTTC_SUBSCRIBE_TIMEOUT,
MQTTC_SUBSCRIBE_LIST_INITIAL_FAILURE,
MQTTC_SUBSCRIBE_FAILURE,
MQTTC_SUBSCRIBE_ADD_REPEAT,
MQTTC_SUBSCRIBE_ADD_FAILURE,
MQTTC_UNSUBSCRIBE_FAILURE,
MQTTC_PUBLISH_FAILURE,
} client_error_e;
typedef void (*subscribe_handle)(const char *topic_name, size_t topic_len,
void *payload, const size_t len,
void *context);
SSL_CTX *ssl_ctx_init(const char *ca_file, const char *ca_path);
void ssl_ctx_uninit(SSL_CTX *ssl_ctx);
int mqtt_option_init(option_t *option);
void mqtt_option_uninit(option_t *option);
int mqtt_option_init_by_config(neu_config_t *config, option_t *option);
#ifdef __cplusplus
}
#endif
#endif