client_shared.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. Copyright (c) 2014-2020 Roger Light <roger@atchoo.org>
  3. All rights reserved. This program and the accompanying materials
  4. are made available under the terms of the Eclipse Public License 2.0
  5. and Eclipse Distribution License v1.0 which accompany this distribution.
  6. The Eclipse Public License is available at
  7. https://www.eclipse.org/legal/epl-2.0/
  8. and the Eclipse Distribution License is available at
  9. http://www.eclipse.org/org/documents/edl-v10.php.
  10. SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
  11. Contributors:
  12. Roger Light - initial implementation and documentation.
  13. */
  14. #ifndef CLIENT_CONFIG_H
  15. #define CLIENT_CONFIG_H
  16. #include <stdio.h>
  17. #ifdef WIN32
  18. # include <winsock2.h>
  19. #else
  20. # include <sys/time.h>
  21. #endif
  22. #ifndef __GNUC__
  23. #define __attribute__(attrib)
  24. #endif
  25. /* pub_client.c modes */
  26. #define MSGMODE_NONE 0
  27. #define MSGMODE_CMD 1
  28. #define MSGMODE_STDIN_LINE 2
  29. #define MSGMODE_STDIN_FILE 3
  30. #define MSGMODE_FILE 4
  31. #define MSGMODE_NULL 5
  32. #define CLIENT_PUB 1
  33. #define CLIENT_SUB 2
  34. #define CLIENT_RR 3
  35. #define CLIENT_RESPONSE_TOPIC 4
  36. #define PORT_UNDEFINED -1
  37. #define PORT_UNIX 0
  38. struct mosq_config {
  39. char *id;
  40. char *id_prefix;
  41. int protocol_version;
  42. int keepalive;
  43. char *host;
  44. int port;
  45. int qos;
  46. bool retain;
  47. int pub_mode; /* pub, rr */
  48. char *file_input; /* pub, rr */
  49. char *message; /* pub, rr */
  50. int msglen; /* pub, rr */
  51. char *topic; /* pub, rr */
  52. char *bind_address;
  53. int repeat_count; /* pub */
  54. struct timeval repeat_delay; /* pub */
  55. #ifdef WITH_SRV
  56. bool use_srv;
  57. #endif
  58. bool debug;
  59. bool quiet;
  60. unsigned int max_inflight;
  61. char *username;
  62. char *password;
  63. char *will_topic;
  64. char *will_payload;
  65. int will_payloadlen;
  66. int will_qos;
  67. bool will_retain;
  68. #ifdef WITH_TLS
  69. char *cafile;
  70. char *capath;
  71. char *certfile;
  72. char *keyfile;
  73. char *ciphers;
  74. bool insecure;
  75. char *tls_alpn;
  76. char *tls_version;
  77. char *tls_engine;
  78. char *tls_engine_kpass_sha1;
  79. char *keyform;
  80. bool tls_use_os_certs;
  81. # ifdef FINAL_WITH_TLS_PSK
  82. char *psk;
  83. char *psk_identity;
  84. # endif
  85. #endif
  86. bool clean_session;
  87. char **topics; /* sub, rr */
  88. int topic_count; /* sub, rr */
  89. bool exit_after_sub; /* sub */
  90. bool no_retain; /* sub */
  91. bool retained_only; /* sub */
  92. bool remove_retained; /* sub */
  93. char **filter_outs; /* sub */
  94. int filter_out_count; /* sub */
  95. char **unsub_topics; /* sub */
  96. int unsub_topic_count; /* sub */
  97. bool verbose; /* sub */
  98. bool eol; /* sub */
  99. int msg_count; /* sub */
  100. char *format; /* sub, rr */
  101. bool pretty; /* sub, rr */
  102. unsigned int timeout; /* sub */
  103. int sub_opts; /* sub */
  104. long session_expiry_interval;
  105. int random_filter; /* sub */
  106. #ifdef WITH_SOCKS
  107. char *socks5_host;
  108. int socks5_port;
  109. char *socks5_username;
  110. char *socks5_password;
  111. #endif
  112. mosquitto_property *connect_props;
  113. mosquitto_property *publish_props;
  114. mosquitto_property *subscribe_props;
  115. mosquitto_property *unsubscribe_props;
  116. mosquitto_property *disconnect_props;
  117. mosquitto_property *will_props;
  118. bool have_topic_alias; /* pub */
  119. char *response_topic; /* rr */
  120. bool tcp_nodelay;
  121. };
  122. int client_config_load(struct mosq_config *config, int pub_or_sub, int argc, char *argv[]);
  123. void client_config_cleanup(struct mosq_config *cfg);
  124. int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg);
  125. int client_id_generate(struct mosq_config *cfg);
  126. int client_connect(struct mosquitto *mosq, struct mosq_config *cfg);
  127. int cfg_parse_property(struct mosq_config *cfg, int argc, char *argv[], int *idx);
  128. void err_printf(const struct mosq_config *cfg, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
  129. #endif