[asterisk-commits] seanbright: branch seanbright/resolve-shadow-warnings r123107 - in /team/sean...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 16 13:31:56 CDT 2008


Author: seanbright
Date: Mon Jun 16 13:31:54 2008
New Revision: 123107

URL: http://svn.digium.com/view/asterisk?view=rev&rev=123107
Log:
Merged revisions 122766,122802,122834,122870,122920,122923,122926,122928,122977,123009,123041,123044,123076 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r122766 | tilghman | 2008-06-13 18:52:20 -0400 (Fri, 13 Jun 2008) | 2 lines

Document the input for ast_realtime_require_field()

................
r122802 | tilghman | 2008-06-15 11:21:16 -0400 (Sun, 15 Jun 2008) | 8 lines

Add some more IAX2-specific information about the channel to the CHANNEL()
function and begin the transition from SIPCHANINFO() to just using CHANNEL().
(closes issue #12856)
 Reported by: mostyn
 Patches: 
       iax_and_sip_channel_info.patch uploaded by mostyn (license 398)
       (with some additional cleanup by me)

................
r122834 | seanbright | 2008-06-15 23:33:03 -0400 (Sun, 15 Jun 2008) | 1 line

Resurrected app_fax
................
r122870 | file | 2008-06-16 08:09:54 -0400 (Mon, 16 Jun 2008) | 14 lines

Merged revisions 122869 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r122869 | file | 2008-06-16 09:08:28 -0300 (Mon, 16 Jun 2008) | 6 lines

Don't send a BYE on a dialog that is already gone during a REFER.
(closes issue #12865)
Reported by: flefoll
Patches:
      chan_sip.c.br14.121495.patch-ALREADYGONE uploaded by flefoll (license 244)

........

................
r122920 | file | 2008-06-16 08:32:02 -0400 (Mon, 16 Jun 2008) | 14 lines

Merged revisions 122919 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r122919 | file | 2008-06-16 09:31:09 -0300 (Mon, 16 Jun 2008) | 6 lines

Only compare the first 15 characters so that even if the charset is specified we still accept it as SDP.
(closes issue #12803)
Reported by: lanzaandrea
Patches:
      chan_sip.c.diff uploaded by lanzaandrea (license 496)

........

................
r122923 | russell | 2008-06-16 08:48:11 -0400 (Mon, 16 Jun 2008) | 5 lines

 - Fix a typo in a timing API call
 - Convert the last part of channel.c over to use the timing API.  This would
   not have made a difference when using the dahdi timing module.  I noticed
   it when trying to use another timing source.  Oops.  :)

................
r122926 | russell | 2008-06-16 09:03:40 -0400 (Mon, 16 Jun 2008) | 4 lines

Add a "timing test" CLI command.  It opens a timer and configures it for
50 ticks per second, and then counts to see how many ticks it actually
gets in a second.

................
r122928 | russell | 2008-06-16 09:08:13 -0400 (Mon, 16 Jun 2008) | 11 lines

Merge res_timing_pthread.  This is a timing interface for Asterisk that
does not require DAHDI.  It's called "pthread" because it uses a pthread
API call in the timing thread for sleeping and ensuring we wake up at
an appropriate time.  I wasn't sure what else to call it.  :)

The timing API requires a file descriptor that can be polled on.  So,
when you open a timer, this module creates a pipe and returns the read
end of the pipe.  There is a background thread that wakes up every 10ms
and checks to see if any of the currently open timers need a 'tick' and
writes to the appropriate pipe.

................
r122977 | russell | 2008-06-16 09:31:36 -0400 (Mon, 16 Jun 2008) | 2 lines

Note that only one timing interface should get loaded.

................
r123009 | seanbright | 2008-06-16 11:25:03 -0400 (Mon, 16 Jun 2008) | 1 line

Coding guidelines stuff only.
................
r123041 | seanbright | 2008-06-16 12:29:18 -0400 (Mon, 16 Jun 2008) | 1 line

Remove some unused variables
................
r123044 | seanbright | 2008-06-16 13:14:11 -0400 (Mon, 16 Jun 2008) | 1 line

Convert to use stringfields.  Still some more work to do on config load/reload.
................
r123076 | seanbright | 2008-06-16 13:33:10 -0400 (Mon, 16 Jun 2008) | 1 line

Last commit for a bit, minor cleanups and move the lock initialization.
................

Added:
    team/seanbright/resolve-shadow-warnings/apps/app_fax.c
      - copied unchanged from r123076, trunk/apps/app_fax.c
    team/seanbright/resolve-shadow-warnings/res/res_timing_pthread.c
      - copied, changed from r123076, trunk/res/res_timing_pthread.c
Modified:
    team/seanbright/resolve-shadow-warnings/   (props changed)
    team/seanbright/resolve-shadow-warnings/UPGRADE.txt
    team/seanbright/resolve-shadow-warnings/cdr/cdr_tds.c
    team/seanbright/resolve-shadow-warnings/channels/chan_iax2.c
    team/seanbright/resolve-shadow-warnings/channels/chan_sip.c
    team/seanbright/resolve-shadow-warnings/configs/modules.conf.sample
    team/seanbright/resolve-shadow-warnings/funcs/func_channel.c
    team/seanbright/resolve-shadow-warnings/include/asterisk/_private.h
    team/seanbright/resolve-shadow-warnings/include/asterisk/config.h
    team/seanbright/resolve-shadow-warnings/include/asterisk/timing.h
    team/seanbright/resolve-shadow-warnings/main/asterisk.c
    team/seanbright/resolve-shadow-warnings/main/channel.c
    team/seanbright/resolve-shadow-warnings/main/timing.c

Propchange: team/seanbright/resolve-shadow-warnings/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Propchange: team/seanbright/resolve-shadow-warnings/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Jun 16 13:31:54 2008
@@ -1,1 +1,1 @@
-/trunk:1-122717
+/trunk:1-123077

Modified: team/seanbright/resolve-shadow-warnings/UPGRADE.txt
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/UPGRADE.txt?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/UPGRADE.txt (original)
+++ team/seanbright/resolve-shadow-warnings/UPGRADE.txt Mon Jun 16 13:31:54 2008
@@ -181,6 +181,9 @@
 	sip:defaultuser at defaultip
   The "username" setting still work, but is deprecated and will not work in 
   the next version of Asterisk.
+* SIP: All of the functionality in SIPCHANINFO() has been implemented in CHANNEL(),
+  and you should start using that function instead for retrieving information about
+  the channel in a technology-agnostic way.
 
 * chan_local.c: the comma delimiter inside the channel name has been changed to a
   semicolon, in order to make the Local channel driver compatible with the comma

Modified: team/seanbright/resolve-shadow-warnings/cdr/cdr_tds.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/cdr/cdr_tds.c?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/cdr/cdr_tds.c (original)
+++ team/seanbright/resolve-shadow-warnings/cdr/cdr_tds.c Mon Jun 16 13:31:54 2008
@@ -84,22 +84,32 @@
 static char *name = "mssql";
 static char *config = "cdr_tds.conf";
 
-static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *charset = NULL, *language = NULL;
-static char *table = NULL;
-
-static int connected = 0;
-
-AST_MUTEX_DEFINE_STATIC(tds_lock);
-
-static TDSSOCKET *tds;
-static TDSLOGIN *login;
-static TDSCONTEXT *context;
+struct cdr_tds_config {
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(hostname);
+		AST_STRING_FIELD(dbname);
+		AST_STRING_FIELD(dbuser);
+		AST_STRING_FIELD(password);
+		AST_STRING_FIELD(table);
+		AST_STRING_FIELD(charset);
+		AST_STRING_FIELD(language);
+	);
+	TDSSOCKET *tds;
+	TDSLOGIN *login;
+	TDSCONTEXT *context;
+	unsigned int connected:1;
+	ast_mutex_t lock;
+};
+
+static struct cdr_tds_config *settings;
 
 static char *anti_injection(const char *, int);
 static void get_date(char *, struct timeval);
 
 static int mssql_connect(void);
 static int mssql_disconnect(void);
+
+static void cdr_tds_config_destroy(void);
 
 static int tds_log(struct ast_cdr *cdr)
 {
@@ -111,7 +121,7 @@
 	TDS_INT result_type;
 #endif
 
-	ast_mutex_lock(&tds_lock);
+	ast_mutex_lock(&settings->lock);
 
 	memset(sqlcmd, 0, 2048);
 
@@ -172,7 +182,7 @@
 			"'%s', "	/* amaflags */
 			"'%s'"		/* uniqueid */
 		")",
-		table,
+		settings->table,
 		accountcode,
 		src,
 		dst,
@@ -193,7 +203,7 @@
 	);
 
 	do {
-		if (!connected) {
+		if (!settings->connected) {
 			if (mssql_connect())
 				ast_log(LOG_ERROR, "Failed to reconnect to SQL database.\n");
 			else
@@ -203,16 +213,16 @@
 		}
 
 #ifdef FREETDS_PRE_0_62
-		if (!connected || (tds_submit_query(tds, sqlcmd) != TDS_SUCCEED) || (tds_process_simple_query(tds, &result_type) != TDS_SUCCEED || result_type != TDS_CMD_SUCCEED))
+		if (!settings->connected || (tds_submit_query(settings->tds, sqlcmd) != TDS_SUCCEED) || (tds_process_simple_query(settings->tds, &result_type) != TDS_SUCCEED || result_type != TDS_CMD_SUCCEED))
 #else
-		if (!connected || (tds_submit_query(tds, sqlcmd) != TDS_SUCCEED) || (tds_process_simple_query(tds) != TDS_SUCCEED))
+		if (!settings->connected || (tds_submit_query(settings->tds, sqlcmd) != TDS_SUCCEED) || (tds_process_simple_query(settings->tds) != TDS_SUCCEED))
 #endif
 		{
 			ast_log(LOG_ERROR, "Failed to insert Call Data Record into SQL database.\n");
 
 			mssql_disconnect();	/* this is ok even if we are already disconnected */
 		}
-	} while (!connected && !retried);
+	} while (!settings->connected && !retried);
 
 	ast_free(accountcode);
 	ast_free(src);
@@ -225,7 +235,7 @@
 	ast_free(lastdata);
 	ast_free(uniqueid);
 
-	ast_mutex_unlock(&tds_lock);
+	ast_mutex_unlock(&settings->lock);
 
 	return res;
 }
@@ -233,36 +243,31 @@
 static char *anti_injection(const char *str, int len)
 {
 	/* Reference to http://www.nextgenss.com/papers/advanced_sql_injection.pdf */
-
 	char *buf;
 	char *buf_ptr, *srh_ptr;
 	char *known_bad[] = {"select", "insert", "update", "delete", "drop", ";", "--", "\0"};
 	int idx;
 
-	if ((buf = ast_malloc(len + 1)) == NULL)
-	{
-		ast_log(LOG_ERROR, "cdr_tds:  Out of memory error\n");
+	if (!(buf = ast_calloc(1, len + 1))) {
+		ast_log(LOG_ERROR, "Out of memory\n");
 		return NULL;
 	}
-	memset(buf, 0, len);
 
 	buf_ptr = buf;
 
 	/* Escape single quotes */
-	for (; *str && strlen(buf) < len; str++)
-	{
-		if (*str == '\'')
+	for (; *str && strlen(buf) < len; str++) {
+		if (*str == '\'') {
 			*buf_ptr++ = '\'';
+		}
 		*buf_ptr++ = *str;
 	}
 	*buf_ptr = '\0';
 
 	/* Erase known bad input */
-	for (idx=0; *known_bad[idx]; idx++)
-	{
-		while((srh_ptr = strcasestr(buf, known_bad[idx])))
-		{
-			memmove(srh_ptr, srh_ptr+strlen(known_bad[idx]), strlen(srh_ptr+strlen(known_bad[idx]))+1);
+	for (idx = 0; *known_bad[idx]; idx++) {
+		while ((srh_ptr = strcasestr(buf, known_bad[idx]))) {
+			memmove(srh_ptr, srh_ptr + strlen(known_bad[idx]), strlen(srh_ptr + strlen(known_bad[idx])) + 1);
 		}
 	}
 
@@ -275,36 +280,33 @@
 	char buf[80];
 
 	/* To make sure we have date variable if not insert null to SQL */
-	if (!ast_tvzero(calldate))
-	{
+	if (!ast_tvzero(tv)) {
 		ast_localtime(&calldate, &tm, NULL);
 		ast_strftime(buf, 80, DATE_FORMAT, &tm);
 		sprintf(dateField, "'%s'", buf);
-	}
-	else
-	{
+	} else {
 		strcpy(dateField, "null");
 	}
 }
 
 static int mssql_disconnect(void)
 {
-	if (tds) {
-		tds_free_socket(tds);
-		tds = NULL;
-	}
-
-	if (context) {
-		tds_free_context(context);
-		context = NULL;
-	}
-
-	if (login) {
-		tds_free_login(login);
-		login = NULL;
-	}
-
-	connected = 0;
+	if (settings->tds) {
+		tds_free_socket(settings->tds);
+		settings->tds = NULL;
+	}
+
+	if (settings->context) {
+		tds_free_context(settings->context);
+		settings->context = NULL;
+	}
+
+	if (settings->login) {
+		tds_free_login(settings->login);
+		settings->login = NULL;
+	}
+
+	settings->connected = 0;
 
 	return 0;
 }
@@ -319,51 +321,48 @@
 	char query[128];
 
 	/* Connect to M$SQL Server */
-	if (!(login = tds_alloc_login()))
-	{
+	if (!(settings->login = tds_alloc_login())) {
 		ast_log(LOG_ERROR, "tds_alloc_login() failed.\n");
 		return -1;
 	}
-	
-	tds_set_server(login, hostname);
-	tds_set_user(login, dbuser);
-	tds_set_passwd(login, password);
-	tds_set_app(login, "TSQL");
-	tds_set_library(login, "TDS-Library");
+
+	tds_set_server(settings->login, settings->hostname);
+	tds_set_user(settings->login, settings->dbuser);
+	tds_set_passwd(settings->login, settings->password);
+	tds_set_app(settings->login, "TSQL");
+	tds_set_library(settings->login, "TDS-Library");
 #ifndef FREETDS_PRE_0_62
-	tds_set_client_charset(login, charset);
-#endif
-	tds_set_language(login, language);
-	tds_set_packet(login, 512);
-	tds_set_version(login, 7, 0);
+	tds_set_client_charset(settings->login, settings->charset);
+#endif
+	tds_set_language(settings->login, settings->language);
+	tds_set_packet(settings->login, 512);
+	tds_set_version(settings->login, 7, 0);
 
 #ifdef FREETDS_0_64
-	if (!(context = tds_alloc_context(NULL)))
+	if (!(settings->context = tds_alloc_context(NULL)))
 #else
-	if (!(context = tds_alloc_context()))
+	if (!(settings->context = tds_alloc_context()))
 #endif
 	{
 		ast_log(LOG_ERROR, "tds_alloc_context() failed.\n");
 		goto connect_fail;
 	}
 
-	if (!(tds = tds_alloc_socket(context, 512))) {
+	if (!(settings->tds = tds_alloc_socket(settings->context, 512))) {
 		ast_log(LOG_ERROR, "tds_alloc_socket() failed.\n");
 		goto connect_fail;
 	}
 
-	tds_set_parent(tds, NULL);
-	connection = tds_read_config_info(tds, login, context->locale);
-	if (!connection)
-	{
+	tds_set_parent(settings->tds, NULL);
+	connection = tds_read_config_info(settings->tds, settings->login, settings->context->locale);
+	if (!connection) {
 		ast_log(LOG_ERROR, "tds_read_config() failed.\n");
 		goto connect_fail;
 	}
 
-	if (tds_connect(tds, connection) == TDS_FAIL)
-	{
+	if (tds_connect(settings->tds, connection) == TDS_FAIL) {
 		ast_log(LOG_ERROR, "Failed to connect to MSSQL server.\n");
-		tds = NULL;	/* freed by tds_connect() on error */
+		settings->tds = NULL;	/* freed by tds_connect() on error */
 #if (defined(FREETDS_0_63) || defined(FREETDS_0_64))
 		tds_free_connection(connection);
 #else
@@ -379,18 +378,18 @@
 #endif
 	connection = NULL;
 
-	sprintf(query, "USE %s", dbname);
+	sprintf(query, "USE %s", settings->dbname);
 #ifdef FREETDS_PRE_0_62
-	if ((tds_submit_query(tds, query) != TDS_SUCCEED) || (tds_process_simple_query(tds, &result_type) != TDS_SUCCEED || result_type != TDS_CMD_SUCCEED))
+	if ((tds_submit_query(settings->tds, query) != TDS_SUCCEED) || (tds_process_simple_query(settings->tds, &result_type) != TDS_SUCCEED || result_type != TDS_CMD_SUCCEED))
 #else
-	if ((tds_submit_query(tds, query) != TDS_SUCCEED) || (tds_process_simple_query(tds) != TDS_SUCCEED))
+	if ((tds_submit_query(settings->tds, query) != TDS_SUCCEED) || (tds_process_simple_query(settings->tds) != TDS_SUCCEED))
 #endif
 	{
-		ast_log(LOG_ERROR, "Could not change database (%s)\n", dbname);
+		ast_log(LOG_ERROR, "Could not change database (%s)\n", settings->dbname);
 		goto connect_fail;
 	}
 
-	connected = 1;
+	settings->connected = 1;
 	return 0;
 
 connect_fail:
@@ -398,37 +397,34 @@
 	return -1;
 }
 
+static void cdr_tds_config_destroy(void)
+{
+	ast_mutex_destroy(&settings->lock);
+	ast_string_field_free_memory(settings);
+	ast_free(settings);	
+}
+
 static int tds_unload_module(void)
 {
 	mssql_disconnect();
 
 	ast_cdr_unregister(name);
 
-	if (hostname) ast_free(hostname);
-	if (dbname) ast_free(dbname);
-	if (dbuser) ast_free(dbuser);
-	if (password) ast_free(password);
-	if (charset) ast_free(charset);
-	if (language) ast_free(language);
-	if (table) ast_free(table);
+	cdr_tds_config_destroy();
 
 	return 0;
 }
 
 static int tds_load_module(int reload)
 {
-	int res = 0;
 	struct ast_config *cfg;
 	struct ast_variable *var;
 	const char *ptr = NULL;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
-#ifdef FREETDS_PRE_0_62
-	TDS_INT result_type;
-#endif
 
 	cfg = ast_config_load(config, config_flags);
 	if (!cfg) {
-		ast_log(LOG_NOTICE, "Unable to load config for MSSQL CDR's: %s\n", config);
+		ast_log(LOG_NOTICE, "Unable to load config for MSSQL CDRs: %s\n", config);
 		return 0;
 	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
 		return 0;
@@ -438,72 +434,82 @@
 		ast_config_destroy(cfg);
 		return 0;
 	}
-	
+
+	if (reload) {
+		ast_string_field_init(settings, 0);
+	} else {
+		settings = ast_calloc(1, sizeof(*settings));
+
+		if (!settings || ast_string_field_init(settings, 256)) {
+			if (settings) {
+				ast_free(settings);
+				settings = NULL;
+			}
+			ast_config_destroy(cfg);
+			return 0;
+		}
+
+		ast_mutex_init(&settings->lock);
+	}
+
 	ptr = ast_variable_retrieve(cfg, "global", "hostname");
 	if (ptr) {
-		if (hostname)
-			ast_free(hostname);
-		hostname = ast_strdup(ptr);
-	} else
+		ast_string_field_set(settings, hostname, ptr);
+	} else {
 		ast_log(LOG_ERROR, "Database server hostname not specified.\n");
+	}
 
 	ptr = ast_variable_retrieve(cfg, "global", "dbname");
 	if (ptr) {
-		if (dbname)
-			ast_free(dbname);
-		dbname = ast_strdup(ptr);
-	} else
+		ast_string_field_set(settings, dbname, ptr);
+	} else {
 		ast_log(LOG_ERROR, "Database dbname not specified.\n");
+	}
 
 	ptr = ast_variable_retrieve(cfg, "global", "user");
 	if (ptr) {
-		if (dbuser)
-			ast_free(dbuser);
-		dbuser = ast_strdup(ptr);
-	} else
+		ast_string_field_set(settings, dbuser, ptr);
+	} else {
 		ast_log(LOG_ERROR, "Database dbuser not specified.\n");
+	}
 
 	ptr = ast_variable_retrieve(cfg, "global", "password");
 	if (ptr) {
-		if (password)
-			ast_free(password);
-		password = ast_strdup(ptr);
-	} else
-		ast_log(LOG_ERROR,"Database password not specified.\n");
+		ast_string_field_set(settings, password, ptr);
+	} else {
+		ast_log(LOG_ERROR, "Database password not specified.\n");
+	}
 
 	ptr = ast_variable_retrieve(cfg, "global", "charset");
-	if (charset)
-		ast_free(charset);
-	if (ptr)
-		charset = ast_strdup(ptr);
-	else
-		charset = ast_strdup("iso_1");
-
-	if (language)
-		ast_free(language);
+	if (ptr) {
+		ast_string_field_set(settings, charset, ptr);
+	} else {
+		ast_string_field_set(settings, charset, "iso_1");
+	}
+
 	ptr = ast_variable_retrieve(cfg, "global", "language");
-	if (ptr)
-		language = ast_strdup(ptr);
-	else
-		language = ast_strdup("us_english");
+	if (ptr) {
+		ast_string_field_set(settings, language, ptr);
+	} else {
+		ast_string_field_set(settings, language, "us_english");
+	}
 
 	ptr = ast_variable_retrieve(cfg, "global", "table");
-	if (ptr == NULL) {
-		ast_debug(1, "cdr_tds: table not specified.  Assuming cdr\n");
-		ptr = "cdr";
-	}
-	if (table)
-		ast_free(table);
-	table = ast_strdup(ptr);
+	if (ptr) {
+		ast_string_field_set(settings, table, ptr);
+	} else {	
+		ast_debug(1, "Table not specified.  Assuming 'cdr'\n");
+		ast_string_field_set(settings, table, "cdr");
+	}
 
 	ast_config_destroy(cfg);
 
-	ast_mutex_lock(&tds_lock);
+	ast_mutex_lock(&settings->lock);
 	mssql_disconnect();
 	mssql_connect();
-	ast_mutex_unlock(&tds_lock);
-
-	return res;
+	ast_mutex_unlock(&settings->lock);
+
+	return 1;
 }
 
 static int reload(void)

Modified: team/seanbright/resolve-shadow-warnings/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/channels/chan_iax2.c?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/channels/chan_iax2.c (original)
+++ team/seanbright/resolve-shadow-warnings/channels/chan_iax2.c Mon Jun 16 13:31:54 2008
@@ -11750,10 +11750,15 @@
 		return -1;
 	}
 
-	if (!strcasecmp(args, "osptoken"))
+	if (!strcasecmp(args, "osptoken")) {
 		ast_copy_string(buf, pvt->osptoken, buflen);
-	else
+	} else if (!strcasecmp(args, "peerip")) {
+		ast_copy_string(buf, pvt->addr.sin_addr.s_addr ? ast_inet_ntoa(pvt->addr.sin_addr) : "", buflen);
+	} else if (!strcasecmp(args, "peername")) {
+		ast_copy_string(buf, pvt->username, buflen);
+	} else {
 		res = -1;
+	}
 
 	ast_mutex_unlock(&iaxsl[callno]);
 

Modified: team/seanbright/resolve-shadow-warnings/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/channels/chan_sip.c?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/channels/chan_sip.c (original)
+++ team/seanbright/resolve-shadow-warnings/channels/chan_sip.c Mon Jun 16 13:31:54 2008
@@ -3132,7 +3132,7 @@
 	if (p->owner) {
 		ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_methods[p->method].text);
 		ast_queue_hangup_with_cause(p->owner, AST_CAUSE_PROTOCOL_ERROR);
-	} else if (p->refer) {
+	} else if (p->refer && !p->alreadygone) {
 		ast_debug(3, "Finally hanging up channel after transfer: %s\n", p->callid);
 		transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
 		append_history(p, "ReferBYE", "Sending BYE on transferer call leg %s", p->callid);
@@ -6566,7 +6566,7 @@
 	content_type = get_header(req, "Content-Type");
 
 	/* if the body contains only SDP, this is easy */
-	if (!strcasecmp(content_type, "application/sdp")) {
+	if (!strncasecmp(content_type, "application/sdp", 15)) {
 		req->sdp_start = 0;
 		req->sdp_end = req->lines;
 		return req->lines ? 1 : 0;
@@ -15509,6 +15509,7 @@
 static int function_sipchaninfo_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
 	struct sip_pvt *p;
+	static int deprecated = 0;
 
 	*buf = 0;
 	
@@ -15522,6 +15523,11 @@
 		ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n");
 		ast_channel_unlock(chan);
 		return -1;
+	}
+
+	if (deprecated++ % 20 == 0) {
+		/* Deprecated in 1.6.1 */
+		ast_log(LOG_WARNING, "SIPCHANINFO() is deprecated.  Please transition to using CHANNEL().\n");
 	}
 
 	p = chan->tech_pvt;
@@ -18523,7 +18529,25 @@
 
 	memset(buf, 0, buflen);
 
-	if (!strcasecmp(args.param, "rtpdest")) {
+	if (!strcasecmp(args.param, "peerip")) {
+		ast_copy_string(buf, p->sa.sin_addr.s_addr ? ast_inet_ntoa(p->sa.sin_addr) : "", buflen);
+	} else if (!strcasecmp(args.param, "recvip")) {
+		ast_copy_string(buf, p->recv.sin_addr.s_addr ? ast_inet_ntoa(p->recv.sin_addr) : "", buflen);
+	} else if (!strcasecmp(args.param, "from")) {
+		ast_copy_string(buf, p->from, buflen);
+	} else if (!strcasecmp(args.param, "uri")) {
+		ast_copy_string(buf, p->uri, buflen);
+	} else if (!strcasecmp(args.param, "useragent")) {
+		ast_copy_string(buf, p->useragent, buflen);
+	} else if (!strcasecmp(args.param, "peername")) {
+		ast_copy_string(buf, p->peername, buflen);
+	} else if (!strcasecmp(args.param, "t38passthrough")) {
+		if (p->t38.state == T38_DISABLED) {
+			ast_copy_string(buf, "0", sizeof("0"));
+		} else {  /* T38 is offered or enabled in this call */
+			ast_copy_string(buf, "1", sizeof("1"));
+		}
+	} else if (!strcasecmp(args.param, "rtpdest")) {
 		struct sockaddr_in sin;
 
 		if (ast_strlen_zero(args.type))

Modified: team/seanbright/resolve-shadow-warnings/configs/modules.conf.sample
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/configs/modules.conf.sample?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/configs/modules.conf.sample (original)
+++ team/seanbright/resolve-shadow-warnings/configs/modules.conf.sample Mon Jun 16 13:31:54 2008
@@ -37,3 +37,10 @@
 noload => chan_alsa.so
 ;noload => chan_oss.so
 ;noload => chan_console.so
+;
+;
+; Only load one timing interface.  If DAHDI is available, use that as it will
+; provide the best results.
+; 
+;noload => res_timing_dahdi.so
+;noload => res_timing_pthread.so

Modified: team/seanbright/resolve-shadow-warnings/funcs/func_channel.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/funcs/func_channel.c?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/funcs/func_channel.c (original)
+++ team/seanbright/resolve-shadow-warnings/funcs/func_channel.c Mon Jun 16 13:31:54 2008
@@ -190,6 +190,13 @@
 #endif
 		"\n"
 		"chan_sip provides the following additional options:\n"
+		"R/O    peerip             Get the IP address of the peer\n"
+		"R/O    recvip             Get the source IP address of the peer\n"
+		"R/O    from               Get the URI from the From: header\n"
+		"R/O    uri                Get the URI from the Contact: header\n"
+		"R/O    useragent          Get the useragent\n"
+		"R/O    peername           Get the name of the peer\n"
+		"R/O    t38passthrough     1 if T38 is offered or enabled in this channel, otherwise 0\n"
 		"R/O    rtpqos             Get QOS information about the RTP stream\n"
 		"       This option takes two additional arguments:\n"
 		"  Argument 1:\n"
@@ -227,6 +234,8 @@
 		"\n"
 		"chan_iax2 provides the following additional options:\n"
 		"R/W    osptoken           Get or set the OSP token information for a call\n"
+		"R/O    peerip             Get the peer's ip address\n"
+		"R/O    peername           Get the peer's username\n"
 		"\n"
 		"Additional items may be available from the channel driver providing\n"
 		"the channel; see its documentation for details.\n"

Modified: team/seanbright/resolve-shadow-warnings/include/asterisk/_private.h
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/include/asterisk/_private.h?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/include/asterisk/_private.h (original)
+++ team/seanbright/resolve-shadow-warnings/include/asterisk/_private.h Mon Jun 16 13:31:54 2008
@@ -37,6 +37,7 @@
 int ast_http_init(void);		/*!< Provided by http.c */
 int ast_http_reload(void);		/*!< Provided by http.c */
 int ast_tps_init(void); 		/*!< Provided by taskprocessor.c */
+int ast_timing_init(void);		/*!< Provided by timing.c */
 
 /*!
  * \brief Reload asterisk modules.

Modified: team/seanbright/resolve-shadow-warnings/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/include/asterisk/config.h?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/include/asterisk/config.h (original)
+++ team/seanbright/resolve-shadow-warnings/include/asterisk/config.h Mon Jun 16 13:31:54 2008
@@ -227,8 +227,22 @@
  * exist in the backend.  The backends may take various actions, such as
  * creating new fields in the data store or warning the administrator that
  * new fields may need to be created, in order to ensure proper function.
- */
-int ast_require_realtime_fields(const char *family, ...) attribute_sentinel;
+ *
+ * The arguments are specified in groups of 3:  column name, column type,
+ * and column size.  The column types are specified as integer constants,
+ * defined by the enum require_type.  Note that the size is specified as
+ * the number of equivalent character fields that a field may take up, even
+ * if a field is otherwise specified as an integer type.  This is due to
+ * the fact that some fields have historically been specified as character
+ * types, even if they contained integer values.
+ *
+ * A family should always specify its fields to the minimum necessary
+ * requirements to fulfill all possible values (within reason; for example,
+ * a timeout value may reasonably be specified as an INTEGER2, with size 5.
+ * Even though values above 32767 seconds are possible, they are unlikely
+ * to be useful, and we should not complain about that size).
+ */
+int ast_realtime_require_field(const char *family, ...) attribute_sentinel;
 
 /*! 
  * \brief Retrieve realtime configuration 
@@ -276,8 +290,6 @@
  * \return 1 if family is configured in realtime and engine exists
 */
 int ast_check_realtime(const char *family);
-
-int ast_realtime_require_field(const char *family, ...) attribute_sentinel;
 
 /*! \brief Check if there's any realtime engines loaded */
 int ast_realtime_enabled(void);

Modified: team/seanbright/resolve-shadow-warnings/include/asterisk/timing.h
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/include/asterisk/timing.h?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/include/asterisk/timing.h (original)
+++ team/seanbright/resolve-shadow-warnings/include/asterisk/timing.h Mon Jun 16 13:31:54 2008
@@ -161,7 +161,7 @@
  * \retval -1 failure, with errno set
  * \retval 0 success
  */
-int ast_timer_disable_continous(int handle);
+int ast_timer_disable_continuous(int handle);
 
 /*!
  * \brief Determine timing event

Modified: team/seanbright/resolve-shadow-warnings/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/main/asterisk.c?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/main/asterisk.c (original)
+++ team/seanbright/resolve-shadow-warnings/main/asterisk.c Mon Jun 16 13:31:54 2008
@@ -3306,6 +3306,11 @@
 
 	ast_autoservice_init();
 
+	if (ast_timing_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
 	if (load_modules(1)) {		/* Load modules, pre-load only */
 		printf("%s", term_quit());
 		exit(1);

Modified: team/seanbright/resolve-shadow-warnings/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/main/channel.c?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/main/channel.c (original)
+++ team/seanbright/resolve-shadow-warnings/main/channel.c Mon Jun 16 13:31:54 2008
@@ -2407,26 +2407,17 @@
 		read(chan->alertpipe[0], &blah, sizeof(blah));
 	}
 
-#ifdef HAVE_DAHDI
-	if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD && ast_test_flag(chan, AST_FLAG_EXCEPTION)) {
-		int res;
+	if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD) {
+		enum ast_timing_event res;
 
 		ast_clear_flag(chan, AST_FLAG_EXCEPTION);
-		blah = -1;
-		/* IF we can't get event, assume it's an expired as-per the old interface */
-		res = ioctl(chan->timingfd, DAHDI_GETEVENT, &blah);
-		if (res)
-			blah = DAHDI_EVENT_TIMER_EXPIRED;
-
-		if (blah == DAHDI_EVENT_TIMER_PING) {
-			if (AST_LIST_EMPTY(&chan->readq) || !AST_LIST_NEXT(AST_LIST_FIRST(&chan->readq), frame_list)) {
-				/* Acknowledge PONG unless we need it again */
-				if (ioctl(chan->timingfd, DAHDI_TIMERPONG, &blah)) {
-					ast_log(LOG_WARNING, "Failed to pong timer on '%s': %s\n", chan->name, strerror(errno));
-				}
-			}
-		} else if (blah == DAHDI_EVENT_TIMER_EXPIRED) {
-			ioctl(chan->timingfd, DAHDI_TIMERACK, &blah);
+
+		res = ast_timer_get_event(chan->timingfd);
+
+		switch (res) {
+		case AST_TIMING_EVENT_EXPIRED:
+			ast_timer_ack(chan->timingfd, 1);
+
 			if (chan->timingfunc) {
 				/* save a copy of func/data before unlocking the channel */
 				int (*func)(const void *) = chan->timingfunc;
@@ -2434,18 +2425,22 @@
 				ast_channel_unlock(chan);
 				func(data);
 			} else {
-				blah = 0;
-				ioctl(chan->timingfd, DAHDI_TIMERCONFIG, &blah);
-				chan->timingdata = NULL;
+				ast_timer_set_rate(chan->timingfd, 0);
 				ast_channel_unlock(chan);
 			}
+
 			/* cannot 'goto done' because the channel is already unlocked */
 			return &ast_null_frame;
-		} else
-			ast_log(LOG_NOTICE, "No/unknown event '%d' on timer for '%s'?\n", blah, chan->name);
-	} else
-#endif
-	if (chan->fds[AST_GENERATOR_FD] > -1 && chan->fdno == AST_GENERATOR_FD) {
+
+		case AST_TIMING_EVENT_CONTINUOUS:
+			if (AST_LIST_EMPTY(&chan->readq) || 
+				!AST_LIST_NEXT(AST_LIST_FIRST(&chan->readq), frame_list)) {
+				ast_timer_disable_continuous(chan->timingfd);
+			}
+			break;
+		}
+
+	} else if (chan->fds[AST_GENERATOR_FD] > -1 && chan->fdno == AST_GENERATOR_FD) {
 		/* if the AST_GENERATOR_FD is set, call the generator with args
 		 * set to -1 so it can do whatever it needs to.
 		 */

Modified: team/seanbright/resolve-shadow-warnings/main/timing.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/main/timing.c?view=diff&rev=123107&r1=123106&r2=123107
==============================================================================
--- team/seanbright/resolve-shadow-warnings/main/timing.c (original)
+++ team/seanbright/resolve-shadow-warnings/main/timing.c Mon Jun 16 13:31:54 2008
@@ -27,8 +27,13 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
+#include "asterisk/_private.h"
+
 #include "asterisk/timing.h"
 #include "asterisk/lock.h"
+#include "asterisk/cli.h"
+#include "asterisk/utils.h"
+#include "asterisk/time.h"
 
 AST_RWLOCK_DEFINE_STATIC(lock);
 
@@ -157,7 +162,7 @@
 	return result;
 }
 
-int ast_timer_disable_continous(int handle)
+int ast_timer_disable_continuous(int handle)
 {
 	int result;
 
@@ -192,3 +197,64 @@
 
 	return result;
 }
+
+static char *timing_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int fd, count = 0;
+	struct timeval start, end;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "timing test";
+		e->usage = "Usage: timing test\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	ast_cli(a->fd, "Attempting to test a timer with 50 ticks per second ...\n");
+
+	if ((fd = ast_timer_open()) == -1) {
+		ast_cli(a->fd, "Failed to open timing fd\n");
+		return CLI_FAILURE;
+	}
+
+	start = ast_tvnow();
+
+	ast_timer_set_rate(fd, 50);
+
+	while (ast_tvdiff_ms((end = ast_tvnow()), start) < 1000) {
+		int res;
+		struct pollfd pfd = {
+			.fd = fd,
+			.events = POLLIN | POLLPRI,
+		};
+
+		res = poll(&pfd, 1, 100);
+
+		if (res == 1) {
+			count++;
+			ast_timer_ack(fd, 1);
+		} else if (!res) {
+			ast_cli(a->fd, "poll() timed out!  This is bad.\n");
+		} else if (errno != EAGAIN && errno != EINTR) {
+			ast_cli(a->fd, "poll() returned error: %s\n", strerror(errno));
+		}
+	}
+
+	ast_timer_close(fd);
+
+	ast_cli(a->fd, "It has been %d milliseconds, and we got %d timer ticks\n", 
+		ast_tvdiff_ms(end, start), count);
+
+	return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry cli_timing[] = {
+	AST_CLI_DEFINE(timing_test, "Run a timing test"),
+};
+
+int ast_timing_init(void)
+{
+	return ast_cli_register_multiple(cli_timing, ARRAY_LEN(cli_timing));
+}

Copied: team/seanbright/resolve-shadow-warnings/res/res_timing_pthread.c (from r123076, trunk/res/res_timing_pthread.c)
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/res/res_timing_pthread.c?view=diff&rev=123107&p1=trunk/res/res_timing_pthread.c&r1=123076&p2=team/seanbright/resolve-shadow-warnings/res/res_timing_pthread.c&r2=123107
==============================================================================
--- trunk/res/res_timing_pthread.c (original)
+++ team/seanbright/resolve-shadow-warnings/res/res_timing_pthread.c Mon Jun 16 13:31:54 2008
@@ -86,7 +86,7 @@
 };
 
 static void pthread_timer_destructor(void *obj);
-static struct pthread_timer *find_timer(int handle, int unlink);
+static struct pthread_timer *find_timer(int handle, int unlinkobj);
 static void write_byte(int wr_fd);
 static void read_pipe(int rd_fd, unsigned int num, int clear);
 
@@ -245,7 +245,7 @@
 	return res;
 }
 
-static struct pthread_timer *find_timer(int handle, int unlink)
+static struct pthread_timer *find_timer(int handle, int unlinkobj)
 {
 	struct pthread_timer *timer;
 	struct pthread_timer tmp_timer;
@@ -253,7 +253,7 @@
 
 	tmp_timer.pipe[PIPE_READ] = handle;
 
-	if (unlink) {
+	if (unlinkobj) {
 		flags |= OBJ_UNLINK;
 	}
 
@@ -338,7 +338,7 @@
 		unsigned char buf[1024];
 		ssize_t res;
 		fd_set rfds;
-		struct timeval tv = {
+		struct timeval timeout = {
 			.tv_sec = 0,
 		};
 
@@ -346,7 +346,7 @@
 		FD_ZERO(&rfds);
 		FD_SET(rd_fd, &rfds);
 
-		if (select(rd_fd + 1, &rfds, NULL, NULL, &tv) != 1) {
+		if (select(rd_fd + 1, &rfds, NULL, NULL, &timeout) != 1) {
 			break;
 		}
 




More information about the asterisk-commits mailing list