Support for withheld or missing CID string
[asterisk-bristuff.git] / apps / app_setcallerid.c
blobfb060f11b0eff645f5912eaea0a60d42df626ab9
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 /* For interface consistency, permit the argument to be specified as a number */
75 if (sscanf(data, "%d", &pres) != 1 || pres < 0 || pres > 255 || (pres & 0x9c)) {
76 pres = ast_parse_caller_presentation(data);
79 if (pres < 0) {
80 ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
81 (char *) data);
82 ast_module_user_remove(u);
83 return 0;
86 chan->cid.cid_pres = pres;
87 ast_module_user_remove(u);
88 return 0;
91 static char *app = "SetCallerID";
93 static char *synopsis = "Set CallerID";
95 static char *descrip =
96 " SetCallerID(clid[|a]): Set Caller*ID on a call to a new\n"
97 "value. Sets ANI as well if a flag is used. \n";
99 static int setcallerid_exec(struct ast_channel *chan, void *data)
101 int res = 0;
102 char *tmp = NULL;
103 char name[256];
104 char num[256];
105 struct ast_module_user *u;
106 char *opt;
107 int anitoo = 0;
108 static int dep_warning = 0;
110 if (ast_strlen_zero(data)) {
111 ast_log(LOG_WARNING, "SetCallerID requires an argument!\n");
112 return 0;
115 u = ast_module_user_add(chan);
117 if (!dep_warning) {
118 dep_warning = 1;
119 ast_log(LOG_WARNING, "SetCallerID is deprecated. Please use Set(CALLERID(all)=...) or Set(CALLERID(ani)=...) instead.\n");
122 tmp = ast_strdupa(data);
124 opt = strchr(tmp, '|');
125 if (opt) {
126 *opt = '\0';
127 opt++;
128 if (*opt == 'a')
129 anitoo = 1;
132 ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num));
133 ast_set_callerid(chan, num, name, anitoo ? num : NULL);
135 ast_module_user_remove(u);
137 return res;
140 static int unload_module(void)
142 int res;
144 res = ast_unregister_application(app2);
145 res |= ast_unregister_application(app);
147 ast_module_user_hangup_all();
149 return res;
152 static int load_module(void)
154 int res;
156 res = ast_register_application(app2, setcallerid_pres_exec, synopsis2, descrip2);
157 res |= ast_register_application(app, setcallerid_exec, synopsis, descrip);
159 return res;
162 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Set CallerID Application");