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
03 Jun '07
Author: anthonyl
Date: Sat Jun 2 21:18:12 2007
New Revision: 5251
Modified:
freeswitch/branches/anthonyl/log2file-branch/src/switch_xml.c
Log:
prevent a segfault if the xml pointer is not valid.
Modified: freeswitch/branches/anthonyl/log2file-branch/src/switch_xml.c
==============================================================================
--- freeswitch/branches/anthonyl/log2file-branch/src/switch_xml.c (original)
+++ freeswitch/branches/anthonyl/log2file-branch/src/switch_xml.c Sat Jun 2 21:18:12 2007
@@ -213,7 +213,9 @@
int i = 0, j = 1;
switch_xml_root_t root = (switch_xml_root_t) xml;
- if (!xml || !xml->attr)
+ if (!xml)
+ return NULL;
+ if (!xml->attr)
return NULL;
while (xml->attr[i] && strcmp(attr, xml->attr[i]))
i += 2;
1
0
[commit] r5250 - freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_log2file
by Freeswitch SVN 02 Jun '07
by Freeswitch SVN 02 Jun '07
02 Jun '07
Author: anthonyl
Date: Sat Jun 2 19:52:16 2007
New Revision: 5250
Added:
freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_log2file/
freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_log2file/mod_log2file.c
Log:
updating with the latest mod_log2file code.
Added: freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_log2file/mod_log2file.c
==============================================================================
--- (empty file)
+++ freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_log2file/mod_log2file.c Sat Jun 2 19:52:16 2007
@@ -0,0 +1,395 @@
+/*
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthmct(a)yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Anthony LaMantia <anthony(a)petabit.net>
+ *
+ *
+ * mod_log2file.c -- Filesystem Logging
+ *
+ */
+#include <switch.h>
+#include <stdlib.h>
+#include <syslog.h>
+
+#define MAX_LENGTH 1024
+#define DEFAULT_FORMAT "${data}"
+#define DEFAULT_LOGFILE "/var/log/freeswitch"
+#define DEFAULT_LIMIT 0x7FFFFFFF
+#define WARM_FUZZY_OFFSET 64
+#define MAX_ROT 4096 /* why not */
+static const uint8_t STATIC_LEVELS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
+static const char modname[] = "mod_log2file";
+
+static switch_status_t load_config(void);
+static switch_status_t mod_log2file_check(void);
+
+static switch_memory_pool_t *module_pool = NULL;
+static switch_hash_t *log_hash = NULL;
+static switch_hash_t *name_hash = NULL;
+static int8_t all_level = -1;
+
+static struct {
+ unsigned int log_fd;
+ unsigned int log_size; /* keep the log size in check for rotation */
+ unsigned int roll_size; /* the size that we want to rotate the file at */
+ unsigned char *logfile;
+ unsigned char *format;
+ switch_file_t *log_afd;
+} globals;
+
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_logfile, globals.logfile)
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_format, globals.format)
+
+/* i know this is strange but it's the fastest way i could think of managing log levels. */
+/* i'd rather not try to search something each time we get a message to log */
+struct level_set {
+ int level;
+ int on;
+}static levels[] = {
+ {SWITCH_LOG_EMERG, 0}, /* 0 */
+ {SWITCH_LOG_ALERT, 0}, /* 1 */
+ {SWITCH_LOG_CRIT, 0}, /* 2 */
+ {SWITCH_LOG_ERROR, 0}, /* 3 */
+ {SWITCH_LOG_WARNING, 0}, /* 4 */
+ {SWITCH_LOG_NOTICE, 0}, /* 5 */
+ {SWITCH_LOG_INFO, 0}, /* 6 */
+ {SWITCH_LOG_DEBUG, 0}, /* 7 */
+ {SWITCH_LOG_CONSOLE, 0}, /* 8 */
+};
+static switch_loadable_module_interface_t log2file_module_interface = {
+ /*.module_name */ modname,
+ /*.endpoint_interface */ NULL,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ NULL,
+ /*.api_interface */ NULL,
+ /*.file_interface */ NULL,
+ /*.speech_interface */ NULL,
+ /*.directory_interface */ NULL
+};
+
+/* this may exist somewhere else in the code? */
+static void log_type2str(switch_log_level_t type)
+{
+ switch(type) {
+ case SWITCH_LOG_CONSOLE:
+ printf("[CONSOLE] ");
+ break;
+ case SWITCH_LOG_DEBUG:
+ printf("[DEBUG] ");
+ break;
+ case SWITCH_LOG_INFO:
+ printf("[INFO] ");
+ break;
+ case SWITCH_LOG_NOTICE:
+ printf("[NOTICE] ");
+ break;
+ case SWITCH_LOG_WARNING:
+ printf("[WARNING] ");
+ break;
+ case SWITCH_LOG_ERROR:
+ printf("[ERROR] ");
+ break;
+ case SWITCH_LOG_CRIT:
+ printf("[CRIT] ");
+ break;
+ case SWITCH_LOG_ALERT:
+ printf("[ALERT] ");
+ break;
+ case SWITCH_LOG_EMERG:
+ printf("[EMERG] ");
+ break;
+ default:
+ break;
+ }
+ return;
+}
+
+void process_levels(char *p)
+{
+ char *q;
+
+ while (q = strsep(&p, ",")) {
+ if (!strncasecmp(q, "emerg", strlen(q))) {
+ levels[SWITCH_LOG_EMERG].on = 1;
+ } else if (!strncasecmp(q, "alert", strlen(q))) {
+ levels[SWITCH_LOG_ALERT].on = 1;
+ } else if (!strncasecmp(q, "crit", strlen(q))) {
+ levels[SWITCH_LOG_CRIT].on = 1;
+ } else if (!strncasecmp(q, "error", strlen(q))) {
+ levels[SWITCH_LOG_ERROR].on = 1;
+ } else if (!strncasecmp(q, "warn", strlen(q))) {
+ levels[SWITCH_LOG_WARNING].on = 1;
+ } else if (!strncasecmp(q, "notice", strlen(q))) {
+ levels[SWITCH_LOG_NOTICE].on = 1;
+ } else if (!strncasecmp(q, "info", strlen(q))) {
+ levels[SWITCH_LOG_INFO].on = 1;
+ } else if (!strncasecmp(q, "debug", strlen(q))) {
+ levels[SWITCH_LOG_DEBUG].on = 1;
+ } else if (!strncasecmp(q, "console", strlen(q))) {
+ levels[SWITCH_LOG_CONSOLE].on = 1;
+ } else if (!strncasecmp(q, "all", strlen(q))) {
+ int i;
+ printf("all option!\n");
+ for (i=0; i < (sizeof(levels) / sizeof(struct level_set)); i++) {
+ levels[i].on = 1;
+ }
+ }
+
+ }
+ return;
+}
+static switch_status_t mod_log2file_openlogfile(void)
+{
+ int fd;
+ switch_file_t *afd;
+ switch_status_t stat;
+
+ stat = switch_file_open(&afd, globals.logfile,
+ APR_CREATE| APR_READ | APR_WRITE | APR_APPEND, NULL, NULL);
+
+ if (stat != SWITCH_STATUS_SUCCESS) {
+ return SWITCH_STATUS_FALSE;
+ }
+ globals.log_afd = afd;
+ mod_log2file_check();
+ return SWITCH_STATUS_SUCCESS;
+}
+
+/* rotate the log file */
+static switch_status_t mod_log2file_rotate(void)
+{
+ unsigned int i = 0;
+ unsigned char *p = NULL;
+ unsigned char *q = NULL;
+ switch_status_t stat = 0;
+ switch_size_t nbytes = 1024;
+ switch_file_t *l_afd = NULL;
+
+ globals.log_size = 0;
+ stat = switch_file_seek(globals.log_afd, APR_SET, 0);
+
+ if (stat != SWITCH_STATUS_SUCCESS)
+ return SWITCH_STATUS_FALSE;
+
+ p = malloc(strlen(globals.logfile)+WARM_FUZZY_OFFSET);
+ if (!p) {
+ return SWITCH_STATUS_FALSE;
+ }
+ q = malloc(1024);
+ if (!q) {
+ free(p);
+ return SWITCH_STATUS_FALSE;
+ }
+ memset(p, '\0', strlen(globals.logfile)+WARM_FUZZY_OFFSET);
+ for (i=1;i<MAX_ROT; i++) {
+ sprintf(p, "%s.%i", globals.logfile, i);
+ stat = switch_file_open(l_afd, p, APR_READ, NULL, NULL);
+ if (stat == SWITCH_STATUS_SUCCESS) {
+ switch_file_close(l_afd);
+ continue;
+ }
+ stat = switch_file_open(l_afd, p, APR_READ | APR_WRITE | APR_CREATE , NULL, NULL);
+ if (stat == SWITCH_STATUS_SUCCESS)
+ break;
+ }
+ while ((stat = switch_file_read(&globals.log_afd, q, &nbytes)) == SWITCH_STATUS_SUCCESS) {
+ switch_file_write(l_afd, q, &nbytes);
+ memset(q, '\0', 1024);
+ nbytes = 1024;
+ }
+ stat = switch_file_seek(&globals.log_afd, APR_SET, 0);
+ free(p);
+ free(q);
+ return SWITCH_STATUS_SUCCESS;
+}
+
+/* check the size of the file for rotation */
+static switch_status_t mod_log2file_check(void)
+{
+ switch_status_t stat;
+ switch_size_t fsize;
+ fsize = switch_file_get_size(&globals.log_afd);
+
+ if (stat != SWITCH_STATUS_SUCCESS)
+ return SWITCH_STATUS_FALSE;
+
+ if (fsize >= globals.roll_size) {
+ return mod_log2file_rotate();
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+/* write to the actual logfile */
+static switch_status_t mod_log2file_write(char *fmt, ...)
+{
+ unsigned int len;
+ char *log_data;
+ switch_status_t stat;
+ va_list args;
+ va_start(args, fmt);
+ printf("Mod Log To File Write\n");
+#ifdef WIN32
+ len = _vasprintf(&log_data, fmt, args);
+#else
+ len = vasprintf(&log_data, fmt, args);
+#endif
+ if (len <= 0)
+ return SWITCH_STATUS_FALSE;
+ stat = switch_file_write(&globals.log_afd, log_data, len);
+ if (stat != SWITCH_STATUS_SUCCESS)
+ return SWITCH_STATUS_FALSE;
+ globals.log_size += len;
+ /* we may want to hold back on this for preformance reasons */
+ mod_log2file_check();
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t mod_log2file_logger(const switch_log_node_t *node, switch_log_level_t level)
+{
+ uint8_t *lookup = NULL;
+ char line_no[sizeof(int)*8+1];
+ char date[80] = "";
+ switch_time_exp_t time;
+ switch_size_t retsize;
+ char *message = NULL;
+
+ if (!levels[node->level].on) {
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ message = (char *)malloc(strlen(globals.format)+2);
+ switch_copy_string(message, globals.format, strlen(globals.format)+1);
+
+ message = switch_string_replace(message, "${message}", node->content);
+
+ if (switch_time_exp_lt(&time, node->timestamp) != SWITCH_STATUS_SUCCESS) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &time);
+
+ message = switch_string_replace(message, "${time}", date);
+ message = switch_string_replace(message, "${file}", node->file);
+ message = switch_string_replace(message, "${func}", node->func);
+
+ snprintf(line_no, sizeof(line_no), "%d", node->line);
+ message = switch_string_replace(message, "${line}", line_no);
+
+ /* work with the log type */
+ log_type2str(node->level);
+ printf("\n");
+ printf("Type: (%i)\n", node->level);
+ if (node->file)
+ printf("File: %s\n", node->file);
+ if (node->line)
+ printf("Line: %i\n", node->line);
+ if (node->func)
+ printf("Func: %s\n", node->func);
+ if (node->data)
+ printf("Data: %s\n", node->data);
+ if (node->content)
+ printf("Cont: %s\n", node->content);
+
+
+ if (!switch_strlen_zero(message)) {
+ mod_log2file_write("%s", message);
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+static switch_status_t load_config(void)
+{
+ char *cf = "log2file.conf";
+ switch_xml_t cfg, xml, settings, param;
+
+ if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
+ } else {
+ 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, "logfile")) {
+ set_global_logfile(val);
+ } else if (!strcmp(var, "format")) {
+ set_global_format(val);
+ } else if (!strcmp(var, "level")) {
+ process_levels(val);
+ } else if (!strcmp(var, "rollover")) {
+ globals.roll_size = atoi(val);
+ }
+ }
+ }
+ switch_xml_free(xml);
+ }
+ if (globals.roll_size == 0) {
+ globals.roll_size = DEFAULT_LIMIT;
+ }
+ if (switch_strlen_zero(globals.logfile)) {
+ set_global_logfile(DEFAULT_LOGFILE);
+ }
+ if (switch_strlen_zero(globals.format)) {
+ set_global_format(DEFAULT_FORMAT);
+ }
+ return 0;
+}
+
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **interface, char *filename)
+{
+ switch_status_t status;
+
+ if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
+ return SWITCH_STATUS_TERM;
+ }
+
+ *interface = &log2file_module_interface;
+
+ if ((status=load_config()) != SWITCH_STATUS_SUCCESS) {
+ return status;
+ }
+ mod_log2file_openlogfile();
+ switch_log_bind_logger(mod_log2file_logger, SWITCH_LOG_DEBUG);
+ return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_unload(const switch_loadable_module_interface_t **interface)
+{
+ closelog();
+ return SWITCH_STATUS_SUCCESS;
+}
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:nil
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
+ */
1
0
02 Jun '07
Author: anthonyl
Date: Sat Jun 2 19:46:57 2007
New Revision: 5249
Added:
freeswitch/branches/anthonyl/log2file-branch/
- copied from r5248, /freeswitch/trunk/
Log:
a new branch off trunk just for the log2file code.
1
0
[commit] r5246 - freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file
by Freeswitch SVN 01 Jun '07
by Freeswitch SVN 01 Jun '07
01 Jun '07
Author: anthonyl
Date: Fri Jun 1 17:24:29 2007
New Revision: 5246
Modified:
freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c
Log:
replace the last fseek call with something that we can use.
Modified: freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c
==============================================================================
--- freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c (original)
+++ freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c Fri Jun 1 17:24:29 2007
@@ -220,7 +220,7 @@
memset(q, '\0', 1024);
nbytes = 1024;
}
- /* ret = fseek(globals.log_fd, 0, SEEK_SET); replace me */
+ stat = switch_file_seek(&globals.log_afd, APR_SET, 0);
free(p);
free(q);
return SWITCH_STATUS_SUCCESS;
1
0
[commit] r5245 - freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file
by Freeswitch SVN 01 Jun '07
by Freeswitch SVN 01 Jun '07
01 Jun '07
Author: anthonyl
Date: Fri Jun 1 17:23:03 2007
New Revision: 5245
Modified:
freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c
Log:
the apr file api rewrites nbytes on exit, so restore it to the default value before we move on.
Modified: freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c
==============================================================================
--- freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c (original)
+++ freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c Fri Jun 1 17:23:03 2007
@@ -181,14 +181,12 @@
/* rotate the log file */
static switch_status_t mod_log2file_rotate(void)
{
- int fd;
- int ret;
- unsigned int i;
- unsigned char *p;
- unsigned char *q;
- switch_status_t stat;
- switch_size_t nbytes;
- switch_file_t *l_afd;
+ unsigned int i = 0;
+ unsigned char *p = NULL;
+ unsigned char *q = NULL;
+ switch_status_t stat = 0;
+ switch_size_t nbytes = 1024;
+ switch_file_t *l_afd = NULL;
globals.log_size = 0;
stat = switch_file_seek(globals.log_afd, APR_SET, 0);
@@ -217,12 +215,12 @@
if (stat == SWITCH_STATUS_SUCCESS)
break;
}
- nbytes = 1024;
while ((stat = switch_file_read(&globals.log_afd, q, &nbytes)) == SWITCH_STATUS_SUCCESS) {
switch_file_write(l_afd, q, &nbytes);
memset(q, '\0', 1024);
+ nbytes = 1024;
}
- ret = fseek(globals.log_fd, 0, SEEK_SET);
+ /* ret = fseek(globals.log_fd, 0, SEEK_SET); replace me */
free(p);
free(q);
return SWITCH_STATUS_SUCCESS;
1
0
[commit] r5244 - freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file
by Freeswitch SVN 01 Jun '07
by Freeswitch SVN 01 Jun '07
01 Jun '07
Author: anthonyl
Date: Fri Jun 1 17:20:24 2007
New Revision: 5244
Modified:
freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c
Log:
update. converted all of the calls to switch_file_write that we need.
Modified: freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c
==============================================================================
--- freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c (original)
+++ freeswitch/branches/anthonyl/fs-branch/src/mod/loggers/mod_log2file/mod_log2file.c Fri Jun 1 17:20:24 2007
@@ -55,7 +55,7 @@
unsigned int roll_size; /* the size that we want to rotate the file at */
unsigned char *logfile;
unsigned char *format;
- apr_file_t *log_afd;
+ switch_file_t *log_afd;
} globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_logfile, globals.logfile)
@@ -79,15 +79,15 @@
};
static switch_loadable_module_interface_t log2file_module_interface = {
/*.module_name */ modname,
- /*.endpoint_interface */ NULL,
- /*.timer_interface */ NULL,
- /*.dialplan_interface */ NULL,
- /*.codec_interface */ NULL,
+ /*.endpoint_interface */ NULL,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
/*.application_interface */ NULL,
- /*.api_interface */ NULL,
- /*.file_interface */ NULL,
- /*.speech_interface */ NULL,
- /*.directory_interface */ NULL
+ /*.api_interface */ NULL,
+ /*.file_interface */ NULL,
+ /*.speech_interface */ NULL,
+ /*.directory_interface */ NULL
};
/* this may exist somewhere else in the code? */
@@ -164,13 +164,13 @@
static switch_status_t mod_log2file_openlogfile(void)
{
int fd;
- apr_file_t *afd;
- apr_status_t stat;
+ switch_file_t *afd;
+ switch_status_t stat;
- stat = apr_file_open(&afd, globals.logfile,
+ stat = switch_file_open(&afd, globals.logfile,
APR_CREATE| APR_READ | APR_WRITE | APR_APPEND, NULL, NULL);
- if (stat != APR_SUCCESS) {
+ if (stat != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
globals.log_afd = afd;
@@ -186,13 +186,14 @@
unsigned int i;
unsigned char *p;
unsigned char *q;
- apr_status_t stat;
- apr_file_t *l_afd;
+ switch_status_t stat;
+ switch_size_t nbytes;
+ switch_file_t *l_afd;
globals.log_size = 0;
- stat = apr_file_seek(globals.log_afd, APR_SET, 0);
+ stat = switch_file_seek(globals.log_afd, APR_SET, 0);
- if (stat != APR_SUCCESS)
+ if (stat != SWITCH_STATUS_SUCCESS)
return SWITCH_STATUS_FALSE;
p = malloc(strlen(globals.logfile)+WARM_FUZZY_OFFSET);
@@ -207,23 +208,21 @@
memset(p, '\0', strlen(globals.logfile)+WARM_FUZZY_OFFSET);
for (i=1;i<MAX_ROT; i++) {
sprintf(p, "%s.%i", globals.logfile, i);
- stat = apr_file_open(l_afd, p, APR_READ, NULL, NULL);
- if (stat == APR_SUCCESS) {
- apr_file_close(l_afd);
+ stat = switch_file_open(l_afd, p, APR_READ, NULL, NULL);
+ if (stat == SWITCH_STATUS_SUCCESS) {
+ switch_file_close(l_afd);
continue;
}
- stat = apr_file_open(l_afd, p, APR_READ | APR_WRITE | APR_CREATE , NULL, NULL);
- if (stat == APR_SUCCESS)
+ stat = switch_file_open(l_afd, p, APR_READ | APR_WRITE | APR_CREATE , NULL, NULL);
+ if (stat == SWITCH_STATUS_SUCCESS)
break;
}
- while( ret = fread(q, 1024, 1, globals.log_fd)) {
- fwrite(q, 1024, 1, fd);
- memset(q, '\0', 1024);
+ nbytes = 1024;
+ while ((stat = switch_file_read(&globals.log_afd, q, &nbytes)) == SWITCH_STATUS_SUCCESS) {
+ switch_file_write(l_afd, q, &nbytes);
+ memset(q, '\0', 1024);
}
- /* now we need to resize the original file to 0 */
- /* or just remove it */
ret = fseek(globals.log_fd, 0, SEEK_SET);
- fclose(fd);
free(p);
free(q);
return SWITCH_STATUS_SUCCESS;
@@ -232,16 +231,14 @@
/* check the size of the file for rotation */
static switch_status_t mod_log2file_check(void)
{
- apr_status_t stat;
- apr_finfo_t finfo;
- off_t off;
-
- stat = apr_file_info_get(&finfo, APR_FINFO_SIZE, &globals.log_afd);
-
- if (stat != APR_SUCCESS)
+ switch_status_t stat;
+ switch_size_t fsize;
+ fsize = switch_file_get_size(&globals.log_afd);
+
+ if (stat != SWITCH_STATUS_SUCCESS)
return SWITCH_STATUS_FALSE;
- if (finfo.size >= globals.roll_size) {
+ if (fsize >= globals.roll_size) {
return mod_log2file_rotate();
}
@@ -251,21 +248,23 @@
/* write to the actual logfile */
static switch_status_t mod_log2file_write(char *fmt, ...)
{
- int ret;
unsigned int len;
- char log_data[MAX_LENGTH]; /* seems like a waste of stack space no ;), i'll fix this later */
+ char *log_data;
+ switch_status_t stat;
va_list args;
va_start(args, fmt);
#ifdef WIN32
- _vsnprintf(&log_data, sizeof(log_data), fmt, args);
+ len = _vasprintf(&log_data, fmt, args);
#else
- vsnprintf((char *)&log_data, sizeof(log_data), fmt, args);
+ len = vasprintf(&log_data, fmt, args);
#endif
- if ((ret = fprintf(globals.log_fd, "%s" , log_data))<0) {
+ if (len <= 0)
return SWITCH_STATUS_FALSE;
- }
- globals.log_size += ret;
+ stat = switch_file_write(&globals.log_afd, log_data, len);
+ if (stat != SWITCH_STATUS_SUCCESS)
+ return SWITCH_STATUS_FALSE;
+ globals.log_size += len;
/* we may want to hold back on this for preformance reasons */
mod_log2file_check();
return SWITCH_STATUS_SUCCESS;
1
0
01 Jun '07
Author: greenlizard
Date: Fri Jun 1 14:05:17 2007
New Revision: 5241
Modified:
freeswitch/branches/greenlizard/src/include/private/switch_core_pvt.h
freeswitch/branches/greenlizard/src/include/switch.h
freeswitch/branches/greenlizard/src/include/switch_apr.h
freeswitch/branches/greenlizard/src/include/switch_core.h
freeswitch/branches/greenlizard/src/include/switch_ivr.h
freeswitch/branches/greenlizard/src/mod/applications/mod_commands/mod_commands.c
freeswitch/branches/greenlizard/src/mod/applications/mod_esf/mod_esf.c
freeswitch/branches/greenlizard/src/mod/applications/mod_playback/mod_playback.c
freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.c
freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.h
freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_glue.c
freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_presence.c
freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_reg.c
freeswitch/branches/greenlizard/src/mod/endpoints/mod_wanpipe/Makefile
freeswitch/branches/greenlizard/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
freeswitch/branches/greenlizard/src/mod/languages/mod_python/Makefile
freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
freeswitch/branches/greenlizard/src/switch_apr.c
freeswitch/branches/greenlizard/src/switch_buffer.c
freeswitch/branches/greenlizard/src/switch_caller.c
freeswitch/branches/greenlizard/src/switch_core_io.c
freeswitch/branches/greenlizard/src/switch_core_media_bug.c
freeswitch/branches/greenlizard/src/switch_core_session.c
freeswitch/branches/greenlizard/src/switch_ivr_async.c
freeswitch/branches/greenlizard/src/switch_ivr_originate.c
freeswitch/branches/greenlizard/src/switch_ivr_play_say.c
freeswitch/branches/greenlizard/src/switch_loadable_module.c
freeswitch/branches/greenlizard/src/switch_log.c
freeswitch/branches/greenlizard/src/switch_rtp.c
Log:
merge in changes from trunk 5202 to 5240. Revert to trunk vrsion of python Makefile. No other changes.
Modified: freeswitch/branches/greenlizard/src/include/private/switch_core_pvt.h
==============================================================================
--- freeswitch/branches/greenlizard/src/include/private/switch_core_pvt.h (original)
+++ freeswitch/branches/greenlizard/src/include/private/switch_core_pvt.h Fri Jun 1 14:05:17 2007
@@ -136,6 +136,7 @@
void *user_data;
uint32_t flags;
uint8_t ready;
+ time_t stop_time;
struct switch_media_bug *next;
};
Modified: freeswitch/branches/greenlizard/src/include/switch.h
==============================================================================
--- freeswitch/branches/greenlizard/src/include/switch.h (original)
+++ freeswitch/branches/greenlizard/src/include/switch.h Fri Jun 1 14:05:17 2007
@@ -52,8 +52,13 @@
#define FREESWITCH_ITAD "543"
#define __EXTENSIONS__ 1
#ifndef MACOSX
+#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
+#ifndef __BSD_VISIBLE
+#define __BSD_VISIBLE 1
+#endif
+#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
Modified: freeswitch/branches/greenlizard/src/include/switch_apr.h
==============================================================================
--- freeswitch/branches/greenlizard/src/include/switch_apr.h (original)
+++ freeswitch/branches/greenlizard/src/include/switch_apr.h Fri Jun 1 14:05:17 2007
@@ -732,6 +732,7 @@
* be returned. APR_EINTR is never returned.
*/
SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t * thefile, const void *buf, switch_size_t *nbytes);
+SWITCH_DECLARE(int) switch_file_printf(switch_file_t *thefile, const char *format, ...);
SWITCH_DECLARE(switch_status_t) switch_file_mktemp(switch_file_t **thefile, char *templ, int32_t flags, switch_memory_pool_t *pool);
Modified: freeswitch/branches/greenlizard/src/include/switch_core.h
==============================================================================
--- freeswitch/branches/greenlizard/src/include/switch_core.h (original)
+++ freeswitch/branches/greenlizard/src/include/switch_core.h Fri Jun 1 14:05:17 2007
@@ -130,7 +130,7 @@
*/
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t *session,
switch_media_bug_callback_t callback,
- void *user_data, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug);
+ void *user_data, time_t stop_time, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug);
/*!
\brief Obtain private data from a media bug
\param bug the bug to get the data from
Modified: freeswitch/branches/greenlizard/src/include/switch_ivr.h
==============================================================================
--- freeswitch/branches/greenlizard/src/include/switch_ivr.h (original)
+++ freeswitch/branches/greenlizard/src/include/switch_ivr.h Fri Jun 1 14:05:17 2007
@@ -198,7 +198,7 @@
\param fh file handle to use (NULL for builtin one)
\return SWITCH_STATUS_SUCCESS if all is well
*/
-SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, switch_file_handle_t *fh);
+SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, uint32_t limit, switch_file_handle_t *fh);
/*!
\brief Stop Recording a session
Modified: freeswitch/branches/greenlizard/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/applications/mod_commands/mod_commands.c (original)
+++ freeswitch/branches/greenlizard/src/mod/applications/mod_commands/mod_commands.c Fri Jun 1 14:05:17 2007
@@ -550,6 +550,7 @@
char *mycmd = NULL, *argv[4] = { 0 };
char *uuid = NULL, *action = NULL, *path = NULL;
int argc = 0;
+ uint32_t limit = 0;
if (session) {
return SWITCH_STATUS_FALSE;
@@ -570,7 +571,8 @@
uuid = argv[0];
action = argv[1];
path = argv[2];
-
+ limit = argv[3] ? atoi(argv[3]) : 0;
+
if (!(rsession = switch_core_session_locate(uuid))) {
stream->write_function(stream, "-Error Cannot locate session!\n");
return SWITCH_STATUS_SUCCESS;
@@ -581,7 +583,7 @@
}
if (!strcasecmp(action, "start")) {
- switch_ivr_record_session(rsession, path, NULL);
+ switch_ivr_record_session(rsession, path, limit, NULL);
} else if (!strcasecmp(action, "stop")) {
switch_ivr_stop_record_session(rsession, path);
} else {
@@ -1230,7 +1232,7 @@
/*.interface_name */ "session_record",
/*.desc */ "session record",
/*.function */ session_record_function,
- /*.syntax */ "<uuid> [start|stop] <path>",
+ /*.syntax */ "<uuid> [start|stop] <path> [<limit>]",
/*.next */ &broadcast_api_interface
};
Modified: freeswitch/branches/greenlizard/src/mod/applications/mod_esf/mod_esf.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/applications/mod_esf/mod_esf.c (original)
+++ freeswitch/branches/greenlizard/src/mod/applications/mod_esf/mod_esf.c Fri Jun 1 14:05:17 2007
@@ -57,7 +57,7 @@
{
switch_channel_t *channel;
switch_socket_t *socket;
- switch_sockaddr_t *audio_addr, *control_packet_addr;
+ switch_sockaddr_t *audio_addr = NULL, *control_packet_addr;
switch_frame_t *read_frame;
switch_status_t status;
switch_size_t bytes;
@@ -65,7 +65,7 @@
switch_codec_t *read_codec;
uint32_t flags = 0;
const char *err;
- switch_rtp_t *rtp_session;
+ switch_rtp_t *rtp_session = NULL;
switch_port_t rtp_port;
char guess_ip[25];
ls_how_t ready = SEND_TYPE_UNKNOWN;
@@ -215,7 +215,7 @@
fail:
- if (ready == SEND_TYPE_RTP && switch_rtp_ready(rtp_session)) {
+ if (rtp_session && ready == SEND_TYPE_RTP && switch_rtp_ready(rtp_session)) {
switch_rtp_destroy(&rtp_session);
}
Modified: freeswitch/branches/greenlizard/src/mod/applications/mod_playback/mod_playback.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/applications/mod_playback/mod_playback.c (original)
+++ freeswitch/branches/greenlizard/src/mod/applications/mod_playback/mod_playback.c Fri Jun 1 14:05:17 2007
@@ -142,6 +142,11 @@
path = switch_core_session_strdup(session, data);
if ((p = strchr(path, '+'))) {
+ char *q = p - 1;
+ while(q && *q == ' ') {
+ *q = '\0';
+ q--;
+ }
*p++ = '\0';
limit = atoi(p);
}
@@ -158,10 +163,24 @@
static void record_session_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
+ char *p, *path = NULL;
+ uint32_t limit = 0;
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
- switch_ivr_record_session(session, data, NULL);
+ path = switch_core_session_strdup(session, data);
+ if ((p = strchr(path, '+'))) {
+ char *q = p - 1;
+ while(q && *q == ' ') {
+ *q = '\0';
+ q--;
+ }
+ *p++ = '\0';
+ limit = atoi(p);
+ }
+
+ switch_ivr_record_session(session, path, limit, NULL);
}
Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.c (original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.c Fri Jun 1 14:05:17 2007
@@ -317,7 +317,7 @@
}
nua_respond(tech_pvt->nh, SIP_200_OK,
- SIPTAG_CONTACT_STR(tech_pvt->profile->url),
+ SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
}
@@ -680,7 +680,7 @@
sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), msg->string_arg, 1);
}
nua_respond(tech_pvt->nh, SIP_200_OK,
- SIPTAG_CONTACT_STR(tech_pvt->profile->url),
+ SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
switch_channel_mark_answered(channel);
}
Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.h (original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.h Fri Jun 1 14:05:17 2007
@@ -114,6 +114,11 @@
PFLAG_RESPAWN = (1 << 9)
} PFLAGS;
+
+typedef enum {
+ PFLAG_NDLB_TO_IN_200_CONTACT = (1 << 1)
+} sofia_NDLB_t;
+
typedef enum {
TFLAG_IO = (1 << 0),
TFLAG_CHANGE_MEDIA = (1 << 1),
@@ -223,6 +228,7 @@
int dtmf_duration;
unsigned int flags;
unsigned int pflags;
+ unsigned int ndlb;
uint32_t max_calls;
uint32_t nonce_ttl;
nua_t *nua;
@@ -287,6 +293,7 @@
switch_port_t adv_sdp_audio_port;
char *proxy_sdp_audio_ip;
switch_port_t proxy_sdp_audio_port;
+ char *reply_contact;
char *from_uri;
char *to_uri;
char *from_address;
Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia.c (original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia.c Fri Jun 1 14:05:17 2007
@@ -110,6 +110,28 @@
su_root_break(profile->s_root);
}
break;
+
+ case nua_r_message:
+ {
+ if (status == 503) {
+ const char *user = NULL, *host = NULL;
+ char *sql;
+
+ if (sip->sip_to && sip->sip_to->a_url) {
+ user = sip->sip_to->a_url->url_user;
+ host = sip->sip_to->a_url->url_host;
+
+ sql = switch_mprintf("delete from sip_registrations where user='%q' and host='%q'", user, host);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Deleting registration for %s@%s\n", user, host);
+ sofia_glue_execute_sql(profile, SWITCH_TRUE, sql, NULL);
+ switch_safe_free(sql);
+ }
+ }
+
+ nua_handle_destroy(nh);
+
+ }
+ break;
case nua_r_get_params:
case nua_r_invite:
case nua_r_unregister:
@@ -120,7 +142,6 @@
case nua_i_bye:
case nua_r_unsubscribe:
case nua_r_publish:
- case nua_r_message:
case nua_r_notify:
case nua_i_notify:
case nua_i_cancel:
@@ -768,6 +789,10 @@
if (switch_true(val)) {
profile->pflags |= PFLAG_PRESENCE;
}
+ } else if (!strcasecmp(var, "NDLB-to-in-200-contact")) {
+ if (switch_true(val)) {
+ profile->ndlb |= PFLAG_NDLB_TO_IN_200_CONTACT;
+ }
} else if (!strcasecmp(var, "pass-rfc2833")) {
if (switch_true(val)) {
profile->pflags |= PFLAG_PASS_RFC2833;
@@ -1812,7 +1837,19 @@
}
if (sip->sip_to && sip->sip_to->a_url) {
+ char *val;
url_set_chanvars(session, sip->sip_to->a_url, sip_to);
+ if ((val = switch_channel_get_variable(channel, "sip_to_uri"))) {
+ tech_pvt->to_uri = switch_core_session_sprintf(session, "sip:%s", val);
+ if (profile->ndlb & PFLAG_NDLB_TO_IN_200_CONTACT) {
+ tech_pvt->reply_contact = tech_pvt->to_uri;
+ } else {
+ tech_pvt->to_uri = switch_core_session_strdup(session, profile->url);
+ }
+ } else {
+ tech_pvt->to_uri = switch_core_session_strdup(session, profile->url);
+ tech_pvt->reply_contact = tech_pvt->to_uri;
+ }
}
if (sip->sip_contact && sip->sip_contact->m_url) {
@@ -1897,7 +1934,7 @@
}
} else if (!strncasecmp(un->un_name, "Remote-Party-ID", 15)) {
process_rpid(un, tech_pvt);
- } else if (!strncasecmp(un->un_name, "X-", 2)) {
+ } else if (!strncasecmp(un->un_name, "X-", 2) || !strncasecmp(un->un_name, "P-", 2)) {
if (!switch_strlen_zero(un->un_value)) {
char *new_name;
if ((new_name = switch_mprintf("%s%s", SOFIA_SIP_HEADER_PREFIX, un->un_name))) {
Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_glue.c (original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_glue.c Fri Jun 1 14:05:17 2007
@@ -162,10 +162,11 @@
}
- if (switch_test_flag(tech_pvt, TFLAG_VIDEO)) {
+ if (switch_test_flag(tech_pvt, TFLAG_VIDEO) && tech_pvt->video_rm_encoding) {
sofia_glue_tech_choose_video_port(tech_pvt);
if ((v_port = tech_pvt->adv_sdp_video_port)) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "m=video %d RTP/AVP", v_port);
+
sofia_glue_tech_set_video_codec(tech_pvt, 0);
@@ -955,7 +956,6 @@
if (switch_test_flag(tech_pvt, TFLAG_VIDEO) && tech_pvt->video_rm_encoding) {
flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_DATAWAIT | SWITCH_RTP_FLAG_NOBLOCK | SWITCH_RTP_FLAG_RAW_WRITE);
-
sofia_glue_tech_set_video_codec(tech_pvt, 0);
tech_pvt->video_rtp_session = switch_rtp_new(tech_pvt->local_sdp_audio_ip,
Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_presence.c (original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_presence.c Fri Jun 1 14:05:17 2007
@@ -94,7 +94,7 @@
nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR("text/html"), SIPTAG_PAYLOAD_STR(body), TAG_END());
-
+
switch_safe_free(ffrom);
free(user);
Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_reg.c (original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/sofia_reg.c Fri Jun 1 14:05:17 2007
@@ -136,6 +136,24 @@
return 0;
}
+int sofia_reg_nat_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+ sofia_profile_t *profile = (sofia_profile_t *) pArg;
+ nua_handle_t *nh;
+ char *contact;
+ char to[128] = "";
+
+ snprintf(to, sizeof(to), "%s@%s", argv[0], argv[1]);
+ contact = sofia_glue_get_url_from_contact(argv[2], 1);
+
+ nh = nua_handle(profile->nua, NULL, SIPTAG_FROM_STR(profile->url), SIPTAG_TO_STR(to), NUTAG_URL(contact), SIPTAG_CONTACT_STR(profile->url), TAG_END());
+
+ nua_message(nh, SIPTAG_CONTENT_TYPE_STR("text/plain"),
+ SIPTAG_PAYLOAD_STR("You suffer from Connectile Dysfunction.\nYou should use stun....\n"), TAG_END());
+
+ return 0;
+}
+
int sofia_reg_del_callback(void *pArg, int argc, char **argv, char **columnNames)
{
switch_event_t *s_event;
@@ -153,6 +171,7 @@
return 0;
}
+
void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
{
char sql[1024];
@@ -205,6 +224,16 @@
}
sofia_glue_execute_sql(profile, SWITCH_TRUE, sql, NULL);
+ if (now) {
+ snprintf(sql, sizeof(sql), "select * from sip_registrations where status like '%%NATHACK%%'");
+ sofia_glue_execute_sql_callback(profile,
+ SWITCH_TRUE,
+ NULL,
+ sql,
+ sofia_reg_nat_callback,
+ profile);
+ }
+
switch_mutex_unlock(profile->ireg_mutex);
}
@@ -263,12 +292,15 @@
const char *rpid = "unknown";
const char *display = "\"user\"";
char network_ip[80];
+ int network_port;
+ int cd = 0;
/* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */
assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL);
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_addr);
-
+ network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
+
expires = sip->sip_expires;
authorization = sip->sip_authorization;
contact = sip->sip_contact;
@@ -333,11 +365,21 @@
}
if (v_event && *v_event && (v_contact_str = switch_event_get_header(*v_event, "force-contact"))) {
- char *p;
- switch_copy_string(contact_str, v_contact_str, sizeof(contact_str));
- for(p = contact_str; p && *p; p++) {
- if (*p == '\'' || *p == '[' || *p == ']') {
- *p = '"';
+ if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") || !strcasecmp(v_contact_str, "NDLB-connectile-dysfunction")) {
+ if (contact->m_url->url_params) {
+ snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d;%s>",
+ display, contact->m_url->url_user, network_ip, network_port, contact->m_url->url_params);
+ } else {
+ snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>", display, contact->m_url->url_user, network_ip, network_port);
+ }
+ cd = 1;
+ } else {
+ char *p;
+ switch_copy_string(contact_str, v_contact_str, sizeof(contact_str));
+ for(p = contact_str; p && *p; p++) {
+ if (*p == '\'' || *p == '[' || *p == ']') {
+ *p = '"';
+ }
}
}
}
@@ -386,8 +428,8 @@
if (exptime) {
if (!sofia_reg_find_reg_url(profile, from_user, from_host, buf, sizeof(buf))) {
- sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','Registered', '%q', %ld)",
- from_user, from_host, contact_str, rpid, (long) time(NULL) + (long) exptime * 2);
+ sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','%q', '%q', %ld)",
+ from_user, from_host, contact_str, cd ? "Registered(NATHACK)" : "Registered", rpid, (long) time(NULL) + (long) exptime * 2);
} else {
sql =
Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_wanpipe/Makefile
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_wanpipe/Makefile (original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_wanpipe/Makefile Fri Jun 1 14:05:17 2007
@@ -3,8 +3,8 @@
LIBPRI=libpri-1.2.4
LIBPRI_FILE=$(LIBPRI).tar.gz
LIBPRI_DIR=$(BASE)/libs/$(LIBPRI)
-WANPIPE=wanpipe-3.1.0.p18
-WANPIPE_HOST=ftp://ftp.sangoma.com/linux/custom/3.1
+WANPIPE=wanpipe-3.1.0
+WANPIPE_HOST=ftp://ftp.sangoma.com/linux/current_wanpipe/
WANPIPE_FILE=$(WANPIPE).tgz
WANPIPE_DIR=$(BASE)/libs/$(WANPIPE)
WANPIPE_INCLUDE=$(WANPIPE_DIR)/patches/kdrivers/include
@@ -12,11 +12,25 @@
WANPIPE_INSTALLED_KO=$(shell echo "/lib/modules/`uname -r`/kernel/drivers/net/wan/wanpipe.ko")
LIBSANGOMA_DIR=./libsangoma
LOCAL_CFLAGS =-w -I$(WANPIPE_INCLUDE) -I$(LIBSANGOMA_DIR) -I/usr/local/include -I$(LIBPRI_DIR) -I/usr/src/linux/include -I. -I/usr/include
-LOCAL_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -I$(switch_srcdir)/libs/libteletone/src -D_GNUC_ -DWANPIPE_TDM_API
-LOCAL_OBJS = ss7boost_client.o $(LIBPRI_DIR)/copy_string.o $(LIBPRI_DIR)/pri.o $(LIBPRI_DIR)/q921.o $(LIBPRI_DIR)/prisched.o $(LIBPRI_DIR)/q931.o $(LIBPRI_DIR)/pri_facility.o $(LIBSANGOMA_DIR)/libsangoma.o $(LIBSANGOMA_DIR)/sangoma_pri.o
+LOCAL_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -I$(switch_srcdir)/libs/libteletone/src -D_GNUC_ -DWANPIPE_TDM_API -w -fPIC
+LOCAL_OBJS = ss7boost_client.o $(LIBPRI_DIR)/copy_string.o $(LIBPRI_DIR)/pri.o $(LIBPRI_DIR)/q921.o $(LIBPRI_DIR)/prisched.o $(LIBPRI_DIR)/q931.o $(LIBPRI_DIR)/pri_facility.o $(LIBSANGOMA_DIR)/libsangoma.o $(LIBSANGOMA_DIR)/sangoma_pri.o
+WTF=-fPIC -w -std=gnu99 -I$(BASE)/libs/wanpipe-3.1.0/patches/kdrivers/include -I./libsangoma -I/usr/local/include -I../../../../libs/libpri-1.2.4 -I/usr/src/linux/include -I. -I/usr/include -D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -I$(BASE)/libs/libteletone/src -D_GNUC_ -DWANPIPE_TDM_API -w -I$(BASE)/src/include -I$(BASE)/libs/libteletone/src -fPIC -g -O2 -Wall -D_GNU_SOURCE -DHAVE_CONFIG_H
+
+
include $(BASE)/build/modmake.rules
+mod_wanpipe.o: mod_wanpipe.c
+ @echo Compiling $<...
+ $(CC) $(WTF) -c -o $@ $< || exit 1
+
+
+$(LIBSANGOMA_DIR)/libsangoma.o: $(LIBSANGOMA_DIR)/libsangoma.c
+ $(CC) -c -I$(WANPIPE_DIR) $(LOCAL_CFLAGS) $(LIBSANGOMA_DIR)/libsangoma.c -o $(LIBSANGOMA_DIR)/libsangoma.o
+
+$(LIBSANGOMA_DIR)/sangoma_pri.o: $(LIBSANGOMA_DIR)/sangoma_pri.c
+ $(CC) -c -I$(WANPIPE_DIR) $(LOCAL_CFLAGS) $(LIBSANGOMA_DIR)/sangoma_pri.c -o $(LIBSANGOMA_DIR)/sangoma_pri.o
+
testapp: testapp.c $(LIBSANGOMA_DIR)/libsangoma.o
$(CC) -I$(WANPIPE_DIR)/api/lib $(CFLAGS) $(LOCAL_CFLAGS) lib_api.c testapp.c $(LIBSANGOMA_DIR)/libsangoma.o -o testapp
@@ -27,7 +41,7 @@
$(GETLIB) $(WANPIPE_HOST) $(WANPIPE_FILE)
$(WANPIPE_KO): $(WANPIPE_DIR)
- cd $(WANPIPE_DIR) && $(MAKE)
+ cd $(WANPIPE_DIR) && $(MAKE) && $(MAKE) install
@$(TOUCH_TARGET)
$(WANPIPE_INSTALLED_KO): $(WANPIPE_KO)
@@ -37,3 +51,5 @@
local_install: $(WANPIPE_INSTALLED_KO)
+local_clean:
+ rm -f libsangoma/*.o
Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c (original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c Fri Jun 1 14:05:17 2007
@@ -1568,7 +1568,6 @@
ret = 0;
goto done;
}
- switch_core_session_thread_launch(session);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create new Inbound Channel!\n");
}
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/Makefile
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/Makefile (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/Makefile Fri Jun 1 14:05:17 2007
@@ -3,9 +3,8 @@
# and define these variables to impact your build
-LOCAL_CFLAGS=-I$(PREFIX)/include/python2.4/ -I/usr/include/python2.4/
-LOCAL_LDFLAGS=-lpython2.4 -L$(PREFIX)/lib/python2.4/config/ -lutil -lstdc++
-
+LOCAL_CFLAGS=-I$(PREFIX)/include/python2.5/
+LOCAL_LDFLAGS=-lpython2.5 -L$(PREFIX)/lib/python2.5/config/ -lutil -lstdc++
LOCAL_OBJS=freeswitch_python.o mod_python_wrap.o
include ../../../../build/modmake.rules
@@ -15,17 +14,16 @@
SWIGIFILE=../../../switch_swig.i
local_depend:
- MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install Python-2.5.1.tgz --prefix=$(PREFIX) --enable-threads CFLAGSFORSHARED="-fPIC"
+MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install Python-2.5.1.tgz --prefix=$(PREFIX) --enable-threads CFLAGSFORSHARED="-fPIC"
reswig:
- swig -python -shadow -c++ -I../../../../src/include -o mod_python_wrap.cpp mod_python.i
+swig -python -shadow -c++ -o mod_python_wrap.cpp mod_python.i
switch_swig_wrap.o: switch_swig_wrap.c Makefile
- $(CC) -w $(CFLAGS) -c $< -o $@
+$(CC) -w $(CFLAGS) -c $< -o $@
switch_swig.o: $(SWIGCFILE) Makefile
- $(CC) -w $(CFLAGS) -c $< -o $@
+$(CC) -w $(CFLAGS) -c $< -o $@
local_install:
- cp -f freeswitch.py /usr/lib/python2.4/site-packages/
-
+cp -f freeswitch.py $(PREFIX)/lib/python2.5/site-packages/
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c Fri Jun 1 14:05:17 2007
@@ -201,7 +201,7 @@
if (!strcasecmp(how, "xml")) {
switch_xml_t xml;
char *xmlstr;
- if ((xml = switch_event_xmlize(ro->stream->event, NULL))) {
+ if ((xml = switch_event_xmlize(ro->stream->event, SWITCH_VA_NONE))) {
xmlstr = switch_xml_toxml(xml);
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, xmlstr));
return JS_TRUE;
Modified: freeswitch/branches/greenlizard/src/switch_apr.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_apr.c (original)
+++ freeswitch/branches/greenlizard/src/switch_apr.c Fri Jun 1 14:05:17 2007
@@ -335,6 +335,15 @@
return apr_file_write(thefile, buf, nbytes);
}
+SWITCH_DECLARE(int) switch_file_printf(switch_file_t *thefile, const char *format, ...)
+{
+ va_list ap;
+ int ret;
+ ret = apr_file_printf(thefile, format, ap);
+ va_end(ap);
+ return ret;
+}
+
SWITCH_DECLARE(switch_status_t) switch_file_mktemp(switch_file_t **thefile, char *templ, int32_t flags, switch_memory_pool_t *pool)
{
return apr_file_mktemp(thefile, templ, flags, pool);
Modified: freeswitch/branches/greenlizard/src/switch_buffer.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_buffer.c (original)
+++ freeswitch/branches/greenlizard/src/switch_buffer.c Fri Jun 1 14:05:17 2007
@@ -260,6 +260,7 @@
assert(buffer->data != NULL);
buffer->used = 0;
+ buffer->actually_used = 0;
buffer->head = buffer->data;
}
Modified: freeswitch/branches/greenlizard/src/switch_caller.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_caller.c (original)
+++ freeswitch/branches/greenlizard/src/switch_caller.c Fri Jun 1 14:05:17 2007
@@ -193,6 +193,16 @@
snprintf(header_name, sizeof(header_name), "%s-Channel-Name", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->chan_name);
}
+ if (caller_profile->times) {
+ snprintf(header_name, sizeof(header_name), "%s-Channel-Created-Time", prefix);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
+ snprintf(header_name, sizeof(header_name), "%s-Channel-Answered-Time", prefix);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
+ snprintf(header_name, sizeof(header_name), "%s-Channel-Hangup-Time", prefix);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
+ snprintf(header_name, sizeof(header_name), "%s-Channel-Transfer-Time", prefix);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->transferred);
+ }
snprintf(header_name, sizeof(header_name), "%s-Screen-Bit", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_SCREEN) ? "yes" : "no");
@@ -203,7 +213,7 @@
snprintf(header_name, sizeof(header_name), "%s-Privacy-Hide-Number", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER) ? "yes" : "no");
-
+
}
Modified: freeswitch/branches/greenlizard/src/switch_core_io.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_core_io.c (original)
+++ freeswitch/branches/greenlizard/src/switch_core_io.c Fri Jun 1 14:05:17 2007
@@ -232,7 +232,7 @@
switch_mutex_lock(bp->read_mutex);
switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen);
if (bp->callback) {
- if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE) {
+ if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE || (bp->stop_time && bp->stop_time >= time(NULL))) {
bp->ready = 0;
if (last) {
last->next = bp->next;
@@ -505,6 +505,11 @@
}
}
+ if (bp->stop_time && bp->stop_time >= time(NULL)) {
+ ok = SWITCH_FALSE;
+ }
+
+
if (ok == SWITCH_FALSE) {
bp->ready = 0;
if (last) {
Modified: freeswitch/branches/greenlizard/src/switch_core_media_bug.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_core_media_bug.c (original)
+++ freeswitch/branches/greenlizard/src/switch_core_media_bug.c Fri Jun 1 14:05:17 2007
@@ -144,7 +144,7 @@
#define MAX_BUG_BUFFER 1024 * 512
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t *session,
switch_media_bug_callback_t callback,
- void *user_data, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug)
+ void *user_data, time_t stop_time, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug)
{
switch_media_bug_t *bug, *bp;
switch_size_t bytes;
@@ -170,6 +170,7 @@
bug->session = session;
bug->flags = flags;
bug->ready = 1;
+ bug->stop_time = stop_time;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attaching BUG to %s\n", switch_channel_get_name(session->channel));
bytes = session->read_codec->implementation->bytes_per_frame;
Modified: freeswitch/branches/greenlizard/src/switch_core_session.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_core_session.c (original)
+++ freeswitch/branches/greenlizard/src/switch_core_session.c Fri Jun 1 14:05:17 2007
@@ -681,6 +681,7 @@
switch_core_media_bug_remove_all(*session);
switch_buffer_destroy(&(*session)->raw_read_buffer);
switch_buffer_destroy(&(*session)->raw_write_buffer);
+
switch_channel_uninit((*session)->channel);
pool = (*session)->pool;
@@ -717,23 +718,31 @@
SWITCH_DECLARE(switch_status_t) switch_core_session_thread_launch(switch_core_session_t *session)
{
+ switch_status_t status = SWITCH_STATUS_FALSE;
switch_thread_t *thread;
switch_threadattr_t *thd_attr;;
+
switch_threadattr_create(&thd_attr, session->pool);
switch_threadattr_detach_set(thd_attr, 1);
+ switch_mutex_lock(session->mutex);
+
if (!session->thread_running) {
+ session->thread_running = 1;
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
if (switch_thread_create(&thread, thd_attr, switch_core_session_thread, session, session->pool) == SWITCH_STATUS_SUCCESS) {
- return SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS;
} else {
+ session->thread_running = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot create thread!\n");
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot double-launch thread!\n");
}
- return SWITCH_STATUS_FALSE;
+ switch_mutex_unlock(session->mutex);
+
+ return status;
}
Modified: freeswitch/branches/greenlizard/src/switch_ivr_async.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_ivr_async.c (original)
+++ freeswitch/branches/greenlizard/src/switch_ivr_async.c Fri Jun 1 14:05:17 2007
@@ -147,7 +147,7 @@
}
-SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, switch_file_handle_t *fh)
+SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, uint32_t limit, switch_file_handle_t *fh)
{
switch_channel_t *channel;
switch_codec_t *read_codec;
@@ -155,6 +155,7 @@
const char *vval;
switch_media_bug_t *bug;
switch_status_t status;
+ time_t to = 0;
if (!fh) {
if (!(fh = switch_core_session_alloc(session, sizeof(*fh)))) {
@@ -220,9 +221,11 @@
switch_channel_set_variable(channel, "RECORD_DATE", NULL);
}
+ if (limit) {
+ to = time(NULL) + limit;
+ }
-
- if ((status = switch_core_media_bug_add(session, record_callback, fh, SMBF_BOTH, &bug)) != SWITCH_STATUS_SUCCESS) {
+ if ((status = switch_core_media_bug_add(session, record_callback, fh, to, SMBF_BOTH, &bug)) != SWITCH_STATUS_SUCCESS) {
switch_core_file_close(fh);
return status;
}
@@ -312,7 +315,7 @@
switch_channel_answer(channel);
- if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) {
+ if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) {
return status;
}
@@ -597,7 +600,7 @@
sth->session = session;
sth->ah = ah;
- if ((status = switch_core_media_bug_add(session, speech_callback, sth, SMBF_READ_STREAM, &sth->bug)) != SWITCH_STATUS_SUCCESS) {
+ if ((status = switch_core_media_bug_add(session, speech_callback, sth, 0, SMBF_READ_STREAM, &sth->bug)) != SWITCH_STATUS_SUCCESS) {
switch_core_asr_close(ah, &flags);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return status;
Modified: freeswitch/branches/greenlizard/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_ivr_originate.c (original)
+++ freeswitch/branches/greenlizard/src/switch_ivr_originate.c Fri Jun 1 14:05:17 2007
@@ -177,13 +177,13 @@
(early_ok && len == 1 && switch_channel_test_flag(peer_channels[i], CF_EARLY_MEDIA))) &&
!switch_channel_test_flag(peer_channels[i], CF_TAGGED)) {
- if (key) {
+ if (!switch_strlen_zero(key)) {
struct key_collect *collect;
if ((collect = switch_core_session_alloc(peer_sessions[i], sizeof(*collect)))) {
switch_channel_set_flag(peer_channels[i], CF_TAGGED);
collect->key = key;
- if (file) {
+ if (!switch_strlen_zero(file)) {
collect->file = switch_core_session_strdup(peer_sessions[i], file);
}
@@ -260,7 +260,7 @@
switch_codec_t write_codec = { 0 };
switch_frame_t write_frame = { 0 };
uint8_t fdata[1024], pass = 0;
- char *file = NULL, *key = NULL, *odata, *var;
+ char key[80] = "", file[512] = "", *odata, *var;
switch_call_cause_t reason = SWITCH_CAUSE_UNALLOCATED;
uint8_t to = 0;
char *var_val, *vars = NULL, *ringback_data = NULL;
@@ -362,9 +362,9 @@
}
if ((var = switch_event_get_header(var_event, "group_confirm_key"))) {
- key = switch_core_session_strdup(session, var);
+ switch_copy_string(key, var, sizeof(key));
if ((var = switch_event_get_header(var_event, "group_confirm_file"))) {
- file = switch_core_session_strdup(session, var);
+ switch_copy_string(file, var, sizeof(file));
}
}
// When using the AND operator, the fail_on_single_reject flag may be set in order to indicate that a single
@@ -373,8 +373,8 @@
fail_on_single_reject = 1;
}
- if (file && !strcmp(file, "undef")) {
- file = NULL;
+ if (!switch_strlen_zero(file) && !strcmp(file, "undef")) {
+ *file = '\0';
}
if ((var_val = switch_event_get_header(var_event, "ignore_early_media")) && switch_true(var_val)) {
@@ -440,8 +440,6 @@
read_frame = NULL;
pool = NULL;
pass = 0;
- file = NULL;
- key = NULL;
var = NULL;
to = 0;
Modified: freeswitch/branches/greenlizard/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_ivr_play_say.c (original)
+++ freeswitch/branches/greenlizard/src/switch_ivr_play_say.c Fri Jun 1 14:05:17 2007
@@ -831,7 +831,6 @@
status = SWITCH_STATUS_SUCCESS;
continue;
} else if (status != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bad Write\n");
done = 1;
break;
}
@@ -852,6 +851,7 @@
switch_yield(10000);
}
status = switch_core_session_read_frame(session, &read_frame, -1, 0);
+
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
@@ -1043,7 +1043,6 @@
write_frame.timestamp = timer->samplecount;
}
if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bad Write\n");
done = 1;
break;
}
@@ -1125,7 +1124,6 @@
write_frame.timestamp = timer->samplecount;
}
if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bad Write\n");
done = 1;
break;
}
@@ -1146,7 +1144,6 @@
write_frame.timestamp = timer->samplecount;
}
if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bad Write\n");
done = 1;
break;
}
Modified: freeswitch/branches/greenlizard/src/switch_loadable_module.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_loadable_module.c (original)
+++ freeswitch/branches/greenlizard/src/switch_loadable_module.c Fri Jun 1 14:05:17 2007
@@ -785,7 +785,6 @@
SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir, char *fname, const char **err)
{
- switch_size_t len = 0;
char *path = NULL;
char *file = NULL;
switch_loadable_module_t *module = NULL;
@@ -808,17 +807,9 @@
path = strdup(file);
} else {
if (strchr(file, '.')) {
- len = strlen(dir);
- len += strlen(file);
- len += 4;
- path = (char *) switch_core_alloc(loadable_modules.pool, len);
- snprintf(path, len, "%s%s%s", dir, SWITCH_PATH_SEPARATOR, file);
+ path = switch_mprintf("%s%s%s", dir, SWITCH_PATH_SEPARATOR, file);
} else {
- len = strlen(dir);
- len += strlen(file);
- len += 8;
- path = (char *) malloc(len);
- snprintf(path, len, "%s%s%s%s", dir, SWITCH_PATH_SEPARATOR, file, ext);
+ path = switch_mprintf("%s%s%s%s", dir, SWITCH_PATH_SEPARATOR, file, ext);
}
}
@@ -833,6 +824,7 @@
do_shutdown(module);
}
} else {
+ *err = "No such module!";
status = SWITCH_STATUS_FALSE;
}
switch_mutex_unlock(loadable_modules.mutex);
@@ -1259,7 +1251,7 @@
if (cur != name) {
if (strchr(cur, 'i')) {
interval = atoi(cur);
- } else if (strchr(cur, 'k')) {
+ } else if (strchr(cur, 'k' || strchr(cur, 'h'))) {
rate = atoi(cur);
}
}
Modified: freeswitch/branches/greenlizard/src/switch_log.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_log.c (original)
+++ freeswitch/branches/greenlizard/src/switch_log.c Fri Jun 1 14:05:17 2007
@@ -114,8 +114,9 @@
static void *SWITCH_THREAD_FUNC log_thread(switch_thread_t * thread, void *obj)
{
- /* To Be or Not To Be */
- assert(obj == NULL || obj != NULL);
+ if (!obj) {
+ obj = NULL;
+ }
THREAD_RUNNING = 1;
while (THREAD_RUNNING == 1) {
Modified: freeswitch/branches/greenlizard/src/switch_rtp.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_rtp.c (original)
+++ freeswitch/branches/greenlizard/src/switch_rtp.c Fri Jun 1 14:05:17 2007
@@ -578,7 +578,7 @@
SWITCH_DECLARE(void) switch_rtp_set_telephony_event(switch_rtp_t *rtp_session, switch_payload_t te)
{
- if (te > 96) {
+ if (te > 95) {
rtp_session->te = te;
}
}
@@ -752,8 +752,13 @@
rtp_session->dtmf_data.out_digit_packet[3] = (unsigned char) duration;
+
+ rtp_session->dtmf_data.timestamp_dtmf += samples;
+
+
for (x = 0; x < loops; x++) {
rtp_session->dtmf_data.out_digit_seq++;
+
switch_rtp_write_manual(rtp_session,
rtp_session->dtmf_data.out_digit_packet,
4,
@@ -765,10 +770,13 @@
loops == 1 ? "middle" : "end", rtp_session->dtmf_data.out_digit, rtp_session->dtmf_data.timestamp_dtmf,
rtp_session->dtmf_data.out_digit_sofar, duration, rtp_session->dtmf_data.out_digit_seq);
+
}
if (loops == 1) {
rtp_session->last_write_seq = 0;
+ } else {
+ rtp_session->dtmf_data.out_digit_seq = 0;
}
}
@@ -797,7 +805,7 @@
for (x = 0; x < 3; x++) {
- //rtp_session->dtmf_data.out_digit_seq++;
+ rtp_session->dtmf_data.out_digit_seq++;
switch_rtp_write_manual(rtp_session,
rtp_session->dtmf_data.out_digit_packet,
4,
@@ -811,7 +819,7 @@
rtp_session->dtmf_data.out_digit,
rtp_session->dtmf_data.timestamp_dtmf, rtp_session->dtmf_data.out_digit_sofar, 0, rtp_session->dtmf_data.out_digit_seq);
}
-
+ rtp_session->dtmf_data.timestamp_dtmf += samples;
free(rdigit);
}
}
@@ -1409,7 +1417,7 @@
}
- if (rtp_session->last_write_seq >0 && rtp_session->last_write_seq <= rtp_session->dtmf_data.out_digit_seq) {
+ if (rtp_session->last_write_seq > 0 && rtp_session->last_write_seq <= rtp_session->dtmf_data.out_digit_seq) {
send = 0;
}
1
0
[commit] r5212 - freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr
by Freeswitch SVN 24 May '07
by Freeswitch SVN 24 May '07
24 May '07
Author: cparker
Date: Thu May 24 11:21:45 2007
New Revision: 5212
Modified:
freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c
Log:
Add Start/Stop Functionality and new initializer function
Modified: freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c
==============================================================================
--- freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c (original)
+++ freeswitch/branches/cparker/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c Thu May 24 11:21:45 2007
@@ -45,7 +45,84 @@
static char * my_retries; /* 3 */
static char my_servers[SERVER_MAX][255];
-static switch_status_t my_on_hangup(switch_core_session_t *session)
+static rc_handle * my_radius_init(void)
+{
+ rc_handle *rad_config;
+
+ rad_config = rc_new();
+
+ if (rad_config == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing rc_handle!\n");
+ return NULL;
+ }
+
+ rad_config = rc_config_init(rad_config);
+
+ if (rad_config == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing radius config!\n");
+ rc_destroy(rad_config);
+ return NULL;
+ }
+
+ /* Some hardcoded ( for now ) defaults needed to initialize radius */
+ if (rc_add_config(rad_config, "auth_order", "radius", "mod_radius_cdr.c", 0) != 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "[mod_radius_cdr] failed setting auth_order = radius\n");
+ rc_destroy(rad_config);
+ return NULL;
+ }
+
+ if (rc_add_config(rad_config, "seqfile", "/var/run/radius.seq", "mod_radius_cdr.c", 0) != 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed setting seqfile = /var/run/radius.seq\n");
+ rc_destroy(rad_config);
+ return NULL;
+ }
+
+
+ /* Add the module configs to initialize rad_config */
+
+ for (int i = 0; i < SERVER_MAX && my_servers[i][0] != '\0'; i++) {
+ if (rc_add_config(rad_config, "acctserver", my_servers[i], cf, 0) != 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting acctserver = %s failed\n", my_servers[i]);
+ rc_destroy(rad_config);
+ return NULL;
+ }
+ }
+
+ if (rc_add_config(rad_config, "dictionary", my_dictionary, cf, 0) != 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed setting dictionary = %s failed\n", my_dictionary);
+ rc_destroy(rad_config);
+ return NULL;
+ }
+
+ if (rc_add_config(rad_config, "radius_timeout", my_timeout, cf, 0) != 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed setting radius_timeout = %s failed\n", my_timeout);
+ rc_destroy(rad_config);
+ return NULL;
+ }
+
+ if (rc_add_config(rad_config, "radius_retries", my_retries, cf, 0) != 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed setting radius_retries = %s failed\n", my_retries);
+ rc_destroy(rad_config);
+ return NULL;
+ }
+
+ /* Read the dictionary file(s) */
+ if (rc_read_dictionary(rad_config, rc_conf_str(rad_config, "dictionary")) != 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed reading dictionary file(s): %s\n", my_dictionary);
+ rc_destroy(rad_config);
+ return NULL;
+ }
+
+ return rad_config;
+}
+
+static switch_status_t my_on_ring(switch_core_session_t *session)
{
switch_xml_t cdr;
switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -53,87 +130,141 @@
int retval = 0;
VALUE_PAIR *send = NULL;
UINT4 client_port = 0;
- UINT4 status_type = PW_STATUS_STOP;
+ UINT4 status_type = PW_STATUS_START;
char *uuid_str;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Entering my_on_hangup\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Entering my_on_ring\n");
- rad_config = rc_new();
+ rad_config = my_radius_init();
if (rad_config == NULL) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing rc_handle!\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing radius, Start packet not logged.\n");
return SWITCH_STATUS_TERM;
}
- rad_config = rc_config_init(rad_config);
+ if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
+ uuid_str = switch_core_session_get_uuid(session);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error Generating Data!\n");
+ return SWITCH_STATUS_TERM;
+ }
- if (rad_config == NULL) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing radius config!\n");
+ /* Create the radius packet */
+
+ /* Set Status Type */
+ if (rc_avpair_add(rad_config, &send, PW_ACCT_STATUS_TYPE, &status_type, -1, 0) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Failed setting Acct-Status-Type: Start\n");
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
- }
+ }
- if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
- uuid_str = switch_core_session_get_uuid(session);
+ if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_ID, uuid_str, -1, 0) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Failed adding Acct-Session-ID: %s\n", uuid_str);
+ rc_destroy(rad_config);
+ return SWITCH_STATUS_TERM;
+ }
+
+ /* Add VSAs */
+
+ if(channel) {
+ /*switch_call_cause_t cause;*/
+ switch_caller_profile_t *profile;
- /* Some hardcoded ( for now ) defaults needed to initialize radius */
- if (rc_add_config(rad_config, "auth_order", "radius", "internal radius config", 0) != 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "failed setting auth_order = radius failed\n");
+ /*
+ cause = switch_channel_get_cause(channel);
+ if (rc_avpair_add(rad_config, &send, PW_FS_HANGUPCAUSE, &cause, -1, PW_FS_PEC) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Hangupcause: %d\n", cause);
rc_destroy(rad_config);
- return SWITCH_STATUS_TERM;
+ return SWITCH_STATUS_TERM;
}
+ */
+
+ profile = switch_channel_get_caller_profile(channel);
- if (rc_add_config(rad_config, "seqfile", "/var/run/radius.seq", "internal radius config", 0) != 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "failed setting seqfile = /var/run/radius.seq\n");
- rc_destroy(rad_config);
- return SWITCH_STATUS_TERM;
+ if(profile) {
+ if(profile->caller_id_number) {
+ if (rc_avpair_add(rad_config, &send, PW_FS_SRC, profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
+ rc_destroy(rad_config);
+ return SWITCH_STATUS_TERM;
+ }
+ }
+ if(profile->caller_id_name) {
+ if (rc_avpair_add(rad_config, &send, PW_FS_CLID, profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
+ rc_destroy(rad_config);
+ return SWITCH_STATUS_TERM;
+ }
+ }
+ if(profile->destination_number) {
+ if (rc_avpair_add(rad_config, &send, PW_FS_DST, profile->destination_number, -1, PW_FS_PEC) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed adding Freeswitch-Dst: %s\n", profile->destination_number);
+ rc_destroy(rad_config);
+ return SWITCH_STATUS_TERM;
+ }
+ }
+ if(profile->dialplan) {
+ if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, profile->dialplan, -1, PW_FS_PEC) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
+ rc_destroy(rad_config);
+ return SWITCH_STATUS_TERM;
+ }
+ }
+ if(profile->source) {
+ if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP, profile->source, -1, PW_FS_PEC) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "failed adding Freeswitch-Lastapp: %s\n", profile->source);
+ rc_destroy(rad_config);
+ return SWITCH_STATUS_TERM;
+ }
+ }
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "profile == NULL\n");
}
+ }
+ if(rc_acct(rad_config, client_port, send) == OK_RC) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] RADIUS Accounting OK\n");
+ retval = SWITCH_STATUS_SUCCESS;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] RADIUS Accounting Failed\n");
+ retval = SWITCH_STATUS_TERM;
+ }
+ rc_avpair_free(send);
- /* Add the module configs to initialize rad_config */
+ return(retval);
+}
- for (int i = 0; i < SERVER_MAX && my_servers[i][0] != '\0'; i++) {
- if (rc_add_config(rad_config, "acctserver", my_servers[i], cf, 0) != 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting acctserver = %s failed\n", my_servers[i]);
- rc_destroy(rad_config);
- return SWITCH_STATUS_TERM;
- }
- }
+static switch_status_t my_on_hangup(switch_core_session_t *session)
+{
+ switch_xml_t cdr;
+ switch_channel_t *channel = switch_core_session_get_channel(session);
+ rc_handle *rad_config;
+ int retval = 0;
+ VALUE_PAIR *send = NULL;
+ UINT4 client_port = 0;
+ UINT4 status_type = PW_STATUS_STOP;
- if (rc_add_config(rad_config, "dictionary", my_dictionary, cf, 0) != 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "failed setting dictionary = %s failed\n", my_dictionary);
- rc_destroy(rad_config);
- return SWITCH_STATUS_TERM;
- }
+ char *uuid_str;
- if (rc_add_config(rad_config, "radius_timeout", my_timeout, cf, 0) != 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "failed setting radius_timeout = %s failed\n", my_timeout);
- rc_destroy(rad_config);
- return SWITCH_STATUS_TERM;
- }
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Entering my_on_hangup\n");
- if (rc_add_config(rad_config, "radius_retries", my_retries, cf, 0) != 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "failed setting radius_retries = %s failed\n", my_retries);
- rc_destroy(rad_config);
- return SWITCH_STATUS_TERM;
- }
+ rad_config = my_radius_init();
- /* Read the dictionary file(s) */
- if (rc_read_dictionary(rad_config, rc_conf_str(rad_config, "dictionary")) != 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "failed reading dictionary file(s): %s\n", my_dictionary);
- rc_destroy(rad_config);
- return SWITCH_STATUS_TERM;
- }
+ if (rad_config == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing radius, session not logged.\n");
+ return SWITCH_STATUS_TERM;
+ }
+ if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
+ uuid_str = switch_core_session_get_uuid(session);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Generating Data!\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error Generating Data!\n");
return SWITCH_STATUS_TERM;
}
@@ -283,7 +414,7 @@
static const switch_state_handler_table_t state_handlers = {
/*.on_init */ NULL,
- /*.on_ring */ NULL,
+ /*.on_ring */ my_on_ring,
/*.on_execute */ NULL,
/*.on_hangup */ my_on_hangup,
/*.on_loopback */ NULL,
1
0
[commit] r5203 - freeswitch/branches/greenlizard/src/mod/languages/mod_python
by Freeswitch SVN 17 May '07
by Freeswitch SVN 17 May '07
17 May '07
Author: greenlizard
Date: Thu May 17 19:01:23 2007
New Revision: 5203
Modified:
freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py
freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp
freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h
freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i
freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp
Log:
remove set_dtmf_handler which no longer works and is not present in javascript either, fix bug which segfaults when the python dtmf handler returns None. now compares returned value with Py_None
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py Thu May 17 19:01:23 2007
@@ -127,7 +127,6 @@
__swig_destroy__ = _freeswitch.delete_PySession
__del__ = lambda self : None;
def streamfile(*args): return _freeswitch.PySession_streamfile(*args)
- def set_dtmf_callback(*args): return _freeswitch.PySession_set_dtmf_callback(*args)
def begin_allow_threads(*args): return _freeswitch.PySession_begin_allow_threads(*args)
def end_allow_threads(*args): return _freeswitch.PySession_end_allow_threads(*args)
PySession_swigregister = _freeswitch.PySession_swigregister
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp Thu May 17 19:01:23 2007
@@ -2,17 +2,6 @@
#define sanity_check(x) do { if (!session) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
-void PySession::set_dtmf_callback(PyObject *pyfunc)
-{
- sanity_check();
- if (!PyCallable_Check(pyfunc)) {
- dtmfCallbackFunction = NULL;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF function is not a python function.");
- }
- else {
- dtmfCallbackFunction = pyfunc;
- }
-}
int PySession::streamfile(char *file, PyObject *pyfunc, char *funcargs, int starting_sample_count)
{
@@ -27,14 +16,13 @@
if (!PyCallable_Check(pyfunc)) {
dtmfCallbackFunction = NULL;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF function is not a python function.");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "DTMF function is not a python function.");
}
else {
dtmfCallbackFunction = pyfunc;
}
if (dtmfCallbackFunction) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setting DTMF callback\n");
cb_state.function = dtmfCallbackFunction;
cb_state.extra = &fh;
args.buf = &cb_state;
@@ -42,9 +30,6 @@
args.input_callback = PythonDTMFCallback; // defined in mod_python.i, will use ptrs in cb_state
ap = &args;
}
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NOT Setting DTMF callback\n");
- }
this->begin_allow_threads();
@@ -59,12 +44,10 @@
void PySession::begin_allow_threads(void) {
threadState = PyEval_SaveThread();
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Py_BEGIN_ALLOW_THREADS\n");
}
void PySession::end_allow_threads(void) {
PyEval_RestoreThread(threadState);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Py_END_ALLOW_THREADS\n");
}
PySession::~PySession() {
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h Thu May 17 19:01:23 2007
@@ -42,7 +42,6 @@
PySession(switch_core_session_t *session) : CoreSession(session) {};
~PySession();
int streamfile(char *file, PyObject *pyfunc, char *funcargs, int starting_sample_count);
- void set_dtmf_callback(PyObject *pyfunc);
void begin_allow_threads();
void end_allow_threads();
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i Thu May 17 19:01:23 2007
@@ -65,13 +65,17 @@
result = PyEval_CallObject(func, arglist);
threadState = PyEval_SaveThread();
+
Py_DECREF(arglist); // Trash arglist
- if (result) {
+ if (result && result != Py_None) {
resultStr = (char *) PyString_AsString(result);
+ Py_XDECREF(result);
+ return process_callback_result(resultStr, cb_state, session);
+ }
+ else {
+ return SWITCH_STATUS_FALSE;
}
- Py_XDECREF(result);
- return process_callback_result(resultStr, cb_state, session);
}
@@ -84,6 +88,11 @@
switch_file_handle_t *fh = NULL;
fh = (switch_file_handle_t *) cb_state->extra;
+
+ if (!ret) {
+ return SWITCH_STATUS_FALSE;
+ }
+
if (!strncasecmp(ret, "speed", 4)) {
char *p;
@@ -111,6 +120,8 @@
switch_set_flag(fh, SWITCH_FILE_PAUSE);
}
return SWITCH_STATUS_SUCCESS;
+ } else if (!strcasecmp(ret, "stop")) {
+ return SWITCH_STATUS_FALSE;
} else if (!strcasecmp(ret, "restart")) {
unsigned int pos = 0;
fh->speed = 0;
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp Thu May 17 19:01:23 2007
@@ -2927,13 +2927,17 @@
result = PyEval_CallObject(func, arglist);
threadState = PyEval_SaveThread();
+
Py_DECREF(arglist); // Trash arglist
- if (result) {
+ if (result && result != Py_None) {
resultStr = (char *) PyString_AsString(result);
+ Py_XDECREF(result);
+ return process_callback_result(resultStr, cb_state, session);
+ }
+ else {
+ return SWITCH_STATUS_FALSE;
}
- Py_XDECREF(result);
- return process_callback_result(resultStr, cb_state, session);
}
@@ -2946,6 +2950,11 @@
switch_file_handle_t *fh = NULL;
fh = (switch_file_handle_t *) cb_state->extra;
+
+ if (!ret) {
+ return SWITCH_STATUS_FALSE;
+ }
+
if (!strncasecmp(ret, "speed", 4)) {
char *p;
@@ -2973,6 +2982,10 @@
switch_set_flag(fh, SWITCH_FILE_PAUSE);
}
return SWITCH_STATUS_SUCCESS;
+ } else if (!strcasecmp(ret, "stop")) {
+ return SWITCH_STATUS_FALSE;
+ } else if (!strcasecmp(ret, "hangup")) {
+ return SWITCH_STATUS_BREAK;
} else if (!strcasecmp(ret, "restart")) {
unsigned int pos = 0;
fh->speed = 0;
@@ -4672,30 +4685,6 @@
}
-SWIGINTERN PyObject *_wrap_PySession_set_dtmf_callback(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
- PyObject *resultobj = 0;
- PySession *arg1 = (PySession *) 0 ;
- PyObject *arg2 = (PyObject *) 0 ;
- void *argp1 = 0 ;
- int res1 = 0 ;
- PyObject * obj0 = 0 ;
- PyObject * obj1 = 0 ;
-
- if (!PyArg_ParseTuple(args,(char *)"OO:PySession_set_dtmf_callback",&obj0,&obj1)) SWIG_fail;
- res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_PySession, 0 | 0 );
- if (!SWIG_IsOK(res1)) {
- SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "PySession_set_dtmf_callback" "', argument " "1"" of type '" "PySession *""'");
- }
- arg1 = reinterpret_cast< PySession * >(argp1);
- arg2 = obj1;
- (arg1)->set_dtmf_callback(arg2);
- resultobj = SWIG_Py_Void();
- return resultobj;
-fail:
- return NULL;
-}
-
-
SWIGINTERN PyObject *_wrap_PySession_begin_allow_threads(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
PySession *arg1 = (PySession *) 0 ;
@@ -4789,7 +4778,6 @@
{ (char *)"new_PySession", _wrap_new_PySession, METH_VARARGS, NULL},
{ (char *)"delete_PySession", _wrap_delete_PySession, METH_VARARGS, NULL},
{ (char *)"PySession_streamfile", _wrap_PySession_streamfile, METH_VARARGS, NULL},
- { (char *)"PySession_set_dtmf_callback", _wrap_PySession_set_dtmf_callback, METH_VARARGS, NULL},
{ (char *)"PySession_begin_allow_threads", _wrap_PySession_begin_allow_threads, METH_VARARGS, NULL},
{ (char *)"PySession_end_allow_threads", _wrap_PySession_end_allow_threads, METH_VARARGS, NULL},
{ (char *)"PySession_swigregister", PySession_swigregister, METH_VARARGS, NULL},
1
0
[commit] r5202 - in freeswitch/branches/greenlizard/src: . include mod/formats/mod_shout mod/languages/mod_python
by Freeswitch SVN 17 May '07
by Freeswitch SVN 17 May '07
17 May '07
Author: greenlizard
Date: Thu May 17 14:34:07 2007
New Revision: 5202
Modified:
freeswitch/branches/greenlizard/src/include/switch_cpp.h
freeswitch/branches/greenlizard/src/mod/formats/mod_shout/mod_shout.c
freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py
freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp
freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h
freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp
freeswitch/branches/greenlizard/src/switch_cpp.cpp
Log:
Sync up changes from trunk version 5186 to 5202. streamfile method is working for mod_python now
Modified: freeswitch/branches/greenlizard/src/include/switch_cpp.h
==============================================================================
--- freeswitch/branches/greenlizard/src/include/switch_cpp.h (original)
+++ freeswitch/branches/greenlizard/src/include/switch_cpp.h Thu May 17 14:34:07 2007
@@ -44,6 +44,7 @@
int playAndGetDigits(int min_digits, int max_digits, int max_tries, int timeout, char *terminators,
char *audio_files, char *bad_input_audio_files, char *dtmf_buf,
char *digits_regex);
+ int streamfile(char *file, void *cb_func, char *funcargs, int starting_sample_count);
void execute(char *app, char *data);
void begin_allow_threads();
void end_allow_threads();
Modified: freeswitch/branches/greenlizard/src/mod/formats/mod_shout/mod_shout.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/formats/mod_shout/mod_shout.c (original)
+++ freeswitch/branches/greenlizard/src/mod/formats/mod_shout/mod_shout.c Thu May 17 14:34:07 2007
@@ -271,7 +271,8 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decoder Error!\n");
}
dlen = 0;
- continue;
+ //continue;
+ goto error;
}
context->mp3err = 0;
@@ -728,7 +729,11 @@
} else if (context->fp) {
*cur_sample = fseek(context->fp, *cur_sample, whence);
}
+
+ ExitMP3(&context->mp);
+ InitMP3(&context->mp, OUTSCALE, context->samplerate);
switch_buffer_zero(context->audio_buffer);
+
} else {
context->err++;
}
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py Thu May 17 14:34:07 2007
@@ -77,6 +77,7 @@
def getDigits(*args): return _freeswitch.CoreSession_getDigits(*args)
def transfer(*args): return _freeswitch.CoreSession_transfer(*args)
def playAndGetDigits(*args): return _freeswitch.CoreSession_playAndGetDigits(*args)
+ def streamfile(*args): return _freeswitch.CoreSession_streamfile(*args)
def execute(*args): return _freeswitch.CoreSession_execute(*args)
def begin_allow_threads(*args): return _freeswitch.CoreSession_begin_allow_threads(*args)
def end_allow_threads(*args): return _freeswitch.CoreSession_end_allow_threads(*args)
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp Thu May 17 14:34:07 2007
@@ -14,25 +14,16 @@
}
}
-int PySession::streamfile(char *file, PyObject *pyfunc, PyObject *funcargs, int starting_sample_count)
+int PySession::streamfile(char *file, PyObject *pyfunc, char *funcargs, int starting_sample_count)
{
- // TODO: callback_args is currently ignored
- // NOTE: funcargs is expected to contain a string
-
switch_status_t status;
switch_input_args_t args = { 0 }, *ap = NULL;
struct input_callback_state cb_state = { 0 };
switch_file_handle_t fh = { 0 };
- char *s;
sanity_check(-1);
- if (PyArg_ParseTuple(funcargs, "s", &s)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "funcargs: %s.", s);
- cb_state.funcargs = s;
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "could not get funcargs");
- }
+ cb_state.funcargs = funcargs;
+ fh.samples = starting_sample_count;
if (!PyCallable_Check(pyfunc)) {
dtmfCallbackFunction = NULL;
@@ -42,15 +33,13 @@
dtmfCallbackFunction = pyfunc;
}
- fh.samples = starting_sample_count;
-
if (dtmfCallbackFunction) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setting DTMF callback\n");
cb_state.function = dtmfCallbackFunction;
cb_state.extra = &fh;
args.buf = &cb_state;
args.buflen = sizeof(cb_state); // not sure what this is used for, copy mod_spidermonkey
- args.input_callback = PythonDTMFCallback; // defined in mod_python.i, will use stuff in cb_state
+ args.input_callback = PythonDTMFCallback; // defined in mod_python.i, will use ptrs in cb_state
ap = &args;
}
else {
@@ -65,7 +54,6 @@
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
-
}
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h Thu May 17 14:34:07 2007
@@ -41,7 +41,7 @@
PySession(char *uuid) : CoreSession(uuid) {};
PySession(switch_core_session_t *session) : CoreSession(session) {};
~PySession();
- int streamfile(char *file, PyObject *pyfunc, PyObject *funcargs, int starting_sample_count);
+ int streamfile(char *file, PyObject *pyfunc, char *funcargs, int starting_sample_count);
void set_dtmf_callback(PyObject *pyfunc);
void begin_allow_threads();
void end_allow_threads();
Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp (original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp Thu May 17 14:34:07 2007
@@ -4039,6 +4039,68 @@
}
+SWIGINTERN PyObject *_wrap_CoreSession_streamfile(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+ PyObject *resultobj = 0;
+ CoreSession *arg1 = (CoreSession *) 0 ;
+ char *arg2 = (char *) 0 ;
+ void *arg3 = (void *) 0 ;
+ char *arg4 = (char *) 0 ;
+ int arg5 ;
+ int result;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ int res2 ;
+ char *buf2 = 0 ;
+ int alloc2 = 0 ;
+ int res3 ;
+ int res4 ;
+ char *buf4 = 0 ;
+ int alloc4 = 0 ;
+ int val5 ;
+ int ecode5 = 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+ PyObject * obj2 = 0 ;
+ PyObject * obj3 = 0 ;
+ PyObject * obj4 = 0 ;
+
+ if (!PyArg_ParseTuple(args,(char *)"OOOOO:CoreSession_streamfile",&obj0,&obj1,&obj2,&obj3,&obj4)) SWIG_fail;
+ res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_streamfile" "', argument " "1"" of type '" "CoreSession *""'");
+ }
+ arg1 = reinterpret_cast< CoreSession * >(argp1);
+ res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
+ if (!SWIG_IsOK(res2)) {
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_streamfile" "', argument " "2"" of type '" "char *""'");
+ }
+ arg2 = buf2;
+ res3 = SWIG_ConvertPtr(obj2,SWIG_as_voidptrptr(&arg3), 0, 0);
+ if (!SWIG_IsOK(res3)) {
+ SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_streamfile" "', argument " "3"" of type '" "void *""'");
+ }
+ res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4);
+ if (!SWIG_IsOK(res4)) {
+ SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "CoreSession_streamfile" "', argument " "4"" of type '" "char *""'");
+ }
+ arg4 = buf4;
+ ecode5 = SWIG_AsVal_int(obj4, &val5);
+ if (!SWIG_IsOK(ecode5)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "CoreSession_streamfile" "', argument " "5"" of type '" "int""'");
+ }
+ arg5 = static_cast< int >(val5);
+ result = (int)(arg1)->streamfile(arg2,arg3,arg4,arg5);
+ resultobj = SWIG_From_int(static_cast< int >(result));
+ if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+ if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
+ return resultobj;
+fail:
+ if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+ if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
+ return NULL;
+}
+
+
SWIGINTERN PyObject *_wrap_CoreSession_execute(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
CoreSession *arg1 = (CoreSession *) 0 ;
@@ -4557,7 +4619,7 @@
PySession *arg1 = (PySession *) 0 ;
char *arg2 = (char *) 0 ;
PyObject *arg3 = (PyObject *) 0 ;
- PyObject *arg4 = (PyObject *) 0 ;
+ char *arg4 = (char *) 0 ;
int arg5 ;
int result;
void *argp1 = 0 ;
@@ -4565,6 +4627,9 @@
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
+ int res4 ;
+ char *buf4 = 0 ;
+ int alloc4 = 0 ;
int val5 ;
int ecode5 = 0 ;
PyObject * obj0 = 0 ;
@@ -4585,7 +4650,11 @@
}
arg2 = buf2;
arg3 = obj2;
- arg4 = obj3;
+ res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4);
+ if (!SWIG_IsOK(res4)) {
+ SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "PySession_streamfile" "', argument " "4"" of type '" "char *""'");
+ }
+ arg4 = buf4;
ecode5 = SWIG_AsVal_int(obj4, &val5);
if (!SWIG_IsOK(ecode5)) {
SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "PySession_streamfile" "', argument " "5"" of type '" "int""'");
@@ -4594,9 +4663,11 @@
result = (int)(arg1)->streamfile(arg2,arg3,arg4,arg5);
resultobj = SWIG_From_int(static_cast< int >(result));
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+ if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
return resultobj;
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+ if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
return NULL;
}
@@ -4698,6 +4769,7 @@
{ (char *)"CoreSession_getDigits", _wrap_CoreSession_getDigits, METH_VARARGS, NULL},
{ (char *)"CoreSession_transfer", _wrap_CoreSession_transfer, METH_VARARGS, NULL},
{ (char *)"CoreSession_playAndGetDigits", _wrap_CoreSession_playAndGetDigits, METH_VARARGS, NULL},
+ { (char *)"CoreSession_streamfile", _wrap_CoreSession_streamfile, METH_VARARGS, NULL},
{ (char *)"CoreSession_execute", _wrap_CoreSession_execute, METH_VARARGS, NULL},
{ (char *)"CoreSession_begin_allow_threads", _wrap_CoreSession_begin_allow_threads, METH_VARARGS, NULL},
{ (char *)"CoreSession_end_allow_threads", _wrap_CoreSession_end_allow_threads, METH_VARARGS, NULL},
Modified: freeswitch/branches/greenlizard/src/switch_cpp.cpp
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_cpp.cpp (original)
+++ freeswitch/branches/greenlizard/src/switch_cpp.cpp Thu May 17 14:34:07 2007
@@ -171,6 +171,10 @@
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
+int CoreSession::streamfile(char *file, void *cb_func, char *funcargs, int starting_sample_count) {
+ return 0;
+}
+
void CoreSession::begin_allow_threads() {
}
1
0