2014-05-25 00:04:42 +02:00
|
|
|
/*
|
2021-11-03 23:08:24 +01:00
|
|
|
Copyright (c) 2014-2021 Roger Light <roger@atchoo.org>
|
2014-05-25 00:04:42 +02:00
|
|
|
|
|
|
|
|
All rights reserved. This program and the accompanying materials
|
2020-11-25 18:34:21 +01:00
|
|
|
are made available under the terms of the Eclipse Public License 2.0
|
2014-05-25 00:04:42 +02:00
|
|
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
2021-10-05 16:20:37 +02:00
|
|
|
|
2014-05-25 00:04:42 +02:00
|
|
|
The Eclipse Public License is available at
|
2020-11-25 18:34:21 +01:00
|
|
|
https://www.eclipse.org/legal/epl-2.0/
|
2014-05-25 00:04:42 +02:00
|
|
|
and the Eclipse Distribution License is available at
|
|
|
|
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
2021-10-05 16:20:37 +02:00
|
|
|
|
2021-01-20 12:46:18 +01:00
|
|
|
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
2020-12-01 19:21:59 +01:00
|
|
|
|
2014-05-25 00:04:42 +02:00
|
|
|
Contributors:
|
|
|
|
|
Roger Light - initial implementation and documentation.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-21 11:33:55 +01:00
|
|
|
#ifndef CLIENT_SHARED_H
|
|
|
|
|
#define CLIENT_SHARED_H
|
2014-05-25 00:04:42 +02:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2019-04-25 22:22:51 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
|
# include <winsock2.h>
|
|
|
|
|
#else
|
|
|
|
|
# include <sys/time.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-03 16:00:08 +01:00
|
|
|
#ifdef WITH_TLS
|
|
|
|
|
# include <openssl/ssl.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-03-21 23:50:48 +01:00
|
|
|
#ifndef __GNUC__
|
|
|
|
|
#define __attribute__(attrib)
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-05-25 00:04:42 +02:00
|
|
|
/* pub_client.c modes */
|
|
|
|
|
#define MSGMODE_NONE 0
|
|
|
|
|
#define MSGMODE_CMD 1
|
|
|
|
|
#define MSGMODE_STDIN_LINE 2
|
|
|
|
|
#define MSGMODE_STDIN_FILE 3
|
|
|
|
|
#define MSGMODE_FILE 4
|
|
|
|
|
#define MSGMODE_NULL 5
|
|
|
|
|
|
|
|
|
|
#define CLIENT_PUB 1
|
|
|
|
|
#define CLIENT_SUB 2
|
2019-03-30 22:19:51 +01:00
|
|
|
#define CLIENT_RR 3
|
|
|
|
|
#define CLIENT_RESPONSE_TOPIC 4
|
2014-05-25 00:04:42 +02:00
|
|
|
|
2019-10-08 21:49:34 +02:00
|
|
|
#define PORT_UNDEFINED -1
|
|
|
|
|
#define PORT_UNIX 0
|
|
|
|
|
|
2014-05-25 00:04:42 +02:00
|
|
|
struct mosq_config {
|
|
|
|
|
char *id;
|
|
|
|
|
char *id_prefix;
|
2015-01-27 01:32:20 +01:00
|
|
|
int protocol_version;
|
2014-05-25 00:04:42 +02:00
|
|
|
int keepalive;
|
|
|
|
|
char *host;
|
|
|
|
|
int port;
|
|
|
|
|
int qos;
|
|
|
|
|
bool retain;
|
2019-03-30 22:19:51 +01:00
|
|
|
int pub_mode; /* pub, rr */
|
|
|
|
|
char *file_input; /* pub, rr */
|
|
|
|
|
char *message; /* pub, rr */
|
2020-04-17 00:26:14 +02:00
|
|
|
int msglen; /* pub, rr */
|
2019-03-30 22:19:51 +01:00
|
|
|
char *topic; /* pub, rr */
|
2014-05-25 00:04:42 +02:00
|
|
|
char *bind_address;
|
2019-04-11 20:13:59 +02:00
|
|
|
int repeat_count; /* pub */
|
|
|
|
|
struct timeval repeat_delay; /* pub */
|
2014-11-12 21:47:16 +01:00
|
|
|
#ifdef WITH_SRV
|
2014-05-25 00:04:42 +02:00
|
|
|
bool use_srv;
|
2014-11-12 21:47:16 +01:00
|
|
|
#endif
|
2014-05-25 00:04:42 +02:00
|
|
|
bool debug;
|
|
|
|
|
bool quiet;
|
|
|
|
|
unsigned int max_inflight;
|
|
|
|
|
char *username;
|
|
|
|
|
char *password;
|
|
|
|
|
char *will_topic;
|
|
|
|
|
char *will_payload;
|
2020-04-17 00:26:14 +02:00
|
|
|
int will_payloadlen;
|
2014-05-25 00:04:42 +02:00
|
|
|
int will_qos;
|
|
|
|
|
bool will_retain;
|
|
|
|
|
#ifdef WITH_TLS
|
|
|
|
|
char *cafile;
|
|
|
|
|
char *capath;
|
|
|
|
|
char *certfile;
|
|
|
|
|
char *keyfile;
|
|
|
|
|
char *ciphers;
|
|
|
|
|
bool insecure;
|
2019-04-11 12:52:34 +02:00
|
|
|
char *tls_alpn;
|
2014-05-25 00:04:42 +02:00
|
|
|
char *tls_version;
|
2018-08-09 21:37:33 +02:00
|
|
|
char *tls_engine;
|
2019-02-26 18:11:29 +01:00
|
|
|
char *tls_engine_kpass_sha1;
|
2018-08-09 21:37:33 +02:00
|
|
|
char *keyform;
|
2020-12-01 12:51:13 +01:00
|
|
|
bool tls_use_os_certs;
|
2023-03-03 16:00:08 +01:00
|
|
|
char *tls_keylog;
|
|
|
|
|
SSL_CTX *ssl_ctx;
|
2018-12-09 14:40:38 +01:00
|
|
|
# ifdef FINAL_WITH_TLS_PSK
|
2014-05-25 00:04:42 +02:00
|
|
|
char *psk;
|
|
|
|
|
char *psk_identity;
|
|
|
|
|
# endif
|
2014-05-26 00:41:17 +02:00
|
|
|
#endif
|
2017-07-17 21:43:06 +02:00
|
|
|
bool clean_session;
|
2019-10-15 15:44:25 +02:00
|
|
|
char **topics; /* sub, rr */
|
|
|
|
|
int topic_count; /* sub, rr */
|
2018-09-27 23:16:38 +02:00
|
|
|
bool exit_after_sub; /* sub */
|
2014-05-25 00:04:42 +02:00
|
|
|
bool no_retain; /* sub */
|
2016-02-02 21:57:37 +01:00
|
|
|
bool retained_only; /* sub */
|
2019-03-02 23:14:54 +01:00
|
|
|
bool remove_retained; /* sub */
|
2014-05-25 00:04:42 +02:00
|
|
|
char **filter_outs; /* sub */
|
|
|
|
|
int filter_out_count; /* sub */
|
2015-12-29 21:15:00 +01:00
|
|
|
char **unsub_topics; /* sub */
|
|
|
|
|
int unsub_topic_count; /* sub */
|
2014-05-25 00:04:42 +02:00
|
|
|
bool verbose; /* sub */
|
|
|
|
|
bool eol; /* sub */
|
2015-01-30 23:23:51 +01:00
|
|
|
int msg_count; /* sub */
|
2019-10-15 15:44:25 +02:00
|
|
|
char *format; /* sub, rr */
|
|
|
|
|
bool pretty; /* sub, rr */
|
2020-04-17 00:26:14 +02:00
|
|
|
unsigned int timeout; /* sub */
|
2018-12-14 14:21:53 +01:00
|
|
|
int sub_opts; /* sub */
|
2020-01-30 12:19:09 +01:00
|
|
|
long session_expiry_interval;
|
2020-03-03 15:12:30 +01:00
|
|
|
int random_filter; /* sub */
|
2021-09-10 00:55:33 +02:00
|
|
|
int transport;
|
2022-07-21 16:51:52 +02:00
|
|
|
#ifndef WIN32
|
2021-06-25 12:48:49 +02:00
|
|
|
bool watch; /* sub */
|
2022-07-21 16:51:52 +02:00
|
|
|
#endif
|
2014-09-30 01:56:57 +02:00
|
|
|
#ifdef WITH_SOCKS
|
|
|
|
|
char *socks5_host;
|
|
|
|
|
int socks5_port;
|
|
|
|
|
char *socks5_username;
|
|
|
|
|
char *socks5_password;
|
|
|
|
|
#endif
|
2018-10-31 13:38:39 +01:00
|
|
|
mosquitto_property *connect_props;
|
|
|
|
|
mosquitto_property *publish_props;
|
|
|
|
|
mosquitto_property *subscribe_props;
|
|
|
|
|
mosquitto_property *unsubscribe_props;
|
|
|
|
|
mosquitto_property *disconnect_props;
|
|
|
|
|
mosquitto_property *will_props;
|
2019-03-30 22:19:51 +01:00
|
|
|
char *response_topic; /* rr */
|
2021-04-10 01:39:54 +02:00
|
|
|
char *options_file;
|
2021-04-15 10:52:34 +02:00
|
|
|
bool have_topic_alias; /* pub */
|
|
|
|
|
bool tcp_nodelay;
|
|
|
|
|
bool no_tls;
|
2014-05-25 00:04:42 +02:00
|
|
|
};
|
|
|
|
|
|
2024-02-26 01:19:32 +01:00
|
|
|
extern const char hexseplist[32];
|
|
|
|
|
|
2014-05-25 00:04:42 +02:00
|
|
|
int client_config_load(struct mosq_config *config, int pub_or_sub, int argc, char *argv[]);
|
2014-11-17 00:41:06 +01:00
|
|
|
void client_config_cleanup(struct mosq_config *cfg);
|
2014-05-25 00:04:42 +02:00
|
|
|
int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg);
|
2023-01-16 19:46:35 +01:00
|
|
|
int clientid_generate(struct mosq_config *cfg);
|
2014-05-25 00:04:42 +02:00
|
|
|
int client_connect(struct mosquitto *mosq, struct mosq_config *cfg);
|
|
|
|
|
|
2018-10-31 13:38:39 +01:00
|
|
|
int cfg_parse_property(struct mosq_config *cfg, int argc, char *argv[], int *idx);
|
|
|
|
|
|
2021-03-21 23:50:48 +01:00
|
|
|
void err_printf(const struct mosq_config *cfg, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
2014-05-25 00:04:42 +02:00
|
|
|
#endif
|