aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-08-16 14:48:05 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-08-16 14:48:05 +0000
commitb7fbd14cece6a0345918a946fdba5bdc3268e539 (patch)
treefcbef020d83e4b58d4c02767b399ff6820ded89e
parentc3ef7b672f25621ba670ba22955a3dfc0953c739 (diff)
New "show codecs" option and mysql feature requests from Tilghman
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1349 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xcdr/cdr_mysql.c41
-rwxr-xr-xconfigs/cdr_mysql.conf.sample9
-rwxr-xr-xframe.c111
-rwxr-xr-xinclude/asterisk/frame.h8
4 files changed, 165 insertions, 4 deletions
diff --git a/cdr/cdr_mysql.c b/cdr/cdr_mysql.c
index f60936133..a74756b24 100755
--- a/cdr/cdr_mysql.c
+++ b/cdr/cdr_mysql.c
@@ -37,8 +37,9 @@
static char *desc = "MySQL CDR Backend";
static char *name = "mysql";
static char *config = "cdr_mysql.conf";
-static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL;
-static int hostname_alloc = 0, dbname_alloc = 0, dbuser_alloc = 0, password_alloc = 0;
+static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *dbsock = NULL;
+static int hostname_alloc = 0, dbname_alloc = 0, dbuser_alloc = 0, password_alloc = 0, dbsock_alloc = 0;
+static int dbport = 0;
static int connected = 0;
static ast_mutex_t mysql_lock = AST_MUTEX_INITIALIZER;
@@ -61,10 +62,10 @@ static int mysql_log(struct ast_cdr *cdr)
localtime_r(&t,&tm);
strftime(timestr,128,DATE_FORMAT,&tm);
- if ((!connected) && hostname && dbuser && password && dbname) {
+ if ((!connected) && (hostname || dbsock) && dbuser && password && dbname) {
/* Attempt to connect */
mysql_init(&mysql);
- if (mysql_real_connect(&mysql, hostname, dbuser, password, dbname, 0, NULL, 0)) {
+ if (mysql_real_connect(&mysql, hostname, dbuser, password, dbname, dbport, dbsock, 0)) {
connected = 1;
} else {
ast_log(LOG_ERROR, "cdr_mysql: cannot connect to database server %s. Call will not be logged\n", hostname);
@@ -129,11 +130,17 @@ int unload_module(void)
dbuser = NULL;
dbuser_alloc = 0;
}
+ if (dbsock && dbsock_alloc) {
+ free(dbsock);
+ dbsock = NULL;
+ dbsock_alloc = 0;
+ }
if (password && password_alloc) {
free(password);
password = NULL;
password_alloc = 0;
}
+ dbport = 0;
ast_cdr_unregister(name);
return 0;
}
@@ -202,6 +209,21 @@ int load_module(void)
dbuser = "root";
}
+ tmp = ast_variable_retrieve(cfg,"global","sock");
+ if (tmp) {
+ dbsock = malloc(strlen(tmp) + 1);
+ if (dbsock != NULL) {
+ dbsock_alloc = 1;
+ strcpy(dbsock,tmp);
+ } else {
+ ast_log(LOG_ERROR,"Out of memory error.\n");
+ return -1;
+ }
+ } else {
+ ast_log(LOG_WARNING,"MySQL database sock file not specified. Assuming default\n");
+ dbsock = NULL;
+ }
+
tmp = ast_variable_retrieve(cfg,"global","password");
if (tmp) {
password = malloc(strlen(tmp) + 1);
@@ -217,9 +239,20 @@ int load_module(void)
password = "";
}
+ tmp = ast_variable_retrieve(cfg,"global","port");
+ if (tmp) {
+ if (sscanf(tmp,"%d",&dbport) < 1) {
+ ast_log(LOG_WARNING,"Invalid MySQL port number. Using default\n");
+ dbport = 0;
+ }
+ }
+
ast_destroy(cfg);
ast_log(LOG_DEBUG,"cdr_mysql: got hostname of %s\n",hostname);
+ ast_log(LOG_DEBUG,"cdr_mysql: got port of %d\n",dbport);
+ if (dbsock)
+ ast_log(LOG_DEBUG,"cdr_mysql: got sock file of %s\n",dbsock);
ast_log(LOG_DEBUG,"cdr_mysql: got user of %s\n",dbuser);
ast_log(LOG_DEBUG,"cdr_mysql: got dbname of %s\n",dbname);
ast_log(LOG_DEBUG,"cdr_mysql: got password of %s\n",password);
diff --git a/configs/cdr_mysql.conf.sample b/configs/cdr_mysql.conf.sample
index 0c2fbb996..46b1dd34e 100755
--- a/configs/cdr_mysql.conf.sample
+++ b/configs/cdr_mysql.conf.sample
@@ -3,8 +3,17 @@
; asterisk server, you can achieve a local Unix socket connection by
; setting hostname=localhost
;
+; port and sock are both optional parameters. If hostname is specified
+; and is not "localhost", then cdr_mysql will attempt to connect to the
+; port specified or use the default port. If hostname is not specified
+; or if hostname is "localhost", then cdr_mysql will attempt to connect
+; to the socket file specified by sock or otherwise use the default socket
+; file.
+;
;[global]
;hostname=database.host.name
;dbname=asteriskcdrdb
;password=password
;user=asteriskcdruser
+;port=3306
+;sock=/tmp/mysql.sock
diff --git a/frame.c b/frame.c
index 2e53f8d1e..b2f6736b0 100755
--- a/frame.c
+++ b/frame.c
@@ -411,6 +411,112 @@ int ast_getformatbyname(char *name)
return 0;
}
+char *ast_codec2str(int codec) {
+ static char codecs[25][30] = {
+ /* Audio formats */
+ "G.723.1", /* 0 */
+ "GSM", /* 1 */
+ "G.711 u-law", /* 2 */
+ "G.711 A-law", /* 3 */
+ "MPEG-2 layer 3", /* 4 */
+ "ADPCM", /* 5 */
+ "16 bit Signed Linear PCM", /* 6 */
+ "LPC10", /* 7 */
+ "G.729A audio", /* 8 */
+ "SpeeX", /* 9 */
+ "iLBC", /* 10 */
+ "undefined", /* 11 */
+ "undefined", /* 12 */
+ "undefined", /* 13 */
+ "undefined", /* 14 */
+ "Maximum audio format", /* 15 */
+ /* Image formats */
+ "JPEG image", /* 16 */
+ "PNG image", /* 17 */
+ "H.261 Video", /* 18 */
+ "H.263 Video", /* 19 */
+ "undefined", /* 20 */
+ "undefined", /* 21 */
+ "undefined", /* 22 */
+ "undefined", /* 23 */
+ "Maximum video format", /* 24 */
+ };
+ return codecs[codec];
+}
+
+static int show_codecs(int fd, int argc, char *argv[])
+{
+ int i, found=0;
+
+ if ((argc < 2) || (argc > 3))
+ return RESULT_SHOWUSAGE;
+
+ if ((argc == 2) || (!strcasecmp(argv[1],"audio"))) {
+ found = 1;
+ for (i=0;i<11;i++)
+ ast_cli(fd, "%8d (1 << %2d) %s\n",1 << i,i,ast_codec2str(i));
+ }
+
+ if ((argc == 2) || (!strcasecmp(argv[1],"image"))) {
+ found = 1;
+ for (i=16;i<18;i++)
+ ast_cli(fd, "%8d (1 << %2d) %s\n",1 << i,i,ast_codec2str(i));
+ }
+
+ if ((argc == 2) || (!strcasecmp(argv[1],"video"))) {
+ found = 1;
+ for (i=18;i<20;i++)
+ ast_cli(fd, "%8d (1 << %2d) %s\n",1 << i,i,ast_codec2str(i));
+ }
+
+ if (! found)
+ return RESULT_SHOWUSAGE;
+ else
+ return RESULT_SUCCESS;
+}
+
+static char frame_show_codecs_usage[] =
+"Usage: show [audio|video|image] codecs\n"
+" Displays codec mapping\n";
+
+struct ast_cli_entry cli_show_codecs =
+{ { "show", "codecs", NULL }, show_codecs, "Shows codecs", frame_show_codecs_usage };
+struct ast_cli_entry cli_show_codecs_audio =
+{ { "show", "audio", "codecs", NULL }, show_codecs, "Shows audio codecs", frame_show_codecs_usage };
+struct ast_cli_entry cli_show_codecs_video =
+{ { "show", "video", "codecs", NULL }, show_codecs, "Shows video codecs", frame_show_codecs_usage };
+struct ast_cli_entry cli_show_codecs_image =
+{ { "show", "image", "codecs", NULL }, show_codecs, "Shows image codecs", frame_show_codecs_usage };
+
+static int show_codec_n(int fd, int argc, char *argv[])
+{
+ int codec, i, found=0;
+
+ if (argc != 3)
+ return RESULT_SHOWUSAGE;
+
+ if (sscanf(argv[2],"%d",&codec) != 1)
+ return RESULT_SHOWUSAGE;
+
+ for (i=0;i<32;i++)
+ if (codec == (1 << i)) {
+ found = 1;
+ ast_cli(fd, "%d (1 << %d) %s\n",1 << i,i,ast_codec2str(i));
+ }
+
+ if (! found)
+ ast_cli(fd, "Codec %d not found\n", codec);
+
+ return RESULT_SUCCESS;
+}
+
+static char frame_show_codec_n_usage[] =
+"Usage: show codec <number>\n"
+" Displays codec mapping\n";
+
+struct ast_cli_entry cli_show_codec_n =
+{ { "show", "codec", NULL }, show_codec_n, "Shows a specific codec", frame_show_codec_n_usage };
+
void ast_frame_dump(char *name, struct ast_frame *f, char *prefix)
{
char *n = "unknown";
@@ -598,5 +704,10 @@ int init_framer(void)
#ifdef TRACE_FRAMES
ast_cli_register(&cli_frame_stats);
#endif
+ ast_cli_register(&cli_show_codecs);
+ ast_cli_register(&cli_show_codecs_audio);
+ ast_cli_register(&cli_show_codecs_video);
+ ast_cli_register(&cli_show_codecs_image);
+ ast_cli_register(&cli_show_codec_n);
return 0;
}
diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h
index bd1bb2a72..66b080f42 100755
--- a/include/asterisk/frame.h
+++ b/include/asterisk/frame.h
@@ -323,6 +323,14 @@ extern char* ast_getformatname(int format);
*/
extern int ast_getformatbyname(char *name);
+//! Get a name from a format
+/*!
+ * \param codec codec number (1,2,4,8,16,etc.)
+ * Gets a name from a format
+ * This returns a static string identifying the format on success, 0 on error.
+ */
+extern char *ast_codec2str(int codec);
+
//! Pick the best codec
/* Choose the best codec... Uhhh... Yah. */
extern int ast_best_codec(int fmts);