@@ -47,8 +47,8 @@ static int s_reconnect_timeout_ms = 0;
47
47
static mgos_timer_id s_reconnect_timer_id = MGOS_INVALID_TIMER_ID ;
48
48
static struct mg_connection * s_conn = NULL ;
49
49
static bool s_connected = false;
50
- static mgos_mqtt_auth_callback_t s_auth_cb = NULL ;
51
- static void * s_auth_cb_arg = NULL ;
50
+ static mgos_mqtt_connect_fn_t s_connect_fn = NULL ;
51
+ static void * s_connect_fn_arg = NULL ;
52
52
static int s_max_qos = 2 ;
53
53
54
54
SLIST_HEAD (topic_handlers , topic_handler ) s_topic_handlers ;
@@ -121,30 +121,23 @@ static void mgos_mqtt_ev(struct mg_connection *nc, int ev, void *ev_data,
121
121
if (!success ) break ;
122
122
struct mg_send_mqtt_handshake_opts opts ;
123
123
memset (& opts , 0 , sizeof (opts ));
124
- char * cb_client_id = NULL , * cb_user = NULL , * cb_pass = NULL ;
125
- if (s_auth_cb != NULL ) {
126
- s_auth_cb (& cb_client_id , & cb_user , & cb_pass , s_auth_cb_arg );
127
- opts .user_name = cb_user ;
128
- opts .password = cb_pass ;
129
- } else {
130
- opts .user_name = mgos_sys_config_get_mqtt_user ();
131
- opts .password = mgos_sys_config_get_mqtt_pass ();
132
- }
124
+ // char *cb_client_id = NULL, *cb_user = NULL, *cb_pass = NULL;
125
+ opts .user_name = mgos_sys_config_get_mqtt_user ();
126
+ opts .password = mgos_sys_config_get_mqtt_pass ();
133
127
if (mgos_sys_config_get_mqtt_clean_session ()) {
134
128
opts .flags |= MG_MQTT_CLEAN_SESSION ;
135
129
}
136
130
opts .keep_alive = mgos_sys_config_get_mqtt_keep_alive ();
137
131
opts .will_topic = mgos_sys_config_get_mqtt_will_topic ();
138
132
opts .will_message = mgos_sys_config_get_mqtt_will_message ();
139
- const char * client_id =
140
- (cb_client_id != NULL ? cb_client_id
141
- : (mgos_sys_config_get_mqtt_client_id () != NULL
142
- ? mgos_sys_config_get_mqtt_client_id ()
143
- : mgos_sys_config_get_device_id ()));
144
- mg_send_mqtt_handshake_opt (nc , client_id , opts );
145
- free (cb_client_id );
146
- free (cb_user );
147
- free (cb_pass );
133
+ const char * client_id = (mgos_sys_config_get_mqtt_client_id () != NULL
134
+ ? mgos_sys_config_get_mqtt_client_id ()
135
+ : mgos_sys_config_get_device_id ());
136
+ if (s_connect_fn != NULL ) {
137
+ s_connect_fn (nc , client_id , & opts , s_connect_fn_arg );
138
+ } else {
139
+ mg_send_mqtt_handshake_opt (nc , client_id , opts );
140
+ }
148
141
break ;
149
142
}
150
143
case MG_EV_CLOSE : {
@@ -220,9 +213,9 @@ void mgos_mqtt_add_global_handler(mg_event_handler_t handler, void *ud) {
220
213
SLIST_INSERT_HEAD (& s_global_handlers , gh , entries );
221
214
}
222
215
223
- void mgos_mqtt_set_auth_callback ( mgos_mqtt_auth_callback_t cb , void * cb_arg ) {
224
- s_auth_cb = cb ;
225
- s_auth_cb_arg = cb_arg ;
216
+ void mgos_mqtt_set_connect_fn ( mgos_mqtt_connect_fn_t fn , void * fn_arg ) {
217
+ s_connect_fn = fn ;
218
+ s_connect_fn_arg = fn_arg ;
226
219
}
227
220
228
221
static void mgos_mqtt_net_ev (enum mgos_net_event ev ,
0 commit comments