diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-05-15 17:45:30 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-05-15 17:45:30 +0000 |
commit | 025aeb8f62d8b5c199846c20c73ff25720dae21e (patch) | |
tree | 0dca6952bac0dc48b1b51a445fb7c60fd5caf1ff /funcs/func_callerid.c | |
parent | b59e7819bd13b8713fa249affc2b5c7e9a41a717 (diff) |
add dialplan functions for Caller ID, language and timeouts (bug #4219, with mods)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5679 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_callerid.c')
-rwxr-xr-x | funcs/func_callerid.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/funcs/func_callerid.c b/funcs/func_callerid.c new file mode 100755 index 000000000..fb70269a2 --- /dev/null +++ b/funcs/func_callerid.c @@ -0,0 +1,129 @@ +/* + * Asterisk -- A telephony toolkit for Linux. + * + * Caller ID related dialplan functions + * + * Copyright (C) 2005, Digium, Inc. + * + * This program is free software, distributed under the terms of + * the GNU General Public License + */ + +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> + +#ifndef BUILTIN_FUNC +#include "asterisk/module.h" +#endif /* BUILTIN_FUNC */ +#include "asterisk/channel.h" +#include "asterisk/pbx.h" +#include "asterisk/logger.h" +#include "asterisk/utils.h" +#include "asterisk/app.h" +#include "asterisk/options.h" + +static char *callerid_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +{ + if (strncasecmp("name", data, 4) == 0) { + if (chan->cid.cid_name) { + ast_copy_string(buf, chan->cid.cid_name, len); + } + } else if (strncasecmp("num", data, 3) == 0 || strncasecmp("number", data, 6) == 0) { + if (chan->cid.cid_num) { + ast_copy_string(buf, chan->cid.cid_num, len); + } + } else if (strncasecmp("ani", data, 3) == 0) { + if (chan->cid.cid_ani) { + ast_copy_string(buf, chan->cid.cid_ani, len); + } + } else if (strncasecmp("dnid", data, 4) == 0) { + if (chan->cid.cid_dnid) { + ast_copy_string(buf, chan->cid.cid_dnid, len); + } + } else if (strncasecmp("rdnis", data, 5) == 0) { + if (chan->cid.cid_rdnis) { + ast_copy_string(buf, chan->cid.cid_rdnis, len); + } + } else { + ast_log(LOG_ERROR, "Unknown callerid data type.\n"); + } + + return buf; +} + +static void callerid_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +{ + if (!value) + return; + + if (strncasecmp("name", data, 4) == 0) { + ast_set_callerid(chan, NULL, value, NULL); + } else if (strncasecmp("num", data, 3) == 0 || strncasecmp("number", data, 6) == 0) { + ast_set_callerid(chan, value, NULL, NULL); + } else if (strncasecmp("ani", data, 3) == 0) { + ast_set_callerid(chan, NULL, NULL, value); + } else if (strncasecmp("dnid", data, 4) == 0) { + /* do we need to lock chan here? */ + if (chan->cid.cid_dnid) + free(chan->cid.cid_dnid); + chan->cid.cid_dnid = ast_strlen_zero(value) ? NULL : strdup(value); + } else if (strncasecmp("rdnis", data, 5) == 0) { + /* do we need to lock chan here? */ + if (chan->cid.cid_rdnis) + free(chan->cid.cid_rdnis); + chan->cid.cid_rdnis = ast_strlen_zero(value) ? NULL : strdup(value); + } else { + ast_log(LOG_ERROR, "Unknown callerid data type.\n"); + } +} + +#ifndef BUILTIN_FUNC +static +#endif /* BUILTIN_FUNC */ +struct ast_custom_function callerid_function = { + .name = "CALLERID", + .synopsis = "Gets or sets Caller*ID data on the channel.", + .syntax = "CALLERID(datatype)", + .desc = "Gets or sets Caller*ID data on the channel. The allowable datatypes\n" + "are \"name\", \"number\", \"ANI\", \"DNID\", \"RDNIS\".\n", + .read = callerid_read, + .write = callerid_write, +}; + +#ifndef BUILTIN_FUNC +static char *tdesc = "Caller ID related dialplan function"; + +int unload_module(void) +{ + return ast_custom_function_unregister(&callerid_function); +} + +int load_module(void) +{ + return ast_custom_function_register(&callerid_function); +} + +char *description(void) +{ + return tdesc; +} + +int usecount(void) +{ + return 0; +} + +char *key() +{ + return ASTERISK_GPL_KEY; +} +#endif /* BUILTIN_FUNC */ + +/* +Local Variables: +mode: C +c-file-style: "linux" +indent-tabs-mode: nil +End: +*/ |