From ebcd6c2932e7232dedadd2aee6d61c07c89e0a1e Mon Sep 17 00:00:00 2001 From: Ken Rice Date: Tue, 23 Dec 2008 20:25:10 +0000 Subject: [PATCH] switch to using getopt so we can specify host, port and password on the command line git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10927 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- libs/esl/fs_cli.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/libs/esl/fs_cli.c b/libs/esl/fs_cli.c index c430aaa905..5c1825d8d3 100644 --- a/libs/esl/fs_cli.c +++ b/libs/esl/fs_cli.c @@ -35,10 +35,10 @@ static void handle_SIGINT(int sig) return; } + static const char* COLORS[] = { ESL_SEQ_DEFAULT_COLOR, ESL_SEQ_FRED, ESL_SEQ_FRED, ESL_SEQ_FRED, ESL_SEQ_FMAGEN, ESL_SEQ_FCYAN, ESL_SEQ_FGREEN, ESL_SEQ_FYELLOW }; - static void *msg_thread_run(esl_thread_t *me, void *obj) { @@ -167,6 +167,7 @@ int main(int argc, char *argv[]) esl_config_t cfg; cli_profile_t *profile = &profiles[0]; int cur = 0; + int opt; strncpy(profiles[0].host, "localhost", sizeof(profiles[0].host)); strncpy(profiles[0].pass, "ClueCon", sizeof(profiles[0].pass)); @@ -215,15 +216,41 @@ int main(int argc, char *argv[]) esl_config_close_file(&cfg); } - if (argv[1]) { - if (get_profile(argv[1], &profile)) { - esl_log(ESL_LOG_INFO, "Chosen profile %s does not exist using builtin default\n", argv[1]); + while ((opt = getopt (argc, argv, "H:U:P:S:p:h?")) != -1){ + switch (opt) + { + case 'H': + printf("Host: %s\n", optarg); + esl_set_string(profile[0].host, optarg); + break; + case 'P': + printf("Port: %s\n", optarg); + profile[0].port= (esl_port_t)atoi(optarg); + break; + case 'p': + printf("password: %s\n", optarg); + esl_set_string(profile[0].pass, optarg); + break; + printf("profile: %s\n", optarg); + break; + case 'h': + case '?': + printf("%s [-H ] [-P ] [-s ] [-p ]\n", argv[0]); + return 0; + default: + opt = 0; + } + } + + if (optind < argc) { + if (get_profile(argv[optind], &profile)) { + esl_log(ESL_LOG_INFO, "Chosen profile %s does not exist using builtin default\n", argv[optind]); profile = &profiles[0]; } else { esl_log(ESL_LOG_INFO, "Chosen profile %s\n", profile->name); } } - + esl_log(ESL_LOG_INFO, "Using profile %s\n", profile->name); gethostname(hostname, sizeof(hostname));