From 54db895cb35ef6cdef0137af0429956383f9ebb1 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 27 Nov 2018 10:02:10 +0000 Subject: [PATCH] Rename clean_session to clean_start for v5. --- lib/connect.c | 2 +- lib/mosquitto.c | 12 ++++++------ lib/mosquitto_internal.h | 2 +- lib/socks_mosq.c | 2 +- src/bridge.c | 16 ++++++++-------- src/conf.c | 2 +- src/context.c | 6 +++--- src/handle_connect.c | 26 +++++++++++++------------- src/loop.c | 8 ++++---- src/mosquitto_broker_internal.h | 2 +- src/persist.c | 6 +++--- src/plugin.c | 2 +- 12 files changed, 43 insertions(+), 43 deletions(-) diff --git a/lib/connect.c b/lib/connect.c index f0b78753..6fbc776e 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -205,7 +205,7 @@ static int mosquitto__reconnect(struct mosquitto *mosq, bool blocking, const mos }else #endif { - return send__connect(mosq, mosq->keepalive, mosq->clean_session, properties); + return send__connect(mosq, mosq->keepalive, mosq->clean_start, properties); } } diff --git a/lib/mosquitto.c b/lib/mosquitto.c index be449fbe..688312d3 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -64,12 +64,12 @@ int mosquitto_lib_cleanup(void) return MOSQ_ERR_SUCCESS; } -struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *userdata) +struct mosquitto *mosquitto_new(const char *id, bool clean_start, void *userdata) { struct mosquitto *mosq = NULL; int rc; - if(clean_session == false && id == NULL){ + if(clean_start == false && id == NULL){ errno = EINVAL; return NULL; } @@ -86,7 +86,7 @@ struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *userda #ifdef WITH_THREADING mosq->thread_id = pthread_self(); #endif - rc = mosquitto_reinitialise(mosq, id, clean_session, userdata); + rc = mosquitto_reinitialise(mosq, id, clean_start, userdata); if(rc){ mosquitto_destroy(mosq); if(rc == MOSQ_ERR_INVAL){ @@ -102,13 +102,13 @@ struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *userda return mosq; } -int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_session, void *userdata) +int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_start, void *userdata) { int i; if(!mosq) return MOSQ_ERR_INVAL; - if(clean_session == false && id == NULL){ + if(clean_start == false && id == NULL){ return MOSQ_ERR_INVAL; } @@ -125,7 +125,7 @@ int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_se mosq->sockpairR = INVALID_SOCKET; mosq->sockpairW = INVALID_SOCKET; mosq->keepalive = 60; - mosq->clean_session = clean_session; + mosq->clean_start = clean_start; if(id){ if(STREMPTY(id)){ return MOSQ_ERR_INVAL; diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index fe0a6e24..1ca5f3c3 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -208,7 +208,7 @@ struct mosquitto { pthread_mutex_t mid_mutex; pthread_t thread_id; #endif - bool clean_session; + bool clean_start; #ifdef WITH_BROKER char *old_id; /* for when a duplicate client connects, but we still want to know what the id was */ diff --git a/lib/socks_mosq.c b/lib/socks_mosq.c index a3cfc015..5f43d16a 100644 --- a/lib/socks_mosq.c +++ b/lib/socks_mosq.c @@ -417,7 +417,7 @@ int socks5__read(struct mosquitto *mosq) /* Auth passed */ packet__cleanup(&mosq->in_packet); mosq->state = mosq_cs_new; - return send__connect(mosq, mosq->keepalive, mosq->clean_session, NULL); + return send__connect(mosq, mosq->keepalive, mosq->clean_start, NULL); }else{ i = mosq->in_packet.payload[1]; packet__cleanup(&mosq->in_packet); diff --git a/src/bridge.c b/src/bridge.c index 2446184d..59e7b516 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -124,18 +124,18 @@ int bridge__connect_step1(struct mosquitto_db *db, struct mosquitto *context) context->last_msg_in = mosquitto_time(); context->next_msg_out = mosquitto_time() + context->bridge->keepalive; context->keepalive = context->bridge->keepalive; - context->clean_session = context->bridge->clean_session; + context->clean_start = context->bridge->clean_start; context->in_packet.payload = NULL; context->ping_t = 0; context->bridge->lazy_reconnect = false; bridge__packet_cleanup(context); db__message_reconnect_reset(db, context); - if(context->clean_session){ + if(context->clean_start){ db__messages_delete(db, context); } - /* Delete all local subscriptions even for clean_session==false. We don't + /* Delete all local subscriptions even for clean_start==false. We don't * remove any messages and the next loop carries out the resubscription * anyway. This means any unwanted subs will be removed. */ @@ -256,7 +256,7 @@ int bridge__connect_step3(struct mosquitto_db *db, struct mosquitto *context) context->bridge->primary_retry = mosquitto_time() + 5; } - rc = send__connect(context, context->keepalive, context->clean_session, NULL); + rc = send__connect(context, context->keepalive, context->clean_start, NULL); if(rc == MOSQ_ERR_SUCCESS){ return MOSQ_ERR_SUCCESS; }else if(rc == MOSQ_ERR_ERRNO && errno == ENOTCONN){ @@ -290,18 +290,18 @@ int bridge__connect(struct mosquitto_db *db, struct mosquitto *context) context->last_msg_in = mosquitto_time(); context->next_msg_out = mosquitto_time() + context->bridge->keepalive; context->keepalive = context->bridge->keepalive; - context->clean_session = context->bridge->clean_session; + context->clean_start = context->bridge->clean_start; context->in_packet.payload = NULL; context->ping_t = 0; context->bridge->lazy_reconnect = false; bridge__packet_cleanup(context); db__message_reconnect_reset(db, context); - if(context->clean_session){ + if(context->clean_start){ db__messages_delete(db, context); } - /* Delete all local subscriptions even for clean_session==false. We don't + /* Delete all local subscriptions even for clean_start==false. We don't * remove any messages and the next loop carries out the resubscription * anyway. This means any unwanted subs will be removed. */ @@ -375,7 +375,7 @@ int bridge__connect(struct mosquitto_db *db, struct mosquitto *context) HASH_ADD(hh_sock, db->contexts_by_sock, sock, sizeof(context->sock), context); - rc2 = send__connect(context, context->keepalive, context->clean_session, NULL); + rc2 = send__connect(context, context->keepalive, context->clean_start, NULL); if(rc2 == MOSQ_ERR_SUCCESS){ return rc; }else if(rc2 == MOSQ_ERR_ERRNO && errno == ENOTCONN){ diff --git a/src/conf.c b/src/conf.c index 20609e07..00d30b2e 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1112,7 +1112,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration."); return MOSQ_ERR_INVAL; } - if(conf__parse_bool(&token, "cleansession", &cur_bridge->clean_session, saveptr)) return MOSQ_ERR_INVAL; + if(conf__parse_bool(&token, "cleansession", &cur_bridge->clean_start, saveptr)) return MOSQ_ERR_INVAL; #else log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available."); #endif diff --git a/src/context.c b/src/context.c index a78ea1e1..164969db 100644 --- a/src/context.c +++ b/src/context.c @@ -41,7 +41,7 @@ struct mosquitto *context__init(struct mosquitto_db *db, mosq_sock_t sock) context->last_msg_in = mosquitto_time(); context->next_msg_out = mosquitto_time() + 60; context->keepalive = 60; /* Default to 60s */ - context->clean_session = true; + context->clean_start = true; context->disconnect_t = 0; context->id = NULL; context->last_mid = 0; @@ -144,7 +144,7 @@ void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool d context->password = NULL; net__socket_close(db, context); - if((do_free || context->clean_session) && db){ + if((do_free || context->clean_start) && db){ sub__clean_session(db, context); db__messages_delete(db, context); } @@ -178,7 +178,7 @@ void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool d context->out_packet = context->out_packet->next; mosquitto__free(packet); } - if(do_free || context->clean_session){ + if(do_free || context->clean_start){ msg = context->inflight_msgs; while(msg){ next = msg->next; diff --git a/src/handle_connect.c b/src/handle_connect.c index 0e87303b..e0b50f7d 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -120,7 +120,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context) char *will_topic_mount; uint16_t will_payloadlen; struct mosquitto_message_all *will_struct = NULL; - uint8_t will, will_retain, will_qos, clean_session; + uint8_t will, will_retain, will_qos, clean_start; uint8_t username_flag, password_flag; char *username = NULL, *password = NULL; int rc; @@ -223,7 +223,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context) } } - clean_session = (connect_flags & 0x02) >> 1; + clean_start = (connect_flags & 0x02) >> 1; will = connect_flags & 0x04; will_qos = (connect_flags & 0x18) >> 3; if(will_qos == 3){ @@ -276,7 +276,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context) }else{ allow_zero_length_clientid = db->config->security_options.allow_zero_length_clientid; } - if(clean_session == 0 || allow_zero_length_clientid == false){ + if(clean_start == 0 || allow_zero_length_clientid == false){ send__connack(db, context, 0, CONNACK_REFUSED_IDENTIFIER_REJECTED); rc = MOSQ_ERR_PROTOCOL; goto handle_connect_error; @@ -577,14 +577,14 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context) } if(context->protocol == mosq_p_mqtt311 || context->protocol == mosq_p_mqtt5){ - if(clean_session == 0){ + if(clean_start == 0){ connect_ack |= 0x01; } } - context->clean_session = clean_session; + context->clean_start = clean_start; - if(context->clean_session == false && found_context->clean_session == false){ + if(context->clean_start == false && found_context->clean_start == false){ if(found_context->inflight_msgs || found_context->queued_msgs){ context->inflight_msgs = found_context->inflight_msgs; context->queued_msgs = found_context->queued_msgs; @@ -611,7 +611,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context) } } - found_context->clean_session = true; + found_context->clean_start = true; found_context->state = mosq_cs_duplicate; do_disconnect(db, found_context); } @@ -664,15 +664,15 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context) if(db->config->connection_messages == true){ if(context->is_bridge){ if(context->username){ - log__printf(NULL, MOSQ_LOG_NOTICE, "New bridge connected from %s as %s (c%d, k%d, u'%s').", context->address, client_id, clean_session, context->keepalive, context->username); + log__printf(NULL, MOSQ_LOG_NOTICE, "New bridge connected from %s as %s (c%d, k%d, u'%s').", context->address, client_id, clean_start, context->keepalive, context->username); }else{ - log__printf(NULL, MOSQ_LOG_NOTICE, "New bridge connected from %s as %s (c%d, k%d).", context->address, client_id, clean_session, context->keepalive); + log__printf(NULL, MOSQ_LOG_NOTICE, "New bridge connected from %s as %s (c%d, k%d).", context->address, client_id, clean_start, context->keepalive); } }else{ if(context->username){ - log__printf(NULL, MOSQ_LOG_NOTICE, "New client connected from %s as %s (c%d, k%d, u'%s').", context->address, client_id, clean_session, context->keepalive, context->username); + log__printf(NULL, MOSQ_LOG_NOTICE, "New client connected from %s as %s (c%d, k%d, u'%s').", context->address, client_id, clean_start, context->keepalive, context->username); }else{ - log__printf(NULL, MOSQ_LOG_NOTICE, "New client connected from %s as %s (p%d, c%d, k%d).", context->address, client_id, context->protocol, clean_session, context->keepalive); + log__printf(NULL, MOSQ_LOG_NOTICE, "New client connected from %s as %s (p%d, c%d, k%d).", context->address, client_id, context->protocol, clean_start, context->keepalive); } } @@ -690,7 +690,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context) context->id = client_id; client_id = NULL; - context->clean_session = clean_session; + context->clean_start = clean_start; context->ping_t = 0; context->is_dropping = false; if((protocol_version&0x80) == 0x80){ @@ -703,7 +703,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context) HASH_ADD_KEYPTR(hh_id, db->contexts_by_id, context->id, strlen(context->id), context); #ifdef WITH_PERSISTENCE - if(!clean_session){ + if(!clean_start){ db->persistence_changes++; } #endif diff --git a/src/loop.c b/src/loop.c index 97147209..dd6b2139 100644 --- a/src/loop.c +++ b/src/loop.c @@ -466,7 +466,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li now_time = time(NULL); if(db->config->persistent_client_expiration > 0 && now_time > expiration_check_time){ HASH_ITER(hh_id, db->contexts_by_id, context, ctxt_tmp){ - if(context->sock == INVALID_SOCKET && context->clean_session == 0){ + if(context->sock == INVALID_SOCKET && context->clean_start == 0){ /* This is a persistent client, check to see if the * last time it connected was longer than * persistent_client_expiration seconds ago. If so, @@ -480,7 +480,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li } log__printf(NULL, MOSQ_LOG_NOTICE, "Expiring persistent client %s due to timeout.", id); G_CLIENTS_EXPIRED_INC(); - context->clean_session = true; + context->clean_start = true; context->state = mosq_cs_expiring; do_disconnect(db, context); } @@ -665,9 +665,9 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context) #endif context__disconnect(db, context); #ifdef WITH_BRIDGE - if(context->clean_session && !context->bridge){ + if(context->clean_start && !context->bridge){ #else - if(context->clean_session){ + if(context->clean_start){ #endif context__add_to_disused(db, context); if(context->id){ diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 694bd649..9c4439d3 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -435,7 +435,7 @@ struct mosquitto__bridge{ bool round_robin; bool try_private; bool try_private_accepted; - bool clean_session; + bool clean_start; int keepalive; struct mosquitto__bridge_topic *topics; int topic_count; diff --git a/src/persist.c b/src/persist.c index c434a41e..d105c413 100644 --- a/src/persist.c +++ b/src/persist.c @@ -55,7 +55,7 @@ static struct mosquitto *persist__find_or_add_context(struct mosquitto_db *db, c return NULL; } - context->clean_session = false; + context->clean_start = false; HASH_ADD_KEYPTR(hh_id, db->contexts_by_id, context->id, strlen(context->id), context); } @@ -234,7 +234,7 @@ static int persist__client_write(struct mosquitto_db *db, FILE *db_fptr) assert(db_fptr); HASH_ITER(hh_id, db->contexts_by_id, context, ctxt_tmp){ - if(context && context->clean_session == false){ + if(context && context->clean_start == false){ length = htonl(2+strlen(context->id) + sizeof(uint16_t) + sizeof(time_t)); i16temp = htons(DB_CHUNK_CLIENT); @@ -287,7 +287,7 @@ static int persist__subs_retain_write(struct mosquitto_db *db, FILE *db_fptr, st sub = node->subs; while(sub){ - if(sub->context->clean_session == false){ + if(sub->context->clean_start == false){ length = htonl(2+strlen(sub->context->id) + 2+strlen(thistopic) + sizeof(uint8_t)); i16temp = htons(DB_CHUNK_SUB); diff --git a/src/plugin.c b/src/plugin.c index 3365bfbf..fd387869 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -32,7 +32,7 @@ const char *mosquitto_client_address(const struct mosquitto *client) bool mosquitto_client_clean_session(const struct mosquitto *client) { - return client->clean_session; + return client->clean_start; }