DETECT_DEADLOCKS can't be enabled without DEBUG_THREADS or it does nothing
[asterisk-bristuff.git] / apps / app_setcallerid.c
blob4456e1ee02fe003ee2fb60a18defdb0b2a1ce5aa
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
19 /*! \file
21 * \brief App to set callerid
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
28 #include "asterisk.h"
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
36 #include "asterisk/lock.h"
37 #include "asterisk/file.h"
38 #include "asterisk/logger.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/pbx.h"
41 #include "asterisk/module.h"
42 #include "asterisk/translate.h"
43 #include "asterisk/image.h"
44 #include "asterisk/callerid.h"
46 static char *app2 = "SetCallerPres";
48 static char *synopsis2 = "Set CallerID Presentation";
51 static char *descrip2 =
52 " SetCallerPres(presentation): Set Caller*ID presentation on a call.\n"
53 " Valid presentations are:\n"
54 "\n"
55 " allowed_not_screened : Presentation Allowed, Not Screened\n"
56 " allowed_passed_screen : Presentation Allowed, Passed Screen\n"
57 " allowed_failed_screen : Presentation Allowed, Failed Screen\n"
58 " allowed : Presentation Allowed, Network Number\n"
59 " prohib_not_screened : Presentation Prohibited, Not Screened\n"
60 " prohib_passed_screen : Presentation Prohibited, Passed Screen\n"
61 " prohib_failed_screen : Presentation Prohibited, Failed Screen\n"
62 " prohib : Presentation Prohibited, Network Number\n"
63 " unavailable : Number Unavailable\n"
64 "\n"
67 static int setcallerid_pres_exec(struct ast_channel *chan, void *data)
69 struct ast_module_user *u;
70 int pres = -1;
72 u = ast_module_user_add(chan);
74 pres = ast_parse_caller_presentation(data);
76 if (pres < 0) {
77 ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
78 (char *) data);
79 ast_module_user_remove(u);
80 return 0;
83 chan->cid.cid_pres = pres;
84 ast_module_user_remove(u);
85 return 0;
88 static char *app = "SetCallerID";
90 static char *synopsis = "Set CallerID";
92 static char *descrip =
93 " SetCallerID(clid[|a]): Set Caller*ID on a call to a new\n"
94 "value. Sets ANI as well if a flag is used. \n";
96 static int setcallerid_exec(struct ast_channel *chan, void *data)
98 int res = 0;
99 char *tmp = NULL;
100 char name[256];
101 char num[256];
102 struct ast_module_user *u;
103 char *opt;
104 int anitoo = 0;
105 static int dep_warning = 0;
107 if (ast_strlen_zero(data)) {
108 ast_log(LOG_WARNING, "SetCallerID requires an argument!\n");
109 return 0;
112 u = ast_module_user_add(chan);
114 if (!dep_warning) {
115 dep_warning = 1;
116 ast_log(LOG_WARNING, "SetCallerID is deprecated. Please use Set(CALLERID(all)=...) or Set(CALLERID(ani)=...) instead.\n");
119 tmp = ast_strdupa(data);
121 opt = strchr(tmp, '|');
122 if (opt) {
123 *opt = '\0';
124 opt++;
125 if (*opt == 'a')
126 anitoo = 1;
129 ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num));
130 ast_set_callerid(chan, num, name, anitoo ? num : NULL);
132 ast_module_user_remove(u);
134 return res;
137 static int unload_module(void)
139 int res;
141 res = ast_unregister_application(app2);
142 res |= ast_unregister_application(app);
144 ast_module_user_hangup_all();
146 return res;
149 static int load_module(void)
151 int res;
153 res = ast_register_application(app2, setcallerid_pres_exec, synopsis2, descrip2);
154 res |= ast_register_application(app, setcallerid_exec, synopsis, descrip);
156 return res;
159 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Set CallerID Application");