[asterisk-commits] pcadach: trunk r44685 - in /trunk: ./ funcs/ include/asterisk/ main/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Oct 7 07:45:50 MST 2006


Author: pcadach
Date: Sat Oct  7 09:45:49 2006
New Revision: 44685

URL: http://svn.digium.com/view/asterisk?rev=44685&view=rev
Log:
Extend CALLERID() function for "pres" and "ton" values

Modified:
    trunk/CHANGES
    trunk/funcs/func_callerid.c
    trunk/include/asterisk/callerid.h
    trunk/main/callerid.c

Modified: trunk/CHANGES
URL: http://svn.digium.com/view/asterisk/trunk/CHANGES?rev=44685&r1=44684&r2=44685&view=diff
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Sat Oct  7 09:45:49 2006
@@ -37,3 +37,6 @@
      Read() - timeout now can be floating pt.
      WaitForRing() now takes floating pt timeout arg.
      SpeechBackground() -- clarified in the docstrings that the timeout is an integer seconds.
+  * Extend CALLERID() function with "pres" and "ton" parameters to
+     fetch string representation of calling number presentation indicator
+     and numeric representation of type of calling number value.

Modified: trunk/funcs/func_callerid.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_callerid.c?rev=44685&r1=44684&r2=44685&view=diff
==============================================================================
--- trunk/funcs/func_callerid.c (original)
+++ trunk/funcs/func_callerid.c Sat Oct  7 09:45:49 2006
@@ -87,6 +87,10 @@
 			if (chan->cid.cid_rdnis) {
 				ast_copy_string(buf, chan->cid.cid_rdnis, len);
 			}
+		} else if (!strncasecmp("pres", data, 4)) {
+			ast_copy_string(buf, ast_named_caller_presentation(chan->cid.cid_pres), len);
+		} else if (!strncasecmp("ton", data, 3)) {
+			snprintf(buf, len, "%d", chan->cid.cid_ton);
 		} else {
 			ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
 		}
@@ -124,6 +128,34 @@
 		if (chan->cid.cid_rdnis)
 			free(chan->cid.cid_rdnis);
 		chan->cid.cid_rdnis = ast_strdup(value);
+	} else if (!strncasecmp("pres", data, 4)) {
+		int i;
+		char *s, *val;
+
+		/* Strip leading spaces */
+		while ((value[0] == '\t') || (value[0] == ' '))
+			++value;
+
+		val = ast_strdupa(value);
+
+		/* Strip trailing spaces */
+		s = val + strlen(val);
+		while ((s != val) && ((s[-1] == '\t') || (s[-1] == ' ')))
+			--s;
+		*s = '\0';
+
+		if ((val[0] >= '0') && (val[0] <= '9'))
+			i = atoi(val);
+		else
+			i = ast_parse_caller_presentation(val);
+
+		if (i < 0)
+			ast_log(LOG_ERROR, "Unknown calling number presentation '%s', value unchanged\n", val);
+		else
+			chan->cid.cid_pres = i;
+	} else if (!strncasecmp("ton", data, 3)) {
+		int i = atoi(value);
+		chan->cid.cid_ton = i;
 	} else {
 		ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
 	}
@@ -137,7 +169,8 @@
 	.syntax = "CALLERID(datatype[,<optional-CID>])",
 	.desc =
 		"Gets or sets Caller*ID data on the channel.  The allowable datatypes\n"
-		"are \"all\", \"name\", \"num\", \"ANI\", \"DNID\", \"RDNIS\".\n"
+		"are \"all\", \"name\", \"num\", \"ANI\", \"DNID\", \"RDNIS\", \"pres\",\n"
+		"and \"ton\".\n"
 		"Uses channel callerid by default or optional callerid, if specified.\n",
 	.read = callerid_read,
 	.write = callerid_write,

Modified: trunk/include/asterisk/callerid.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/callerid.h?rev=44685&r1=44684&r2=44685&view=diff
==============================================================================
--- trunk/include/asterisk/callerid.h (original)
+++ trunk/include/asterisk/callerid.h Sat Oct  7 09:45:49 2006
@@ -311,6 +311,7 @@
 
 int ast_parse_caller_presentation(const char *data);
 const char *ast_describe_caller_presentation(int data);
+const char *ast_named_caller_presentation(int data);
 
 /*! \page Def_CallerPres Caller ID Presentation
 

Modified: trunk/main/callerid.c
URL: http://svn.digium.com/view/asterisk/trunk/main/callerid.c?rev=44685&r1=44684&r2=44685&view=diff
==============================================================================
--- trunk/main/callerid.c (original)
+++ trunk/main/callerid.c Sat Oct  7 09:45:49 2006
@@ -1048,8 +1048,8 @@
 /*! \brief Translation table for Caller ID Presentation settings */
 static struct {
 	int val;
-	char *name;
-	char *description;
+	const char *name;
+	const char *description;
 } pres_types[] = {
 	{  AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, "allowed_not_screened", "Presentation Allowed, Not Screened"},
 	{  AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, "allowed_passed_screen", "Presentation Allowed, Passed Screen"},
@@ -1094,3 +1094,19 @@
 
 	return "unknown";
 }
+
+/*! \brief Convert caller ID pres value to text code
+	\param data text string
+	\return string for config file
+*/
+const char *ast_named_caller_presentation(int data)
+{
+	int i;
+
+	for (i = 0; i < ((sizeof(pres_types) / sizeof(pres_types[0]))); i++) {
+		if (pres_types[i].val == data)
+			return pres_types[i].name;
+	}
+
+	return "unknown";
+}



More information about the asterisk-commits mailing list