mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-27 04:50:59 +00:00
enhance the show command
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2011 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
75d61d12b1
commit
ca98141ed7
@ -186,15 +186,46 @@ static switch_status_t pause_function(char *cmd, switch_stream_handle_t *stream)
|
|||||||
|
|
||||||
struct holder {
|
struct holder {
|
||||||
switch_stream_handle_t *stream;
|
switch_stream_handle_t *stream;
|
||||||
|
char *http;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
|
static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
|
||||||
struct holder *holder = (struct holder *) pArg;
|
struct holder *holder = (struct holder *) pArg;
|
||||||
|
int x;
|
||||||
|
|
||||||
|
|
||||||
|
if (holder->count == 0) {
|
||||||
|
if (holder->http) {
|
||||||
|
holder->stream->write_function(holder->stream, "\n<tr>");
|
||||||
|
}
|
||||||
|
|
||||||
|
for(x = 0; x < argc; x++) {
|
||||||
|
if (holder->http) {
|
||||||
|
holder->stream->write_function(holder->stream, "<td>");
|
||||||
|
holder->stream->write_function(holder->stream, "<b>%s</b>%s", columnNames[x], x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
|
||||||
|
} else {
|
||||||
|
holder->stream->write_function(holder->stream, "%s%s", columnNames[x], x == (argc - 1) ? "\n" : ",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (holder->http) {
|
||||||
|
holder->stream->write_function(holder->stream, "<tr bgcolor=%s>", holder->count % 2 == 0 ? "eeeeee" : "ffffff");
|
||||||
|
}
|
||||||
|
|
||||||
|
for(x = 0; x < argc; x++) {
|
||||||
|
if (holder->http) {
|
||||||
|
holder->stream->write_function(holder->stream, "<td>");
|
||||||
|
holder->stream->write_function(holder->stream, "%s%s", argv[x], x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
|
||||||
|
} else {
|
||||||
|
holder->stream->write_function(holder->stream, "%s%s", argv[x], x == (argc - 1) ? "\n" : ",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
holder->stream->write_function(holder->stream, "%s|%s\n", argv[0], argv[1] ? argv[1] : "NULL");
|
|
||||||
holder->count++;
|
holder->count++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -204,7 +235,11 @@ static switch_status_t show_function(char *cmd, switch_stream_handle_t *stream)
|
|||||||
char sql[1024];
|
char sql[1024];
|
||||||
char *errmsg;
|
char *errmsg;
|
||||||
switch_core_db_t *db = switch_core_db_handle();
|
switch_core_db_t *db = switch_core_db_handle();
|
||||||
struct holder holder;
|
struct holder holder = {0};
|
||||||
|
|
||||||
|
if (stream->event) {
|
||||||
|
holder.http = switch_event_get_header(stream->event, "http-host");
|
||||||
|
}
|
||||||
|
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
sprintf (sql, "select * from interfaces");
|
sprintf (sql, "select * from interfaces");
|
||||||
@ -231,14 +266,23 @@ static switch_status_t show_function(char *cmd, switch_stream_handle_t *stream)
|
|||||||
holder.stream = stream;
|
holder.stream = stream;
|
||||||
holder.count = 0;
|
holder.count = 0;
|
||||||
|
|
||||||
|
if (holder.http) {
|
||||||
|
holder.stream->write_function(holder.stream, "<table cellpadding=1 cellspacing=4 border=1>\n");
|
||||||
|
}
|
||||||
|
|
||||||
switch_core_db_exec(db, sql, show_callback, &holder, &errmsg);
|
switch_core_db_exec(db, sql, show_callback, &holder, &errmsg);
|
||||||
|
|
||||||
|
if (holder.http) {
|
||||||
|
holder.stream->write_function(holder.stream, "</table>");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (errmsg) {
|
if (errmsg) {
|
||||||
stream->write_function(stream, "SQL ERR [%s]\n",errmsg);
|
stream->write_function(stream, "SQL ERR [%s]\n",errmsg);
|
||||||
switch_core_db_free(errmsg);
|
switch_core_db_free(errmsg);
|
||||||
errmsg = NULL;
|
errmsg = NULL;
|
||||||
} else {
|
} else {
|
||||||
stream->write_function(stream, "%u total.\n", holder.count);
|
stream->write_function(stream, "\n%u total.\n", holder.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_core_db_close(db);
|
switch_core_db_close(db);
|
||||||
|
@ -593,6 +593,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw
|
|||||||
{
|
{
|
||||||
switch_caller_profile_t *caller_profile, *originator_caller_profile, *originatee_caller_profile;
|
switch_caller_profile_t *caller_profile, *originator_caller_profile, *originatee_caller_profile;
|
||||||
switch_hash_index_t *hi;
|
switch_hash_index_t *hi;
|
||||||
|
switch_codec_t *codec;
|
||||||
void *val;
|
void *val;
|
||||||
const void *var;
|
const void *var;
|
||||||
char state_num[25];
|
char state_num[25];
|
||||||
@ -607,6 +608,15 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw
|
|||||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", switch_channel_get_name(channel));
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", switch_channel_get_name(channel));
|
||||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session));
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session));
|
||||||
|
|
||||||
|
if ((codec = switch_core_session_get_read_codec(channel->session))) {
|
||||||
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Name", codec->implementation->iananame);
|
||||||
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Rate", "%u", codec->implementation->samples_per_second);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((codec = switch_core_session_get_write_codec(channel->session))) {
|
||||||
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Name", codec->implementation->iananame);
|
||||||
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Rate", "%u", codec->implementation->samples_per_second);
|
||||||
|
}
|
||||||
|
|
||||||
/* Index Caller's Profile */
|
/* Index Caller's Profile */
|
||||||
if (caller_profile) {
|
if (caller_profile) {
|
||||||
|
@ -2821,9 +2821,13 @@ static void core_event_handler(switch_event_t *event)
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case SWITCH_EVENT_CHANNEL_EXECUTE:
|
case SWITCH_EVENT_CHANNEL_EXECUTE:
|
||||||
sql = switch_core_db_mprintf("update channels set application='%q',application_data='%q' where uuid='%q'",
|
sql = switch_core_db_mprintf("update channels set application='%q',application_data='%q', read_codec='%q',read_rate='%q',write_codec='%q',write_rate='%q' where uuid='%q'",
|
||||||
switch_event_get_header(event, "application"),
|
switch_event_get_header(event, "application"),
|
||||||
switch_event_get_header(event, "application-data"),
|
switch_event_get_header(event, "application-data"),
|
||||||
|
switch_event_get_header(event, "channel-read-codec-name"),
|
||||||
|
switch_event_get_header(event, "channel-read-codec-rate"),
|
||||||
|
switch_event_get_header(event, "channel-write-codec-name"),
|
||||||
|
switch_event_get_header(event, "channel-write-codec-rate"),
|
||||||
switch_event_get_header(event, "unique-id")
|
switch_event_get_header(event, "unique-id")
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@ -3018,7 +3022,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(char *console, const char **err
|
|||||||
" ip_addr VARCHAR(255),\n"
|
" ip_addr VARCHAR(255),\n"
|
||||||
" dest VARCHAR(255),\n"
|
" dest VARCHAR(255),\n"
|
||||||
" application VARCHAR(255),\n"
|
" application VARCHAR(255),\n"
|
||||||
" application_data VARCHAR(255)\n"
|
" application_data VARCHAR(255),\n"
|
||||||
|
" read_codec VARCHAR(255),\n"
|
||||||
|
" read_rate VARCHAR(255),\n"
|
||||||
|
" write_codec VARCHAR(255),\n"
|
||||||
|
" write_rate VARCHAR(255)\n"
|
||||||
");\n";
|
");\n";
|
||||||
char create_calls_sql[] =
|
char create_calls_sql[] =
|
||||||
"CREATE TABLE calls (\n"
|
"CREATE TABLE calls (\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user