FS-6450 [unimrcp] Update library

[apr] Backport APR_RING_FOREACH and APR_RING_FOREACH_SAFE macros to APR for unimrcp compatibility.

 [unimrcp] configure.gnu - need full path, not relative path for library paths

 [unimrcp] added uni_revision.h - couldn't get it to autogenerate from build

 [mod_unimrcp] add better logging and error checking on module load.  Currently dumps core on MRCPv1 TTS attempt

 [mod_unimrcp] don't configure MRCPv1 session with a connection agent- causes crash
This commit is contained in:
Chris Rienzo committed 2014-11-18 14:23:54 -05:00
1 parent f198d82bac
commit 8330336e9a
533 files changed
+16386 -18997

No files matched your search

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010 Arsen Chaloyan
* Copyright 2008-2014 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: main.c 1785 2010-09-22 06:14:29Z achaloyan $
* $Id: main.c 2204 2014-10-31 01:01:42Z achaloyan@gmail.com $
*/
#include <stdlib.h>
@@ -22,16 +22,21 @@
#include "apt_pool.h"
#include "apt_dir_layout.h"
#include "apt_log.h"
#include "uni_version.h"
typedef struct {
const char *root_dir_path;
const char *dir_layout_conf;
apt_bool_t foreground;
const char *log_priority;
const char *log_output;
#ifdef WIN32
const char *svcname;
#endif
} server_options_t;
#ifdef WIN32
apt_bool_t uni_service_run(apt_dir_layout_t *dir_layout, apr_pool_t *pool);
apt_bool_t uni_service_run(const char *name, apt_dir_layout_t *dir_layout, apr_pool_t *pool);
#else
apt_bool_t uni_daemon_run(apt_dir_layout_t *dir_layout, apr_pool_t *pool);
#endif
@@ -42,6 +47,10 @@ apt_bool_t uni_cmdline_run(apt_dir_layout_t *dir_layout, apr_pool_t *pool);
static void usage()
{
printf(
"\n"
" * "UNI_COPYRIGHT"\n"
" *\n"
UNI_LICENSE"\n"
"\n"
"Usage:\n"
"\n"
@@ -49,7 +58,10 @@ static void usage()
"\n"
" Available options:\n"
"\n"
" -r [--root-dir] path : Set the project root directory path.\n"
" -r [--root-dir] path : Set the path to the project root directory.\n"
"\n"
" -c [--dir-layout] path : Set the path to the dir layout config file.\n"
" (takes the precedence over --root-dir option)\n"
"\n"
" -l [--log-prio] priority : Set the log priority.\n"
" (0-emergency, ..., 7-debug)\n"
@@ -58,12 +70,16 @@ static void usage()
" (0-none, 1-console only, 2-file only, 3-both)\n"
"\n"
#ifdef WIN32
" -s [--service] : Run as the Windows service.\n"
" -s [--service] : Run as a Windows service.\n"
"\n"
" -n [--name] svcname : Set the service name (default: unimrcp)\n"
"\n"
#else
" -d [--daemon] : Run as the daemon.\n"
" -d [--daemon] : Run as a daemon.\n"
"\n"
#endif
" -v [--version] : Show the version.\n"
"\n"
" -h [--help] : Show the help.\n"
"\n");
}
@@ -77,16 +93,19 @@ static apt_bool_t options_load(server_options_t *options, int argc, const char *
const apr_getopt_option_t opt_option[] = {
/* long-option, short-option, has-arg flag, description */
{ "root-dir", 'r', TRUE, "path to root dir" }, /* -r arg or --root-dir arg */
{ "log-prio", 'l', TRUE, "log priority" }, /* -l arg or --log-prio arg */
{ "log-output", 'o', TRUE, "log output mode" }, /* -o arg or --log-output arg */
{ "root-dir", 'r', TRUE, "path to root dir" }, /* -r arg or --root-dir arg */
{ "dir-layout", 'c', TRUE, "path to dir layout conf" }, /* -c arg or --dir-layout arg */
{ "log-prio", 'l', TRUE, "log priority" }, /* -l arg or --log-prio arg */
{ "log-output", 'o', TRUE, "log output mode" }, /* -o arg or --log-output arg */
#ifdef WIN32
{ "service", 's', FALSE, "run as service" }, /* -s or --service */
{ "service", 's', FALSE, "run as service" }, /* -s or --service */
{ "name", 'n', TRUE, "service name" }, /* -n or --name arg */
#else
{ "daemon", 'd', FALSE, "start as daemon" }, /* -d or --daemon */
{ "daemon", 'd', FALSE, "start as daemon" }, /* -d or --daemon */
#endif
{ "help", 'h', FALSE, "show help" }, /* -h or --help */
{ NULL, 0, 0, NULL }, /* end */
{ "version", 'v', FALSE, "show version" }, /* -v or --version */
{ "help", 'h', FALSE, "show help" }, /* -h or --help */
{ NULL, 0, 0, NULL }, /* end */
};
rv = apr_getopt_init(&opt, pool , argc, argv);
@@ -94,11 +113,24 @@ static apt_bool_t options_load(server_options_t *options, int argc, const char *
return FALSE;
}
/* reset the options */
options->root_dir_path = NULL;
options->dir_layout_conf = NULL;
options->foreground = TRUE;
options->log_priority = NULL;
options->log_output = NULL;
#ifdef WIN32
options->svcname = NULL;
#endif
while((rv = apr_getopt_long(opt, opt_option, &optch, &optarg)) == APR_SUCCESS) {
switch(optch) {
case 'r':
options->root_dir_path = optarg;
break;
case 'c':
options->dir_layout_conf = optarg;
break;
case 'l':
options->log_priority = optarg;
break;
@@ -109,11 +141,17 @@ static apt_bool_t options_load(server_options_t *options, int argc, const char *
case 's':
options->foreground = FALSE;
break;
case 'n':
options->svcname = optarg;
break;
#else
case 'd':
options->foreground = FALSE;
break;
#endif
case 'v':
printf(UNI_VERSION_STRING);
return FALSE;
case 'h':
usage();
return FALSE;
@@ -130,10 +168,10 @@ static apt_bool_t options_load(server_options_t *options, int argc, const char *
int main(int argc, const char * const *argv)
{
apr_pool_t *pool = NULL;
apr_pool_t *pool;
server_options_t options;
apt_dir_layout_t *dir_layout;
const char *log_conf_path;
apt_dir_layout_t *dir_layout = NULL;
/* APR global initialization */
if(apr_initialize() != APR_SUCCESS) {
@@ -148,12 +186,6 @@ int main(int argc, const char * const *argv)
return 0;
}
/* set the default options */
options.root_dir_path = "../";
options.foreground = TRUE;
options.log_priority = NULL;
options.log_output = NULL;
/* load options */
if(options_load(&options,argc,argv,pool) != TRUE) {
apr_pool_destroy(pool);
@@ -161,9 +193,24 @@ int main(int argc, const char * const *argv)
return 0;
}
/* create the structure of default directories layout */
dir_layout = apt_default_dir_layout_create(options.root_dir_path,pool);
if(options.dir_layout_conf) {
/* create and load directories layout from the configuration file */
dir_layout = apt_dir_layout_create(pool);
if(dir_layout)
apt_dir_layout_load(dir_layout,options.dir_layout_conf,pool);
}
else {
/* create default directories layout */
dir_layout = apt_default_dir_layout_create(options.root_dir_path,pool);
}
if(!dir_layout) {
printf("Failed to Create Directories Layout\n");
apr_pool_destroy(pool);
apr_terminate();
return 0;
}
/* get path to logger configuration file */
log_conf_path = apt_confdir_filepath_get(dir_layout,"logger.xml",pool);
/* create and load singleton logger */
@@ -180,7 +227,8 @@ int main(int argc, const char * const *argv)
if(apt_log_output_mode_check(APT_LOG_OUTPUT_FILE) == TRUE) {
/* open the log file */
apt_log_file_open(dir_layout->log_dir_path,"unimrcpserver",MAX_LOG_FILE_SIZE,MAX_LOG_FILE_COUNT,TRUE,pool);
const char *log_dir_path = apt_dir_layout_path_get(dir_layout,APT_LAYOUT_LOG_DIR);
apt_log_file_open(log_dir_path,"unimrcpserver",MAX_LOG_FILE_SIZE,MAX_LOG_FILE_COUNT,TRUE,pool);
}
if(options.foreground == TRUE) {
@@ -190,7 +238,7 @@ int main(int argc, const char * const *argv)
#ifdef WIN32
else {
/* run as windows service */
uni_service_run(dir_layout,pool);
uni_service_run(options.svcname,dir_layout,pool);
}
#else
else {
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010 Arsen Chaloyan
* Copyright 2008-2014 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: uni_cmdline.c 1474 2010-02-07 20:51:47Z achaloyan $
* $Id: uni_cmdline.c 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
*/
#include <stdio.h>
@@ -52,7 +52,7 @@ apt_bool_t uni_cmdline_run(apt_dir_layout_t *dir_layout, apr_pool_t *pool)
{
apt_bool_t running = TRUE;
char cmdline[1024];
int i;
apr_size_t i;
mrcp_server_t *server;
/* start server */
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010 Arsen Chaloyan
* Copyright 2008-2014 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: uni_daemon.c 1474 2010-02-07 20:51:47Z achaloyan $
* $Id: uni_daemon.c 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
*/
#include <apr_signal.h>
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010 Arsen Chaloyan
* Copyright 2008-2014 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: uni_service.c 1474 2010-02-07 20:51:47Z achaloyan $
* $Id: uni_service.c 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
*/
#include <windows.h>
@@ -28,11 +28,25 @@ static SERVICE_STATUS win_service_status;
static mrcp_server_t *server = NULL;
static apt_dir_layout_t *service_dir_layout = NULL;
static const char *svcname = NULL;
/** Display error message with Windows error code and description */
static void winerror(const char *file, int line, const char *msg)
{
char buf[128];
DWORD err = GetLastError();
int ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, sizeof(buf), NULL);
apt_log(file, line, APT_PRIO_WARNING, "%s: %lu %.*s\n", msg, err, ret, buf);
}
/** SCM state change handler */
static void WINAPI win_service_handler(DWORD control)
{
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Service Handler %d",control);
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Service Handler 0x%02lx",control);
switch (control)
{
case SERVICE_CONTROL_INTERROGATE:
@@ -42,7 +56,7 @@ static void WINAPI win_service_handler(DWORD control)
if(server) {
win_service_status.dwCurrentState = SERVICE_STOP_PENDING;
if(!SetServiceStatus(win_service_status_handle, &win_service_status)) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Set Service Status %d",GetLastError());
winerror(APT_LOG_MARK, "Failed to Set Service Status");
}
/* shutdown server */
@@ -55,7 +69,7 @@ static void WINAPI win_service_handler(DWORD control)
}
if(!SetServiceStatus(win_service_status_handle, &win_service_status)) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Set Service Status %d",GetLastError());
winerror(APT_LOG_MARK, "Failed to Set Service Status");
}
}
@@ -69,15 +83,15 @@ static void WINAPI win_service_main(DWORD argc, LPTSTR *argv)
win_service_status.dwCheckPoint = 0;
win_service_status.dwWaitHint = 0;
win_service_status_handle = RegisterServiceCtrlHandler(WIN_SERVICE_NAME, win_service_handler);
win_service_status_handle = RegisterServiceCtrlHandler(svcname, win_service_handler);
if(win_service_status_handle == (SERVICE_STATUS_HANDLE)0) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Register Service Control Handler %d",GetLastError());
winerror(APT_LOG_MARK, "Failed to Register Service Control Handler");
return;
}
win_service_status.dwCurrentState = SERVICE_START_PENDING;
if(!SetServiceStatus(win_service_status_handle, &win_service_status)) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Set Service Status %d",GetLastError());
winerror(APT_LOG_MARK, "Failed to Set Service Status");
}
/* start server */
@@ -85,22 +99,23 @@ static void WINAPI win_service_main(DWORD argc, LPTSTR *argv)
win_service_status.dwCurrentState = server ? SERVICE_RUNNING : SERVICE_STOPPED;
if(!SetServiceStatus(win_service_status_handle, &win_service_status)) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Set Service Status %d",GetLastError());
winerror(APT_LOG_MARK, "Failed to Set Service Status");
}
}
/** Run SCM service */
apt_bool_t uni_service_run(apt_dir_layout_t *dir_layout, apr_pool_t *pool)
apt_bool_t uni_service_run(const char *name, apt_dir_layout_t *dir_layout, apr_pool_t *pool)
{
SERVICE_TABLE_ENTRY win_service_table[] = {
{ WIN_SERVICE_NAME, win_service_main },
{ NULL, NULL }
};
SERVICE_TABLE_ENTRY win_service_table[2];
svcname = name ? name : WIN_SERVICE_NAME;
memset(&win_service_table, 0, sizeof(win_service_table));
win_service_table->lpServiceName = (char *) svcname;
win_service_table->lpServiceProc = win_service_main;
service_dir_layout = dir_layout;
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Run as Service");
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Run as Service %s",svcname);
if(!StartServiceCtrlDispatcher(win_service_table)) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Connect to SCM %d",GetLastError());
winerror(APT_LOG_MARK, "Failed to Connect to SCM");
}
return TRUE;
}