|
|
|
@ -265,8 +265,32 @@ void client_config_cleanup(struct mosq_config *cfg)
|
|
|
|
|
mosquitto_property_free_all(&cfg->unsubscribe_props);
|
|
|
|
|
mosquitto_property_free_all(&cfg->disconnect_props);
|
|
|
|
|
mosquitto_property_free_all(&cfg->will_props);
|
|
|
|
|
free(cfg->options_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find if there is "-o" in the options */
|
|
|
|
|
static int client_config_options_file(struct mosq_config *cfg, int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for(i=1; i<argc; i++){
|
|
|
|
|
if(!strcmp(argv[i], "-o")){
|
|
|
|
|
if(cfg->options_file){
|
|
|
|
|
fprintf(stderr, "Error: Duplicate -o argument given.\n\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if(i==argc-1){
|
|
|
|
|
fprintf(stderr, "Error: -o argument given but no options file specified.\n\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}else{
|
|
|
|
|
cfg->options_file = strdup(argv[i+1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
@ -286,6 +310,11 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
|
|
|
|
|
|
|
|
|
|
init_config(cfg, pub_or_sub);
|
|
|
|
|
|
|
|
|
|
if(client_config_options_file(cfg, argc, argv)){
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(cfg->options_file == NULL){
|
|
|
|
|
/* Default config file */
|
|
|
|
|
#ifndef WIN32
|
|
|
|
|
env = getenv("XDG_CONFIG_HOME");
|
|
|
|
@ -343,9 +372,16 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
|
|
|
|
|
loc[len-1] = '\0';
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(loc){
|
|
|
|
|
if(cfg->options_file){
|
|
|
|
|
fptr = fopen(cfg->options_file, "rt");
|
|
|
|
|
}else if(loc){
|
|
|
|
|
fptr = fopen(loc, "rt");
|
|
|
|
|
free(loc);
|
|
|
|
|
}else{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if(fptr){
|
|
|
|
|
while(fgets(line, 1024, fptr)){
|
|
|
|
|
if(line[0] == '#') continue; /* Comments */
|
|
|
|
@ -373,8 +409,6 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
|
|
|
|
|
}
|
|
|
|
|
fclose(fptr);
|
|
|
|
|
}
|
|
|
|
|
free(loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Deal with real argc/argv */
|
|
|
|
|
rc = client_config_line_proc(cfg, pub_or_sub, argc, argv);
|
|
|
|
@ -519,6 +553,7 @@ int cfg_add_topic(struct mosq_config *cfg, int type, char *topic, const char *ar
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Process a tokenised single line from a file or set of real argc/argv */
|
|
|
|
|
int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
@ -841,6 +876,14 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
|
|
|
|
|
goto unknown_option;
|
|
|
|
|
}
|
|
|
|
|
cfg->eol = false;
|
|
|
|
|
}else if(!strcmp(argv[i], "-o")){
|
|
|
|
|
if(i==argc-1){
|
|
|
|
|
fprintf(stderr, "Error: -o argument given but no options file specified.\n\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}else{
|
|
|
|
|
/* Already handled */
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}else if(!strcmp(argv[i], "-p") || !strcmp(argv[i], "--port")){
|
|
|
|
|
if(i==argc-1){
|
|
|
|
|
fprintf(stderr, "Error: -p argument given but no port specified.\n\n");
|
|
|
|
|