aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpcadach <pcadach@f38db490-d61c-443f-a65b-d21fe96a405b>2006-10-07 14:45:49 +0000
committerpcadach <pcadach@f38db490-d61c-443f-a65b-d21fe96a405b>2006-10-07 14:45:49 +0000
commitd2747c97ad264252b06ca01aa67bf314a0f3b822 (patch)
treeedf636fb3b4a73b2530dc5c6d62ceb0427adb945
parente9ae66821f212c77e4b89ff962ef59218666846d (diff)
Extend CALLERID() function for "pres" and "ton" values
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@44685 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--CHANGES3
-rw-r--r--funcs/func_callerid.c35
-rw-r--r--include/asterisk/callerid.h1
-rw-r--r--main/callerid.c20
4 files changed, 56 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 4625ee0c8..6cb3603c1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -37,3 +37,6 @@ Changes since Asterisk 1.4-beta was branched:
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.
diff --git a/funcs/func_callerid.c b/funcs/func_callerid.c
index 6068739d4..5af8e1ca1 100644
--- a/funcs/func_callerid.c
+++ b/funcs/func_callerid.c
@@ -87,6 +87,10 @@ static int callerid_read(struct ast_channel *chan, char *cmd, char *data,
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 @@ static int callerid_write(struct ast_channel *chan, char *cmd, char *data,
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 @@ static struct ast_custom_function callerid_function = {
.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,
diff --git a/include/asterisk/callerid.h b/include/asterisk/callerid.h
index 7347dd9d0..bf4030e15 100644
--- a/include/asterisk/callerid.h
+++ b/include/asterisk/callerid.h
@@ -311,6 +311,7 @@ static inline float callerid_getcarrier(float *cr, float *ci, int bit)
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
diff --git a/main/callerid.c b/main/callerid.c
index 98cb7d081..6bb916bf4 100644
--- a/main/callerid.c
+++ b/main/callerid.c
@@ -1048,8 +1048,8 @@ int ast_callerid_split(const char *buf, char *name, int namelen, char *num, int
/*! \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 @@ const char *ast_describe_caller_presentation(int data)
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";
+}