freeswitch-branches
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
December 2008
- 2 participants
- 88 discussions
[Freeswitch-branches] [commit] r10771 - in freeswitch/branches/gmaruzz/src: . include mod/endpoints/mod_skypiax
by FreeSWITCH SVN 15 Dec '08
by FreeSWITCH SVN 15 Dec '08
15 Dec '08
Author: gmaruzz
Date: Mon Dec 15 12:26:36 2008
New Revision: 10771
Log:
skypiax: prepare for merging with trunk, cleaning the switch_apr.c and switch_apr.h files
Modified:
freeswitch/branches/gmaruzz/src/include/switch_apr.h
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
freeswitch/branches/gmaruzz/src/switch_apr.c
Modified: freeswitch/branches/gmaruzz/src/include/switch_apr.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_apr.h (original)
+++ freeswitch/branches/gmaruzz/src/include/switch_apr.h Mon Dec 15 12:26:36 2008
@@ -1303,7 +1303,17 @@
SWITCH_DECLARE(switch_status_t) switch_match_glob(const char *pattern, switch_array_header_t **result, switch_memory_pool_t *p);
SWITCH_DECLARE(switch_status_t) switch_socket_addr_get(switch_sockaddr_t **sa, switch_bool_t remote, switch_socket_t *sock);
-SWITCH_DECLARE(switch_status_t) switch_file_pipe_create_ex(switch_file_t **in, switch_file_t **out, int32_t blocking, switch_memory_pool_t *p);
+
+/**
+ * Create an anonymous pipe.
+ * @param in The file descriptor to use as input to the pipe.
+ * @param out The file descriptor to use as output from the pipe.
+ * @param pool The pool to operate on.
+ * @remark By default, the returned file descriptors will be inherited
+ * by child processes created using apr_proc_create(). This can be
+ * changed using apr_file_inherit_unset().
+ */
+SWITCH_DECLARE(switch_status_t) switch_file_pipe_create(switch_file_t **in, switch_file_t **out, switch_memory_pool_t *p);
/**
* Get the timeout value for a pipe or manipulate the blocking state.
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c Mon Dec 15 12:26:36 2008
@@ -344,16 +344,14 @@
switch_status_t rv;
rv =
- switch_file_pipe_create_ex(&p->audiopipe[0], &p->audiopipe[1], 2,
- skypiax_module_pool);
+ switch_file_pipe_create(&p->audiopipe[0], &p->audiopipe[1], skypiax_module_pool);
rv = switch_file_pipe_timeout_set(p->audiopipe[0], 100000);
/* the pipe is our audio fd for pbx to poll on */
p->skypiax_sound_capt_fd = p->audiopipe[0];
rv =
- switch_file_pipe_create_ex(&p->audioskypepipe[0], &p->audioskypepipe[1], 2,
- skypiax_module_pool);
+ switch_file_pipe_create(&p->audioskypepipe[0], &p->audioskypepipe[1], skypiax_module_pool);
rv = switch_file_pipe_timeout_set(p->audioskypepipe[0], 100);
if (option_debug > 10) {
DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
@@ -596,8 +594,7 @@
//DWORD MsgWaitResult;
p = obj;
- switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0],
- &p->AsteriskHandlesAst.fdesc[1], 2, skypiax_module_pool);
+ switch_file_pipe_create(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], skypiax_module_pool);
switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100000);
win32_AsteriskHandlesSkype = &p->AsteriskHandlesAst;
@@ -780,8 +777,7 @@
p = obj;
DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
- switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0],
- &p->AsteriskHandlesAst.fdesc[1], 2, skypiax_module_pool);
+ switch_file_pipe_create(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], skypiax_module_pool);
switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100000);
AsteriskHandlesAst = &p->AsteriskHandlesAst;
Modified: freeswitch/branches/gmaruzz/src/switch_apr.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_apr.c (original)
+++ freeswitch/branches/gmaruzz/src/switch_apr.c Mon Dec 15 12:26:36 2008
@@ -942,9 +942,17 @@
return apr_match_glob(pattern, (apr_array_header_t **) result, p);
}
-SWITCH_DECLARE(switch_status_t) switch_file_pipe_create_ex(switch_file_t **in, switch_file_t **out, int32_t blocking, switch_memory_pool_t *p)
+/**
+ * Create an anonymous pipe.
+ * @param in The file descriptor to use as input to the pipe.
+ * @param out The file descriptor to use as output from the pipe.
+ * @param pool The pool to operate on.
+ * @remark By default, the returned file descriptors will be inherited
+ * by child processes created using apr_proc_create(). This can be
+ * changed using apr_file_inherit_unset().
+ */
+SWITCH_DECLARE(switch_status_t) switch_file_pipe_create(switch_file_t **in, switch_file_t **out, switch_memory_pool_t *p)
{
- //return apr_file_pipe_create_ex ((apr_file_t **) in, (apr_file_t **) out, blocking, p);
return apr_file_pipe_create ((apr_file_t **) in, (apr_file_t **) out, p);
}
1
0
[Freeswitch-branches] [commit] r10769 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by FreeSWITCH SVN 15 Dec '08
by FreeSWITCH SVN 15 Dec '08
15 Dec '08
Author: gmaruzz
Date: Mon Dec 15 11:52:02 2008
New Revision: 10769
Log:
skypiax: better performance on linux???
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c Mon Dec 15 11:52:02 2008
@@ -118,9 +118,11 @@
fdselect = fd;
FD_ZERO(&fs);
FD_SET(fdselect, &fs);
- to.tv_usec = 100;
+ to.tv_usec = 10000;
to.tv_sec = 0;
rt = select(fdselect + 1, &fs, NULL, NULL, &to);
+ //usleep(1000);
+ //rt=1;
if (rt > 0) {
len = recv(fd, srv_in, sizeof(short) * SAMPLES_PER_FRAME, 0);
@@ -283,8 +285,10 @@
fdselect = 1;
FD_ZERO(&fs);
FD_SET(fdselect, &fs);
- to.tv_usec = 100;
+ to.tv_usec = 10000;
to.tv_sec = 0;
+ //rt = select(fdselect + 1, &fs, NULL, NULL, &to);
+ usleep(5000);
rt = 1;
if (rt > 0) {
@@ -845,6 +849,7 @@
b = buffer;
while (1) {
+ usleep(1000);
XNextEvent(disp, &an_event);
if (!running)
break;
1
0
[Freeswitch-branches] [commit] r10765 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by FreeSWITCH SVN 15 Dec '08
by FreeSWITCH SVN 15 Dec '08
15 Dec '08
Author: gmaruzz
Date: Mon Dec 15 05:05:50 2008
New Revision: 10765
Log:
skypiax: multiline on linux
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c Mon Dec 15 05:05:50 2008
@@ -595,6 +595,7 @@
{
char *cf = "skypiax.conf";
switch_xml_t cfg, xml, global_settings, param, interfaces, myinterface;
+ skypiax_interface_t *p = NULL;
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, skypiax_module_pool);
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
@@ -672,6 +673,8 @@
char *fail_dial_regex = NULL;
char *enable_callerid = "true";
char *X11_display = NULL;
+ char *tcp_cli_port = NULL;
+ char *tcp_srv_port = NULL;
uint32_t interface_id = 0, to = 0, max = 0;
@@ -695,6 +698,10 @@
fail_dial_regex = val;
} else if (!strcasecmp(var, "hold-music")) {
hold_music = val;
+ } else if (!strcasecmp(var, "tcp_cli_port")) {
+ tcp_cli_port = val;
+ } else if (!strcasecmp(var, "tcp_srv_port")) {
+ tcp_srv_port = val;
} else if (!strcasecmp(var, "X11-display") || !strcasecmp(var, "X11_display")) {
X11_display = val;
} else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) {
@@ -710,7 +717,17 @@
"interface missing REQUIRED param 'X11_display'\n");
continue;
}
+ if (!tcp_cli_port) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "interface missing REQUIRED param 'tcp_cli_port'\n");
+ continue;
+ }
+ if (!tcp_srv_port) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "interface missing REQUIRED param 'tcp_srv_port'\n");
+ continue;
+ }
if (!id) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"interface missing REQUIRED param 'id'\n");
@@ -771,13 +788,25 @@
} else {
switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].name, "N/A");
}
+ globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port = atoi(tcp_cli_port);
+ globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port = atoi(tcp_srv_port);
+ //switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port, tcp_cli_port);
+ //switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port, tcp_srv_port);
switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].X11_display, X11_display);
switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].context, context);
switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].dialplan, dialplan);
+
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].X11_display=%s\n",
interface_id, globals.SKYPIAX_INTERFACES[interface_id].X11_display);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+ "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port=%d\n",
+ interface_id, globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+ "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port=%d\n",
+ interface_id, globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].name=%s\n",
interface_id, globals.SKYPIAX_INTERFACES[interface_id].name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h Mon Dec 15 05:05:50 2008
@@ -148,6 +148,8 @@
char hold_music[256];
char type[256];
char X11_display[256];
+ int tcp_cli_port;
+ int tcp_srv_port;
struct AsteriskHandles AsteriskHandlesAst;
int interface_state; /*!< \brief 'state' of the interface (channel) */
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c Mon Dec 15 05:05:50 2008
@@ -27,9 +27,9 @@
HANDLE volatile win32_hGlobal_PromptConsoleHandle = NULL;
#else /* NOT WIN32 */
#define SKYPE_X11_BUF_SIZE 512
-Window skype_win = (Window) - 1;
-static XErrorHandler old_handler = 0;
-static int xerror = 0;
+//Window skype_win = (Window) - 1;
+//static XErrorHandler old_handler = 0;
+//static int xerror = 0;
#endif /* WIN32 */
@@ -72,7 +72,7 @@
memset(&my_addr, 0, sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_addr.s_addr = htonl(0x7f000001); /* use the localhost */
- my_addr.sin_port = htons(5556); //FIXME configurable!
+ my_addr.sin_port = htons(p->tcp_srv_port); //FIXME configurable!
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
ERRORA("socket Error\n", SKYPIAX_P_LOG);
@@ -235,7 +235,7 @@
memset(&my_addr, 0, sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_addr.s_addr = htonl(0x7f000001); /* use the localhost */
- my_addr.sin_port = htons(5558); //FIXME configurable!
+ my_addr.sin_port = htons(p->tcp_cli_port); //FIXME configurable!
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
ERRORA("socket Error\n", SKYPIAX_P_LOG);
@@ -635,6 +635,7 @@
}
#else /* NOT WIN32 */
+#if 0
int X11_errors_handler(Display * dpy, XErrorEvent * err)
{
(void) dpy;
@@ -656,6 +657,7 @@
XSetErrorHandler(old_handler);
return (xerror != BadValue) && (xerror != BadWindow);
}
+#endif
int skypiax_skype_send_message(struct AsteriskHandles *AsteriskHandlesAst,
const char *message_P)
@@ -664,7 +666,7 @@
Window w_P;
Display *disp;
Window handle_P;
- struct skypiax_interface *p = NULL;
+ //struct skypiax_interface *p = NULL;
w_P = AsteriskHandlesAst->skype_win;
disp = AsteriskHandlesAst->disp;
@@ -675,7 +677,7 @@
unsigned int pos = 0;
unsigned int len = strlen(message_P);
XEvent e;
- int ok;
+ //int ok;
memset(&e, 0, sizeof(e));
e.xclient.type = ClientMessage;
@@ -684,7 +686,7 @@
e.xclient.window = handle_P;
e.xclient.format = 8;
- X11_errors_trap();
+ //X11_errors_trap();
//XLockDisplay(disp);
do {
unsigned int i;
@@ -698,17 +700,17 @@
XSync(disp, False);
//XUnlockDisplay(disp);
- ok = X11_errors_untrap();
+ //ok = X11_errors_untrap();
- if (!ok)
- DEBUGA_SKYPE("Sending message failed with status %d\n", SKYPIAX_P_LOG, xerror);
+ //if (!ok) DEBUGA_SKYPE("Sending message failed with status %d\n", SKYPIAX_P_LOG, xerror);
- return ok;
+ //return ok;
+ return 1;
}
-int skypiax_skype_present(Display * disp)
+int skypiax_skype_present(struct AsteriskHandles *AsteriskHandlesAst)
{
- Atom skype_inst = XInternAtom(disp, "_SKYPE_INSTANCE", True);
+ Atom skype_inst = XInternAtom(AsteriskHandlesAst->disp, "_SKYPE_INSTANCE", True);
Atom type_ret;
int format_ret;
@@ -718,25 +720,25 @@
int status;
struct skypiax_interface *p = NULL;
- X11_errors_trap();
+ //X11_errors_trap();
//XLockDisplay(disp);
status =
- XGetWindowProperty(disp, DefaultRootWindow(disp), skype_inst, 0, 1, False, XA_WINDOW,
+ XGetWindowProperty(AsteriskHandlesAst->disp, DefaultRootWindow(AsteriskHandlesAst->disp), skype_inst, 0, 1, False, XA_WINDOW,
&type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop);
//XUnlockDisplay(disp);
- X11_errors_untrap();
+ //X11_errors_untrap();
/* sanity check */
if (status != Success || format_ret != 32 || nitems_ret != 1) {
- skype_win = (Window) - 1;
+ AsteriskHandlesAst->skype_win = (Window) - 1;
DEBUGA_SKYPE("Skype instance not found\n", SKYPIAX_P_LOG);
return 0;
}
- skype_win = *(const unsigned long *) prop & 0xffffffff;
+ AsteriskHandlesAst->skype_win = *(const unsigned long *) prop & 0xffffffff;
//DEBUGA_SKYPE("Skype instance found with id #%x\n", SKYPIAX_P_LOG,
DEBUGA_SKYPE("Skype instance found with id #%d\n", SKYPIAX_P_LOG,
- (unsigned int) skype_win);
+ (unsigned int) AsteriskHandlesAst->skype_win);
return 1;
}
@@ -798,7 +800,9 @@
//FIXME pthread_cleanup_push(skypiax_skype_clean_disp, &xfd);
DEBUGA_SKYPE("PUSH disp %d\n", SKYPIAX_P_LOG, xfd);
- if (skypiax_skype_present(disp)) {
+ AsteriskHandlesAst->disp = disp;
+
+ if (skypiax_skype_present(AsteriskHandlesAst)) {
root = DefaultRootWindow(disp);
win =
XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0,
@@ -806,11 +810,10 @@
DefaultScreen
(disp)));
- DEBUGA_SKYPE("skype_win=%d win=%d\n", SKYPIAX_P_LOG, (unsigned int) skype_win,
- (unsigned int) win);
+ //DEBUGA_SKYPE("skype_win=%d win=%d\n", SKYPIAX_P_LOG, (unsigned int) skype_win, (unsigned int) win);
- AsteriskHandlesAst->skype_win = skype_win;
- AsteriskHandlesAst->disp = disp;
+ //AsteriskHandlesAst->skype_win = skype_win;
+ //AsteriskHandlesAst->disp = disp;
AsteriskHandlesAst->win = win;
snprintf(buf, SKYPE_X11_BUF_SIZE, "NAME skypiax");
@@ -1309,10 +1312,10 @@
DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
}
switch_sleep(100000);
- sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"5556\"", id);
+ sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id, p->tcp_srv_port);
skypiax_skype_write(p, msg_to_skype);
switch_sleep(100000);
- sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"5558\"", id);
+ sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id, p->tcp_cli_port);
skypiax_skype_write(p, msg_to_skype);
switch_sleep(100000);
}
1
0
[Freeswitch-branches] [commit] r10753 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by FreeSWITCH SVN 13 Dec '08
by FreeSWITCH SVN 13 Dec '08
13 Dec '08
Author: gmaruzz
Date: Sat Dec 13 11:46:57 2008
New Revision: 10753
Log:
skypiax: cleaning, restructuring
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c Sat Dec 13 11:46:57 2008
@@ -2,7 +2,6 @@
SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown);
-//SWITCH_MODULE_RUNTIME_FUNCTION(mod_skypiax_runtime);
SWITCH_MODULE_DEFINITION(mod_skypiax, mod_skypiax_load, mod_skypiax_shutdown, NULL); //mod_skypiax_runtime);
static struct {
@@ -31,10 +30,6 @@
switch_endpoint_interface_t *skypiax_endpoint_interface;
switch_memory_pool_t *skypiax_module_pool = NULL;
int running = 1;
-switch_core_session_t *global_session = NULL;
-#ifdef WIN32
-HWND win32_hInit_MainWindowHandle;
-#endif /* WIN32 */
/*************************************************/
/*************************************************/
/*************************************************/
@@ -905,7 +900,7 @@
if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread){
#ifdef WIN32
- if (SendMessage(win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) { // let's the do_skype_thread die
+ if (SendMessage(p->AsteriskHandlesAst.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) { // let's the do_skype_thread die
ERRORA("WHY FALSE HERE? %d\n", SKYPIAX_P_LOG, GetLastError());
}
#else
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c Sat Dec 13 11:46:57 2008
@@ -2,16 +2,21 @@
extern switch_memory_pool_t *skypiax_module_pool;
extern int option_debug;
-extern switch_core_session_t *global_session;
extern switch_endpoint_interface_t *skypiax_endpoint_interface;
extern int running;
-#ifdef WIN32
-extern HWND win32_hInit_MainWindowHandle;
-#endif /* WIN32 */
+
+
+
/**********************************************************/
/**********************************************************/
/**********************************************************/
+
+
+switch_core_session_t *global_session = NULL;
+
+
#ifdef WIN32
+HWND win32_hInit_MainWindowHandle;
struct AsteriskHandles *win32_AsteriskHandlesSkype;
HINSTANCE win32_hInit_ProcessHandle;
char win32_acInit_WindowClassName[128];
@@ -26,13 +31,13 @@
static XErrorHandler old_handler = 0;
static int xerror = 0;
#endif /* WIN32 */
+
+
+
/**********************************************************/
/**********************************************************/
/**********************************************************/
#define SAMPLES_PER_FRAME 160
-#define SAMPLES_PER_FRAME 160
-#define SAMPLES_PER_FRAME 160
-
static void *SWITCH_THREAD_FUNC skypiax_do_tcp_srv_thread(switch_thread_t * thread,
void *obj)
1
0
[Freeswitch-branches] [commit] r10752 - freeswitch/branches/cseket/src/mod/applications/mod_voicemail
by FreeSWITCH SVN 13 Dec '08
by FreeSWITCH SVN 13 Dec '08
13 Dec '08
Author: cseket
Date: Sat Dec 13 10:22:36 2008
New Revision: 10752
Log:
load profiles on the fly. add loading functions (MODAPP-177)
Modified:
freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c
Modified: freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c (original)
+++ freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c Sat Dec 13 10:22:36 2008
@@ -51,6 +51,7 @@
static switch_status_t voicemail_inject(const char *data);
+const char *global_cf = "voicemail.conf";
static struct {
switch_hash_t *profile_hash;
int debug;
@@ -235,8 +236,24 @@
" password VARCHAR(255)\n"
");\n";
-static void destroy_profile(vm_profile_t *profile)
+
+static void destroy_profile(const char *profile_name)
{
+ vm_profile_t *profile = NULL;
+ switch_mutex_lock(globals.mutex);
+ if ((profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
+ switch_core_hash_delete(globals.profile_hash, profile_name);
+ }
+ switch_mutex_unlock(globals.mutex);
+
+ if (!profile) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile %s\n", profile_name);
+ return;
+ }
+ /* wait readers */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for write lock (Profile %s)\n", profile->name);
+ switch_thread_rwlock_wrlock(profile->rwlock);
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroying Profile %s\n", profile->name);
#ifdef SWITCH_HAVE_ODBC
if (profile->odbc_dsn && profile->master_odbc) {
@@ -247,84 +264,22 @@
switch_core_destroy_memory_pool(&profile->pool);
}
-static vm_profile_t *create_profile(char *name)
+static vm_profile_t * load_profile(const char *profile_name)
{
vm_profile_t *profile = NULL;
- switch_memory_pool_t *pool;
-
- switch_core_new_memory_pool(&pool);
-
- profile = switch_core_alloc(pool, sizeof(*profile));
- profile->pool = pool;
- switch_thread_rwlock_create(&profile->rwlock, pool);
- profile->name = switch_core_strdup(pool, name);
-
- return profile;
-}
-
+ switch_xml_t x_profiles, x_profile, x_email, param, cfg, xml;
-static switch_status_t load_config(void)
-{
- char *cf = "voicemail.conf";
- vm_profile_t *profile = NULL;
- switch_xml_t cfg, xml, settings, param, x_profile, x_profiles, x_email;
- switch_hash_index_t *hi;
- void *val;
-
- if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
- return SWITCH_STATUS_TERM;
+ if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf);
+ return profile;
}
-
- if ((settings = switch_xml_child(cfg, "settings"))) {
- for (param = switch_xml_child(settings, "param"); param; param = param->next) {
- char *var = (char *) switch_xml_attr_soft(param, "name");
- char *val = (char *) switch_xml_attr_soft(param, "value");
-
- if (!strcasecmp(var, "debug")) {
- globals.debug = atoi(val);
- }
- }
- }
-
+
if (!(x_profiles = switch_xml_child(cfg, "profiles"))) {
goto end;
}
-
- /* destroy old profiles */
- destroy:
- for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
- switch_hash_this(hi, NULL, NULL, &val);
- profile = (vm_profile_t *) val;
- int found = 0;
-
- for (x_profile = switch_xml_child(x_profiles, "profile"); x_profile; x_profile = x_profile->next) {
- char *name = (char *) switch_xml_attr_soft(x_profile, "name");
- if (!(strcasecmp(profile->name, name))) {
- found = 1;
- break;
- }
- }
- if (found) {
- continue;
- }
-
- /* delete from hash, so new comers can't find it */
- switch_mutex_lock(globals.mutex);
- switch_core_hash_delete(globals.profile_hash, profile->name);
- switch_mutex_unlock(globals.mutex);
-
- /* wait for readers */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleting profile %s, when readers are left\n", profile->name);
- switch_thread_rwlock_wrlock(profile->rwlock);
-
- destroy_profile(profile);
- goto destroy;
- }
-
- for (x_profile = switch_xml_child(x_profiles, "profile"); x_profile; x_profile = x_profile->next) {
- char *name = (char *) switch_xml_attr_soft(x_profile, "name");
+ if ((x_profile = switch_xml_find_child(x_profiles, "profile", "name", profile_name))) {
+ switch_memory_pool_t *pool;
char *odbc_dsn = NULL, *odbc_user = NULL, *odbc_pass = NULL;
char *terminator_key = "#";
char *play_new_messages_key = "1";
@@ -376,7 +331,6 @@
char *record_title = "FreeSWITCH Voicemail";
char *record_comment = "FreeSWITCH Voicemail";
char *record_copyright = "http://www.freeswitch.org";
- int change_profile = 0;
switch_bool_t auto_playback_recordings = SWITCH_TRUE;
@@ -385,18 +339,21 @@
db = NULL;
- if (switch_strlen_zero(name)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No name specified.\n");
- continue;
+ if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+ goto end;
}
- if (!(profile = switch_core_hash_find(globals.profile_hash, name))) {
- profile = create_profile(name);
- } else {
- change_profile = 1;
- switch_thread_rwlock_wrlock(profile->rwlock);
+ if (!(profile = switch_core_alloc(pool, sizeof(*profile)))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
+ switch_core_destroy_memory_pool(&pool);
+ goto end;
}
+ profile->pool = pool;
+ switch_thread_rwlock_create(&profile->rwlock, pool);
+ profile->name = switch_core_strdup(pool, profile_name);
+
if ((x_email = switch_xml_child(x_profile, "email"))) {
if ((param = switch_xml_child(x_email, "body"))) {
email_body = switch_core_strdup(profile->pool, param->txt);
@@ -677,33 +634,23 @@
}
}
-#ifdef SWITCH_HAVE_ODBC
- if (profile->odbc_dsn && profile->master_odbc) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Closing ODBC Database! %s\n", profile->name);
- switch_odbc_handle_destroy(&profile->master_odbc);
- profile->odbc_dsn = NULL;
- profile->odbc_user = NULL;
- profile->odbc_pass = NULL;
- }
-#endif
-
if (!switch_strlen_zero(odbc_dsn) && !switch_strlen_zero(odbc_user) && !switch_strlen_zero(odbc_pass)) {
profile->odbc_dsn = odbc_dsn;
profile->odbc_user = odbc_user;
profile->odbc_pass = odbc_pass;
} else {
- profile->dbname = switch_core_sprintf(profile->pool, "voicemail_%s", name);
+ profile->dbname = switch_core_sprintf(profile->pool, "voicemail_%s", profile_name);
}
if (profile->odbc_dsn) {
#ifdef SWITCH_HAVE_ODBC
if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
- continue;
+ goto end;
}
if (switch_odbc_handle_connect(profile->master_odbc) != SWITCH_ODBC_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
- continue;
+ goto end;
}
if (switch_odbc_handle_exec(profile->master_odbc, "select count(message_len) from voicemail_msgs", NULL) != SWITCH_ODBC_SUCCESS) {
@@ -728,7 +675,7 @@
"cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags from voicemail_data",
NULL) != SWITCH_ODBC_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to migrate old voicemail_data to voicemail_msgs!\n");
- continue;
+ goto end;
}
switch_odbc_handle_exec(profile->master_odbc, "drop table voicemail_data", NULL);
}
@@ -766,7 +713,7 @@
"alter table voicemail_prefs add password varchar(255)");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
- continue;
+ goto end;
}
switch_core_db_close(db);
}
@@ -832,18 +779,65 @@
switch_copy_string(profile->file_ext, file_ext, sizeof(profile->file_ext));
switch_mutex_init(&profile->mutex, SWITCH_MUTEX_NESTED, profile->pool);
- if (change_profile) {
- switch_thread_rwlock_unlock(profile->rwlock);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name);
- switch_mutex_lock(globals.mutex);
- switch_core_hash_insert(globals.profile_hash, profile->name, profile);
- switch_mutex_unlock(globals.mutex);
- }
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name);
+ switch_core_hash_insert(globals.profile_hash, profile->name, profile);
}
end:
+ if (xml) {
+ switch_xml_free(xml);
+ }
+ return profile;
+
+}
+
+
+static vm_profile_t * get_profile(const char *profile_name)
+{
+ vm_profile_t *profile;
+
+ switch_mutex_lock(globals.mutex);
+ if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
+ profile = load_profile(profile_name);
+ }
+ if (profile) {
+ switch_thread_rwlock_rdlock(profile->rwlock);
+ }
+ switch_mutex_unlock(globals.mutex);
+
+ return profile;
+}
+
+
+static switch_status_t load_config(void)
+{
+ switch_xml_t cfg, xml, settings, param, x_profiles, x_profile;
+
+ if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf);
+ return SWITCH_STATUS_TERM;
+ }
+
+ switch_mutex_lock(globals.mutex);
+ if ((settings = switch_xml_child(cfg, "settings"))) {
+ for (param = switch_xml_child(settings, "param"); param; param = param->next) {
+ char *var = (char *) switch_xml_attr_soft(param, "name");
+ char *val = (char *) switch_xml_attr_soft(param, "value");
+
+ if (!strcasecmp(var, "debug")) {
+ globals.debug = atoi(val);
+ }
+ }
+ }
+
+ if ((x_profiles = switch_xml_child(cfg, "profiles"))) {
+ for (x_profile = switch_xml_child(x_profiles, "profile"); x_profile; x_profile = x_profile->next) {
+ load_profile(switch_xml_attr_soft(x_profile, "name"));
+ }
+ }
+ switch_mutex_unlock(globals.mutex);
+
switch_xml_free(xml);
return SWITCH_STATUS_SUCCESS;
}
@@ -1707,16 +1701,11 @@
caller_id_number = caller_profile->caller_id_number;
}
- switch_mutex_lock(globals.mutex);
-
- if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
+ if (!(profile = get_profile(profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error invalid profile %s\n", profile_name);
- switch_mutex_unlock(globals.mutex);
return;
}
- switch_thread_rwlock_rdlock(profile->rwlock);
- switch_mutex_unlock(globals.mutex);
-
+
timeout = profile->digit_timeout;
attempts = profile->max_login_attempts;
status = switch_ivr_phrase_macro(session, VM_HELLO_MACRO, NULL, NULL, &args);
@@ -2087,8 +2076,6 @@
}
-
-
thepass = thehash = NULL;
switch_snprintf(sql, sizeof(sql), "select * from voicemail_prefs where username='%s' and domain='%s'", myid, domain_name);
vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt);
@@ -2134,7 +2121,6 @@
}
}
-
if (!mypass) {
if (auth) {
@@ -2153,8 +2139,6 @@
}
}
-
-
if (vmhash) {
thehash = vmhash;
}
@@ -2636,23 +2620,18 @@
goto end;
}
- switch_mutex_lock(globals.mutex);
- if (!(profile = switch_core_hash_find(globals.profile_hash, domain))) {
- profile = switch_core_hash_find(globals.profile_hash, "default");
+ if (!(profile = get_profile(domain))) {
+ profile = get_profile("default");
}
if (!profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find profile\n");
status = SWITCH_STATUS_FALSE;
- switch_mutex_unlock(globals.mutex);
} else {
switch_xml_t x_domain, xml_root;
switch_event_t *my_params = NULL;
switch_xml_t ut;
- switch_thread_rwlock_rdlock(profile->rwlock);
- switch_mutex_unlock(globals.mutex);
-
switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS);
switch_assert(my_params);
switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "domain", domain);
@@ -2753,17 +2732,11 @@
memset(&cbt, 0, sizeof(cbt));
- switch_mutex_lock(globals.mutex);
-
- if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
+ if (!(profile = get_profile(profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error invalid profile %s\n", profile_name);
- switch_mutex_unlock(globals.mutex);
return SWITCH_STATUS_FALSE;;
}
- switch_thread_rwlock_rdlock(profile->rwlock);
- switch_mutex_unlock(globals.mutex);
-
if (id) {
int ok = 1;
switch_event_t *params = NULL;
@@ -3668,7 +3641,7 @@
return SWITCH_STATUS_SUCCESS;
}
-#define VOICEMAIL_SYNTAX "rss [<host> <port> <uri> <user> <domain>] | rescan [reloadxml]"
+#define VOICEMAIL_SYNTAX "rss [<host> <port> <uri> <user> <domain>] | [load|unload|reload] <profile> [reloadxml]"
SWITCH_STANDARD_API(voicemail_api_function)
{
int argc = 0;
@@ -3681,6 +3654,9 @@
int rss = 0, xarg = 0;
switch_hash_index_t *hi;
void *val = NULL;
+ switch_xml_t xml_root;
+ const char *err;
+
if (session) {
return SWITCH_STATUS_FALSE;
@@ -3705,27 +3681,40 @@
if (!strcasecmp(argv[0], "rss")) {
rss++;
xarg++;
- } else if (!strcasecmp(argv[0], "rescan")) {
- switch_xml_t xml_root;
- const char *err;
- if (argc > 1 && !strcasecmp(argv[1], "reloadxml")) {
+ } else if (argc > 1 && !strcasecmp(argv[0], "load")) {
+ if (argc > 2 && !strcasecmp(argv[2], "reloadxml")) {
if ((xml_root = switch_xml_open_root(1, &err))) {
switch_xml_free(xml_root);
}
stream->write_function(stream, "Reload XML [%s]\n", err);
}
- if (load_config() == SWITCH_STATUS_SUCCESS) {
- stream->write_function(stream, "+OK scan complete\n");
- } else {
- stream->write_function(stream, "-ERR scan failed\n");
- goto error;
+ if ((profile = get_profile(argv[1]))) {
+ switch_thread_rwlock_unlock(profile->rwlock);
}
+ stream->write_function(stream, "+OK load complete\n");
goto done;
+ } else if (argc > 1 && !strcasecmp(argv[0], "unload")) {
+ destroy_profile(argv[1]);
+ stream->write_function(stream, "+OK unload complete\n");
+ goto done;
+ } else if (argc > 1 && !strcasecmp(argv[0], "reload")) {
+ destroy_profile(argv[1]);
+ if (argc > 2 && !strcasecmp(argv[2], "reloadxml")) {
+ if ((xml_root = switch_xml_open_root(1, &err))) {
+ switch_xml_free(xml_root);
+ }
+ stream->write_function(stream, "Reload XML [%s]\n", err);
+ }
+ if ((profile = get_profile(argv[1]))) {
+ switch_thread_rwlock_unlock(profile->rwlock);
+ }
+ stream->write_function(stream, "+OK reload complete\n");
+ goto done;
+
} else if (!strcasecmp(argv[0], "status")) {
stream->write_function(stream, "============================\n");
switch_mutex_lock(globals.mutex);
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
- vm_profile_t * profile = NULL;
switch_hash_this(hi, NULL, NULL, &val);
profile = (vm_profile_t *) val;
stream->write_function(stream, "Profile: %s\n", profile->name);
@@ -3751,35 +3740,31 @@
goto error;
}
- switch_mutex_lock(globals.mutex);
- profile = switch_core_hash_find(globals.profile_hash, domain);
-
- if (!profile) {
- profile = switch_core_hash_find(globals.profile_hash, "default");
+ if (!(profile = get_profile(domain))) {
+ profile = get_profile("default");
}
if (!profile) {
switch_hash_index_t *hi;
void *val;
+ switch_mutex_lock(globals.mutex);
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
profile = (vm_profile_t *) val;
if (profile) {
+ switch_thread_rwlock_rdlock(profile->rwlock);
break;
}
}
+ switch_mutex_unlock(globals.mutex);
}
if (!profile) {
stream->write_function(stream, "Can't find profile.\n");
- switch_mutex_unlock(globals.mutex);
goto error;
}
- switch_thread_rwlock_rdlock(profile->rwlock);
- switch_mutex_unlock(globals.mutex);
-
if (path_info) {
if (!strncasecmp(path_info, "get/", 4)) {
do_play(profile, user, domain, path_info + 4, stream);
@@ -3793,8 +3778,8 @@
if (rss || (path_info && !strncasecmp(path_info, "rss", 3))) {
do_rss(profile, user, domain, host, port, uri, stream);
}
- switch_thread_rwlock_unlock(profile->rwlock);
+ switch_thread_rwlock_unlock(profile->rwlock);
goto done;
error:
1
0
[Freeswitch-branches] [commit] r10751 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by FreeSWITCH SVN 13 Dec '08
by FreeSWITCH SVN 13 Dec '08
13 Dec '08
Author: gmaruzz
Date: Sat Dec 13 05:29:42 2008
New Revision: 10751
Log:
skypiax: cleaning, restructuring
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c Sat Dec 13 05:29:42 2008
@@ -33,7 +33,6 @@
int running = 1;
switch_core_session_t *global_session = NULL;
#ifdef WIN32
-HANDLE win32_hGlobal_ThreadShutdownEvent;
HWND win32_hInit_MainWindowHandle;
#endif /* WIN32 */
/*************************************************/
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c Sat Dec 13 05:29:42 2008
@@ -8,31 +8,50 @@
#ifdef WIN32
extern HWND win32_hInit_MainWindowHandle;
#endif /* WIN32 */
+/**********************************************************/
+/**********************************************************/
+/**********************************************************/
+#ifdef WIN32
+struct AsteriskHandles *win32_AsteriskHandlesSkype;
+HINSTANCE win32_hInit_ProcessHandle;
+char win32_acInit_WindowClassName[128];
+UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach;
+UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover;
+HWND win32_hGlobal_SkypeAPIWindowHandle = NULL;
+DWORD win32_ulGlobal_PromptConsoleMode = 0;
+HANDLE volatile win32_hGlobal_PromptConsoleHandle = NULL;
+#else /* NOT WIN32 */
+#define SKYPE_X11_BUF_SIZE 512
+Window skype_win = (Window) - 1;
+static XErrorHandler old_handler = 0;
+static int xerror = 0;
+#endif /* WIN32 */
+/**********************************************************/
+/**********************************************************/
+/**********************************************************/
+#define SAMPLES_PER_FRAME 160
+#define SAMPLES_PER_FRAME 160
+#define SAMPLES_PER_FRAME 160
-#define SKYPE_AUDIO
-#ifdef SKYPE_AUDIO
-#define SAMPLES_PER_FRAME 160
-#define NN 160
-#define GG 160
static void *SWITCH_THREAD_FUNC skypiax_do_tcp_srv_thread(switch_thread_t * thread,
void *obj)
{
struct skypiax_interface *p = obj;
- short srv_out[GG / 2];
+ short srv_out[SAMPLES_PER_FRAME / 2];
int s;
#ifdef WIN32
unsigned int len;
unsigned int i;
unsigned int a;
- short srv_in[GG];
+ short srv_in[SAMPLES_PER_FRAME];
int sin_size;
unsigned int fd;
#else
int len;
int i;
int a;
- short srv_in[GG];
+ short srv_in[SAMPLES_PER_FRAME];
unsigned int sin_size;
int fd;
#endif /* WIN32 */
@@ -99,7 +118,7 @@
rt = select(fdselect + 1, &fs, NULL, NULL, &to);
if (rt > 0) {
- len = recv(fd, srv_in, sizeof(short) * GG, 0);
+ len = recv(fd, srv_in, sizeof(short) * SAMPLES_PER_FRAME, 0);
//DEBUGA_SKYPE("recv %d\n", SKYPIAX_P_LOG, len);
if (len > 0) {
a = 0;
@@ -116,7 +135,7 @@
p->audiobuf_is_loaded = 1;
} else {
unsigned int howmany;
- short totalbuf[GG];
+ short totalbuf[SAMPLES_PER_FRAME];
howmany = len / 2 / 2;
for (i = 0; i < howmany; i++)
@@ -132,7 +151,7 @@
switch_file_write(p->audiopipe[1], totalbuf, &howmany);
p->audiobuf_is_loaded = 0;
- //DEBUGA_SKYPE("read=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, sizeof(short)*GG, len, (len*sizeof(short))/2, howmany);
+ //DEBUGA_SKYPE("read=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, sizeof(short)*SAMPLES_PER_FRAME, len, (len*sizeof(short))/2, howmany);
}
} else if (len == 0) {
@@ -191,16 +210,16 @@
unsigned int len;
unsigned int i;
unsigned int a;
- short cli_in[NN / 2];
- short cli_out[NN];
+ short cli_in[SAMPLES_PER_FRAME / 2];
+ short cli_out[SAMPLES_PER_FRAME];
int sin_size;
unsigned int fd;
#else
int len;
int i;
int a;
- short cli_in[NN / 2];
- short cli_out[NN];
+ short cli_in[SAMPLES_PER_FRAME / 2];
+ short cli_out[SAMPLES_PER_FRAME];
unsigned int sin_size;
int fd;
#endif /* WIN32 */
@@ -264,7 +283,7 @@
rt = 1;
if (rt > 0) {
- got = (NN / 2) * sizeof(short);
+ got = (SAMPLES_PER_FRAME / 2) * sizeof(short);
switch_file_read(p->audioskypepipe[0], cli_in, &got);
if (got > 0) {
@@ -374,17 +393,8 @@
return SWITCH_STATUS_SUCCESS;
}
-#endif /* SKYPE_AUDIO */
#ifdef WIN32
-struct AsteriskHandles *win32_AsteriskHandlesSkype;
-HINSTANCE win32_hInit_ProcessHandle;
-char win32_acInit_WindowClassName[128];
-UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach;
-UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover;
-HWND win32_hGlobal_SkypeAPIWindowHandle = NULL;
-DWORD win32_ulGlobal_PromptConsoleMode = 0;
-HANDLE volatile win32_hGlobal_PromptConsoleHandle = NULL;
enum {
SKYPECONTROLAPI_ATTACH_SUCCESS = 0, /* Client is successfully
@@ -620,12 +630,6 @@
}
#else /* NOT WIN32 */
-
-#define SKYPE_X11_BUF_SIZE 512
-Window skype_win = (Window) - 1;
-static XErrorHandler old_handler = 0;
-static int xerror = 0;
-
int X11_errors_handler(Display * dpy, XErrorEvent * err)
{
(void) dpy;
1
0
[Freeswitch-branches] [commit] r10750 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by FreeSWITCH SVN 13 Dec '08
by FreeSWITCH SVN 13 Dec '08
13 Dec '08
Author: gmaruzz
Date: Sat Dec 13 03:31:50 2008
New Revision: 10750
Log:
skypiax: cleaning, restructuring
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c Sat Dec 13 03:31:50 2008
@@ -20,6 +20,7 @@
int fd;
int calls;
char hold_music[256];
+ skypiax_interface_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES];
switch_mutex_t *mutex;
} globals;
@@ -30,14 +31,11 @@
switch_endpoint_interface_t *skypiax_endpoint_interface;
switch_memory_pool_t *skypiax_module_pool = NULL;
int running = 1;
-skypiax_interface_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES];
switch_core_session_t *global_session = NULL;
#ifdef WIN32
HANDLE win32_hGlobal_ThreadShutdownEvent;
HWND win32_hInit_MainWindowHandle;
#endif /* WIN32 */
-switch_thread_t *skypiax_do_controldev_thread_thread;
-switch_thread_t *do_skype_thread_thread;
/*************************************************/
/*************************************************/
/*************************************************/
@@ -509,7 +507,7 @@
switch_core_session_add_stream(*new_session, NULL);
if ((tech_pvt =
(private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
- tech_pvt->p = &SKYPIAX_INTERFACES[2]; //FIXME
+ tech_pvt->p = &globals.SKYPIAX_INTERFACES[2]; //FIXME
channel = switch_core_session_get_channel(*new_session);
skypiax_tech_init(tech_pvt, *new_session, NULL);
} else {
@@ -754,44 +752,54 @@
if (name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "name=%s\n", name);
}
+
+#ifndef WIN32
+ if (!XInitThreads()) {
+ ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
+ } else {
+ DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
+ }
+ switch_sleep(100);
+#endif /* WIN32 */
+
if (interface_id && interface_id < SKYPIAX_MAX_INTERFACES) {
struct skypiax_interface newconf;
switch_threadattr_t *do_skype_thd_attr = NULL;
switch_threadattr_t *skypiax_do_controldev_thread_thd_attr = NULL;
memset(&newconf, '\0', sizeof(newconf));
- SKYPIAX_INTERFACES[interface_id] = newconf;
+ globals.SKYPIAX_INTERFACES[interface_id] = newconf;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"CONFIGURING interface_id=%d\n", interface_id);
- switch_set_string(SKYPIAX_INTERFACES[interface_id].interface_id, id);
+ switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].interface_id, id);
if (name) {
- switch_set_string(SKYPIAX_INTERFACES[interface_id].name, name);
+ switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].name, name);
} else {
- switch_set_string(SKYPIAX_INTERFACES[interface_id].name, "N/A");
+ switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].name, "N/A");
}
- switch_set_string(SKYPIAX_INTERFACES[interface_id].X11_display, X11_display);
- switch_set_string(SKYPIAX_INTERFACES[interface_id].context, context);
- switch_set_string(SKYPIAX_INTERFACES[interface_id].dialplan, dialplan);
+ switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].X11_display, X11_display);
+ switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].context, context);
+ switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].dialplan, dialplan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "interface_id=%d SKYPIAX_INTERFACES[interface_id].X11_display=%s\n",
- interface_id, SKYPIAX_INTERFACES[interface_id].X11_display);
+ "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].X11_display=%s\n",
+ interface_id, globals.SKYPIAX_INTERFACES[interface_id].X11_display);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "interface_id=%d SKYPIAX_INTERFACES[interface_id].name=%s\n",
- interface_id, SKYPIAX_INTERFACES[interface_id].name);
+ "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].name=%s\n",
+ interface_id, globals.SKYPIAX_INTERFACES[interface_id].name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "interface_id=%d SKYPIAX_INTERFACES[interface_id].context=%s\n",
- interface_id, SKYPIAX_INTERFACES[interface_id].context);
+ "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].context=%s\n",
+ interface_id, globals.SKYPIAX_INTERFACES[interface_id].context);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "interface_id=%d SKYPIAX_INTERFACES[interface_id].dialplan=%s\n",
- interface_id, SKYPIAX_INTERFACES[interface_id].dialplan);
+ "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].dialplan=%s\n",
+ interface_id, globals.SKYPIAX_INTERFACES[interface_id].dialplan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
"STARTING interface_id=%d\n", interface_id);
switch_threadattr_create(&do_skype_thd_attr, skypiax_module_pool);
//switch_threadattr_detach_set(do_skype_thd_attr, 1);
switch_threadattr_stacksize_set(do_skype_thd_attr, SWITCH_THREAD_STACKSIZE);
- switch_thread_create(&do_skype_thread_thread, do_skype_thd_attr, do_skype_thread,
- &SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
+ switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread, do_skype_thd_attr, do_skype_thread,
+ &globals.SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
switch_sleep(100000);
@@ -800,14 +808,14 @@
//switch_threadattr_detach_set(skypiax_do_controldev_thread_thd_attr, 1);
switch_threadattr_stacksize_set(skypiax_do_controldev_thread_thd_attr,
SWITCH_THREAD_STACKSIZE);
- switch_thread_create(&skypiax_do_controldev_thread_thread,
+ switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread,
skypiax_do_controldev_thread_thd_attr,
skypiax_do_controldev_thread,
- &SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
+ &globals.SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
switch_sleep(1000000);
- skypiax_skypeaudio_init(&SKYPIAX_INTERFACES[interface_id]);
+ skypiax_skypeaudio_init(&globals.SKYPIAX_INTERFACES[interface_id]);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
"STARTED interface_id=%d\n", interface_id);
@@ -822,22 +830,22 @@
}
for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) {
- if (strlen(SKYPIAX_INTERFACES[i].name)) {
+ if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "i=%d SKYPIAX_INTERFACES[%d].interface_id=%s\n", i, i,
- SKYPIAX_INTERFACES[i].interface_id);
+ "i=%d globals.SKYPIAX_INTERFACES[%d].interface_id=%s\n", i, i,
+ globals.SKYPIAX_INTERFACES[i].interface_id);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "i=%d SKYPIAX_INTERFACES[%d].X11_display=%s\n", i, i,
- SKYPIAX_INTERFACES[i].X11_display);
+ "i=%d globals.SKYPIAX_INTERFACES[%d].X11_display=%s\n", i, i,
+ globals.SKYPIAX_INTERFACES[i].X11_display);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "i=%d SKYPIAX_INTERFACES[%d].name=%s\n", i, i,
- SKYPIAX_INTERFACES[i].name);
+ "i=%d globals.SKYPIAX_INTERFACES[%d].name=%s\n", i, i,
+ globals.SKYPIAX_INTERFACES[i].name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "i=%d SKYPIAX_INTERFACES[%d].context=%s\n", i, i,
- SKYPIAX_INTERFACES[i].context);
+ "i=%d globals.SKYPIAX_INTERFACES[%d].context=%s\n", i, i,
+ globals.SKYPIAX_INTERFACES[i].context);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "i=%d SKYPIAX_INTERFACES[%d].dialplan=%s\n", i, i,
- SKYPIAX_INTERFACES[i].dialplan);
+ "i=%d globals.SKYPIAX_INTERFACES[%d].dialplan=%s\n", i, i,
+ globals.SKYPIAX_INTERFACES[i].dialplan);
}
}
}
@@ -849,21 +857,12 @@
SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load)
{
- struct skypiax_interface *p = NULL;
+ struct skypiax_interface *p = NULL; //for logging
skypiax_module_pool = pool;
memset(&globals, '\0', sizeof(globals));
- memset(SKYPIAX_INTERFACES, '\0', sizeof(SKYPIAX_INTERFACES));
-
-#ifndef WIN32
- if (!XInitThreads()) {
- ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
- } else {
- DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
- }
- switch_sleep(100);
-#endif /* _WINDOWS_ */
+ //memset(globals.SKYPIAX_INTERFACES, '\0', sizeof(globals.SKYPIAX_INTERFACES));
load_config();
@@ -892,13 +891,20 @@
struct skypiax_interface *p = NULL;
switch_status_t status;
unsigned int howmany = 8;
+int interface_id;
- p = &SKYPIAX_INTERFACES[2];
+ //p = &globals.SKYPIAX_INTERFACES[2];
running = 0;
+for(interface_id=0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++){
+ p = &globals.SKYPIAX_INTERFACES[interface_id];
+
+if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread){
switch_file_write(p->AsteriskHandlesAst.fdesc[1], "sciutati", &howmany); // let's the controldev_thread die
+ }
+if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread){
#ifdef WIN32
if (SendMessage(win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) { // let's the do_skype_thread die
ERRORA("WHY FALSE HERE? %d\n", SKYPIAX_P_LOG, GetLastError());
@@ -917,12 +923,18 @@
XSendEvent(p->AsteriskHandlesAst.disp, p->AsteriskHandlesAst.win, False, 0, &e);
XSync(p->AsteriskHandlesAst.disp, False);
#endif
+ }
while (x) {
x--;
switch_yield(20000);
}
- switch_thread_join(&status, skypiax_do_controldev_thread_thread);
- switch_thread_join(&status, do_skype_thread_thread);
+if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread){
+ switch_thread_join(&status, globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread);
+ }
+if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread){
+ switch_thread_join(&status, globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread);
+ }
+ }
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h Sat Dec 13 03:31:50 2008
@@ -173,6 +173,8 @@
switch_file_t *audioskypepipe[2];
switch_thread_t *tcp_srv_thread;
switch_thread_t *tcp_cli_thread;
+ switch_thread_t *skypiax_do_controldev_thread_thread;
+ switch_thread_t *skypiax_do_skype_thread_thread;
short audiobuf[160];
int audiobuf_is_loaded;
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c Sat Dec 13 03:31:50 2008
@@ -5,7 +5,6 @@
extern switch_core_session_t *global_session;
extern switch_endpoint_interface_t *skypiax_endpoint_interface;
extern int running;
-extern skypiax_interface_t SKYPIAX_INTERFACES;
#ifdef WIN32
extern HWND win32_hInit_MainWindowHandle;
#endif /* WIN32 */
@@ -575,7 +574,7 @@
/* destroy window class */
struct skypiax_interface *p;
- DWORD MsgWaitResult;
+ //DWORD MsgWaitResult;
p = obj;
switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0],
@@ -603,7 +602,7 @@
if (!running)
break;
while (GetMessage(&oMessage, 0, 0, 0)) {
- break;
+ //break;
TranslateMessage(&oMessage);
DispatchMessage(&oMessage);
}
1
0
[Freeswitch-branches] [commit] r10729 - freeswitch/branches/cseket/src/mod/applications/mod_voicemail
by FreeSWITCH SVN 12 Dec '08
by FreeSWITCH SVN 12 Dec '08
12 Dec '08
Author: cseket
Date: Fri Dec 12 05:20:25 2008
New Revision: 10729
Log:
memory leak version of MODAPP-177
Modified:
freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c
Modified: freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c (original)
+++ freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c Fri Dec 12 05:20:25 2008
@@ -266,7 +266,7 @@
static switch_status_t load_config(void)
{
char *cf = "voicemail.conf";
- vm_profile_t *profile = NULL, *oldprofile = NULL;
+ vm_profile_t *profile = NULL;
switch_xml_t cfg, xml, settings, param, x_profile, x_profiles, x_email;
switch_hash_index_t *hi;
void *val;
@@ -376,6 +376,7 @@
char *record_title = "FreeSWITCH Voicemail";
char *record_comment = "FreeSWITCH Voicemail";
char *record_copyright = "http://www.freeswitch.org";
+ int change_profile = 0;
switch_bool_t auto_playback_recordings = SWITCH_TRUE;
@@ -389,8 +390,12 @@
continue;
}
- oldprofile = switch_core_hash_find(globals.profile_hash, name);
- profile = create_profile(name);
+ if (!(profile = switch_core_hash_find(globals.profile_hash, name))) {
+ profile = create_profile(name);
+ } else {
+ change_profile = 1;
+ switch_thread_rwlock_wrlock(profile->rwlock);
+ }
if ((x_email = switch_xml_child(x_profile, "email"))) {
if ((param = switch_xml_child(x_email, "body"))) {
@@ -672,6 +677,15 @@
}
}
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn && profile->master_odbc) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Closing ODBC Database! %s\n", profile->name);
+ switch_odbc_handle_destroy(&profile->master_odbc);
+ profile->odbc_dsn = NULL;
+ profile->odbc_user = NULL;
+ profile->odbc_pass = NULL;
+ }
+#endif
if (!switch_strlen_zero(odbc_dsn) && !switch_strlen_zero(odbc_user) && !switch_strlen_zero(odbc_pass)) {
profile->odbc_dsn = odbc_dsn;
@@ -818,23 +832,13 @@
switch_copy_string(profile->file_ext, file_ext, sizeof(profile->file_ext));
switch_mutex_init(&profile->mutex, SWITCH_MUTEX_NESTED, profile->pool);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name);
- if (oldprofile) {
-
- /* wait */
- /* deadlock on concurrent voicemail rescan */
- while (switch_thread_rwlock_trywrlock_timeout(oldprofile->rwlock, 10) != SWITCH_STATUS_SUCCESS);
-
+ if (change_profile) {
+ switch_thread_rwlock_unlock(profile->rwlock);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name);
switch_mutex_lock(globals.mutex);
- /* change the profile*/
- switch_core_hash_delete(globals.profile_hash, oldprofile->name);
switch_core_hash_insert(globals.profile_hash, profile->name, profile);
switch_mutex_unlock(globals.mutex);
-
- destroy_profile(oldprofile);
-
- } else {
- switch_core_hash_insert(globals.profile_hash, profile->name, profile);
}
}
1
0
[Freeswitch-branches] [commit] r10728 - freeswitch/branches/cseket/src/mod/applications/mod_voicemail
by FreeSWITCH SVN 12 Dec '08
by FreeSWITCH SVN 12 Dec '08
12 Dec '08
Author: cseket
Date: Fri Dec 12 04:16:12 2008
New Revision: 10728
Log:
deadlock version of MODAPP-177
Modified:
freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c
Modified: freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c (original)
+++ freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c Fri Dec 12 04:16:12 2008
@@ -816,7 +816,7 @@
profile->record_comment = switch_core_strdup(profile->pool, record_comment);
profile->record_copyright = switch_core_strdup(profile->pool, record_copyright);
switch_copy_string(profile->file_ext, file_ext, sizeof(profile->file_ext));
- switch_mutex_init(&profile->mutex, SWITCH_MUTEX_UNNESTED, profile->pool);
+ switch_mutex_init(&profile->mutex, SWITCH_MUTEX_NESTED, profile->pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name);
if (oldprofile) {
1
0
[Freeswitch-branches] [commit] r10727 - freeswitch/branches/cseket/src/mod/applications/mod_voicemail
by FreeSWITCH SVN 12 Dec '08
by FreeSWITCH SVN 12 Dec '08
12 Dec '08
Author: cseket
Date: Fri Dec 12 03:58:45 2008
New Revision: 10727
Log:
incomplete profile rescan (MODAPP-177)
Modified:
freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c
Modified: freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c (original)
+++ freeswitch/branches/cseket/src/mod/applications/mod_voicemail/mod_voicemail.c Fri Dec 12 03:58:45 2008
@@ -54,6 +54,7 @@
static struct {
switch_hash_t *profile_hash;
int debug;
+ switch_mutex_t *mutex;
switch_memory_pool_t *pool;
} globals;
@@ -125,6 +126,8 @@
uint32_t record_sample_rate;
switch_odbc_handle_t *master_odbc;
switch_bool_t auto_playback_recordings;
+ switch_thread_rwlock_t *rwlock;
+ switch_memory_pool_t *pool;
};
typedef struct vm_profile vm_profile_t;
@@ -232,15 +235,41 @@
" password VARCHAR(255)\n"
");\n";
+static void destroy_profile(vm_profile_t *profile)
+{
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroying Profile %s\n", profile->name);
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn && profile->master_odbc) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Closing ODBC Database! %s\n", profile->name);
+ switch_odbc_handle_destroy(&profile->master_odbc);
+ }
+#endif
+ switch_core_destroy_memory_pool(&profile->pool);
+}
+
+static vm_profile_t *create_profile(char *name)
+{
+ vm_profile_t *profile = NULL;
+ switch_memory_pool_t *pool;
+
+ switch_core_new_memory_pool(&pool);
+
+ profile = switch_core_alloc(pool, sizeof(*profile));
+ profile->pool = pool;
+ switch_thread_rwlock_create(&profile->rwlock, pool);
+ profile->name = switch_core_strdup(pool, name);
+
+ return profile;
+}
+
+
static switch_status_t load_config(void)
{
char *cf = "voicemail.conf";
- vm_profile_t *profile = NULL;
+ vm_profile_t *profile = NULL, *oldprofile = NULL;
switch_xml_t cfg, xml, settings, param, x_profile, x_profiles, x_email;
-
- memset(&globals, 0, sizeof(globals));
- switch_core_new_memory_pool(&globals.pool);
- switch_core_hash_init(&globals.profile_hash, globals.pool);
+ switch_hash_index_t *hi;
+ void *val;
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
@@ -262,6 +291,38 @@
goto end;
}
+
+ /* destroy old profiles */
+ destroy:
+ for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, NULL, NULL, &val);
+ profile = (vm_profile_t *) val;
+ int found = 0;
+
+ for (x_profile = switch_xml_child(x_profiles, "profile"); x_profile; x_profile = x_profile->next) {
+ char *name = (char *) switch_xml_attr_soft(x_profile, "name");
+ if (!(strcasecmp(profile->name, name))) {
+ found = 1;
+ break;
+ }
+ }
+ if (found) {
+ continue;
+ }
+
+ /* delete from hash, so new comers can't find it */
+ switch_mutex_lock(globals.mutex);
+ switch_core_hash_delete(globals.profile_hash, profile->name);
+ switch_mutex_unlock(globals.mutex);
+
+ /* wait for readers */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleting profile %s, when readers are left\n", profile->name);
+ switch_thread_rwlock_wrlock(profile->rwlock);
+
+ destroy_profile(profile);
+ goto destroy;
+ }
+
for (x_profile = switch_xml_child(x_profiles, "profile"); x_profile; x_profile = x_profile->next) {
char *name = (char *) switch_xml_attr_soft(x_profile, "name");
char *odbc_dsn = NULL, *odbc_user = NULL, *odbc_pass = NULL;
@@ -323,13 +384,21 @@
db = NULL;
+ if (switch_strlen_zero(name)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No name specified.\n");
+ continue;
+ }
+
+ oldprofile = switch_core_hash_find(globals.profile_hash, name);
+ profile = create_profile(name);
+
if ((x_email = switch_xml_child(x_profile, "email"))) {
if ((param = switch_xml_child(x_email, "body"))) {
- email_body = switch_core_strdup(globals.pool, param->txt);
+ email_body = switch_core_strdup(profile->pool, param->txt);
}
if ((param = switch_xml_child(x_email, "headers"))) {
- email_headers = switch_core_strdup(globals.pool, param->txt);
+ email_headers = switch_core_strdup(profile->pool, param->txt);
}
for (param = switch_xml_child(x_email, "param"); param; param = param->next) {
@@ -588,7 +657,7 @@
}
} else if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) {
#ifdef SWITCH_HAVE_ODBC
- odbc_dsn = switch_core_strdup(globals.pool, val);
+ odbc_dsn = switch_core_strdup(profile->pool, val);
if ((odbc_user = strchr(odbc_dsn, ':'))) {
*odbc_user++ = '\0';
if ((odbc_pass = strchr(odbc_user, ':'))) {
@@ -603,165 +672,173 @@
}
}
- if (switch_strlen_zero(name)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No name specified.\n");
- } else {
- profile = switch_core_alloc(globals.pool, sizeof(*profile));
- profile->name = switch_core_strdup(globals.pool, name);
- if (!switch_strlen_zero(odbc_dsn) && !switch_strlen_zero(odbc_user) && !switch_strlen_zero(odbc_pass)) {
- profile->odbc_dsn = odbc_dsn;
- profile->odbc_user = odbc_user;
- profile->odbc_pass = odbc_pass;
- } else {
- profile->dbname = switch_core_sprintf(globals.pool, "voicemail_%s", name);
- }
- if (profile->odbc_dsn) {
+ if (!switch_strlen_zero(odbc_dsn) && !switch_strlen_zero(odbc_user) && !switch_strlen_zero(odbc_pass)) {
+ profile->odbc_dsn = odbc_dsn;
+ profile->odbc_user = odbc_user;
+ profile->odbc_pass = odbc_pass;
+ } else {
+ profile->dbname = switch_core_sprintf(profile->pool, "voicemail_%s", name);
+ }
+ if (profile->odbc_dsn) {
#ifdef SWITCH_HAVE_ODBC
- if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
- continue;
+ if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
+ continue;
- }
- if (switch_odbc_handle_connect(profile->master_odbc) != SWITCH_ODBC_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
- continue;
- }
+ }
+ if (switch_odbc_handle_connect(profile->master_odbc) != SWITCH_ODBC_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
+ continue;
+ }
- if (switch_odbc_handle_exec(profile->master_odbc, "select count(message_len) from voicemail_msgs", NULL) != SWITCH_ODBC_SUCCESS) {
- switch_odbc_handle_exec(profile->master_odbc, "drop table voicemail_msgs", NULL);
- switch_odbc_handle_exec(profile->master_odbc, vm_sql, NULL);
- }
+ if (switch_odbc_handle_exec(profile->master_odbc, "select count(message_len) from voicemail_msgs", NULL) != SWITCH_ODBC_SUCCESS) {
+ switch_odbc_handle_exec(profile->master_odbc, "drop table voicemail_msgs", NULL);
+ switch_odbc_handle_exec(profile->master_odbc, vm_sql, NULL);
+ }
- if (switch_odbc_handle_exec(profile->master_odbc, "select count(username) from voicemail_prefs", NULL) != SWITCH_ODBC_SUCCESS) {
- switch_odbc_handle_exec(profile->master_odbc, "drop table voicemail_prefs", NULL);
- switch_odbc_handle_exec(profile->master_odbc, vm_pref_sql, NULL);
- }
+ if (switch_odbc_handle_exec(profile->master_odbc, "select count(username) from voicemail_prefs", NULL) != SWITCH_ODBC_SUCCESS) {
+ switch_odbc_handle_exec(profile->master_odbc, "drop table voicemail_prefs", NULL);
+ switch_odbc_handle_exec(profile->master_odbc, vm_pref_sql, NULL);
+ }
- if (switch_odbc_handle_exec(profile->master_odbc, "select count(password) from voicemail_prefs", NULL) != SWITCH_ODBC_SUCCESS) {
- switch_odbc_handle_exec(profile->master_odbc, "alter table voicemail_prefs add password varchar(255)", NULL);
- }
+ if (switch_odbc_handle_exec(profile->master_odbc, "select count(password) from voicemail_prefs", NULL) != SWITCH_ODBC_SUCCESS) {
+ switch_odbc_handle_exec(profile->master_odbc, "alter table voicemail_prefs add password varchar(255)", NULL);
+ }
- if (switch_odbc_handle_exec(profile->master_odbc, "select count(message_len) from voicemail_data", NULL) == SWITCH_ODBC_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Old table voicemail_data found, migrating data!\n");
- /* XXX: Old table found.. migrating data into new table */
- if (switch_odbc_handle_exec(profile->master_odbc,
- "insert into voicemail_msgs select created_epoch, read_epoch, user as username, domain, uuid,"
- "cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags from voicemail_data",
- NULL) != SWITCH_ODBC_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to migrate old voicemail_data to voicemail_msgs!\n");
- continue;
- }
- switch_odbc_handle_exec(profile->master_odbc, "drop table voicemail_data", NULL);
+ if (switch_odbc_handle_exec(profile->master_odbc, "select count(message_len) from voicemail_data", NULL) == SWITCH_ODBC_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Old table voicemail_data found, migrating data!\n");
+ /* XXX: Old table found.. migrating data into new table */
+ if (switch_odbc_handle_exec(profile->master_odbc,
+ "insert into voicemail_msgs select created_epoch, read_epoch, user as username, domain, uuid,"
+ "cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags from voicemail_data",
+ NULL) != SWITCH_ODBC_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to migrate old voicemail_data to voicemail_msgs!\n");
+ continue;
}
+ switch_odbc_handle_exec(profile->master_odbc, "drop table voicemail_data", NULL);
+ }
#endif
- } else {
- if ((db = switch_core_db_open_file(profile->dbname))) {
- char *errmsg;
- switch_core_db_test_reactive(db, "select count(message_len) from voicemail_msgs", "drop table voicemail_msgs", vm_sql);
-
- switch_core_db_exec(db, "select count(message_len) from voicemail_data", NULL, NULL, &errmsg);
+ } else {
+ if ((db = switch_core_db_open_file(profile->dbname))) {
+ char *errmsg;
+ switch_core_db_test_reactive(db, "select count(message_len) from voicemail_msgs", "drop table voicemail_msgs", vm_sql);
+
+ switch_core_db_exec(db, "select count(message_len) from voicemail_data", NULL, NULL, &errmsg);
+ if (errmsg) {
+ switch_core_db_free(errmsg);
+ errmsg = NULL;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Migrating data from voicemail_data to voicemail_msgs!\n");
+ switch_core_db_exec(db, "insert into voicemail_msgs select created_epoch, read_epoch, user as username, domain, uuid,"
+ "cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags from voicemail_data",
+ NULL, NULL, &errmsg);
if (errmsg) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n", errmsg);
switch_core_db_free(errmsg);
errmsg = NULL;
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Migrating data from voicemail_data to voicemail_msgs!\n");
- switch_core_db_exec(db, "insert into voicemail_msgs select created_epoch, read_epoch, user as username, domain, uuid,"
- "cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags from voicemail_data",
- NULL, NULL, &errmsg);
- if (errmsg) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n", errmsg);
- switch_core_db_free(errmsg);
- errmsg = NULL;
- }
- switch_core_db_exec(db, "drop table voicemail_data", NULL, NULL, &errmsg);
- if (errmsg) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n", errmsg);
- switch_core_db_free(errmsg);
- errmsg = NULL;
- }
}
+ switch_core_db_exec(db, "drop table voicemail_data", NULL, NULL, &errmsg);
+ if (errmsg) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n", errmsg);
+ switch_core_db_free(errmsg);
+ errmsg = NULL;
+ }
+ }
- switch_core_db_test_reactive(db, "select count(username) from voicemail_prefs", "drop table voicemail_prefs", vm_pref_sql);
- switch_core_db_test_reactive(db, "select count(password) from voicemail_prefs", NULL,
+ switch_core_db_test_reactive(db, "select count(username) from voicemail_prefs", "drop table voicemail_prefs", vm_pref_sql);
+ switch_core_db_test_reactive(db, "select count(password) from voicemail_prefs", NULL,
"alter table voicemail_prefs add password varchar(255)");
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
- continue;
- }
- switch_core_db_close(db);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
+ continue;
}
+ switch_core_db_close(db);
+ }
- profile->web_head = web_head;
- profile->web_tail = web_tail;
+ profile->web_head = web_head;
+ profile->web_tail = web_tail;
- profile->email_body = email_body;
- profile->email_headers = email_headers;
- if (notify_email_headers) {
- profile->notify_email_body = notify_email_body;
- profile->notify_email_headers = notify_email_headers;
- } else {
- profile->notify_email_body = email_body;
- profile->notify_email_headers = email_headers;
- }
- profile->email_from = switch_core_strdup(globals.pool, email_from);
- profile->date_fmt = switch_core_strdup(globals.pool, date_fmt);
- profile->play_date_announcement = play_date_announcement;
-
- profile->digit_timeout = timeout;
- profile->max_login_attempts = max_login_attempts;
- profile->min_record_len = min_record_len;
- profile->max_record_len = max_record_len;
- *profile->terminator_key = *terminator_key;
- *profile->play_new_messages_key = *play_new_messages_key;
- *profile->play_saved_messages_key = *play_saved_messages_key;
- *profile->main_menu_key = *main_menu_key;
- *profile->config_menu_key = *config_menu_key;
- *profile->record_greeting_key = *record_greeting_key;
- *profile->choose_greeting_key = *choose_greeting_key;
- *profile->record_name_key = *record_name_key;
- *profile->change_pass_key = *change_pass_key;
- *profile->record_file_key = *record_file_key;
- *profile->listen_file_key = *listen_file_key;
- *profile->save_file_key = *save_file_key;
- *profile->delete_file_key = *delete_file_key;
- *profile->undelete_file_key = *undelete_file_key;
- *profile->email_key = *email_key;
- *profile->callback_key = *callback_key;
- *profile->pause_key = *pause_key;
- *profile->restart_key = *restart_key;
- *profile->ff_key = *ff_key;
- *profile->rew_key = *rew_key;
- *profile->urgent_key = *urgent_key;
- *profile->operator_key = *operator_key;
- *profile->vmain_key = *vmain_key;
- *profile->forward_key = *forward_key;
- *profile->prepend_key = *prepend_key;
- profile->record_threshold = record_threshold;
- profile->record_silence_hits = record_silence_hits;
- profile->record_sample_rate = record_sample_rate;
-
- profile->auto_playback_recordings = auto_playback_recordings;
- profile->operator_ext = switch_core_strdup(globals.pool, operator_ext);
- profile->vmain_ext = switch_core_strdup(globals.pool, vmain_ext);
- profile->storage_dir = switch_core_strdup(globals.pool, storage_dir);
- profile->tone_spec = switch_core_strdup(globals.pool, tone_spec);
- profile->callback_dialplan = switch_core_strdup(globals.pool, callback_dialplan);
- profile->callback_context = switch_core_strdup(globals.pool, callback_context);
-
- profile->record_title = switch_core_strdup(globals.pool, record_title);
- profile->record_comment = switch_core_strdup(globals.pool, record_comment);
- profile->record_copyright = switch_core_strdup(globals.pool, record_copyright);
+ profile->email_body = email_body;
+ profile->email_headers = email_headers;
+ if (notify_email_headers) {
+ profile->notify_email_body = notify_email_body;
+ profile->notify_email_headers = notify_email_headers;
+ } else {
+ profile->notify_email_body = email_body;
+ profile->notify_email_headers = email_headers;
+ }
+ profile->email_from = switch_core_strdup(profile->pool, email_from);
+ profile->date_fmt = switch_core_strdup(profile->pool, date_fmt);
+ profile->play_date_announcement = play_date_announcement;
+
+ profile->digit_timeout = timeout;
+ profile->max_login_attempts = max_login_attempts;
+ profile->min_record_len = min_record_len;
+ profile->max_record_len = max_record_len;
+ *profile->terminator_key = *terminator_key;
+ *profile->play_new_messages_key = *play_new_messages_key;
+ *profile->play_saved_messages_key = *play_saved_messages_key;
+ *profile->main_menu_key = *main_menu_key;
+ *profile->config_menu_key = *config_menu_key;
+ *profile->record_greeting_key = *record_greeting_key;
+ *profile->choose_greeting_key = *choose_greeting_key;
+ *profile->record_name_key = *record_name_key;
+ *profile->change_pass_key = *change_pass_key;
+ *profile->record_file_key = *record_file_key;
+ *profile->listen_file_key = *listen_file_key;
+ *profile->save_file_key = *save_file_key;
+ *profile->delete_file_key = *delete_file_key;
+ *profile->undelete_file_key = *undelete_file_key;
+ *profile->email_key = *email_key;
+ *profile->callback_key = *callback_key;
+ *profile->pause_key = *pause_key;
+ *profile->restart_key = *restart_key;
+ *profile->ff_key = *ff_key;
+ *profile->rew_key = *rew_key;
+ *profile->urgent_key = *urgent_key;
+ *profile->operator_key = *operator_key;
+ *profile->vmain_key = *vmain_key;
+ *profile->forward_key = *forward_key;
+ *profile->prepend_key = *prepend_key;
+ profile->record_threshold = record_threshold;
+ profile->record_silence_hits = record_silence_hits;
+ profile->record_sample_rate = record_sample_rate;
+ profile->auto_playback_recordings = auto_playback_recordings;
+ profile->operator_ext = switch_core_strdup(profile->pool, operator_ext);
+ profile->vmain_ext = switch_core_strdup(profile->pool, vmain_ext);
+ profile->storage_dir = switch_core_strdup(profile->pool, storage_dir);
+ profile->tone_spec = switch_core_strdup(profile->pool, tone_spec);
+ profile->callback_dialplan = switch_core_strdup(profile->pool, callback_dialplan);
+ profile->callback_context = switch_core_strdup(profile->pool, callback_context);
+ profile->record_title = switch_core_strdup(profile->pool, record_title);
+ profile->record_comment = switch_core_strdup(profile->pool, record_comment);
+ profile->record_copyright = switch_core_strdup(profile->pool, record_copyright);
+ switch_copy_string(profile->file_ext, file_ext, sizeof(profile->file_ext));
+ switch_mutex_init(&profile->mutex, SWITCH_MUTEX_UNNESTED, profile->pool);
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name);
+ if (oldprofile) {
+
+ /* wait */
+ /* deadlock on concurrent voicemail rescan */
+ while (switch_thread_rwlock_trywrlock_timeout(oldprofile->rwlock, 10) != SWITCH_STATUS_SUCCESS);
+
+ switch_mutex_lock(globals.mutex);
+ /* change the profile*/
+ switch_core_hash_delete(globals.profile_hash, oldprofile->name);
+ switch_core_hash_insert(globals.profile_hash, profile->name, profile);
+ switch_mutex_unlock(globals.mutex);
- switch_copy_string(profile->file_ext, file_ext, sizeof(profile->file_ext));
- switch_mutex_init(&profile->mutex, SWITCH_MUTEX_NESTED, globals.pool);
+ destroy_profile(oldprofile);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name);
+ } else {
switch_core_hash_insert(globals.profile_hash, profile->name, profile);
}
}
+
end:
switch_xml_free(xml);
return SWITCH_STATUS_SUCCESS;
@@ -1626,11 +1703,16 @@
caller_id_number = caller_profile->caller_id_number;
}
+ switch_mutex_lock(globals.mutex);
+
if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error invalid profile %s\n", profile_name);
+ switch_mutex_unlock(globals.mutex);
return;
}
-
+ switch_thread_rwlock_rdlock(profile->rwlock);
+ switch_mutex_unlock(globals.mutex);
+
timeout = profile->digit_timeout;
attempts = profile->max_login_attempts;
status = switch_ivr_phrase_macro(session, VM_HELLO_MACRO, NULL, NULL, &args);
@@ -2146,6 +2228,8 @@
end:
+ switch_thread_rwlock_unlock(profile->rwlock);
+
if (switch_channel_ready(channel)) {
if (failed) {
status = switch_ivr_phrase_macro(session, VM_ABORT_MACRO, NULL, NULL, NULL);
@@ -2548,6 +2632,7 @@
goto end;
}
+ switch_mutex_lock(globals.mutex);
if (!(profile = switch_core_hash_find(globals.profile_hash, domain))) {
profile = switch_core_hash_find(globals.profile_hash, "default");
}
@@ -2555,11 +2640,15 @@
if (!profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find profile\n");
status = SWITCH_STATUS_FALSE;
+ switch_mutex_unlock(globals.mutex);
} else {
switch_xml_t x_domain, xml_root;
switch_event_t *my_params = NULL;
switch_xml_t ut;
+ switch_thread_rwlock_rdlock(profile->rwlock);
+ switch_mutex_unlock(globals.mutex);
+
switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS);
switch_assert(my_params);
switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "domain", domain);
@@ -2595,6 +2684,7 @@
}
}
}
+ switch_thread_rwlock_unlock(profile->rwlock);
switch_core_destroy_memory_pool(&pool);
@@ -2658,11 +2748,18 @@
}
memset(&cbt, 0, sizeof(cbt));
+
+ switch_mutex_lock(globals.mutex);
+
if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error invalid profile %s\n", profile_name);
- return SWITCH_STATUS_FALSE;
+ switch_mutex_unlock(globals.mutex);
+ return SWITCH_STATUS_FALSE;;
}
+ switch_thread_rwlock_rdlock(profile->rwlock);
+ switch_mutex_unlock(globals.mutex);
+
if (id) {
int ok = 1;
switch_event_t *params = NULL;
@@ -2903,6 +3000,8 @@
end:
+ switch_thread_rwlock_unlock(profile->rwlock);
+
if (x_domain_root) {
switch_xml_free(x_domain_root);
x_domain_root = NULL;
@@ -3025,7 +3124,7 @@
*p++ = '\0';
how = p;
}
-
+ switch_mutex_lock(globals.mutex);
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
profile = (vm_profile_t *) val;
@@ -3033,6 +3132,7 @@
message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages,
&total_new_urgent_messages, &total_saved_urgent_messages);
}
+ switch_mutex_unlock(globals.mutex);
}
switch_safe_free(id);
@@ -3132,7 +3232,6 @@
}
-#define VOICEMAIL_SYNTAX "rss [<host> <port> <uri> <user> <domain>]"
struct holder {
vm_profile_t *profile;
@@ -3565,6 +3664,7 @@
return SWITCH_STATUS_SUCCESS;
}
+#define VOICEMAIL_SYNTAX "rss [<host> <port> <uri> <user> <domain>] | rescan [reloadxml]"
SWITCH_STANDARD_API(voicemail_api_function)
{
int argc = 0;
@@ -3575,6 +3675,8 @@
vm_profile_t *profile = NULL;
char *path_info = NULL;
int rss = 0, xarg = 0;
+ switch_hash_index_t *hi;
+ void *val = NULL;
if (session) {
return SWITCH_STATUS_FALSE;
@@ -3599,6 +3701,34 @@
if (!strcasecmp(argv[0], "rss")) {
rss++;
xarg++;
+ } else if (!strcasecmp(argv[0], "rescan")) {
+ switch_xml_t xml_root;
+ const char *err;
+ if (argc > 1 && !strcasecmp(argv[1], "reloadxml")) {
+ if ((xml_root = switch_xml_open_root(1, &err))) {
+ switch_xml_free(xml_root);
+ }
+ stream->write_function(stream, "Reload XML [%s]\n", err);
+ }
+ if (load_config() == SWITCH_STATUS_SUCCESS) {
+ stream->write_function(stream, "+OK scan complete\n");
+ } else {
+ stream->write_function(stream, "-ERR scan failed\n");
+ goto error;
+ }
+ goto done;
+ } else if (!strcasecmp(argv[0], "status")) {
+ stream->write_function(stream, "============================\n");
+ switch_mutex_lock(globals.mutex);
+ for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+ vm_profile_t * profile = NULL;
+ switch_hash_this(hi, NULL, NULL, &val);
+ profile = (vm_profile_t *) val;
+ stream->write_function(stream, "Profile: %s\n", profile->name);
+ }
+ switch_mutex_unlock(globals.mutex);
+ stream->write_function(stream, "============================\n");
+ goto done;
}
}
@@ -3617,6 +3747,7 @@
goto error;
}
+ switch_mutex_lock(globals.mutex);
profile = switch_core_hash_find(globals.profile_hash, domain);
if (!profile) {
@@ -3638,9 +3769,13 @@
if (!profile) {
stream->write_function(stream, "Can't find profile.\n");
+ switch_mutex_unlock(globals.mutex);
goto error;
}
+ switch_thread_rwlock_rdlock(profile->rwlock);
+ switch_mutex_unlock(globals.mutex);
+
if (path_info) {
if (!strncasecmp(path_info, "get/", 4)) {
do_play(profile, user, domain, path_info + 4, stream);
@@ -3654,6 +3789,7 @@
if (rss || (path_info && !strncasecmp(path_info, "rss", 3))) {
do_rss(profile, user, domain, host, port, uri, stream);
}
+ switch_thread_rwlock_unlock(profile->rwlock);
goto done;
@@ -3683,6 +3819,12 @@
return SWITCH_STATUS_TERM;
}
+ memset(&globals, 0, sizeof(globals));
+ switch_core_new_memory_pool(&globals.pool);
+ switch_core_hash_init(&globals.profile_hash, globals.pool);
+ switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool);
+
+
if ((status = load_config()) != SWITCH_STATUS_SUCCESS) {
return status;
}
1
0