merge patch FSSCRIPTS-12

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11027 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-12-31 18:45:41 +00:00
parent fc6df88250
commit d4b85e7858
2 changed files with 58 additions and 4 deletions

View File

@ -26,6 +26,8 @@ typedef struct {
char pass[128]; char pass[128];
int debug; int debug;
char *console_fnkeys[12]; char *console_fnkeys[12];
char loglevel[128];
int quiet;
} cli_profile_t; } cli_profile_t;
static cli_profile_t profiles[128] = {{{0}}}; static cli_profile_t profiles[128] = {{{0}}};
@ -156,6 +158,8 @@ static int usage(char *name){
printf(" -P, --port=port Port to connect (1 - 65535)\n"); printf(" -P, --port=port Port to connect (1 - 65535)\n");
printf(" -p, --password=FILENAME Password\n"); printf(" -p, --password=FILENAME Password\n");
printf(" -x, --execute=command Execute Command and Exit\n"); printf(" -x, --execute=command Execute Command and Exit\n");
printf(" -l, --loglevel=command Log Level\n");
printf(" -q, --quiet Disable logging\n");
printf(" -d, --debug=level Debug Level (0 - 7)\n\n"); printf(" -d, --debug=level Debug Level (0 - 7)\n\n");
return 1; return 1;
} }
@ -391,6 +395,8 @@ int main(int argc, char *argv[])
{"password", 1, 0, 'p'}, {"password", 1, 0, 'p'},
{"debug", 1, 0, 'd'}, {"debug", 1, 0, 'd'},
{"execute", 1, 0, 'x'}, {"execute", 1, 0, 'x'},
{"loglevel", 1, 0, 'l'},
{"quiet", 0, 0, 'q'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@ -404,6 +410,8 @@ int main(int argc, char *argv[])
int argv_error = 0; int argv_error = 0;
int argv_exec = 0; int argv_exec = 0;
char argv_command[256] = ""; char argv_command[256] = "";
char argv_loglevel[128] = "";
int argv_quiet = 0;
strncpy(internal_profile.host, "127.0.0.1", sizeof(internal_profile.host)); strncpy(internal_profile.host, "127.0.0.1", sizeof(internal_profile.host));
@ -413,6 +421,7 @@ int main(int argc, char *argv[])
if (home) { if (home) {
snprintf(hfile, sizeof(hfile), "%s/.fs_cli_history", home); snprintf(hfile, sizeof(hfile), "%s/.fs_cli_history", home);
snprintf(cfile, sizeof(cfile), "%s/.fs_cli_conf", home);
} }
signal(SIGINT, handle_SIGINT); signal(SIGINT, handle_SIGINT);
@ -421,7 +430,7 @@ int main(int argc, char *argv[])
for(;;) { for(;;) {
int option_index = 0; int option_index = 0;
opt = getopt_long(argc, argv, "H:U:P:S:p:d:x:h?", options, &option_index); opt = getopt_long(argc, argv, "H:U:P:S:p:d:x:l:qh?", options, &option_index);
if (opt == -1) break; if (opt == -1) break;
switch (opt) switch (opt)
{ {
@ -455,6 +464,12 @@ int main(int argc, char *argv[])
argv_exec = 1; argv_exec = 1;
esl_set_string(argv_command, optarg); esl_set_string(argv_command, optarg);
break; break;
case 'l':
esl_set_string(argv_loglevel, optarg);
break;
case 'q':
argv_quiet = 1;
break;
case 'h': case 'h':
case '?': case '?':
@ -503,6 +518,10 @@ int main(int argc, char *argv[])
if (dt > -1 && dt < 8){ if (dt > -1 && dt < 8){
profiles[pcount-1].debug = dt; profiles[pcount-1].debug = dt;
} }
} else if(!strcasecmp(var, "loglevel")) {
esl_set_string(profiles[pcount-1].loglevel, val);
} else if(!strcasecmp(var, "quiet")) {
profiles[pcount-1].quiet = esl_true(val);
} else if (!strncasecmp(var, "key_F", 5)) { } else if (!strncasecmp(var, "key_F", 5)) {
char *key = var + 5; char *key = var + 5;
@ -543,6 +562,11 @@ int main(int argc, char *argv[])
esl_set_string(profile->pass, temp_pass); esl_set_string(profile->pass, temp_pass);
} }
if (*argv_loglevel) {
esl_set_string(profile->loglevel, argv_loglevel);
profile->quiet = 0;
}
esl_log(ESL_LOG_DEBUG, "Using profile %s [%s]\n", profile->name, profile->host); esl_log(ESL_LOG_DEBUG, "Using profile %s [%s]\n", profile->name, profile->host);
if (argv_host) { if (argv_host) {
@ -633,8 +657,10 @@ int main(int argc, char *argv[])
} }
#endif #endif
snprintf(cmd_str, sizeof(cmd_str), "log info\n\n"); if (!argv_quiet && !profile->quiet) {
snprintf(cmd_str, sizeof(cmd_str), "log %s\n\n", profile->loglevel);
esl_send_recv(&handle, cmd_str); esl_send_recv(&handle, cmd_str);
}
print_banner(stdout); print_banner(stdout);

View File

@ -70,6 +70,34 @@
#define esl_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR)) #define esl_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))
#endif #endif
/*!
\brief Evaluate the truthfullness of a string expression
\param expr a string expression
\return true or false
*/
#define esl_true(expr)\
(expr && ( !strcasecmp(expr, "yes") ||\
!strcasecmp(expr, "on") ||\
!strcasecmp(expr, "true") ||\
!strcasecmp(expr, "enabled") ||\
!strcasecmp(expr, "active") ||\
!strcasecmp(expr, "allow") ||\
atoi(expr))) ? 1 : 0
/*!
\brief Evaluate the falsefullness of a string expression
\param expr a string expression
\return true or false
*/
#define esl_false(expr)\
(expr && ( !strcasecmp(expr, "no") ||\
!strcasecmp(expr, "off") ||\
!strcasecmp(expr, "false") ||\
!strcasecmp(expr, "disabled") ||\
!strcasecmp(expr, "inactive") ||\
!strcasecmp(expr, "disallow") ||\
!atoi(expr))) ? 1 : 0
typedef struct esl_config esl_config_t; typedef struct esl_config esl_config_t;
/*! \brief A simple file handle representing an open configuration file **/ /*! \brief A simple file handle representing an open configuration file **/