Update of /usr/cvsroot/asterisk/funcs
In directory mongoose.digium.com:/tmp/cvs-serv17164/funcs

Modified Files:
        Makefile func_groupcount.c 
Added Files:
        func_callerid.c func_language.c func_timeout.c 
Log Message:
add dialplan functions for Caller ID, language and timeouts (bug #4219, with 
mods)


--- NEW FILE: func_callerid.c ---
/*
 * 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:
*/

--- NEW FILE: func_language.c ---
/*
 * Asterisk -- A telephony toolkit for Linux.
 *
 * Language 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>

#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"

static char *builtin_function_language_read(struct ast_channel *chan, char 
*cmd, char *data, char *buf, size_t len) 
{
        ast_copy_string(buf, chan->language, len);

        return buf;
}

static void builtin_function_language_write(struct ast_channel *chan, char 
*cmd, char *data, const char *value) 
{
        if (value)
                ast_copy_string(chan->language, value, sizeof(chan->language));
}

#ifndef BUILTIN_FUNC
static
#endif
struct ast_custom_function language_function = {
        .name = "LANGUAGE",
        .synopsis = "Gets or sets the channel's language.",
        .syntax = "LANGUAGE()",
        .desc = "Gets or sets the channel language.  This information is used 
for the\n"
        "syntax in generation of numbers, and to choose a natural language 
file\n"
        "when available.  For example, if language is set to 'fr' and the 
file\n"
        "'demo-congrats' is requested to be played, if the file\n"
        "'fr/demo-congrats' exists, then it will play that file, and if not\n"
        "will play the normal 'demo-congrats'.  For some language codes,\n"
        "changing the language also changes the syntax of some Asterisk\n"
        "functions, like SayNumber.\n",
        .read = builtin_function_language_read,
        .write = builtin_function_language_write,
};

/*
Local Variables:
mode: C
c-file-style: "linux"
indent-tabs-mode: nil
End:
*/

--- NEW FILE: func_timeout.c ---
/*
 * Asterisk -- A telephony toolkit for Linux.
 *
 * Channel timeout 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>

#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 *builtin_function_timeout_read(struct ast_channel *chan, char *cmd, 
char *data, char *buf, size_t len) 
{
        time_t myt;

        if (!data) {
                ast_log(LOG_ERROR, "Must specify type of timeout to get.");
                return NULL;
        }
        
        switch(*data) {
        case 'a':
        case 'A':
                if (chan->whentohangup == 0) {
                        ast_copy_string(buf, "0", len);
                } else {
                        time(&myt);
                        snprintf(buf, len, "%d", (int) (chan->whentohangup - 
myt));
                }
                break;

        case 'r':
        case 'R':
                if (chan->pbx) {
                        snprintf(buf, len, "%d", chan->pbx->rtimeout);
                }
                break;

        case 'd':
        case 'D':
                if (chan->pbx) {
                        snprintf(buf, len, "%d", chan->pbx->dtimeout);
                }
                break;

        default:
                ast_log(LOG_ERROR, "Unknown timeout type specified.");
                break;
        }

        return buf;
}

static void builtin_function_timeout_write(struct ast_channel *chan, char *cmd, 
char *data, const char *value) 
{
        int x;
        char timestr[64];
        struct tm myt;

        if (!data) {
                ast_log(LOG_ERROR, "Must specify type of timeout to set.");
                return;
        }
        
        if (!value)
                return;

        x = atoi(value);

        switch(*data) {
        case 'a':
        case 'A':
                ast_channel_setwhentohangup(chan, x);
                if (option_verbose > 2) {
                        if (chan->whentohangup) {
                                strftime(timestr, sizeof(timestr), "%Y-%m-%d 
%H:%M:%S UTC", gmtime_r(&chan->whentohangup, &myt));
                                ast_verbose( VERBOSE_PREFIX_3 "Channel will 
hangup at %s.\n", timestr);
                        } else {
                                ast_verbose( VERBOSE_PREFIX_3 "Channel hangup 
cancelled.\n");
                        } 
                }
                break;

        case 'r':
        case 'R':
                if (chan->pbx) {
                        chan->pbx->rtimeout = x;
                        if (option_verbose > 2)
                                ast_verbose( VERBOSE_PREFIX_3 "Response timeout 
set to %d\n", chan->pbx->rtimeout);
                }
                break;

        case 'd':
        case 'D':
                if (chan->pbx) {
                        chan->pbx->dtimeout = x;
                        if (option_verbose > 2)
                                ast_verbose( VERBOSE_PREFIX_3 "Digit timeout 
set to %d\n", chan->pbx->dtimeout);
                }
                break;

        default:
                ast_log(LOG_ERROR, "Unknown timeout type specified.");
                break;
        }
}

#ifndef BUILTIN_FUNC
static
#endif
struct ast_custom_function timeout_function = {
        .name = "TIMEOUT",
        .synopsis = "Gets or sets timeouts on the channel.",
        .syntax = "TIMEOUT(timeouttype)",
        .desc = "Gets or sets various channel timeouts. The timeouts that can 
be\n"
        "manipulated are:\n"
        "\n"
        "absolute: The absolute maximum amount of time permitted for a call.  
A\n"
        "          setting of 0 disables the timeout.\n"
        "\n"
        "digit:    The maximum amount of time permitted between digits when 
the\n"
        "          user is typing in an extension.  When this timeout 
expires,\n"
        "          after the user has started to type in an extension, the\n"
        "          extension will be considered complete, and will be\n"
        "          interpreted.  Note that if an extension typed in is valid,\n"
        "          it will not have to timeout to be tested, so typically at\n"
        "          the expiry of this timeout, the extension will be 
considered\n"
        "          invalid (and thus control would be passed to the 'i'\n"
        "          extension, or if it doesn't exist the call would be\n"
        "          terminated).  The default timeout is 5 seconds.\n"
        "\n"
        "response: The maximum amount of time permitted after falling through 
a\n"
        "          series of priorities for a channel in which the user may\n"
        "          begin typing an extension.  If the user does not type an\n"
        "          extension in this amount of time, control will pass to the\n"
        "          't' extension if it exists, and if not the call would be\n"
        "          terminated.  The default timeout is 10 seconds.\n",
        .read = builtin_function_timeout_read,
        .write = builtin_function_timeout_write,
};

/*
Local Variables:
mode: C
c-file-style: "linux"
indent-tabs-mode: nil
End:
*/

Index: Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/funcs/Makefile,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Makefile    8 May 2005 18:11:55 -0000       1.5
+++ Makefile    15 May 2005 17:45:30 -0000      1.6
@@ -13,8 +13,15 @@
 
 FUNCS=pbx_functions.so
 
-BUILTINS=func_md5.o func_groupcount.o func_strings.o func_cdr.o \
-         func_logic.o func_env.o func_db.o
+BUILTINS=func_md5.o \
+         func_groupcount.o \
+         func_strings.o \
+         func_cdr.o \
+         func_logic.o \
+         func_env.o \
+         func_db.o \
+         func_timeout.o \
+         func_language.o \
 
 STANDALONE_FUNCS=$(filter-out $(BUILTINS),$(patsubst %.c,%.o,$(wildcard 
func*.c)))
 

Index: func_groupcount.c
===================================================================
RCS file: /usr/cvsroot/asterisk/funcs/func_groupcount.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- func_groupcount.c   8 May 2005 17:17:34 -0000       1.2
+++ func_groupcount.c   15 May 2005 17:45:30 -0000      1.3
@@ -165,3 +165,10 @@
        .write = NULL,
 };
 
+/*
+Local Variables:
+mode: C
+c-file-style: "linux"
+indent-tabs-mode: nil
+End:
+*/

_______________________________________________
Asterisk-Cvs mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-cvs

Reply via email to