2005-05-15 17:45:30 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2005-05-15 17:45:30 +00:00
|
|
|
*
|
2006-02-12 04:28:58 +00:00
|
|
|
* Copyright (C) 1999-2006, Digium, Inc.
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
2005-05-15 17:45:30 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Caller ID related dialplan functions
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2007-01-24 09:05:29 +00:00
|
|
|
* \ingroup functions
|
2005-05-15 17:45:30 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-05-15 17:45:30 +00:00
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/app.h"
|
2005-07-25 18:34:40 +00:00
|
|
|
#include "asterisk/callerid.h"
|
2005-05-15 17:45:30 +00:00
|
|
|
|
2008-11-01 21:10:07 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<function name="CALLERID" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Gets or sets Caller*ID data on the channel.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="datatype" required="true">
|
|
|
|
<para>The allowable datatypes are:</para>
|
|
|
|
<enumlist>
|
|
|
|
<enum name="all" />
|
|
|
|
<enum name="num" />
|
|
|
|
<enum name="ANI" />
|
|
|
|
<enum name="DNID" />
|
|
|
|
<enum name="RDNIS" />
|
|
|
|
<enum name="pres" />
|
|
|
|
<enum name="ton" />
|
|
|
|
</enumlist>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="CID">
|
|
|
|
<para>Optional Caller*ID</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Gets or sets Caller*ID data on the channel. Uses channel callerid by default or optional
|
|
|
|
callerid, if specified.</para>
|
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
<function name="CALLERPRES" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Gets or sets Caller*ID presentation on the channel.
|
|
|
|
</synopsis>
|
|
|
|
<syntax />
|
|
|
|
<description>
|
|
|
|
<para>Gets or sets Caller*ID presentation on the channel. The following values
|
|
|
|
are valid:</para>
|
|
|
|
<enumlist>
|
|
|
|
<enum name="allowed_not_screened">
|
|
|
|
<para>Presentation Allowed, Not Screened.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="allowed_passed_screen">
|
|
|
|
<para>Presentation Allowed, Passed Screen.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="allowed_failed_screen">
|
|
|
|
<para>Presentation Allowed, Failed Screen.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="allowed">
|
|
|
|
<para>Presentation Allowed, Network Number.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="prohib_not_screened">
|
|
|
|
<para>Presentation Prohibited, Not Screened.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="prohib_passed_screen">
|
|
|
|
<para>Presentation Prohibited, Passed Screen.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="prohib_failed_screen">
|
|
|
|
<para>Presentation Prohibited, Failed Screen.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="prohib">
|
|
|
|
<para>Presentation Prohibited, Network Number.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="unavailable">
|
|
|
|
<para>Number Unavailable.</para>
|
|
|
|
</enum>
|
|
|
|
</enumlist>
|
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
***/
|
|
|
|
|
2007-02-03 22:05:02 +00:00
|
|
|
static int callerpres_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
ast_copy_string(buf, ast_named_caller_presentation(chan->cid.cid_pres), len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int callerpres_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
|
|
|
|
{
|
|
|
|
int pres = ast_parse_caller_presentation(value);
|
|
|
|
if (pres < 0)
|
|
|
|
ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show function CALLERPRES')\n", value);
|
|
|
|
else
|
|
|
|
chan->cid.cid_pres = pres;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-07 19:00:36 +00:00
|
|
|
static int callerid_read(struct ast_channel *chan, const char *cmd, char *data,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *buf, size_t len)
|
2005-05-15 17:45:30 +00:00
|
|
|
{
|
2005-12-23 21:03:25 +00:00
|
|
|
char *opt = data;
|
|
|
|
|
2008-10-07 02:02:39 +00:00
|
|
|
/* Ensure that the buffer is empty */
|
|
|
|
*buf = 0;
|
|
|
|
|
2007-04-19 02:51:21 +00:00
|
|
|
if (!chan)
|
|
|
|
return -1;
|
|
|
|
|
2007-07-23 19:51:41 +00:00
|
|
|
if (strchr(opt, ',')) {
|
2005-12-23 21:03:25 +00:00
|
|
|
char name[80], num[80];
|
|
|
|
|
2007-07-23 19:51:41 +00:00
|
|
|
data = strsep(&opt, ",");
|
2005-12-23 21:03:25 +00:00
|
|
|
ast_callerid_split(opt, name, sizeof(name), num, sizeof(num));
|
|
|
|
|
|
|
|
if (!strncasecmp("all", data, 3)) {
|
2006-02-12 04:28:58 +00:00
|
|
|
snprintf(buf, len, "\"%s\" <%s>", name, num);
|
2005-12-23 21:03:25 +00:00
|
|
|
} else if (!strncasecmp("name", data, 4)) {
|
|
|
|
ast_copy_string(buf, name, len);
|
2006-12-25 02:31:04 +00:00
|
|
|
} else if (!strncasecmp("num", data, 3)) {
|
2005-12-23 21:03:25 +00:00
|
|
|
ast_copy_string(buf, num, len);
|
|
|
|
} else {
|
2006-09-19 21:07:49 +00:00
|
|
|
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
|
2005-05-15 17:45:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-11-29 00:28:10 +00:00
|
|
|
ast_channel_lock(chan);
|
|
|
|
|
2005-12-23 21:03:25 +00:00
|
|
|
if (!strncasecmp("all", data, 3)) {
|
2006-02-12 04:28:58 +00:00
|
|
|
snprintf(buf, len, "\"%s\" <%s>",
|
2008-10-07 02:02:39 +00:00
|
|
|
S_OR(chan->cid.cid_name, ""),
|
|
|
|
S_OR(chan->cid.cid_num, ""));
|
2005-12-23 21:03:25 +00:00
|
|
|
} else if (!strncasecmp("name", data, 4)) {
|
|
|
|
if (chan->cid.cid_name) {
|
|
|
|
ast_copy_string(buf, chan->cid.cid_name, len);
|
|
|
|
}
|
2006-12-25 02:31:04 +00:00
|
|
|
} else if (!strncasecmp("num", data, 3)) {
|
2005-12-23 21:03:25 +00:00
|
|
|
if (chan->cid.cid_num) {
|
|
|
|
ast_copy_string(buf, chan->cid.cid_num, len);
|
|
|
|
}
|
|
|
|
} else if (!strncasecmp("ani", data, 3)) {
|
2007-10-11 22:33:57 +00:00
|
|
|
if (!strncasecmp(data + 3, "2", 1)) {
|
|
|
|
snprintf(buf, len, "%d", chan->cid.cid_ani2);
|
|
|
|
} else if (chan->cid.cid_ani) {
|
2005-12-23 21:03:25 +00:00
|
|
|
ast_copy_string(buf, chan->cid.cid_ani, len);
|
|
|
|
}
|
|
|
|
} else if (!strncasecmp("dnid", data, 4)) {
|
|
|
|
if (chan->cid.cid_dnid) {
|
|
|
|
ast_copy_string(buf, chan->cid.cid_dnid, len);
|
|
|
|
}
|
|
|
|
} else if (!strncasecmp("rdnis", data, 5)) {
|
|
|
|
if (chan->cid.cid_rdnis) {
|
|
|
|
ast_copy_string(buf, chan->cid.cid_rdnis, len);
|
|
|
|
}
|
2006-10-07 14:45:49 +00:00
|
|
|
} 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);
|
2005-12-23 21:03:25 +00:00
|
|
|
} else {
|
2006-09-19 21:07:49 +00:00
|
|
|
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
|
2005-12-23 21:03:25 +00:00
|
|
|
}
|
2007-11-29 00:28:10 +00:00
|
|
|
|
|
|
|
ast_channel_unlock(chan);
|
2005-05-15 17:45:30 +00:00
|
|
|
}
|
2006-02-12 04:28:58 +00:00
|
|
|
|
2008-10-07 02:02:39 +00:00
|
|
|
return 0;
|
2005-05-15 17:45:30 +00:00
|
|
|
}
|
|
|
|
|
2007-01-07 19:00:36 +00:00
|
|
|
static int callerid_write(struct ast_channel *chan, const char *cmd, char *data,
|
2006-02-12 04:28:58 +00:00
|
|
|
const char *value)
|
2005-05-15 17:45:30 +00:00
|
|
|
{
|
2007-04-19 02:51:21 +00:00
|
|
|
if (!value || !chan)
|
2006-02-12 04:28:58 +00:00
|
|
|
return -1;
|
|
|
|
|
2008-10-07 02:02:39 +00:00
|
|
|
value = ast_skip_blanks(value);
|
|
|
|
|
2005-07-25 17:26:59 +00:00
|
|
|
if (!strncasecmp("all", data, 3)) {
|
|
|
|
char name[256];
|
|
|
|
char num[256];
|
2006-02-12 04:28:58 +00:00
|
|
|
|
2008-10-07 02:02:39 +00:00
|
|
|
ast_callerid_split(value, name, sizeof(name), num, sizeof(num));
|
|
|
|
ast_set_callerid(chan, num, name, num);
|
2006-02-12 04:28:58 +00:00
|
|
|
} else if (!strncasecmp("name", data, 4)) {
|
|
|
|
ast_set_callerid(chan, NULL, value, NULL);
|
2006-12-25 02:31:04 +00:00
|
|
|
} else if (!strncasecmp("num", data, 3)) {
|
2006-02-12 04:28:58 +00:00
|
|
|
ast_set_callerid(chan, value, NULL, NULL);
|
|
|
|
} else if (!strncasecmp("ani", data, 3)) {
|
2007-10-11 22:33:57 +00:00
|
|
|
if (!strncasecmp(data + 3, "2", 1)) {
|
2008-10-07 02:02:39 +00:00
|
|
|
chan->cid.cid_ani2 = atoi(value);
|
|
|
|
} else {
|
2007-10-11 22:33:57 +00:00
|
|
|
ast_set_callerid(chan, NULL, NULL, value);
|
2008-10-07 02:02:39 +00:00
|
|
|
}
|
2006-02-12 04:28:58 +00:00
|
|
|
} else if (!strncasecmp("dnid", data, 4)) {
|
2007-11-29 00:28:10 +00:00
|
|
|
ast_channel_lock(chan);
|
2008-10-07 02:02:39 +00:00
|
|
|
if (chan->cid.cid_dnid) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(chan->cid.cid_dnid);
|
2008-10-07 02:02:39 +00:00
|
|
|
}
|
2006-04-21 10:51:31 +00:00
|
|
|
chan->cid.cid_dnid = ast_strdup(value);
|
2007-11-29 00:28:10 +00:00
|
|
|
ast_channel_unlock(chan);
|
2006-02-12 04:28:58 +00:00
|
|
|
} else if (!strncasecmp("rdnis", data, 5)) {
|
2007-11-29 00:28:10 +00:00
|
|
|
ast_channel_lock(chan);
|
2008-10-07 02:02:39 +00:00
|
|
|
if (chan->cid.cid_rdnis) {
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(chan->cid.cid_rdnis);
|
2008-10-07 02:02:39 +00:00
|
|
|
}
|
2006-04-21 10:51:31 +00:00
|
|
|
chan->cid.cid_rdnis = ast_strdup(value);
|
2007-11-29 00:28:10 +00:00
|
|
|
ast_channel_unlock(chan);
|
2006-10-07 14:45:49 +00:00
|
|
|
} else if (!strncasecmp("pres", data, 4)) {
|
|
|
|
int i;
|
2008-10-07 02:02:39 +00:00
|
|
|
char *val;
|
2006-10-07 14:45:49 +00:00
|
|
|
|
|
|
|
val = ast_strdupa(value);
|
2008-10-07 02:02:39 +00:00
|
|
|
ast_trim_blanks(val);
|
2006-10-07 14:45:49 +00:00
|
|
|
|
2008-10-07 02:02:39 +00:00
|
|
|
if ((val[0] >= '0') && (val[0] <= '9')) {
|
2006-10-07 14:45:49 +00:00
|
|
|
i = atoi(val);
|
2008-10-07 02:02:39 +00:00
|
|
|
} else {
|
2006-10-07 14:45:49 +00:00
|
|
|
i = ast_parse_caller_presentation(val);
|
2008-10-07 02:02:39 +00:00
|
|
|
}
|
2006-10-07 14:45:49 +00:00
|
|
|
|
2008-10-07 02:02:39 +00:00
|
|
|
if (i < 0) {
|
2006-10-07 14:45:49 +00:00
|
|
|
ast_log(LOG_ERROR, "Unknown calling number presentation '%s', value unchanged\n", val);
|
2008-10-07 02:02:39 +00:00
|
|
|
} else {
|
2006-10-07 14:45:49 +00:00
|
|
|
chan->cid.cid_pres = i;
|
2008-10-07 02:02:39 +00:00
|
|
|
}
|
2006-10-07 14:45:49 +00:00
|
|
|
} else if (!strncasecmp("ton", data, 3)) {
|
2008-10-07 02:02:39 +00:00
|
|
|
chan->cid.cid_ton = atoi(value);
|
2006-02-12 04:28:58 +00:00
|
|
|
} else {
|
2006-09-19 21:07:49 +00:00
|
|
|
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
|
2006-02-12 04:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-05-15 17:45:30 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
static struct ast_custom_function callerid_function = {
|
2005-05-15 17:45:30 +00:00
|
|
|
.name = "CALLERID",
|
|
|
|
.read = callerid_read,
|
|
|
|
.write = callerid_write,
|
|
|
|
};
|
|
|
|
|
2007-02-03 22:05:02 +00:00
|
|
|
static struct ast_custom_function callerpres_function = {
|
|
|
|
.name = "CALLERPRES",
|
|
|
|
.read = callerpres_read,
|
|
|
|
.write = callerpres_write,
|
|
|
|
};
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2005-05-15 17:45:30 +00:00
|
|
|
{
|
2007-02-03 22:05:02 +00:00
|
|
|
int res = ast_custom_function_unregister(&callerpres_function);
|
|
|
|
res |= ast_custom_function_unregister(&callerid_function);
|
|
|
|
return res;
|
2005-05-15 17:45:30 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2005-05-15 17:45:30 +00:00
|
|
|
{
|
2007-02-03 22:05:02 +00:00
|
|
|
int res = ast_custom_function_register(&callerpres_function);
|
|
|
|
res |= ast_custom_function_register(&callerid_function);
|
|
|
|
return res;
|
2005-05-15 17:45:30 +00:00
|
|
|
}
|
|
|
|
|
2007-02-03 22:05:02 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Caller ID related dialplan functions");
|