Fixes for WITH_TLS=no.

This commit is contained in:
Roger A. Light 2014-05-25 23:41:17 +01:00
parent 330a7a882e
commit 58204d984c
2 changed files with 19 additions and 1 deletions

View File

@ -138,10 +138,13 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
if(cfg->password && !cfg->username){ if(cfg->password && !cfg->username){
if(!cfg->quiet) fprintf(stderr, "Warning: Not using password since username not set.\n"); if(!cfg->quiet) fprintf(stderr, "Warning: Not using password since username not set.\n");
} }
#ifdef WITH_TLS
if((cfg->certfile && !cfg->keyfile) || (cfg->keyfile && !cfg->certfile)){ if((cfg->certfile && !cfg->keyfile) || (cfg->keyfile && !cfg->certfile)){
fprintf(stderr, "Error: Both certfile and keyfile must be provided if one of them is.\n"); fprintf(stderr, "Error: Both certfile and keyfile must be provided if one of them is.\n");
return 1; return 1;
} }
#endif
#ifdef WITH_TLS_PSK
if((cfg->cafile || cfg->capath) && cfg->psk){ if((cfg->cafile || cfg->capath) && cfg->psk){
if(!cfg->quiet) fprintf(stderr, "Error: Only one of --psk or --cafile/--capath may be used at once.\n"); if(!cfg->quiet) fprintf(stderr, "Error: Only one of --psk or --cafile/--capath may be used at once.\n");
return 1; return 1;
@ -150,6 +153,7 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
if(!cfg->quiet) fprintf(stderr, "Error: --psk-identity required if --psk used.\n"); if(!cfg->quiet) fprintf(stderr, "Error: --psk-identity required if --psk used.\n");
return 1; return 1;
} }
#endif
if(pub_or_sub == CLIENT_SUB){ if(pub_or_sub == CLIENT_SUB){
if(cfg->clean_session == false && (cfg->id_prefix || !cfg->id)){ if(cfg->clean_session == false && (cfg->id_prefix || !cfg->id)){
@ -200,6 +204,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
cfg->bind_address = strdup(argv[i+1]); cfg->bind_address = strdup(argv[i+1]);
} }
i++; i++;
#ifdef WITH_TLS
}else if(!strcmp(argv[i], "--cafile")){ }else if(!strcmp(argv[i], "--cafile")){
if(i==argc-1){ if(i==argc-1){
fprintf(stderr, "Error: --cafile argument given but no file specified.\n\n"); fprintf(stderr, "Error: --cafile argument given but no file specified.\n\n");
@ -232,6 +237,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
cfg->ciphers = strdup(argv[i+1]); cfg->ciphers = strdup(argv[i+1]);
} }
i++; i++;
#endif
}else if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")){ }else if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")){
cfg->debug = true; cfg->debug = true;
}else if(!strcmp(argv[i], "-f") || !strcmp(argv[i], "--file")){ }else if(!strcmp(argv[i], "-f") || !strcmp(argv[i], "--file")){
@ -259,8 +265,10 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
cfg->host = strdup(argv[i+1]); cfg->host = strdup(argv[i+1]);
} }
i++; i++;
#ifdef WITH_TLS
}else if(!strcmp(argv[i], "--insecure")){ }else if(!strcmp(argv[i], "--insecure")){
cfg->insecure = true; cfg->insecure = true;
#endif
}else if(!strcmp(argv[i], "-i") || !strcmp(argv[i], "--id")){ }else if(!strcmp(argv[i], "-i") || !strcmp(argv[i], "--id")){
if(cfg->id_prefix){ if(cfg->id_prefix){
fprintf(stderr, "Error: -i and -I argument cannot be used together.\n\n"); fprintf(stderr, "Error: -i and -I argument cannot be used together.\n\n");
@ -297,6 +305,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
} }
} }
i++; i++;
#ifdef WITH_TLS
}else if(!strcmp(argv[i], "--key")){ }else if(!strcmp(argv[i], "--key")){
if(i==argc-1){ if(i==argc-1){
fprintf(stderr, "Error: --key argument given but no file specified.\n\n"); fprintf(stderr, "Error: --key argument given but no file specified.\n\n");
@ -305,6 +314,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
cfg->keyfile = strdup(argv[i+1]); cfg->keyfile = strdup(argv[i+1]);
} }
i++; i++;
#endif
}else if(!strcmp(argv[i], "-l") || !strcmp(argv[i], "--stdin-line")){ }else if(!strcmp(argv[i], "-l") || !strcmp(argv[i], "--stdin-line")){
if(pub_or_sub == CLIENT_SUB){ if(pub_or_sub == CLIENT_SUB){
goto unknown_option; goto unknown_option;
@ -349,6 +359,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
}else{ }else{
cfg->pub_mode = MSGMODE_NULL; cfg->pub_mode = MSGMODE_NULL;
} }
#ifdef WITH_TLS_PSK
}else if(!strcmp(argv[i], "--psk")){ }else if(!strcmp(argv[i], "--psk")){
if(i==argc-1){ if(i==argc-1){
fprintf(stderr, "Error: --psk argument given but no key specified.\n\n"); fprintf(stderr, "Error: --psk argument given but no key specified.\n\n");
@ -365,6 +376,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
cfg->psk_identity = strdup(argv[i+1]); cfg->psk_identity = strdup(argv[i+1]);
} }
i++; i++;
#endif
}else if(!strcmp(argv[i], "-q") || !strcmp(argv[i], "--qos")){ }else if(!strcmp(argv[i], "-q") || !strcmp(argv[i], "--qos")){
if(i==argc-1){ if(i==argc-1){
fprintf(stderr, "Error: -q argument given but no QoS specified.\n\n"); fprintf(stderr, "Error: -q argument given but no QoS specified.\n\n");
@ -423,6 +435,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
cfg->filter_outs[cfg->filter_out_count-1] = strdup(argv[i+1]); cfg->filter_outs[cfg->filter_out_count-1] = strdup(argv[i+1]);
} }
i++; i++;
#ifdef WITH_TLS
}else if(!strcmp(argv[i], "--tls-version")){ }else if(!strcmp(argv[i], "--tls-version")){
if(i==argc-1){ if(i==argc-1){
fprintf(stderr, "Error: --tls-version argument given but no version specified.\n\n"); fprintf(stderr, "Error: --tls-version argument given but no version specified.\n\n");
@ -431,6 +444,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
cfg->tls_version = strdup(argv[i+1]); cfg->tls_version = strdup(argv[i+1]);
} }
i++; i++;
#endif
}else if(!strcmp(argv[i], "-u") || !strcmp(argv[i], "--username")){ }else if(!strcmp(argv[i], "-u") || !strcmp(argv[i], "--username")){
if(i==argc-1){ if(i==argc-1){
fprintf(stderr, "Error: -u argument given but no username specified.\n\n"); fprintf(stderr, "Error: -u argument given but no username specified.\n\n");
@ -525,6 +539,7 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg)
mosquitto_lib_cleanup(); mosquitto_lib_cleanup();
return 1; return 1;
} }
#ifdef WITH_TLS
if((cfg->cafile || cfg->capath) if((cfg->cafile || cfg->capath)
&& mosquitto_tls_set(mosq, cfg->cafile, cfg->capath, cfg->certfile, cfg->keyfile, NULL)){ && mosquitto_tls_set(mosq, cfg->cafile, cfg->capath, cfg->certfile, cfg->keyfile, NULL)){
@ -537,16 +552,19 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg)
mosquitto_lib_cleanup(); mosquitto_lib_cleanup();
return 1; return 1;
} }
# ifdef WITH_TLS_PSK
if(cfg->psk && mosquitto_tls_psk_set(mosq, cfg->psk, cfg->psk_identity, NULL)){ if(cfg->psk && mosquitto_tls_psk_set(mosq, cfg->psk, cfg->psk_identity, NULL)){
if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS-PSK options.\n"); if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS-PSK options.\n");
mosquitto_lib_cleanup(); mosquitto_lib_cleanup();
return 1; return 1;
} }
# endif
if(cfg->tls_version && mosquitto_tls_opts_set(mosq, 1, cfg->tls_version, cfg->ciphers)){ if(cfg->tls_version && mosquitto_tls_opts_set(mosq, 1, cfg->tls_version, cfg->ciphers)){
if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS options.\n"); if(!cfg->quiet) fprintf(stderr, "Error: Problem setting TLS options.\n");
mosquitto_lib_cleanup(); mosquitto_lib_cleanup();
return 1; return 1;
} }
#endif
mosquitto_max_inflight_messages_set(mosq, cfg->max_inflight); mosquitto_max_inflight_messages_set(mosq, cfg->max_inflight);
return MOSQ_ERR_SUCCESS; return MOSQ_ERR_SUCCESS;
} }

View File

@ -66,6 +66,7 @@ struct mosq_config {
# ifdef WITH_TLS_PSK # ifdef WITH_TLS_PSK
char *psk; char *psk;
char *psk_identity; char *psk_identity;
# endif
#endif #endif
bool clean_session; /* sub */ bool clean_session; /* sub */
char **topics; /* sub */ char **topics; /* sub */
@ -77,7 +78,6 @@ struct mosq_config {
bool verbose; /* sub */ bool verbose; /* sub */
bool eol; /* sub */ bool eol; /* sub */
bool oneshot; /* sub */ bool oneshot; /* sub */
#endif
}; };
int client_config_load(struct mosq_config *config, int pub_or_sub, int argc, char *argv[]); int client_config_load(struct mosq_config *config, int pub_or_sub, int argc, char *argv[]);