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
- 1655 discussions
[commit] r10284 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by Freeswitch SVN 07 Nov '08
by Freeswitch SVN 07 Nov '08
07 Nov '08
Author: gmaruzz
Date: Fri Nov 7 04:39:44 2008
New Revision: 10284
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
Log:
skypiax: gets X11 DISPLAY from config file
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 Fri Nov 7 04:39:44 2008
@@ -2336,6 +2336,8 @@
char fail_dial_regex[256];
char hold_music[256];
char type[256];
+ char X11_display[256];
+ struct AsteriskHandles AsteriskHandlesAst;
};
typedef struct skypiax_config skypiax_config_t;
@@ -2730,7 +2732,7 @@
/*.receive_event */ channel_receive_event
};
#define SKYPE_THREAD
- struct AsteriskHandles ciapa;
+ //struct AsteriskHandles ciapa;
#ifdef SKYPE_THREAD
#define SKYPE_X11_BUF_SIZE 512
Window skype_win = (Window) - 1;
@@ -2866,19 +2868,17 @@
static void *SWITCH_THREAD_FUNC do_skype_thread(switch_thread_t *thread, void *data)
{
-// struct skypiax_pvt *p;
+ struct skypiax_config *p;
struct AsteriskHandles *AsteriskHandlesAst;
char buf[SKYPE_X11_BUF_SIZE];
Display *disp = NULL;
Window root = -1;
Window win = -1;
- /*
p = data;
- if (option_debug > 10) {
DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
- }
+/*
if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) {
ERRORA("Unable to set cancel type to deferred\n", SKYPIAX_P_LOG);
if (option_debug > 10) {
@@ -2886,16 +2886,17 @@
}
return NULL;
}
+*/
AsteriskHandlesAst = &p->AsteriskHandlesAst;
-*/
- AsteriskHandlesAst = &ciapa;
- disp = XOpenDisplay(getenv("DISPLAY"));
+ //AsteriskHandlesAst = &ciapa;
+ //disp = XOpenDisplay(getenv("DISPLAY"));
+ disp = XOpenDisplay(p->X11_display);
if (!disp) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open X Display, exiting skype thread\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open X Display '%s', exiting skype thread\n", p->X11_display);
return NULL;
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "X Display opened\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "X Display '%s' opened\n", p->X11_display);
}
int xfd;
@@ -3076,6 +3077,7 @@
char *hold_music = NULL;
char *fail_dial_regex = NULL;
char *enable_callerid = "true";
+ char *X11_display = NULL;
uint32_t span_id = 0, to = 0, max = 0;
@@ -3099,6 +3101,8 @@
fail_dial_regex = val;
} else if (!strcasecmp(var, "hold-music")) {
hold_music = val;
+ } else if (!strcasecmp(var, "X11-display") || !strcasecmp(var, "X11_display")) {
+ X11_display = val;
} else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) {
max_digits = val;
} else if (!strcasecmp(var, "hotline")) {
@@ -3106,7 +3110,12 @@
}
}
-
+
+ if (!X11_display) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing REQUIRED param 'X11_display'\n");
+ continue;
+ }
+
if (!id) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing REQUIRED param 'id'\n");
continue;
@@ -3151,8 +3160,10 @@
} else {
switch_set_string(SKYPIAX_CONFIGS[span_id].name, "N/A");
}
+ switch_set_string(SKYPIAX_CONFIGS[span_id].X11_display, X11_display);
switch_set_string(SKYPIAX_CONFIGS[span_id].context, context);
switch_set_string(SKYPIAX_CONFIGS[span_id].dialplan, dialplan);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].X11_display=%s\n", span_id, SKYPIAX_CONFIGS[span_id].X11_display);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].name=%s\n", span_id, SKYPIAX_CONFIGS[span_id].name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].context=%s\n", span_id, SKYPIAX_CONFIGS[span_id].context);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].dialplan=%s\n", span_id, SKYPIAX_CONFIGS[span_id].dialplan);
@@ -3179,6 +3190,7 @@
for(i=0; i < SKYPIAX_MAX_INTERFACES; i++) {
if(strlen(SKYPIAX_CONFIGS[i].name)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_CONFIGS[i].span_id=%s\n", i, SKYPIAX_CONFIGS[i].span_id);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_CONFIGS[i].X11_display=%s\n", i, SKYPIAX_CONFIGS[i].X11_display);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_CONFIGS[i].name=%s\n", i, SKYPIAX_CONFIGS[i].name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_CONFIGS[i].context=%s\n", i, SKYPIAX_CONFIGS[i].context);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_CONFIGS[i].dialplan=%s\n", i, SKYPIAX_CONFIGS[i].dialplan);
@@ -3188,7 +3200,6 @@
switch_xml_free(xml);
- //do_skype_thread(NULL);
//static void unicall_thread_launch(uc_t *uc)
@@ -3206,6 +3217,7 @@
} else {
DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
}
+usleep(10000); //FIXME
#endif /* _WINDOWS_ */
1
0
[commit] r10283 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by Freeswitch SVN 07 Nov '08
by Freeswitch SVN 07 Nov '08
07 Nov '08
Author: gmaruzz
Date: Fri Nov 7 04:10:56 2008
New Revision: 10283
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
Log:
skypiax: starts thread for Skype API read/write
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 Fri Nov 7 04:10:56 2008
@@ -2862,7 +2862,8 @@
DEBUGA_SKYPE("OUT destroyed disp\n", SKYPIAX_P_LOG);
usleep(1000);
}
-void *do_skype_thread(void *data)
+//void *do_skype_thread(void *data)
+static void *SWITCH_THREAD_FUNC do_skype_thread(switch_thread_t *thread, void *data)
{
// struct skypiax_pvt *p;
@@ -2976,7 +2977,7 @@
if (i < 20) { /* last fragment */
write(AsteriskHandlesAst->fdesc[1], b, strlen(b) + 1);
//write(AsteriskHandlesAst->fdesc[1], "\0", 1);
- DEBUGA_SKYPE("SKYPE pipewrite: |||%s|||len=%d serial=%ld\n", SKYPIAX_P_LOG, b,
+ DEBUGA_SKYPE("SKYPE pipewrite: |||%s|||len=%d serial=%ld\n\n\n", SKYPIAX_P_LOG, b,
strlen(b) + 1, an_event.xclient.serial);
//usleep(1000);
memset(buffer, '\0', 17000);
@@ -3156,6 +3157,18 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].context=%s\n", span_id, SKYPIAX_CONFIGS[span_id].context);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].dialplan=%s\n", span_id, SKYPIAX_CONFIGS[span_id].dialplan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "STARTING span_id=%d\n", span_id);
+if(1)
+{
+ switch_thread_t *thread;
+ switch_threadattr_t *thd_attr = NULL;
+
+ switch_threadattr_create(&thd_attr, module_pool);
+ switch_threadattr_detach_set(thd_attr, 1);
+ switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_thread_create(&thread, thd_attr, do_skype_thread, &SKYPIAX_CONFIGS[span_id], module_pool);
+}
+
+
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span id %d is higher than SKYPIAX_MAX_INTERFACES (%d)\n", span_id, SKYPIAX_MAX_INTERFACES);
continue;
@@ -3175,7 +3188,9 @@
switch_xml_free(xml);
- do_skype_thread(NULL);
+ //do_skype_thread(NULL);
+
+//static void unicall_thread_launch(uc_t *uc)
return SWITCH_STATUS_SUCCESS;
}
1
0
[commit] r10282 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by Freeswitch SVN 07 Nov '08
by Freeswitch SVN 07 Nov '08
07 Nov '08
Author: gmaruzz
Date: Fri Nov 7 03:01:55 2008
New Revision: 10282
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
Log:
skypiax: beginning exchange API msgs with Skype client
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 Fri Nov 7 03:01:55 2008
@@ -2920,7 +2920,7 @@
AsteriskHandlesAst->disp = disp;
AsteriskHandlesAst->win = win;
- snprintf(buf, SKYPE_X11_BUF_SIZE, "NAME FS_skypiax");
+ snprintf(buf, SKYPE_X11_BUF_SIZE, "NAME skypiax");
if (!skypiax_skype_send_message(AsteriskHandlesAst, buf)) {
ERRORA
@@ -2944,17 +2944,17 @@
}
/* perform an events loop */
- //FIXME XEvent an_event;
- //FIXME char buf[21]; /* can't be longer */
+ XEvent an_event;
+ char buf[21]; /* can't be longer */
char buffer[17000];
char *b;
- //FIXME int i;
+ int i;
b = buffer;
-#ifdef LOOPI
+#ifndef LOOPI
while (1) {
- pthread_testcancel();
+ //pthread_testcancel();
XNextEvent(disp, &an_event);
switch (an_event.type) {
case ClientMessage:
@@ -2999,7 +2999,7 @@
//p->skype = 0;
//p->skype_thread = AST_PTHREADT_NULL;
//pthread_cleanup_pop(1);
- DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+ //DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
#endif /* NOTDEF */
return NULL;
@@ -3186,17 +3186,17 @@
module_pool = pool;
#ifndef _WINDOWS_ //FIXME
- if (!XInitThreads())
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Not initialized XInitThreads!\n");
- else
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Initialized XInitThreads!\n");
+ if (!XInitThreads()) {
+ ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
+ } else {
+ DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
+ }
#endif /* _WINDOWS_ */
load_config();
- DEBUGA_PBX("CIAPALO FUNC\n", SKYPIAX_P_LOG);
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
skypiax_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
1
0
[commit] r10275 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by Freeswitch SVN 07 Nov '08
by Freeswitch SVN 07 Nov '08
07 Nov '08
Author: gmaruzz
Date: Thu Nov 6 17:55:42 2008
New Revision: 10275
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
Log:
skypiax: ask the Skype client for API connection
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 Thu Nov 6 17:55:42 2008
@@ -2210,6 +2210,53 @@
#include <X11/Xatom.h>
#include <switch.h>
+#define SKYPIAX_SVN_VERSION "SVN 123456"
+
+#define DEBUGA_SKYPE(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_SKYPE %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define DEBUGA_CALL(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_CALL %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define DEBUGA_PBX(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_PBX %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define ERRORA(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][ERRORA %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define WARNINGA(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][WARNINGA %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define NOTICA(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][NOTICA %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+
+
+#define SKYPIAX_P_LOG NULL, (unsigned long)55, __LINE__, "none", -1, -2, -3
+
+#ifdef ASTER
+/* debugging bitmask */
+#define DEBUG_SOUND 1
+#define DEBUG_SERIAL 2
+#define DEBUG_SKYPE 4
+#define DEBUG_AT 8
+#define DEBUG_FBUS2 16
+#define DEBUG_CALL 32
+#define DEBUG_LOCKS 64
+#define DEBUG_PBX 128
+#define DEBUG_MONITORLOCKS 256
+#define DEBUG_ALL DEBUG_SOUND|DEBUG_SERIAL|DEBUG_SKYPE|DEBUG_AT|DEBUG_FBUS2|DEBUG_CALL|DEBUG_PBX|DEBUG_LOCKS|DEBUG_MONITORLOCKS
+/* wrappers for ast_log */
+#define DEBUGA_SOUND(...) if (skypiax_debug & DEBUG_SOUND) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_SOUND %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define DEBUGA_SERIAL(...) if (skypiax_debug & DEBUG_SERIAL) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_SERIAL %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define DEBUGA_SKYPE(...) if (skypiax_debug & DEBUG_SKYPE) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_SKYPE %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define DEBUGA_AT(...) if (skypiax_debug & DEBUG_AT) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_AT %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define DEBUGA_FBUS2(...) if (skypiax_debug & DEBUG_FBUS2) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_FBUS2 %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define DEBUGA_CALL(...) if (skypiax_debug & DEBUG_CALL) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_CALL %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define DEBUGA_PBX(...) if (skypiax_debug & DEBUG_PBX) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_PBX %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define ERRORA(...) ast_log(LOG_ERROR, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][ERROR %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define NOTICA(...) ast_log(LOG_NOTICE, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][NOTICE %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define WARNINGA(...) ast_log(LOG_WARNING, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][WARNING %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+/* macros for logging */
+#define SKYPIAX_P_LOG p ? p->owner : NULL, (unsigned long)pthread_self(), __LINE__, p ? p->name ? p->name : "none" : "none", p ? p->owner ? p->owner->_state : -1 : -1, p ? p->interface_state : -1, p ? p->skype_callflow : -1
+#define SKYPIAX_TMP_LOG tmp ? tmp->owner : NULL, (unsigned long)pthread_self(), __LINE__, tmp ? tmp->name ? tmp->name : "none" : "none", tmp ? tmp->owner ? tmp->owner->_state : -1 : -1, tmp ? tmp->interface_state : -1, tmp ? tmp->skype_callflow : -1
+/* logging wrappers for ast_mutex_lock and ast_mutex_unlock */
+#define LOKKA(x) if (skypiax_debug & DEBUG_LOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_LOCKS %-5d][%-10s][%2d,%2d,%2d] going to lock %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); if (ast_mutex_lock(x)) ast_log(LOG_ERROR, "ast_mutex_lock failed, BAD\n"); if (skypiax_debug & DEBUG_LOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_LOCKS %-5d][%-10s][%2d,%2d,%2d] locked %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????");
+#define UNLOCKA(x) if (skypiax_debug & DEBUG_LOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_LOCKS %-5d][%-10s][%2d,%2d,%2d] going to unlock %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); if (ast_mutex_unlock(x)) ast_log(LOG_ERROR, "ast_mutex_lock failed, BAD\n"); if (skypiax_debug & DEBUG_LOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_LOCKS %-5d][%-10s][%2d,%2d,%2d] unlocked %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????");
+#define PUSHA_UNLOCKA(x) pthread_cleanup_push(skypiax_unlocka_log, (void *) x);
+#define POPPA_UNLOCKA(x) pthread_cleanup_pop(0);
+#define MONITORLOKKA(x) if (skypiax_debug & DEBUG_MONITORLOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_MONITORLOCKS %-5d][%-10s][%2d,%2d,%2d] going to lock %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); if (ast_mutex_lock(x)) ast_log(LOG_ERROR, "ast_mutex_lock failed, BAD\n"); if (skypiax_debug & DEBUG_MONITORLOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_MONITORLOCKS %-5d][%-10s][%2d,%2d,%2d] locked %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????");
+#define MONITORUNLOCKA(x) if (skypiax_debug & DEBUG_MONITORLOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_MONITORLOCKS %-5d][%-10s][%2d,%2d,%2d] going to unlock %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????"); if (ast_mutex_unlock(x)) ast_log(LOG_ERROR, "ast_mutex_lock failed, BAD\n"); if (skypiax_debug & DEBUG_MONITORLOCKS) ast_log(LOG_DEBUG, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_MONITORLOCKS %-5d][%-10s][%2d,%2d,%2d] unlocked %p (%s)\n", SKYPIAX_P_LOG, x, x == &skypiax_monlock ? "MONLOCK" : x == &skypiax_iflock ? "IFLOCK" : x == &skypiax_usecnt_lock ? "USECNT_LOCK" : "?????");
+#endif /* ASTER */
+
#define SKYPIAX_MAX_INTERFACES 64
SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load);
@@ -2222,6 +2269,13 @@
static switch_memory_pool_t *module_pool = NULL;
static int running = 1;
+struct AsteriskHandles {
+ Window skype_win;
+ Display *disp;
+ Window win;
+ int fdesc[2];
+};
+
typedef enum {
TFLAG_IO = (1 << 0),
@@ -2676,16 +2730,147 @@
/*.receive_event */ channel_receive_event
};
#define SKYPE_THREAD
+ struct AsteriskHandles ciapa;
#ifdef SKYPE_THREAD
+#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;
+ //struct skypiax_pvt *p = NULL;
+
+ xerror = err->error_code;
+ DEBUGA_SKYPE("Received error code %d from X Server\n", SKYPIAX_P_LOG, xerror);
+ return 0; /* ignore the error */
+}
+
+static void X11_errors_trap(void)
+{
+ xerror = 0;
+ old_handler = XSetErrorHandler(X11_errors_handler);
+}
+
+static int X11_errors_untrap(void)
+{
+ XSetErrorHandler(old_handler);
+ return (xerror != BadValue) && (xerror != BadWindow);
+}
+
+int skypiax_skype_send_message(struct AsteriskHandles *AsteriskHandlesAst,
+ const char *message_P)
+{
+
+ Window w_P;
+ Display *disp;
+ Window handle_P;
+ //struct skypiax_pvt *p = NULL;
+
+ w_P = AsteriskHandlesAst->skype_win;
+ disp = AsteriskHandlesAst->disp;
+ handle_P = AsteriskHandlesAst->win;
+
+ Atom atom1 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
+ Atom atom2 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
+ unsigned int pos = 0;
+ unsigned int len = strlen(message_P);
+ XEvent e;
+ int ok;
+
+ memset(&e, 0, sizeof(e));
+ e.xclient.type = ClientMessage;
+ e.xclient.message_type = atom1; /* leading message */
+ e.xclient.display = disp;
+ e.xclient.window = handle_P;
+ e.xclient.format = 8;
+
+ X11_errors_trap();
+ //XLockDisplay(disp);
+ do {
+ unsigned int i;
+ for (i = 0; i < 20 && i + pos <= len; ++i)
+ e.xclient.data.b[i] = message_P[i + pos];
+ XSendEvent(disp, w_P, False, 0, &e);
+
+ e.xclient.message_type = atom2; /* following messages */
+ pos += i;
+ } while (pos <= len);
+
+ XSync(disp, False);
+ //XUnlockDisplay(disp);
+ ok = X11_errors_untrap();
+
+ if (!ok)
+ DEBUGA_SKYPE("Sending message failed with status %d\n", SKYPIAX_P_LOG, xerror);
+
+ return ok;
+}
+
+int skypiax_skype_present(Display * disp)
+{
+ Atom skype_inst = XInternAtom(disp, "_SKYPE_INSTANCE", True);
+
+ Atom type_ret;
+ int format_ret;
+ unsigned long nitems_ret;
+ unsigned long bytes_after_ret;
+ unsigned char *prop;
+ int status;
+ //struct skypiax_pvt *p = NULL;
+
+ X11_errors_trap();
+ //XLockDisplay(disp);
+ status =
+ XGetWindowProperty(disp, DefaultRootWindow(disp), skype_inst, 0, 1, False, XA_WINDOW,
+ &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop);
+ //XUnlockDisplay(disp);
+ X11_errors_untrap();
+
+ /* sanity check */
+ if (status != Success || format_ret != 32 || nitems_ret != 1) {
+ skype_win = (Window) - 1;
+ DEBUGA_SKYPE("Skype instance not found\n", SKYPIAX_P_LOG);
+ return 0;
+ }
+
+ 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);
+ return 1;
+}
+
+void skypiax_skype_clean_disp(void *data)
+{
+
+ int *dispptr;
+ int disp;
+ //struct skypiax_pvt *p = NULL;
+
+ dispptr = data;
+ disp = *dispptr;
+
+ if (disp) {
+ DEBUGA_SKYPE("to be destroyed disp %d\n", SKYPIAX_P_LOG, disp);
+ close(disp);
+ DEBUGA_SKYPE("destroyed disp\n", SKYPIAX_P_LOG);
+ } else {
+ DEBUGA_SKYPE("NOT destroyed disp\n", SKYPIAX_P_LOG);
+ }
+ DEBUGA_SKYPE("OUT destroyed disp\n", SKYPIAX_P_LOG);
+ usleep(1000);
+}
void *do_skype_thread(void *data)
{
// struct skypiax_pvt *p;
- // struct AsteriskHandles *AsteriskHandlesAst;
- //FIXME char buf[SKYPE_X11_BUF_SIZE];
+ struct AsteriskHandles *AsteriskHandlesAst;
+ char buf[SKYPE_X11_BUF_SIZE];
Display *disp = NULL;
- //FIXME Window root = -1;
- //FIXME Window win = -1;
+ Window root = -1;
+ Window win = -1;
/*
p = data;
@@ -2703,6 +2888,7 @@
AsteriskHandlesAst = &p->AsteriskHandlesAst;
*/
+ AsteriskHandlesAst = &ciapa;
disp = XOpenDisplay(getenv("DISPLAY"));
if (!disp) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open X Display, exiting skype thread\n");
@@ -2715,8 +2901,8 @@
xfd = XConnectionNumber(disp);
fcntl(xfd, F_SETFD, FD_CLOEXEC);
-#ifdef NOTDEF
- pthread_cleanup_push(skypiax_skype_clean_disp, &xfd);
+#ifndef NOTDEF
+ //FIXME pthread_cleanup_push(skypiax_skype_clean_disp, &xfd);
DEBUGA_SKYPE("PUSH disp %d\n", SKYPIAX_P_LOG, xfd);
if (skypiax_skype_present(disp)) {
@@ -2734,17 +2920,15 @@
AsteriskHandlesAst->disp = disp;
AsteriskHandlesAst->win = win;
- snprintf(buf, SKYPE_X11_BUF_SIZE, "NAME skypiax");
+ snprintf(buf, SKYPE_X11_BUF_SIZE, "NAME FS_skypiax");
if (!skypiax_skype_send_message(AsteriskHandlesAst, buf)) {
ERRORA
("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
SKYPIAX_P_LOG);
- p->skype = 0;
- p->skype_thread = AST_PTHREADT_NULL;
- if (option_debug > 10) {
+ //p->skype = 0;
+ //p->skype_thread = AST_PTHREADT_NULL;
DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
- }
return NULL;
}
@@ -2753,23 +2937,22 @@
ERRORA
("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
SKYPIAX_P_LOG);
- p->skype = 0;
- p->skype_thread = AST_PTHREADT_NULL;
- if (option_debug > 10) {
+ //p->skype = 0;
+ //p->skype_thread = AST_PTHREADT_NULL;
DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
- }
return NULL;
}
/* perform an events loop */
- XEvent an_event;
- char buf[21]; /* can't be longer */
+ //FIXME XEvent an_event;
+ //FIXME char buf[21]; /* can't be longer */
char buffer[17000];
char *b;
- int i;
+ //FIXME int i;
b = buffer;
+#ifdef LOOPI
while (1) {
pthread_testcancel();
XNextEvent(disp, &an_event);
@@ -2804,20 +2987,19 @@
break;
}
}
+#endif // LOOPI
} else {
ERRORA
("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n",
SKYPIAX_P_LOG);
- p->skype = 0;
- p->skype_thread = AST_PTHREADT_NULL;
+ //p->skype = 0;
+ //p->skype_thread = AST_PTHREADT_NULL;
return NULL;
}
- p->skype = 0;
- p->skype_thread = AST_PTHREADT_NULL;
- pthread_cleanup_pop(1);
- if (option_debug > 10) {
+ //p->skype = 0;
+ //p->skype_thread = AST_PTHREADT_NULL;
+ //pthread_cleanup_pop(1);
DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
- }
#endif /* NOTDEF */
return NULL;
@@ -3011,8 +3193,11 @@
#endif /* _WINDOWS_ */
+
load_config();
+ DEBUGA_PBX("CIAPALO FUNC\n", SKYPIAX_P_LOG);
+
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
skypiax_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
skypiax_endpoint_interface->interface_name = "skypiax";
1
0
[commit] r10270 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by Freeswitch SVN 07 Nov '08
by Freeswitch SVN 07 Nov '08
07 Nov '08
Author: gmaruzz
Date: Thu Nov 6 10:14:17 2008
New Revision: 10270
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
Log:
skypiax: added a little X11 init
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 Thu Nov 6 10:14:17 2008
@@ -2205,6 +2205,9 @@
#define MOD_SKYPIAX
#ifdef MOD_SKYPIAX
+#include <X11/Xlib.h>
+#include <X11/Xlibint.h>
+#include <X11/Xatom.h>
#include <switch.h>
#define SKYPIAX_MAX_INTERFACES 64
@@ -2672,6 +2675,157 @@
/*.receive_message */ channel_receive_message,
/*.receive_event */ channel_receive_event
};
+#define SKYPE_THREAD
+#ifdef SKYPE_THREAD
+void *do_skype_thread(void *data)
+{
+
+// struct skypiax_pvt *p;
+ // struct AsteriskHandles *AsteriskHandlesAst;
+ //FIXME char buf[SKYPE_X11_BUF_SIZE];
+ Display *disp = NULL;
+ //FIXME Window root = -1;
+ //FIXME Window win = -1;
+
+ /*
+ p = data;
+
+ if (option_debug > 10) {
+ DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
+ }
+ if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) {
+ ERRORA("Unable to set cancel type to deferred\n", SKYPIAX_P_LOG);
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+ }
+ return NULL;
+ }
+
+ AsteriskHandlesAst = &p->AsteriskHandlesAst;
+*/
+ disp = XOpenDisplay(getenv("DISPLAY"));
+ if (!disp) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open X Display, exiting skype thread\n");
+ return NULL;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "X Display opened\n");
+ }
+
+ int xfd;
+ xfd = XConnectionNumber(disp);
+ fcntl(xfd, F_SETFD, FD_CLOEXEC);
+
+#ifdef NOTDEF
+ pthread_cleanup_push(skypiax_skype_clean_disp, &xfd);
+ DEBUGA_SKYPE("PUSH disp %d\n", SKYPIAX_P_LOG, xfd);
+
+ if (skypiax_skype_present(disp)) {
+ root = DefaultRootWindow(disp);
+ win =
+ XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0,
+ BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp,
+ DefaultScreen
+ (disp)));
+
+ 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->win = win;
+
+ snprintf(buf, SKYPE_X11_BUF_SIZE, "NAME skypiax");
+
+ if (!skypiax_skype_send_message(AsteriskHandlesAst, buf)) {
+ ERRORA
+ ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
+ SKYPIAX_P_LOG);
+ p->skype = 0;
+ p->skype_thread = AST_PTHREADT_NULL;
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+ }
+ return NULL;
+ }
+
+ snprintf(buf, SKYPE_X11_BUF_SIZE, "PROTOCOL 6");
+ if (!skypiax_skype_send_message(AsteriskHandlesAst, buf)) {
+ ERRORA
+ ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
+ SKYPIAX_P_LOG);
+ p->skype = 0;
+ p->skype_thread = AST_PTHREADT_NULL;
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+ }
+ return NULL;
+ }
+
+ /* perform an events loop */
+ XEvent an_event;
+ char buf[21]; /* can't be longer */
+ char buffer[17000];
+ char *b;
+ int i;
+
+ b = buffer;
+
+ while (1) {
+ pthread_testcancel();
+ XNextEvent(disp, &an_event);
+ switch (an_event.type) {
+ case ClientMessage:
+
+ if (an_event.xclient.format != 8)
+ break;
+
+ for (i = 0; i < 20 && an_event.xclient.data.b[i] != '\0'; ++i)
+ buf[i] = an_event.xclient.data.b[i];
+
+ buf[i] = '\0';
+
+ //NOTICA("ClientMessage buf:|||%s||| buffer:|||%s||| serial=%ld|||\r\n",SKYPIAX_P_LOG,buf, buffer,an_event.xclient.serial);
+ //NOTICA ("SKYPE read: |||%s|||%d\n", SKYPIAX_P_LOG, buf, strlen(buf));
+ //NOTICA ("SKYPE buffer: |||%s|||%d\n", SKYPIAX_P_LOG, buffer, strlen(buffer));
+
+ strcat(buffer, buf);
+
+ if (i < 20) { /* last fragment */
+ write(AsteriskHandlesAst->fdesc[1], b, strlen(b) + 1);
+ //write(AsteriskHandlesAst->fdesc[1], "\0", 1);
+ DEBUGA_SKYPE("SKYPE pipewrite: |||%s|||len=%d serial=%ld\n", SKYPIAX_P_LOG, b,
+ strlen(b) + 1, an_event.xclient.serial);
+ //usleep(1000);
+ memset(buffer, '\0', 17000);
+ }
+
+ break;
+ default:
+ break;
+ }
+ }
+ } else {
+ ERRORA
+ ("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n",
+ SKYPIAX_P_LOG);
+ p->skype = 0;
+ p->skype_thread = AST_PTHREADT_NULL;
+ return NULL;
+ }
+ p->skype = 0;
+ p->skype_thread = AST_PTHREADT_NULL;
+ pthread_cleanup_pop(1);
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+ }
+#endif /* NOTDEF */
+ return NULL;
+
+}
+
+
+#endif /* SKYPE_THREAD */
+
static switch_status_t load_config(void)
{
@@ -2805,7 +2959,6 @@
if(span_id && span_id < SKYPIAX_MAX_INTERFACES ) {
struct skypiax_config newconf;
- //skypax_config_t newconf;
memset(&newconf, '\0', sizeof(newconf));
SKYPIAX_CONFIGS[span_id]=newconf;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CONFIGURING span_id=%d\n", span_id);
@@ -2840,15 +2993,24 @@
switch_xml_free(xml);
+ do_skype_thread(NULL);
+
return SWITCH_STATUS_SUCCESS;
}
-
SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load)
{
module_pool = pool;
+#ifndef _WINDOWS_ //FIXME
+ if (!XInitThreads())
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Not initialized XInitThreads!\n");
+ else
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Initialized XInitThreads!\n");
+#endif /* _WINDOWS_ */
+
+
load_config();
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
@@ -2860,60 +3022,6 @@
/*****************************************/
#ifdef CICOPET
{
- int i;
- struct ast_config *cfg;
- struct skypiax_pvt *tmp;
- struct skypiax_pvt *p = NULL;
-
-#ifndef __CYGWIN__
- if (!XInitThreads())
- ast_log(LOG_ERROR, "Not initialized XInitThreads!\n");
-#endif /* __CYGWIN__ */
-
- /* load skypiax.conf config file */
- cfg = ast_config_load(skypiax_config);
- if (cfg != NULL) {
- char *ctg = NULL;
- int is_first_category = 1;
- while ((ctg = ast_category_browse(cfg, ctg)) != NULL) {
- /* create one interface for each category in skypiax.conf config file, first one set the defaults */
- tmp = skypiax_mkif(cfg, ctg, is_first_category);
- if (tmp) {
- DEBUGA_PBX
- ("Created channel Skypiax: skypiax.conf category '[%s]', channel name '%s'"
- "\n", SKYPIAX_P_LOG, ctg, tmp->name);
- /* add interface to skypiax_iflist */
- tmp->next = skypiax_iflist;
- skypiax_iflist = tmp;
- /* next one will not be the first ;) */
- if (is_first_category == 1) {
- is_first_category = 0;
- skypiax_console_active = tmp->name;
- }
- } else {
- ERRORA("Unable to create channel Skypiax from skypiax.conf category '[%s]'\n",
- SKYPIAX_P_LOG, ctg);
- /* if error, unload config from memory and return */
- ast_config_destroy(cfg);
- ast_channel_unregister(&skypiax_tech);
- if (option_debug > 10) {
- DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
- }
- return -1;
- }
- /* do it for each category described in config */
- }
-
- /* we finished, unload config from memory */
- ast_config_destroy(cfg);
- } else {
- ERRORA("Unable to load skypiax_config skypiax.conf\n", SKYPIAX_P_LOG);
- ast_channel_unregister(&skypiax_tech);
- if (option_debug > 10) {
- DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
- }
- return -1;
- }
#ifndef ASTERISK_VERSION_1_6
ast_cli_register_multiple(myclis, sizeof(myclis) / sizeof(struct ast_cli_entry));
#endif /* ASTERISK_VERSION_1_6 */
1
0
[commit] r10269 - in freeswitch/branches/gmaruzz: src/mod/endpoints/mod_skypiax stuff
by Freeswitch SVN 07 Nov '08
by Freeswitch SVN 07 Nov '08
07 Nov '08
Author: gmaruzz
Date: Thu Nov 6 09:04:02 2008
New Revision: 10269
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml
Log:
skypiax: continue to parse nested configuration, eg: multiple interfaces
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 Thu Nov 6 09:04:02 2008
@@ -2271,6 +2271,7 @@
typedef struct private_object private_t;
struct skypiax_config {
+ char span_id[80];
char name[80];
char dialplan[80];
char context[80];
@@ -2723,6 +2724,8 @@
}
if ((spans = switch_xml_child(cfg, "analog_spans"))) {
+ int i=0;
+
for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) {
char *id = (char *) switch_xml_attr(myspan, "id");
char *name = (char *) switch_xml_attr(myspan, "name");
@@ -2771,6 +2774,13 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing REQUIRED param 'id'\n");
continue;
}
+ if (switch_is_number(id)) {
+ span_id = atoi(id);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d\n", span_id);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span param 'id' MUST be a number, now id='%s'\n", id);
+ continue;
+ }
if (!name) {
@@ -2793,17 +2803,13 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "name=%s\n", name);
}
- if (switch_is_number(id)) {
- span_id = atoi(id);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d\n", span_id);
- }
-
if(span_id && span_id < SKYPIAX_MAX_INTERFACES ) {
struct skypiax_config newconf;
//skypax_config_t newconf;
memset(&newconf, '\0', sizeof(newconf));
SKYPIAX_CONFIGS[span_id]=newconf;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CONFIGURING span_id=%d\n", span_id);
+ switch_set_string(SKYPIAX_CONFIGS[span_id].span_id, id);
if (name) {
switch_set_string(SKYPIAX_CONFIGS[span_id].name, name);
} else {
@@ -2811,6 +2817,7 @@
}
switch_set_string(SKYPIAX_CONFIGS[span_id].context, context);
switch_set_string(SKYPIAX_CONFIGS[span_id].dialplan, dialplan);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].name=%s\n", span_id, SKYPIAX_CONFIGS[span_id].name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].context=%s\n", span_id, SKYPIAX_CONFIGS[span_id].context);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].dialplan=%s\n", span_id, SKYPIAX_CONFIGS[span_id].dialplan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "STARTING span_id=%d\n", span_id);
@@ -2819,17 +2826,18 @@
continue;
}
- for(span_id=0; span_id < SKYPIAX_MAX_INTERFACES; span_id++) {
- if(strlen(SKYPIAX_CONFIGS[span_id].name)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].context=%s\n", span_id, SKYPIAX_CONFIGS[span_id].context);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].dialplan=%s\n", span_id, SKYPIAX_CONFIGS[span_id].dialplan);
- }
+ }
+ for(i=0; i < SKYPIAX_MAX_INTERFACES; i++) {
+ if(strlen(SKYPIAX_CONFIGS[i].name)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_CONFIGS[i].span_id=%s\n", i, SKYPIAX_CONFIGS[i].span_id);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_CONFIGS[i].name=%s\n", i, SKYPIAX_CONFIGS[i].name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_CONFIGS[i].context=%s\n", i, SKYPIAX_CONFIGS[i].context);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_CONFIGS[i].dialplan=%s\n", i, SKYPIAX_CONFIGS[i].dialplan);
}
}
}
-
switch_xml_free(xml);
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml (original)
+++ freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml Thu Nov 6 09:04:02 2008
@@ -46,7 +46,29 @@
<param name="dial-regex" value="9996"/>
<param name="dial-regex-fail" value="9996"/>
</span>
- <span id="2" name="cucu">
+ <span id="55" name="cucu">
+ <param name="hold-music" value="$${moh_uri}"/>
+ <param name="tonegroup" value="us"/>
+ <param name="digit-timeout" value="2000"/>
+ <param name="max-digits" value="11"/>
+ <param name="dialplan" value="XML"/>
+ <param name="context" value="default"/>
+ <param name="enable-callerid" value="true"/>
+ <param name="dial-regex" value="9996"/>
+ <param name="dial-regex-fail" value="9996"/>
+ </span>
+ <span id="55c" name="cucu">
+ <param name="hold-music" value="$${moh_uri}"/>
+ <param name="tonegroup" value="us"/>
+ <param name="digit-timeout" value="2000"/>
+ <param name="max-digits" value="11"/>
+ <param name="dialplan" value="XML"/>
+ <param name="context" value="default"/>
+ <param name="enable-callerid" value="true"/>
+ <param name="dial-regex" value="9996"/>
+ <param name="dial-regex-fail" value="9996"/>
+ </span>
+ <span id="73">
<param name="hold-music" value="$${moh_uri}"/>
<param name="tonegroup" value="us"/>
<param name="digit-timeout" value="2000"/>
@@ -68,6 +90,5 @@
<param name="dial-regex" value="9996"/>
<param name="dial-regex-fail" value="9996"/>
</span>
-
</analog_spans>
</configuration>
1
0
[commit] r10268 - in freeswitch/branches/gmaruzz: src/mod/endpoints/mod_skypiax stuff
by Freeswitch SVN 07 Nov '08
by Freeswitch SVN 07 Nov '08
07 Nov '08
Author: gmaruzz
Date: Thu Nov 6 08:40:41 2008
New Revision: 10268
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml
Log:
skypiax: continue to parse nested configuration, eg: multiple interfaces
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 Thu Nov 6 08:40:41 2008
@@ -2271,6 +2271,7 @@
typedef struct private_object private_t;
struct skypiax_config {
+ char name[80];
char dialplan[80];
char context[80];
char dial_regex[256];
@@ -2774,7 +2775,6 @@
if (!name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "span missing param 'name', not nice, but works\n");
- //continue;
}
if (!tonegroup) {
@@ -2798,57 +2798,34 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d\n", span_id);
}
- if(span_id) {
+ if(span_id && span_id < SKYPIAX_MAX_INTERFACES ) {
struct skypiax_config newconf;
//skypax_config_t newconf;
memset(&newconf, '\0', sizeof(newconf));
SKYPIAX_CONFIGS[span_id]=newconf;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CONFIGURING span_id=%d\n", span_id);
+ if (name) {
+ switch_set_string(SKYPIAX_CONFIGS[span_id].name, name);
+ } else {
+ switch_set_string(SKYPIAX_CONFIGS[span_id].name, "N/A");
+ }
switch_set_string(SKYPIAX_CONFIGS[span_id].context, context);
switch_set_string(SKYPIAX_CONFIGS[span_id].dialplan, dialplan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].context=%s\n", span_id, SKYPIAX_CONFIGS[span_id].context);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].dialplan=%s\n", span_id, SKYPIAX_CONFIGS[span_id].dialplan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "STARTING span_id=%d\n", span_id);
- }
-//FIXME
- /*
- if (zstatus != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error finding Skypiax span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name));
- continue;
- }
-
- if (!span_id) {
- span_id = span->span_id;
- }
- if (zap_configure_span("analog", span, on_analog_signal,
- "tonemap", tonegroup,
- "digit_timeout", &to,
- "max_dialstr", &max,
- "hotline", hotline,
- "enable_callerid", enable_callerid,
- TAG_END) != ZAP_SUCCESS) {
- zap_log(ZAP_LOG_ERROR, "Error starting Skypiax span %d\n", span_id);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span id %d is higher than SKYPIAX_MAX_INTERFACES (%d)\n", span_id, SKYPIAX_MAX_INTERFACES);
continue;
}
- SPAN_CONFIG[span->span_id].span = span;
- switch_set_string(SPAN_CONFIG[span->span_id].context, context);
- switch_set_string(SPAN_CONFIG[span->span_id].dialplan, dialplan);
-
- if (dial_regex) {
- switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex);
- }
-
- if (fail_dial_regex) {
- switch_set_string(SPAN_CONFIG[span->span_id].fail_dial_regex, fail_dial_regex);
- }
+ for(span_id=0; span_id < SKYPIAX_MAX_INTERFACES; span_id++) {
+ if(strlen(SKYPIAX_CONFIGS[span_id].name)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].context=%s\n", span_id, SKYPIAX_CONFIGS[span_id].context);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].dialplan=%s\n", span_id, SKYPIAX_CONFIGS[span_id].dialplan);
+ }
- if (hold_music) {
- switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music);
}
- switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog", sizeof(SPAN_CONFIG[span->span_id].type));
- zap_span_start(span);
- */
}
}
Modified: freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml (original)
+++ freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml Thu Nov 6 08:40:41 2008
@@ -22,6 +22,7 @@
<param name="dial-regex" value="9996"/>
<param name="dial-regex-fail" value="9996"/>
</span>
+ <!-- following has no id, error! -->
<span name="ciapalo">
<param name="hold-music" value="$${moh_uri}"/>
<param name="tonegroup" value="us"/>
@@ -33,6 +34,7 @@
<param name="dial-regex" value="9996"/>
<param name="dial-regex-fail" value="9996"/>
</span>
+ <!-- following has no id, error! -->
<span>
<param name="hold-music" value="$${moh_uri}"/>
<param name="tonegroup" value="us"/>
@@ -44,5 +46,28 @@
<param name="dial-regex" value="9996"/>
<param name="dial-regex-fail" value="9996"/>
</span>
+ <span id="2" name="cucu">
+ <param name="hold-music" value="$${moh_uri}"/>
+ <param name="tonegroup" value="us"/>
+ <param name="digit-timeout" value="2000"/>
+ <param name="max-digits" value="11"/>
+ <param name="dialplan" value="XML"/>
+ <param name="context" value="default"/>
+ <param name="enable-callerid" value="true"/>
+ <param name="dial-regex" value="9996"/>
+ <param name="dial-regex-fail" value="9996"/>
+ </span>
+ <span id="3">
+ <param name="hold-music" value="$${moh_uri}"/>
+ <param name="tonegroup" value="us"/>
+ <param name="digit-timeout" value="2000"/>
+ <param name="max-digits" value="11"/>
+ <param name="dialplan" value="XML"/>
+ <param name="context" value="default"/>
+ <param name="enable-callerid" value="true"/>
+ <param name="dial-regex" value="9996"/>
+ <param name="dial-regex-fail" value="9996"/>
+ </span>
+
</analog_spans>
</configuration>
1
0
[commit] r10267 - in freeswitch/branches/gmaruzz: src/mod/endpoints/mod_skypiax stuff
by Freeswitch SVN 07 Nov '08
by Freeswitch SVN 07 Nov '08
07 Nov '08
Author: gmaruzz
Date: Thu Nov 6 07:59:10 2008
New Revision: 10267
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml
Log:
skypiax: continue to parse nested configuration, eg: multiple interfaces
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 Thu Nov 6 07:59:10 2008
@@ -2207,6 +2207,8 @@
#ifdef MOD_SKYPIAX
#include <switch.h>
+#define SKYPIAX_MAX_INTERFACES 64
+
SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown);
//SWITCH_MODULE_RUNTIME_FUNCTION(mod_skypiax_runtime);
@@ -2251,7 +2253,6 @@
int calls;
char hold_music[256];
switch_mutex_t *mutex;
- //analog_option_t analog_options;
} globals;
struct private_object {
@@ -2269,6 +2270,22 @@
typedef struct private_object private_t;
+struct skypiax_config {
+ char dialplan[80];
+ char context[80];
+ char dial_regex[256];
+ char fail_dial_regex[256];
+ char hold_music[256];
+ char type[256];
+};
+
+typedef struct skypiax_config skypiax_config_t;
+
+//static struct skypiax_config SKYPIAX_CONFIGS[SKYPIAX_MAX_INTERFACES] = {{0}};
+skypiax_config_t SKYPIAX_CONFIGS[SKYPIAX_MAX_INTERFACES];
+
+
+
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string);
@@ -2654,7 +2671,6 @@
/*.receive_event */ channel_receive_event
};
-#ifndef NOTDEF
static switch_status_t load_config(void)
{
char *cf = "skypiax.conf";
@@ -2750,12 +2766,16 @@
}
- if (!id && !name) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing BOTH required param 'id' AND 'name'\n");
+ if (!id) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing REQUIRED param 'id'\n");
continue;
}
+ if (!name) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "span missing param 'name', not nice, but works\n");
+ //continue;
+ }
if (!tonegroup) {
tonegroup = "us";
@@ -2771,13 +2791,25 @@
if (name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "name=%s\n", name);
- } else {
- if (switch_is_number(id)) {
+ }
+
+ if (switch_is_number(id)) {
span_id = atoi(id);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d\n", span_id);
- }
}
+ if(span_id) {
+ struct skypiax_config newconf;
+ //skypax_config_t newconf;
+ memset(&newconf, '\0', sizeof(newconf));
+ SKYPIAX_CONFIGS[span_id]=newconf;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CONFIGURING span_id=%d\n", span_id);
+ switch_set_string(SKYPIAX_CONFIGS[span_id].context, context);
+ switch_set_string(SKYPIAX_CONFIGS[span_id].dialplan, dialplan);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].context=%s\n", span_id, SKYPIAX_CONFIGS[span_id].context);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d SKYPIAX_CONFIGS[span_id].dialplan=%s\n", span_id, SKYPIAX_CONFIGS[span_id].dialplan);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "STARTING span_id=%d\n", span_id);
+ }
//FIXME
/*
if (zstatus != ZAP_SUCCESS) {
@@ -2825,62 +2857,7 @@
return SWITCH_STATUS_SUCCESS;
}
-#endif /* NOTDEF */
-
-
-#ifdef NOTDEF
-static switch_status_t load_config(void)
-{
- char *cf = "skypiax.conf";
- switch_xml_t cfg, xml, settings, param;
-
- memset(&globals, 0, sizeof(globals));
- switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
- 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 ((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 (!strcmp(var, "debug")) {
- globals.debug = atoi(val);
- } else if (!strcmp(var, "port")) {
- globals.port = atoi(val);
- } else if (!strcmp(var, "ip")) {
- set_global_ip(val);
- } else if (!strcmp(var, "codec-master")) {
- if (!strcasecmp(val, "us")) {
- switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS);
- }
- } else if (!strcmp(var, "dialplan")) {
- set_global_dialplan(val);
- } else if (!strcmp(var, "codec-prefs")) {
- set_global_codec_string(val);
- globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
- } else if (!strcmp(var, "codec-rates")) {
- set_global_codec_rates_string(val);
- globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
- }
- }
- }
-
- if (!globals.dialplan) {
- set_global_dialplan("default");
- }
-
- if (!globals.port) {
- globals.port = 4569;
- }
-
- switch_xml_free(xml);
-
- return SWITCH_STATUS_SUCCESS;
-}
-#endif /* NOTDEF */
SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load)
{
Modified: freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml (original)
+++ freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml Thu Nov 6 07:59:10 2008
@@ -22,7 +22,18 @@
<param name="dial-regex" value="9996"/>
<param name="dial-regex-fail" value="9996"/>
</span>
- <span id="2">
+ <span name="ciapalo">
+ <param name="hold-music" value="$${moh_uri}"/>
+ <param name="tonegroup" value="us"/>
+ <param name="digit-timeout" value="2000"/>
+ <param name="max-digits" value="11"/>
+ <param name="dialplan" value="XML"/>
+ <param name="context" value="default"/>
+ <param name="enable-callerid" value="true"/>
+ <param name="dial-regex" value="9996"/>
+ <param name="dial-regex-fail" value="9996"/>
+ </span>
+ <span>
<param name="hold-music" value="$${moh_uri}"/>
<param name="tonegroup" value="us"/>
<param name="digit-timeout" value="2000"/>
1
0
[commit] r10266 - in freeswitch/branches/gmaruzz: src/mod/endpoints/mod_skypiax stuff
by Freeswitch SVN 07 Nov '08
by Freeswitch SVN 07 Nov '08
07 Nov '08
Author: gmaruzz
Date: Thu Nov 6 05:31:25 2008
New Revision: 10266
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml
Log:
skypiax: continue to parse nested configuration, eg: multiple interfaces
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 Thu Nov 6 05:31:25 2008
@@ -2688,7 +2688,7 @@
if (!strcasecmp(val, "us")) {
switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS);
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.debug=%d\n", globals.debug);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "codec-master globals.debug=%d\n", globals.debug);
} else if (!strcmp(var, "dialplan")) {
set_global_dialplan(val);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.dialplan=%s\n", globals.dialplan);
@@ -2709,7 +2709,6 @@
for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) {
char *id = (char *) switch_xml_attr(myspan, "id");
char *name = (char *) switch_xml_attr(myspan, "name");
- //FIXME zap_status_t zstatus = ZAP_FAIL;
char *context = "default";
char *dialplan = "XML";
char *tonegroup = NULL;
@@ -2722,8 +2721,6 @@
char *enable_callerid = "true";
uint32_t span_id = 0, to = 0, max = 0;
- //FIXME zap_span_t *span = NULL;
- //analog_option_t analog_options = ANALOG_OPTION_NONE;
for (param = switch_xml_child(myspan, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -2754,7 +2751,7 @@
}
if (!id && !name) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing BOTH required param 'id' AND 'name'\n");
continue;
}
@@ -2773,28 +2770,24 @@
}
if (name) {
- //FIXME zstatus = zap_span_find_by_name(name, &span);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "name=%s\n", name);
} else {
if (switch_is_number(id)) {
span_id = atoi(id);
- //FIXME zstatus = zap_span_find(span_id, &span);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "span_id=%d\n", span_id);
}
-
- //FIXME if (zstatus != ZAP_SUCCESS) {
- //FIXME zstatus = zap_span_find_by_name(id, &span);
- //FIXME }
}
- //FIXME if (zstatus != ZAP_SUCCESS) {
- //FIXME zap_log(ZAP_LOG_ERROR, "Error finding Skypiax span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name));
- //FIXME continue;
- //FIXME }
+//FIXME
+ /*
+ if (zstatus != ZAP_SUCCESS) {
+ zap_log(ZAP_LOG_ERROR, "Error finding Skypiax span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name));
+ continue;
+ }
if (!span_id) {
- //FIXME span_id = span->span_id;
+ span_id = span->span_id;
}
-//FIXME
- /*
if (zap_configure_span("analog", span, on_analog_signal,
"tonemap", tonegroup,
"digit_timeout", &to,
@@ -2809,7 +2802,6 @@
SPAN_CONFIG[span->span_id].span = span;
switch_set_string(SPAN_CONFIG[span->span_id].context, context);
switch_set_string(SPAN_CONFIG[span->span_id].dialplan, dialplan);
- //SPAN_CONFIG[span->span_id].analog_options = analog_options | globals.analog_options;
if (dial_regex) {
switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex);
Modified: freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml
==============================================================================
--- freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml (original)
+++ freeswitch/branches/gmaruzz/stuff/skypiax.conf.xml Thu Nov 6 05:31:25 2008
@@ -1,5 +1,4 @@
-
-<configuration name="skypiax.conf" description="Skype Endpoint">
+<configuration name="skypiax.conf" description="Skypiax Configuration">
<settings>
<param name="debug" value="8"/>
<param name="port" value="4569"/>
@@ -8,39 +7,31 @@
<param name="dialplan" value="default"/>
<param name="codec-prefs" value="gsm,ulaw"/>
<param name="codec-rates" value="8000,16000"/>
-
- <!-- PORTAUDIO BEGINS -->
- <!-- indev, outdev, ringdev:
- partial case sensitive string match on something in the name
- or the device number prefixed with # eg "#1" (or blank for default) -->
-
- <!-- device to use for input -->
- <param name="indev" value="#7"/>
- <!-- device to use for output -->
- <param name="outdev" value="#7"/>
-
- <!--device to use for inbound ring -->
- <param name="ringdev" value="#7"/>
- <!--File to play as the ring sound -->
- <!--<param name="ring-file" value="/sounds/ring.wav"/>-->
- <!--Number of seconds to pause between rings -->
- <!--<param name="ring-interval" value="5"/>-->
-
- <!--file to play when calls are on hold-->
- <!--<param name="hold-file" value="/sounds/holdmusic.wav"/>-->
- <!--Timer to use for hold music (i'd leave this one commented)-->
- <!--<param name="timer-name" value="soft"/>-->
-
- <!--Default dialplan and caller-id info -->
- <!--
- <param name="dialplan" value="XML"/>
- -->
- <param name="cid-name" value="$${outbound_caller_name}"/>
- <param name="cid-num" value="$${outbound_caller_id}"/>
-
- <!--audio sample rate and interval -->
- <param name="sample-rate" value="8000"/>
- <param name="codec-ms" value="20"/>
- <!-- PORTAUDIO ENDS -->
+ <param name="hold-music" value="$${moh_uri}"/>
</settings>
+ <!-- one entry here per skypiax span -->
+ <analog_spans>
+ <span id="1">
+ <param name="hold-music" value="$${moh_uri}"/>
+ <param name="tonegroup" value="us"/>
+ <param name="digit-timeout" value="2000"/>
+ <param name="max-digits" value="11"/>
+ <param name="dialplan" value="XML"/>
+ <param name="context" value="default"/>
+ <param name="enable-callerid" value="true"/>
+ <param name="dial-regex" value="9996"/>
+ <param name="dial-regex-fail" value="9996"/>
+ </span>
+ <span id="2">
+ <param name="hold-music" value="$${moh_uri}"/>
+ <param name="tonegroup" value="us"/>
+ <param name="digit-timeout" value="2000"/>
+ <param name="max-digits" value="11"/>
+ <param name="dialplan" value="XML"/>
+ <param name="context" value="default"/>
+ <param name="enable-callerid" value="true"/>
+ <param name="dial-regex" value="9996"/>
+ <param name="dial-regex-fail" value="9996"/>
+ </span>
+ </analog_spans>
</configuration>
1
0
[commit] r10265 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
by Freeswitch SVN 07 Nov '08
by Freeswitch SVN 07 Nov '08
07 Nov '08
Author: gmaruzz
Date: Thu Nov 6 05:00:22 2008
New Revision: 10265
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
Log:
skypiax: let's begin to parse nested configuration, eg: multiple interfaces
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 Thu Nov 6 05:00:22 2008
@@ -1,3 +1,5 @@
+#undef MOD_OPENZAP
+#ifdef MOD_OPENZAP
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct(a)yahoo.com>
@@ -2199,3 +2201,820 @@
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
+#endif /* MOD_OPENZAP */
+
+#define MOD_SKYPIAX
+#ifdef MOD_SKYPIAX
+#include <switch.h>
+
+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);
+
+
+switch_endpoint_interface_t *skypiax_endpoint_interface;
+static switch_memory_pool_t *module_pool = NULL;
+static int running = 1;
+
+
+typedef enum {
+ TFLAG_IO = (1 << 0),
+ TFLAG_INBOUND = (1 << 1),
+ TFLAG_OUTBOUND = (1 << 2),
+ TFLAG_DTMF = (1 << 3),
+ TFLAG_VOICE = (1 << 4),
+ TFLAG_HANGUP = (1 << 5),
+ TFLAG_LINEAR = (1 << 6),
+ TFLAG_CODEC = (1 << 7),
+ TFLAG_BREAK = (1 << 8)
+} TFLAGS;
+
+typedef enum {
+ GFLAG_MY_CODEC_PREFS = (1 << 0)
+} GFLAGS;
+
+
+static struct {
+ int debug;
+ char *ip;
+ int port;
+ char *dialplan;
+ char *codec_string;
+ char *codec_order[SWITCH_MAX_CODECS];
+ int codec_order_last;
+ char *codec_rates_string;
+ char *codec_rates[SWITCH_MAX_CODECS];
+ int codec_rates_last;
+ unsigned int flags;
+ int fd;
+ int calls;
+ char hold_music[256];
+ switch_mutex_t *mutex;
+ //analog_option_t analog_options;
+} globals;
+
+struct private_object {
+ unsigned int flags;
+ switch_codec_t read_codec;
+ switch_codec_t write_codec;
+ switch_frame_t read_frame;
+ unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
+ switch_core_session_t *session;
+ switch_caller_profile_t *caller_profile;
+ switch_mutex_t *mutex;
+ switch_mutex_t *flag_mutex;
+ //switch_thread_cond_t *cond;
+};
+
+typedef struct private_object private_t;
+
+
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip);
+
+
+
+static switch_status_t channel_on_init(switch_core_session_t *session);
+static switch_status_t channel_on_hangup(switch_core_session_t *session);
+static switch_status_t channel_on_routing(switch_core_session_t *session);
+static switch_status_t channel_on_exchange_media(switch_core_session_t *session);
+static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
+ switch_caller_profile_t *outbound_profile,
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags);
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
+static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
+
+
+
+static void tech_init(private_t *tech_pvt, switch_core_session_t *session)
+{
+ tech_pvt->read_frame.data = tech_pvt->databuf;
+ tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
+ switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+ switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+ switch_core_session_set_private(session, tech_pvt);
+ tech_pvt->session = session;
+}
+
+/*
+ State methods they get called when the state changes to the specific state
+ returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
+ so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
+*/
+static switch_status_t channel_on_init(switch_core_session_t *session)
+{
+ switch_channel_t *channel;
+ private_t *tech_pvt = NULL;
+
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ switch_set_flag_locked(tech_pvt, TFLAG_IO);
+
+ /* Move channel's state machine to ROUTING. This means the call is trying
+ to get from the initial start where the call because, to the point
+ where a destination has been identified. If the channel is simply
+ left in the initial state, nothing will happen. */
+ switch_channel_set_state(channel, CS_ROUTING);
+ switch_mutex_lock(globals.mutex);
+ globals.calls++;
+ switch_mutex_unlock(globals.mutex);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_routing(switch_core_session_t *session)
+{
+ switch_channel_t *channel = NULL;
+ private_t *tech_pvt = NULL;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL ROUTING\n", switch_channel_get_name(channel));
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_execute(switch_core_session_t *session)
+{
+
+ switch_channel_t *channel = NULL;
+ private_t *tech_pvt = NULL;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel));
+
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_hangup(switch_core_session_t *session)
+{
+ switch_channel_t *channel = NULL;
+ private_t *tech_pvt = NULL;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+
+ switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+ switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+ //switch_thread_cond_signal(tech_pvt->cond);
+
+ if (tech_pvt->read_codec.implementation) {
+ switch_core_codec_destroy(&tech_pvt->read_codec);
+ }
+
+ if (tech_pvt->write_codec.implementation) {
+ switch_core_codec_destroy(&tech_pvt->write_codec);
+ }
+
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel));
+ switch_mutex_lock(globals.mutex);
+ globals.calls--;
+ if (globals.calls < 0) {
+ globals.calls = 0;
+ }
+ switch_mutex_unlock(globals.mutex);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig)
+{
+ switch_channel_t *channel = NULL;
+ private_t *tech_pvt = NULL;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+
+ switch (sig) {
+ case SWITCH_SIG_KILL:
+ switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+ switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+ switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+ //switch_thread_cond_signal(tech_pvt->cond);
+ break;
+ case SWITCH_SIG_BREAK:
+ switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
+ break;
+ default:
+ break;
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_exchange_media(switch_core_session_t *session)
+{
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n");
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_soft_execute(switch_core_session_t *session)
+{
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL TRANSMIT\n");
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
+{
+ private_t *tech_pvt = switch_core_session_get_private(session);
+ switch_assert(tech_pvt != NULL);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
+{
+ switch_channel_t *channel = NULL;
+ private_t *tech_pvt = NULL;
+ //switch_time_t started = switch_time_now();
+ //unsigned int elapsed;
+ switch_byte_t *data;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ tech_pvt->read_frame.flags = SFF_NONE;
+ *frame = NULL;
+
+ while (switch_test_flag(tech_pvt, TFLAG_IO)) {
+
+ if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
+ switch_clear_flag(tech_pvt, TFLAG_BREAK);
+ goto cng;
+ }
+
+ if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) {
+ switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+ if (!tech_pvt->read_frame.datalen) {
+ continue;
+ }
+ *frame = &tech_pvt->read_frame;
+#ifdef BIGENDIAN
+ if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
+ switch_swap_linear((*frame)->data, (int) (*frame)->datalen / 2);
+ }
+#endif
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ switch_yield(1000);
+ }
+
+
+ return SWITCH_STATUS_FALSE;
+
+ cng:
+ data = (switch_byte_t *) tech_pvt->read_frame.data;
+ data[0] = 65;
+ data[1] = 0;
+ tech_pvt->read_frame.datalen = 2;
+ tech_pvt->read_frame.flags = SFF_CNG;
+ *frame = &tech_pvt->read_frame;
+ return SWITCH_STATUS_SUCCESS;
+
+}
+
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
+{
+ switch_channel_t *channel = NULL;
+ private_t *tech_pvt = NULL;
+ //switch_frame_t *pframe;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+
+ if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
+ return SWITCH_STATUS_FALSE;
+ }
+#ifdef BIGENDIAN
+ if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
+ switch_swap_linear(frame->data, (int) frame->datalen / 2);
+ }
+#endif
+
+
+ return SWITCH_STATUS_SUCCESS;
+
+}
+
+static switch_status_t channel_answer_channel(switch_core_session_t *session)
+{
+ private_t *tech_pvt;
+ switch_channel_t *channel = NULL;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+
+static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
+{
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ tech_pvt = (private_t *) switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+
+ switch (msg->message_id) {
+ case SWITCH_MESSAGE_INDICATE_ANSWER:
+ {
+ channel_answer_channel(session);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
+ that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
+*/
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
+ switch_caller_profile_t *outbound_profile,
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
+{
+ if ((*new_session = switch_core_session_request(skypiax_endpoint_interface, pool)) != 0) {
+ private_t *tech_pvt;
+ switch_channel_t *channel;
+ switch_caller_profile_t *caller_profile;
+
+ switch_core_session_add_stream(*new_session, NULL);
+ if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
+ channel = switch_core_session_get_channel(*new_session);
+ tech_init(tech_pvt, *new_session);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
+ switch_core_session_destroy(new_session);
+ return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+ }
+
+ if (outbound_profile) {
+ char name[128];
+
+ snprintf(name, sizeof(name), "SKYPIAX/%s", outbound_profile->destination_number);
+ switch_channel_set_name(channel, name);
+
+ caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
+ switch_channel_set_caller_profile(channel, caller_profile);
+ tech_pvt->caller_profile = caller_profile;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
+ switch_core_session_destroy(new_session);
+ return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+ }
+
+
+
+ switch_channel_set_flag(channel, CF_OUTBOUND);
+ switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
+ switch_channel_set_state(channel, CS_INIT);
+ return SWITCH_CAUSE_SUCCESS;
+ }
+
+ return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+
+}
+
+static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event)
+{
+ struct private_object *tech_pvt = switch_core_session_get_private(session);
+ char *body = switch_event_get_body(event);
+ switch_assert(tech_pvt != NULL);
+
+ if (!body) {
+ body = "";
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+
+
+switch_state_handler_table_t skypiax_state_handlers = {
+ /*.on_init */ channel_on_init,
+ /*.on_routing */ channel_on_routing,
+ /*.on_execute */ channel_on_execute,
+ /*.on_hangup */ channel_on_hangup,
+ /*.on_exchange_media */ channel_on_exchange_media,
+ /*.on_soft_execute */ channel_on_soft_execute
+};
+
+switch_io_routines_t skypiax_io_routines = {
+ /*.outgoing_channel */ channel_outgoing_channel,
+ /*.read_frame */ channel_read_frame,
+ /*.write_frame */ channel_write_frame,
+ /*.kill_channel */ channel_kill_channel,
+ /*.send_dtmf */ channel_send_dtmf,
+ /*.receive_message */ channel_receive_message,
+ /*.receive_event */ channel_receive_event
+};
+
+#ifndef NOTDEF
+static switch_status_t load_config(void)
+{
+ char *cf = "skypiax.conf";
+ switch_xml_t cfg, xml, settings, param, spans, myspan;
+
+ memset(&globals, 0, sizeof(globals));
+ switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
+ 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 ((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);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.debug=%d\n", globals.debug);
+ } else if (!strcasecmp(var, "hold-music")) {
+ switch_set_string(globals.hold_music, val);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.hold_music=%s\n", globals.hold_music);
+ } else if (!strcmp(var, "port")) {
+ globals.port = atoi(val);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.port=%d\n", globals.port);
+ } else if (!strcmp(var, "ip")) {
+ set_global_ip(val);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.ip=%s\n", globals.ip);
+ } else if (!strcmp(var, "codec-master")) {
+ if (!strcasecmp(val, "us")) {
+ switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS);
+ }
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.debug=%d\n", globals.debug);
+ } else if (!strcmp(var, "dialplan")) {
+ set_global_dialplan(val);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.dialplan=%s\n", globals.dialplan);
+ } else if (!strcmp(var, "codec-prefs")) {
+ set_global_codec_string(val);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.codec_string=%s\n", globals.codec_string);
+ globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
+ } else if (!strcmp(var, "codec-rates")) {
+ set_global_codec_rates_string(val);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.codec_rates_string=%s\n", globals.codec_rates_string);
+ globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
+ }
+
+ }
+ }
+
+ if ((spans = switch_xml_child(cfg, "analog_spans"))) {
+ for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) {
+ char *id = (char *) switch_xml_attr(myspan, "id");
+ char *name = (char *) switch_xml_attr(myspan, "name");
+ //FIXME zap_status_t zstatus = ZAP_FAIL;
+ char *context = "default";
+ char *dialplan = "XML";
+ char *tonegroup = NULL;
+ char *digit_timeout = NULL;
+ char *max_digits = NULL;
+ char *hotline = NULL;
+ char *dial_regex = NULL;
+ char *hold_music = NULL;
+ char *fail_dial_regex = NULL;
+ char *enable_callerid = "true";
+
+ uint32_t span_id = 0, to = 0, max = 0;
+ //FIXME zap_span_t *span = NULL;
+ //analog_option_t analog_options = ANALOG_OPTION_NONE;
+
+ for (param = switch_xml_child(myspan, "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, "tonegroup")) {
+ tonegroup = val;
+ } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) {
+ digit_timeout = val;
+ } else if (!strcasecmp(var, "context")) {
+ context = val;
+ } else if (!strcasecmp(var, "dialplan")) {
+ dialplan = val;
+ } else if (!strcasecmp(var, "dial-regex")) {
+ dial_regex = val;
+ } else if (!strcasecmp(var, "enable-callerid")) {
+ enable_callerid = val;
+ } else if (!strcasecmp(var, "fail-dial-regex")) {
+ fail_dial_regex = val;
+ } else if (!strcasecmp(var, "hold-music")) {
+ hold_music = val;
+ } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) {
+ max_digits = val;
+ } else if (!strcasecmp(var, "hotline")) {
+ hotline = val;
+ }
+
+ }
+
+ if (!id && !name) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n");
+ continue;
+ }
+
+
+
+ if (!tonegroup) {
+ tonegroup = "us";
+ }
+
+ if (digit_timeout) {
+ to = atoi(digit_timeout);
+ }
+
+ if (max_digits) {
+ max = atoi(max_digits);
+ }
+
+ if (name) {
+ //FIXME zstatus = zap_span_find_by_name(name, &span);
+ } else {
+ if (switch_is_number(id)) {
+ span_id = atoi(id);
+ //FIXME zstatus = zap_span_find(span_id, &span);
+ }
+
+ //FIXME if (zstatus != ZAP_SUCCESS) {
+ //FIXME zstatus = zap_span_find_by_name(id, &span);
+ //FIXME }
+ }
+
+ //FIXME if (zstatus != ZAP_SUCCESS) {
+ //FIXME zap_log(ZAP_LOG_ERROR, "Error finding Skypiax span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name));
+ //FIXME continue;
+ //FIXME }
+
+ if (!span_id) {
+ //FIXME span_id = span->span_id;
+ }
+//FIXME
+ /*
+ if (zap_configure_span("analog", span, on_analog_signal,
+ "tonemap", tonegroup,
+ "digit_timeout", &to,
+ "max_dialstr", &max,
+ "hotline", hotline,
+ "enable_callerid", enable_callerid,
+ TAG_END) != ZAP_SUCCESS) {
+ zap_log(ZAP_LOG_ERROR, "Error starting Skypiax span %d\n", span_id);
+ continue;
+ }
+
+ SPAN_CONFIG[span->span_id].span = span;
+ switch_set_string(SPAN_CONFIG[span->span_id].context, context);
+ switch_set_string(SPAN_CONFIG[span->span_id].dialplan, dialplan);
+ //SPAN_CONFIG[span->span_id].analog_options = analog_options | globals.analog_options;
+
+ if (dial_regex) {
+ switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex);
+ }
+
+ if (fail_dial_regex) {
+ switch_set_string(SPAN_CONFIG[span->span_id].fail_dial_regex, fail_dial_regex);
+ }
+
+ if (hold_music) {
+ switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music);
+ }
+ switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog", sizeof(SPAN_CONFIG[span->span_id].type));
+ zap_span_start(span);
+ */
+ }
+ }
+
+
+ switch_xml_free(xml);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+#endif /* NOTDEF */
+
+
+#ifdef NOTDEF
+static switch_status_t load_config(void)
+{
+ char *cf = "skypiax.conf";
+ switch_xml_t cfg, xml, settings, param;
+
+ memset(&globals, 0, sizeof(globals));
+ switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
+ 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 ((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 (!strcmp(var, "debug")) {
+ globals.debug = atoi(val);
+ } else if (!strcmp(var, "port")) {
+ globals.port = atoi(val);
+ } else if (!strcmp(var, "ip")) {
+ set_global_ip(val);
+ } else if (!strcmp(var, "codec-master")) {
+ if (!strcasecmp(val, "us")) {
+ switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS);
+ }
+ } else if (!strcmp(var, "dialplan")) {
+ set_global_dialplan(val);
+ } else if (!strcmp(var, "codec-prefs")) {
+ set_global_codec_string(val);
+ globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
+ } else if (!strcmp(var, "codec-rates")) {
+ set_global_codec_rates_string(val);
+ globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
+ }
+ }
+ }
+
+ if (!globals.dialplan) {
+ set_global_dialplan("default");
+ }
+
+ if (!globals.port) {
+ globals.port = 4569;
+ }
+
+ switch_xml_free(xml);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+#endif /* NOTDEF */
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load)
+{
+
+ module_pool = pool;
+
+ load_config();
+
+ *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+ skypiax_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
+ skypiax_endpoint_interface->interface_name = "skypiax";
+ skypiax_endpoint_interface->io_routines = &skypiax_io_routines;
+ skypiax_endpoint_interface->state_handler = &skypiax_state_handlers;
+
+/*****************************************/
+#ifdef CICOPET
+{
+ int i;
+ struct ast_config *cfg;
+ struct skypiax_pvt *tmp;
+ struct skypiax_pvt *p = NULL;
+
+#ifndef __CYGWIN__
+ if (!XInitThreads())
+ ast_log(LOG_ERROR, "Not initialized XInitThreads!\n");
+#endif /* __CYGWIN__ */
+
+ /* load skypiax.conf config file */
+ cfg = ast_config_load(skypiax_config);
+ if (cfg != NULL) {
+ char *ctg = NULL;
+ int is_first_category = 1;
+ while ((ctg = ast_category_browse(cfg, ctg)) != NULL) {
+ /* create one interface for each category in skypiax.conf config file, first one set the defaults */
+ tmp = skypiax_mkif(cfg, ctg, is_first_category);
+ if (tmp) {
+ DEBUGA_PBX
+ ("Created channel Skypiax: skypiax.conf category '[%s]', channel name '%s'"
+ "\n", SKYPIAX_P_LOG, ctg, tmp->name);
+ /* add interface to skypiax_iflist */
+ tmp->next = skypiax_iflist;
+ skypiax_iflist = tmp;
+ /* next one will not be the first ;) */
+ if (is_first_category == 1) {
+ is_first_category = 0;
+ skypiax_console_active = tmp->name;
+ }
+ } else {
+ ERRORA("Unable to create channel Skypiax from skypiax.conf category '[%s]'\n",
+ SKYPIAX_P_LOG, ctg);
+ /* if error, unload config from memory and return */
+ ast_config_destroy(cfg);
+ ast_channel_unregister(&skypiax_tech);
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+ }
+ return -1;
+ }
+ /* do it for each category described in config */
+ }
+
+ /* we finished, unload config from memory */
+ ast_config_destroy(cfg);
+ } else {
+ ERRORA("Unable to load skypiax_config skypiax.conf\n", SKYPIAX_P_LOG);
+ ast_channel_unregister(&skypiax_tech);
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+ }
+ return -1;
+ }
+#ifndef ASTERISK_VERSION_1_6
+ ast_cli_register_multiple(myclis, sizeof(myclis) / sizeof(struct ast_cli_entry));
+#endif /* ASTERISK_VERSION_1_6 */
+ /* start to monitor the interfaces (skypiax_iflist) for the first time */
+ if (skypiax_restart_monitor()) {
+ ERRORA("skypiax_restart_monitor failed, BAD\n", SKYPIAX_P_LOG);
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+ }
+ return -1;
+ }
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+ }
+ return 0;
+}
+#endif /* CICOPET */
+ /********************************************/
+
+ /* indicate that the module should continue to be loaded */
+ return SWITCH_STATUS_SUCCESS;
+}
+
+/*
+SWITCH_MODULE_RUNTIME_FUNCTION(mod_skypiax_runtime)
+{
+ return SWITCH_STATUS_TERM;
+}
+*/
+
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown)
+{
+ int x = 0;
+
+ running = -1;
+
+ while (running) {
+ if (x++ > 100) {
+ break;
+ }
+ switch_yield(20000);
+ }
+ return SWITCH_STATUS_SUCCESS;
+}
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
+ */
+
+#endif /* MOD_SKYPIAX */
+
1
0