Merge "BuildSystem: For consistency, avoid double-checking via if clauses."
[asterisk/asterisk.git] / apps / app_setcallerid.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
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.
13  *
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.
17  */
18
19 /*! \file
20  *
21  * \brief App to set callerid presentation
22  *
23  * \author Mark Spencer <markster@digium.com>
24  *
25  * \ingroup applications
26  */
27
28 /*** MODULEINFO
29         <defaultenabled>no</defaultenabled>
30         <support_level>deprecated</support_level>
31         <replacement>func_callerid</replacement>
32  ***/
33
34 #include "asterisk.h"
35
36 #include "asterisk/lock.h"
37 #include "asterisk/file.h"
38 #include "asterisk/channel.h"
39 #include "asterisk/pbx.h"
40 #include "asterisk/module.h"
41 #include "asterisk/translate.h"
42 #include "asterisk/image.h"
43 #include "asterisk/callerid.h"
44
45 /*** DOCUMENTATION
46         <application name="SetCallerPres" language="en_US">
47                 <synopsis>
48                         Set CallerID Presentation.
49                 </synopsis>
50                 <syntax>
51                         <parameter name="presentation" required="true">
52                                 <enumlist>
53                                         <enum name="allowed_not_screened">
54                                                 <para>Presentation Allowed, Not Screened.</para>
55                                         </enum>
56                                         <enum name="allowed_passed_screen">
57                                                 <para>Presentation Allowed, Passed Screen.</para>
58                                         </enum>
59                                         <enum name="allowed_failed_screen">
60                                                 <para>Presentation Allowed, Failed Screen.</para>
61                                         </enum>
62                                         <enum name="allowed">
63                                                 <para>Presentation Allowed, Network Number.</para>
64                                         </enum>
65                                         <enum name="prohib_not_screened">
66                                                 <para>Presentation Prohibited, Not Screened.</para>
67                                         </enum>
68                                         <enum name="prohib_passed_screen">
69                                                 <para>Presentation Prohibited, Passed Screen.</para>
70                                         </enum>
71                                         <enum name="prohib_failed_screen">
72                                                 <para>Presentation Prohibited, Failed Screen.</para>
73                                         </enum>
74                                         <enum name="prohib">
75                                                 <para>Presentation Prohibited, Network Number.</para>
76                                         </enum>
77                                         <enum name="unavailable">
78                                                 <para>Number Unavailable.</para>
79                                         </enum>
80                                 </enumlist>
81                         </parameter>
82                 </syntax>
83                 <description>
84                         <para>Set Caller*ID presentation on a call.</para>
85                 </description>
86         </application>
87  ***/
88
89 static char *app2 = "SetCallerPres";
90
91 static int setcallerid_pres_exec(struct ast_channel *chan, const char *data)
92 {
93         int pres = -1;
94         static int deprecated = 0;
95
96         if (!deprecated) {
97                 deprecated = 1;
98                 ast_log(LOG_WARNING, "SetCallerPres is deprecated.  Please use Set(CALLERPRES()=%s) instead.\n", (char *)data);
99         }
100
101         /* For interface consistency, permit the argument to be specified as a number */
102         if (sscanf(data, "%30d", &pres) != 1 || pres < 0 || pres > 255 || (pres & 0x9c)) {
103                 pres = ast_parse_caller_presentation(data);
104         }
105
106         if (pres < 0) {
107                 ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
108                         (char *) data);
109                 return 0;
110         }
111
112         /* Set the combined caller id presentation. */
113         ast_channel_caller(chan)->id.name.presentation = pres;
114         ast_channel_caller(chan)->id.number.presentation = pres;
115         return 0;
116 }
117
118 static int unload_module(void)
119 {
120         return ast_unregister_application(app2);
121 }
122
123 static int load_module(void)
124 {
125         return ast_register_application_xml(app2, setcallerid_pres_exec);
126 }
127
128 AST_MODULE_INFO_STANDARD_DEPRECATED(ASTERISK_GPL_KEY, "Set CallerID Presentation Application");