Sat Mar 24 23:25:59 2007

Asterisk developer's documentation


app_setrdnis.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  * Oliver Daudey <traveler@xs4all.nl>
00008  *
00009  * See http://www.asterisk.org for more information about
00010  * the Asterisk project. Please do not directly contact
00011  * any of the maintainers of this project for assistance;
00012  * the project provides a web site, mailing lists and IRC
00013  * channels for your use.
00014  *
00015  * This program is free software, distributed under the terms of
00016  * the GNU General Public License Version 2. See the LICENSE file
00017  * at the top of the source tree.
00018  */
00019 
00020 /*! \file
00021  *
00022  * \brief App to set rdnis
00023  *
00024  * \ingroup applications
00025  */
00026  
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 #include <string.h>
00030 
00031 #include "asterisk.h"
00032 
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00034 
00035 #include "asterisk/lock.h"
00036 #include "asterisk/file.h"
00037 #include "asterisk/logger.h"
00038 #include "asterisk/channel.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/module.h"
00041 #include "asterisk/translate.h"
00042 #include "asterisk/image.h"
00043 #include "asterisk/callerid.h"
00044 #include "asterisk/utils.h"
00045 
00046 static char *tdesc = "Set RDNIS Number";
00047 
00048 static char *app = "SetRDNIS";
00049 
00050 static char *synopsis = "Set RDNIS Number";
00051 
00052 static char *descrip = 
00053 "  SetRDNIS(cnum): Set RDNIS Number on a call to a new\n"
00054 "value.\n"
00055 "SetRDNIS has been deprecated in favor of the function\n"
00056 "CALLERID(rdnis)\n";
00057 
00058 STANDARD_LOCAL_USER;
00059 
00060 LOCAL_USER_DECL;
00061 
00062 static int setrdnis_exec(struct ast_channel *chan, void *data)
00063 {
00064    struct localuser *u;
00065    char *opt, *n, *l;
00066    char *tmp = NULL;
00067    static int deprecation_warning = 0;
00068 
00069    LOCAL_USER_ADD(u);
00070    
00071    if (!deprecation_warning) {
00072       ast_log(LOG_WARNING, "SetRDNIS is deprecated, please use Set(CALLERID(rdnis)=value) instead.\n");
00073       deprecation_warning = 1;
00074    }
00075 
00076    if (data)
00077       tmp = ast_strdupa(data);
00078    else
00079       tmp = "";   
00080 
00081    opt = strchr(tmp, '|');
00082    if (opt)
00083       *opt = '\0';
00084    
00085    n = l = NULL;
00086    ast_callerid_parse(tmp, &n, &l);
00087    if (l) {
00088       ast_shrink_phone_number(l);
00089       ast_mutex_lock(&chan->lock);
00090       if (chan->cid.cid_rdnis)
00091          free(chan->cid.cid_rdnis);
00092       chan->cid.cid_rdnis = (l[0]) ? strdup(l) : NULL;
00093       ast_mutex_unlock(&chan->lock);
00094    }
00095 
00096    LOCAL_USER_REMOVE(u);
00097    
00098    return 0;
00099 }
00100 
00101 int unload_module(void)
00102 {
00103    int res;
00104    
00105    res = ast_unregister_application(app);
00106    
00107    STANDARD_HANGUP_LOCALUSERS;
00108 
00109    return res; 
00110 }
00111 
00112 int load_module(void)
00113 {
00114    return ast_register_application(app, setrdnis_exec, synopsis, descrip);
00115 }
00116 
00117 char *description(void)
00118 {
00119    return tdesc;
00120 }
00121 
00122 int usecount(void)
00123 {
00124    int res;
00125    STANDARD_USECOUNT(res);
00126    return res;
00127 }
00128 
00129 char *key()
00130 {
00131    return ASTERISK_GPL_KEY;
00132 }

Generated on Sat Mar 24 23:25:59 2007 for Asterisk - the Open Source PBX by  doxygen 1.4.6