diff --git a/client/client_shared.c b/client/client_shared.c index 53ac1f9a..1cee5aa5 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -1059,9 +1059,6 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg) int client_id_generate(struct mosq_config *cfg, const char *id_base) { - int len; - char hostname[256]; - if(cfg->id_prefix){ cfg->id = malloc(strlen(cfg->id_prefix)+10); if(!cfg->id){ @@ -1070,22 +1067,6 @@ int client_id_generate(struct mosq_config *cfg, const char *id_base) return 1; } snprintf(cfg->id, strlen(cfg->id_prefix)+10, "%s%d", cfg->id_prefix, getpid()); - }else if(!cfg->id && (cfg->protocol_version == MQTT_PROTOCOL_V31 || cfg->protocol_version == MQTT_PROTOCOL_V311)){ - hostname[0] = '\0'; - gethostname(hostname, 256); - hostname[255] = '\0'; - len = strlen(id_base) + strlen("|-") + 6 + strlen(hostname); - cfg->id = malloc(len); - if(!cfg->id){ - if(!cfg->quiet) fprintf(stderr, "Error: Out of memory.\n"); - mosquitto_lib_cleanup(); - return 1; - } - snprintf(cfg->id, len, "%s|%d-%s", id_base, getpid(), hostname); - if(strlen(cfg->id) > MOSQ_MQTT_ID_MAX_LENGTH){ - /* Enforce maximum client id length of 23 characters */ - cfg->id[MOSQ_MQTT_ID_MAX_LENGTH] = '\0'; - } } return MOSQ_ERR_SUCCESS; } diff --git a/lib/connect.c b/lib/connect.c index ee00bf95..90b481cc 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -30,6 +30,8 @@ Contributors: #include "socks_mosq.h" #include "util_mosq.h" +static char alphanum[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + static int mosquitto__reconnect(struct mosquitto *mosq, bool blocking, const mosquitto_property *properties); static int mosquitto__connect_init(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address); @@ -57,7 +59,7 @@ static int mosquitto__connect_init(struct mosquitto *mosq, const char *host, int if(rc) return rc; for(i=5; i<23; i++){ - mosq->id[i] = (mosq->id[i]%73)+48; + mosq->id[i] = alphanum[(mosq->id[i]&0x7F)%(sizeof(alphanum)-1)]; } }