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) const char *mosquitto_strerror(int mosq_errno)
{ {
switch(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: case MOSQ_ERR_CONN_PENDING:
return "Connection pending."; return "Connection pending.";
case MOSQ_ERR_SUCCESS: case MOSQ_ERR_SUCCESS:
@ -379,6 +385,8 @@ const char *mosquitto_strerror(int mosq_errno)
return "Requested QoS not supported on server."; return "Requested QoS not supported on server.";
case MOSQ_ERR_OVERSIZE_PACKET: case MOSQ_ERR_OVERSIZE_PACKET:
return "Packet larger than supported by the server."; return "Packet larger than supported by the server.";
case MOSQ_ERR_OCSP:
return "OCSP error.";
default: default:
return "Unknown error."; 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->clean_start = true;
found_context->session_expiry_interval = 0; found_context->session_expiry_interval = 0;
context__set_state(found_context, mosq_cs_duplicate); 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); 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); 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->protocol == mosq_p_mqtt311 || context->protocol == mosq_p_mqtt5){
if((context->in_packet.command&0x0F) != 0x00){ if((context->in_packet.command&0x0F) != 0x00){
do_disconnect(db, context); do_disconnect(db, context, MOSQ_ERR_PROTOCOL);
return MOSQ_ERR_PROTOCOL; return MOSQ_ERR_PROTOCOL;
} }
} }
@ -68,6 +68,6 @@ int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context)
}else{ }else{
context__set_state(context, mosq_cs_disconnecting); context__set_state(context, mosq_cs_disconnecting);
} }
do_disconnect(db, context); do_disconnect(db, context, MOSQ_ERR_SUCCESS);
return 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 */ /* 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++; pollfd_index++;
#endif #endif
}else{ }else{
do_disconnect(db, context); do_disconnect(db, context, MOSQ_ERR_CONN_LOST);
} }
}else{ }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 */ /* 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(); G_CLIENTS_EXPIRED_INC();
context->session_expiry_interval = 0; context->session_expiry_interval = 0;
context__set_state(context, mosq_cs_expiring); 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; 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; char *id;
#ifdef WITH_EPOLL #ifdef WITH_EPOLL
@ -628,7 +620,7 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context)
} }
#ifdef WITH_WEBSOCKETS #ifdef WITH_WEBSOCKETS
if(context->wsi){ 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); context__set_state(context, mosq_cs_disconnect_ws);
} }
if(context->wsi){ if(context->wsi){
@ -654,8 +646,26 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context)
}else{ }else{
id = "<unknown>"; id = "<unknown>";
} }
if(context->state != mosq_cs_disconnecting){ if(context->state != mosq_cs_disconnecting && context->state != mosq_cs_disconnect_with_will){
log__printf(NULL, MOSQ_LOG_NOTICE, "Socket error on client %s, disconnecting.", id); 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{ }else{
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected.", id); 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 #endif
} }
}else{ }else{
do_disconnect(db, context); do_disconnect(db, context, MOSQ_ERR_CONN_LOST);
continue; continue;
} }
} }
if(packet__write(context)){ if(packet__write(context)){
do_disconnect(db, context); do_disconnect(db, context, MOSQ_ERR_CONN_LOST);
continue; continue;
} }
} }
@ -798,7 +808,7 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol
#endif #endif
do{ do{
if(packet__read(db, context)){ if(packet__read(db, context)){
do_disconnect(db, context); do_disconnect(db, context, MOSQ_ERR_CONN_LOST);
continue; continue;
} }
}while(SSL_DATA_PENDING(context)); }while(SSL_DATA_PENDING(context));
@ -808,7 +818,7 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol
#else #else
if(context->pollfd_index >= 0 && pollfds[context->pollfd_index].revents & (POLLERR | POLLNVAL | POLLHUP)){ if(context->pollfd_index >= 0 && pollfds[context->pollfd_index].revents & (POLLERR | POLLNVAL | POLLHUP)){
#endif #endif
do_disconnect(db, context); do_disconnect(db, context, MOSQ_ERR_CONN_LOST);
continue; 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); struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *listener, const struct mosquitto__config *conf);
# endif # endif
#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 * Will delay

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

Loading…
Cancel
Save