Improve some messages when client disconnects.

pull/1239/head
Roger A. Light 7 years ago
parent fb1979c0ea
commit baf1909ffb

@ -333,6 +333,12 @@ bool mosquitto_want_write(struct mosquitto *mosq)
const char *mosquitto_strerror(int mosq_errno)
{
switch(mosq_errno){
case MOSQ_ERR_AUTH_CONTINUE:
return "Continue with authentication.";
case MOSQ_ERR_NO_SUBSCRIBERS:
return "No subscribers.";
case MOSQ_ERR_SUB_EXISTS:
return "Subscription already exists.";
case MOSQ_ERR_CONN_PENDING:
return "Connection pending.";
case MOSQ_ERR_SUCCESS:
@ -379,6 +385,8 @@ const char *mosquitto_strerror(int mosq_errno)
return "Requested QoS not supported on server.";
case MOSQ_ERR_OVERSIZE_PACKET:
return "Packet larger than supported by the server.";
case MOSQ_ERR_OCSP:
return "OCSP error.";
default:
return "Unknown error.";
}

@ -160,7 +160,7 @@ int connect__on_authorised(struct mosquitto_db *db, struct mosquitto *context, v
found_context->clean_start = true;
found_context->session_expiry_interval = 0;
context__set_state(found_context, mosq_cs_duplicate);
do_disconnect(db, found_context);
do_disconnect(db, found_context, MOSQ_ERR_SUCCESS);
}
rc = acl__find_acls(db, context);

@ -59,7 +59,7 @@ int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context)
log__printf(NULL, MOSQ_LOG_DEBUG, "Received DISCONNECT from %s", context->id);
if(context->protocol == mosq_p_mqtt311 || context->protocol == mosq_p_mqtt5){
if((context->in_packet.command&0x0F) != 0x00){
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_PROTOCOL);
return MOSQ_ERR_PROTOCOL;
}
}
@ -68,6 +68,6 @@ int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context)
}else{
context__set_state(context, mosq_cs_disconnecting);
}
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_SUCCESS);
return MOSQ_ERR_SUCCESS;
}

@ -92,7 +92,7 @@ static void temp__expire_websockets_clients(struct mosquitto_db *db)
}
}
/* Client has exceeded keepalive*1.5 */
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_KEEPALIVE);
}
}
}
@ -314,19 +314,11 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
pollfd_index++;
#endif
}else{
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_CONN_LOST);
}
}else{
if(db->config->connection_messages == true){
if(context->id){
id = context->id;
}else{
id = "<unknown>";
}
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s has exceeded timeout, disconnecting.", id);
}
/* Client has exceeded keepalive*1.5 */
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_KEEPALIVE);
}
}
}
@ -485,7 +477,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
G_CLIENTS_EXPIRED_INC();
context->session_expiry_interval = 0;
context__set_state(context, mosq_cs_expiring);
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_SUCCESS);
}
}
}
@ -616,7 +608,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
return MOSQ_ERR_SUCCESS;
}
void do_disconnect(struct mosquitto_db *db, struct mosquitto *context)
void do_disconnect(struct mosquitto_db *db, struct mosquitto *context, int reason)
{
char *id;
#ifdef WITH_EPOLL
@ -628,7 +620,7 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context)
}
#ifdef WITH_WEBSOCKETS
if(context->wsi){
if(context->state != mosq_cs_disconnecting){
if(context->state != mosq_cs_disconnecting && context->state != mosq_cs_disconnect_with_will){
context__set_state(context, mosq_cs_disconnect_ws);
}
if(context->wsi){
@ -654,8 +646,26 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context)
}else{
id = "<unknown>";
}
if(context->state != mosq_cs_disconnecting){
log__printf(NULL, MOSQ_LOG_NOTICE, "Socket error on client %s, disconnecting.", id);
if(context->state != mosq_cs_disconnecting && context->state != mosq_cs_disconnect_with_will){
switch(reason){
case MOSQ_ERR_SUCCESS:
break;
case MOSQ_ERR_PROTOCOL:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected due to protocol error.", id);
break;
case MOSQ_ERR_CONN_LOST:
log__printf(NULL, MOSQ_LOG_NOTICE, "Socket error on client %s, disconnecting.", id);
break;
case MOSQ_ERR_AUTH:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected, no longer authorised.", id);
break;
case MOSQ_ERR_KEEPALIVE:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s has exceeded timeout, disconnecting.", id);
break;
default:
log__printf(NULL, MOSQ_LOG_NOTICE, "Socket error on client %s, disconnecting.", id);
break;
}
}else{
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected.", id);
}
@ -751,12 +761,12 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol
#endif
}
}else{
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_CONN_LOST);
continue;
}
}
if(packet__write(context)){
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_CONN_LOST);
continue;
}
}
@ -798,7 +808,7 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol
#endif
do{
if(packet__read(db, context)){
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_CONN_LOST);
continue;
}
}while(SSL_DATA_PENDING(context));
@ -808,7 +818,7 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol
#else
if(context->pollfd_index >= 0 && pollfds[context->pollfd_index].revents & (POLLERR | POLLNVAL | POLLHUP)){
#endif
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_CONN_LOST);
continue;
}
}

@ -725,7 +725,7 @@ struct lws_context *mosq_websockets_init(struct mosquitto__listener *listener, c
struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *listener, const struct mosquitto__config *conf);
# endif
#endif
void do_disconnect(struct mosquitto_db *db, struct mosquitto *context);
void do_disconnect(struct mosquitto_db *db, struct mosquitto *context, int reason);
/* ============================================================
* Will delay

@ -970,13 +970,13 @@ int mosquitto_security_apply_default(struct mosquitto_db *db)
if(!allow_anonymous && !context->username){
context__set_state(context, mosq_cs_disconnecting);
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_AUTH);
continue;
}
/* Check for connected clients that are no longer authorised */
if(mosquitto_unpwd_check(db, context, context->username, context->password) != MOSQ_ERR_SUCCESS){
context__set_state(context, mosq_cs_disconnecting);
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_AUTH);
continue;
}
/* Check for ACLs and apply to user. */
@ -986,7 +986,7 @@ int mosquitto_security_apply_default(struct mosquitto_db *db)
}else{
if(context->state != mosq_cs_connected){
context__set_state(context, mosq_cs_disconnecting);
do_disconnect(db, context);
do_disconnect(db, context, MOSQ_ERR_AUTH);
continue;
}
}

Loading…
Cancel
Save