aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
Loading...
Searching...
No Matches
Mqtt5Client.h
Go to the documentation of this file.
1#pragma once
6#include <aws/crt/Config.h>
7#include <aws/crt/Exports.h>
10#include <aws/iot/MqttCommon.h>
11
12#if !BYO_CRYPTO
13
14namespace Aws
15{
16 using namespace Crt::Mqtt5;
17
18 namespace Crt
19 {
20 namespace Io
21 {
22 class ClientBootstrap;
23 class L4ProxyConfig;
24 class SocketOptions;
25 class TlsContextOptions;
26 class WebsocketConfig;
27 } // namespace Io
28 } // namespace Crt
29
30 namespace Iot
31 {
32
37 {
38 public:
42 Mqtt5CustomAuthConfig(Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
43 virtual ~Mqtt5CustomAuthConfig();
44
47
48 Mqtt5CustomAuthConfig &operator=(const Mqtt5CustomAuthConfig &rhs);
50
51 Mqtt5CustomAuthConfig &WithAuthorizerName(Crt::String authName);
52 Mqtt5CustomAuthConfig &WithUsername(Crt::String username);
53 Mqtt5CustomAuthConfig &WithPassword(Crt::ByteCursor password);
54 Mqtt5CustomAuthConfig &WithTokenKeyName(Crt::String tokenKeyName);
55 Mqtt5CustomAuthConfig &WithTokenValue(Crt::String tokenValue);
56 Mqtt5CustomAuthConfig &WithTokenSignature(Crt::String tokenSignature);
57
58 const Crt::Optional<Crt::String> &GetAuthorizerName();
59 const Crt::Optional<Crt::String> &GetUsername();
60 const Crt::Optional<Crt::ByteCursor> &GetPassword();
61 const Crt::Optional<Crt::String> &GetTokenKeyName();
62 const Crt::Optional<Crt::String> &GetTokenValue();
63 const Crt::Optional<Crt::String> &GetTokenSignature();
64
65 private:
72 Crt::Optional<Crt::String> m_authorizerName;
73
87
93
100 Crt::Optional<Crt::String> m_tokenKeyName;
101
108 Crt::Optional<Crt::String> m_tokenValue;
109
116 Crt::Optional<Crt::String> m_tokenSignature;
117
118 Crt::ByteBuf m_passwordStorage;
119 Crt::Allocator *m_allocator;
120 };
121
127 {
128 public:
140 static std::shared_ptr<Mqtt5ClientBuilder> CreateMqtt5ClientBuilderWithMtlsFromPath(
141 const Crt::String &hostName,
142 const char *certPath,
143 const char *pkeyPath,
144 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
145
157 static std::shared_ptr<Mqtt5ClientBuilder> CreateMqtt5ClientBuilderWithMtlsFromMemory(
158 const Crt::String &hostName,
159 const Crt::ByteCursor &cert,
160 const Crt::ByteCursor &pkey,
161 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
162
174 static std::shared_ptr<Mqtt5ClientBuilder> CreateMqtt5ClientBuilderWithMtlsPkcs11(
175 const Crt::String &hostName,
176 const Crt::Io::TlsContextPkcs11Options &pkcs11Options,
177 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
178
190 static std::shared_ptr<Mqtt5ClientBuilder> CreateMqtt5ClientBuilderWithMtlsPkcs12(
191 const Crt::String &hostName,
192 const struct Pkcs12Options &options,
193 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
194
208 static std::shared_ptr<Mqtt5ClientBuilder> CreateMqtt5ClientBuilderWithWindowsCertStorePath(
209 const Crt::String &hostName,
210 const char *windowsCertStorePath,
211 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
212
222 static std::shared_ptr<Mqtt5ClientBuilder> CreateMqtt5ClientBuilderWithWebsocket(
223 const Crt::String &hostName,
224 const WebsocketConfig &config,
225 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
226
236 static std::shared_ptr<Mqtt5ClientBuilder> CreateMqtt5ClientBuilderWithCustomAuthorizer(
237 const Crt::String &hostName,
238 const Mqtt5CustomAuthConfig &customAuthConfig,
239 Crt::Allocator *allocator) noexcept;
240
251 static std::shared_ptr<Mqtt5ClientBuilder> CreateMqtt5ClientBuilderWithCustomAuthorizerWebsocket(
252 const Crt::String &hostName,
253 const Mqtt5CustomAuthConfig &customAuthConfig,
254 const WebsocketConfig &config,
255 Crt::Allocator *allocator) noexcept;
256
264 Mqtt5ClientBuilder &WithHostName(Crt::String hostname);
265
273 Mqtt5ClientBuilder &WithPort(uint32_t port) noexcept;
274
283 Mqtt5ClientBuilder &WithBootstrap(Crt::Io::ClientBootstrap *bootStrap) noexcept;
284
293 Mqtt5ClientBuilder &WithCertificateAuthority(const char *caPath) noexcept;
294
303 Mqtt5ClientBuilder &WithCertificateAuthority(const Crt::ByteCursor &cert) noexcept;
304
315 Mqtt5ClientBuilder &WithTlsCipherPreference(aws_tls_cipher_pref cipherPref) noexcept;
316
324 Mqtt5ClientBuilder &WithSocketOptions(Crt::Io::SocketOptions socketOptions) noexcept;
325
333 Mqtt5ClientBuilder &WithHttpProxyOptions(
334 const Crt::Http::HttpClientConnectionProxyOptions &proxyOptions) noexcept;
335
343 Mqtt5ClientBuilder &WithL4ProxyOptions(
344 const std::shared_ptr<Aws::Crt::Io::L4ProxyConfig> &proxyOptions) noexcept;
345
351 Mqtt5ClientBuilder &WithCustomAuthorizer(const Iot::Mqtt5CustomAuthConfig &config) noexcept;
352
360 Mqtt5ClientBuilder &WithConnectOptions(std::shared_ptr<ConnectPacket> packetConnect) noexcept;
361
369 Mqtt5ClientBuilder &WithSessionBehavior(ClientSessionBehaviorType sessionBehavior) noexcept;
370
380 Mqtt5ClientBuilder &WithClientExtendedValidationAndFlowControl(
381 ClientExtendedValidationAndFlowControl clientExtendedValidationAndFlowControl) noexcept;
382
393 Mqtt5ClientBuilder &WithOfflineQueueBehavior(
394 ClientOperationQueueBehaviorType offlineQueueBehavior) noexcept;
395
404 Mqtt5ClientBuilder &WithReconnectOptions(ReconnectOptions reconnectOptions) noexcept;
405
412 Mqtt5ClientBuilder &WithTopicAliasingOptions(TopicAliasingOptions topicAliasingOptions) noexcept;
413
424 uint64_t minConnectedTimeToResetReconnectDelayMs) noexcept;
425
434 Mqtt5ClientBuilder &WithPingTimeoutMs(uint32_t pingTimeoutMs) noexcept;
435
444 Mqtt5ClientBuilder &WithConnackTimeoutMs(uint32_t connackTimeoutMs) noexcept;
445
454 Mqtt5ClientBuilder &WithAckTimeoutSec(uint32_t ackTimeoutSec) noexcept;
455
466 Mqtt5ClientBuilder &WithAckTimeoutSeconds(uint32_t ackTimeoutSec) noexcept;
467
475 Mqtt5ClientBuilder &WithSdkName(const Crt::String &sdkName);
476
484 Mqtt5ClientBuilder &WithSdkVersion(const Crt::String &sdkVersion);
485
491 std::shared_ptr<Mqtt5Client> Build() noexcept;
492
496 explicit operator bool() const noexcept { return m_lastError == 0; }
497
501 int LastError() const noexcept { return m_lastError ? m_lastError : AWS_ERROR_UNKNOWN; }
502
504 {
505 if (m_options)
506 {
507 delete m_options;
508 }
509 };
514
522 Mqtt5ClientBuilder &WithClientConnectionSuccessCallback(OnConnectionSuccessHandler callback) noexcept;
523
531 Mqtt5ClientBuilder &WithClientConnectionFailureCallback(OnConnectionFailureHandler callback) noexcept;
532
540 Mqtt5ClientBuilder &WithClientDisconnectionCallback(OnDisconnectionHandler callback) noexcept;
541
549 Mqtt5ClientBuilder &WithClientStoppedCallback(OnStoppedHandler callback) noexcept;
550
558 Mqtt5ClientBuilder &WithClientAttemptingConnectCallback(OnAttemptingConnectHandler callback) noexcept;
559
567 Mqtt5ClientBuilder &WithPublishReceivedCallback(OnPublishReceivedHandler callback) noexcept;
568
572 static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithMtlsFromPath(
573 const Crt::String hostName,
574 const char *certPath,
575 const char *pkeyPath,
576 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
577
581 static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithMtlsFromMemory(
582 const Crt::String hostName,
583 const Crt::ByteCursor &cert,
584 const Crt::ByteCursor &pkey,
585 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
586
590 static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithMtlsPkcs11(
591 const Crt::String hostName,
592 const Crt::Io::TlsContextPkcs11Options &pkcs11Options,
593 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
594
598 static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithMtlsPkcs12(
599 const Crt::String hostName,
600 const struct Pkcs12Options &options,
601 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
602
606 static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithWindowsCertStorePath(
607 const Crt::String hostName,
608 const char *windowsCertStorePath,
609 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
610
614 static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithWebsocket(
615 const Crt::String hostName,
616 const WebsocketConfig &config,
617 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
618
622 static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithCustomAuthorizer(
623 const Crt::String hostName,
624 const Mqtt5CustomAuthConfig &customAuthConfig,
625 Crt::Allocator *allocator) noexcept;
626
630 static Mqtt5ClientBuilder *NewMqtt5ClientBuilderWithCustomAuthorizerWebsocket(
631 const Crt::String hostName,
632 const Mqtt5CustomAuthConfig &customAuthConfig,
633 const WebsocketConfig &config,
634 Crt::Allocator *allocator) noexcept;
635
636 private:
637 // Common setup shared by all valid constructors
638 Mqtt5ClientBuilder(Crt::Allocator *allocator) noexcept;
639 // Common setup shared by all valid constructors
640 Mqtt5ClientBuilder(int error, Crt::Allocator *allocator) noexcept;
641
642 /*
643 * Creates a new Mqtt5ClientBuilder instance with default values.
644 */
645 static std::shared_ptr<Mqtt5ClientBuilder> CreateMqtt5ClientBuilder(
646 Crt::Allocator *allocator = Crt::ApiAllocator()) noexcept;
647
648 Crt::Allocator *m_allocator;
649
653 uint32_t m_port;
654
659 Crt::Optional<Crt::Io::TlsContextOptions> m_tlsConnectionOptions;
660
664 Crt::Optional<Crt::Http::HttpClientConnectionProxyOptions> m_proxyOptions;
665
666 std::shared_ptr<Aws::Crt::Io::L4ProxyConfig> m_l4ProxyOptions;
667
671 Crt::Optional<WebsocketConfig> m_websocketConfig;
672
676 Crt::Optional<Mqtt5CustomAuthConfig> m_customAuthConfig;
677
682 std::shared_ptr<ConnectPacket> m_connectOptions;
683
684 Crt::Mqtt5::Mqtt5ClientOptions *m_options;
685
686 /* Error */
687 int m_lastError;
688
690 bool m_enableMetricsCollection;
691 Crt::String m_sdkName;
692# ifdef AWS_IOT_SDK_VERSION
693 Crt::String m_sdkVersion = AWS_IOT_SDK_VERSION;
694# else
695 Crt::String m_sdkVersion = AWS_CRT_CPP_VERSION;
696# endif
697 };
698
699 } // namespace Iot
700} // namespace Aws
701
702#endif // !BYO_CRYPTO
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition Bootstrap.h:35
Definition SocketOptions.h:70
Definition TlsOptions.h:242
Definition Mqtt5Packets.h:672
Definition Mqtt5Client.h:503
Definition Mqtt5Client.h:127
Mqtt5ClientBuilder & operator=(const Mqtt5ClientBuilder &)=delete
Mqtt5ClientBuilder(const Mqtt5ClientBuilder &)=delete
Mqtt5ClientBuilder & operator=(Mqtt5ClientBuilder &&)=delete
Mqtt5ClientBuilder(Mqtt5ClientBuilder &&)=delete
Mqtt5ClientBuilder & WithMinConnectedTimeToResetReconnectDelayMs(uint64_t minConnectedTimeToResetReconnectDelayMs) noexcept
~Mqtt5ClientBuilder()
Definition Mqtt5Client.h:503
int LastError() const noexcept
Definition Mqtt5Client.h:501
Definition Mqtt5Client.h:37
Mqtt5CustomAuthConfig & operator=(Mqtt5CustomAuthConfig &&rhs)=delete
Mqtt5CustomAuthConfig(Mqtt5CustomAuthConfig &&rhs)=delete
aws_mqtt5_client_operation_queue_behavior_type ClientOperationQueueBehaviorType
Definition Mqtt5Types.h:223
aws_mqtt5_client_session_behavior_type ClientSessionBehaviorType
Definition Mqtt5Types.h:186
std::function< void(const PublishReceivedEventData &)> OnPublishReceivedHandler
Definition Mqtt5Client.h:344
std::function< void(const OnStoppedEventData &)> OnStoppedHandler
Definition Mqtt5Client.h:316
std::function< void(const OnDisconnectionEventData &)> OnDisconnectionHandler
Definition Mqtt5Client.h:304
std::function< void(const OnConnectionSuccessEventData &)> OnConnectionSuccessHandler
Definition Mqtt5Client.h:294
std::function< void(const OnAttemptingConnectEventData &)> OnAttemptingConnectHandler
Definition Mqtt5Client.h:310
std::function< void(const OnConnectionFailureEventData &)> OnConnectionFailureHandler
Definition Mqtt5Client.h:299
aws_mqtt5_extended_validation_and_flow_control_options ClientExtendedValidationAndFlowControl
Definition Mqtt5Types.h:200
aws_byte_cursor ByteCursor
Definition Types.h:31
aws_allocator Allocator
Definition Allocator.h:14
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition Types.h:45
aws_byte_buf ByteBuf
Definition Types.h:30
std::unique_ptr< T, std::function< void(T *)> > ScopedResource
Definition Types.h:168
Definition Allocator.h:11
Definition StringView.h:862
Definition Mqtt5Client.h:158
Definition Mqtt5Client.h:114
Definition MqttCommon.h:105
Definition MqttCommon.h:24