Asterisk data retrieval API.
[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 #include "asterisk.h"
29
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
31
32 #include "asterisk/lock.h"
33 #include "asterisk/file.h"
34 #include "asterisk/channel.h"
35 #include "asterisk/pbx.h"
36 #include "asterisk/module.h"
37 #include "asterisk/translate.h"
38 #include "asterisk/image.h"
39 #include "asterisk/callerid.h"
40
41 /*** DOCUMENTATION
42         <application name="SetCallerPres" language="en_US">
43                 <synopsis>
44                         Set CallerID Presentation.
45                 </synopsis>
46                 <syntax>
47                         <parameter name="presentation" required="true">
48                                 <enumlist>
49                                         <enum name="allowed_not_screened">
50                                                 <para>Presentation Allowed, Not Screened.</para>
51                                         </enum>
52                                         <enum name="allowed_passed_screen">
53                                                 <para>Presentation Allowed, Passed Screen.</para>
54                                         </enum>
55                                         <enum name="allowed_failed_screen">
56                                                 <para>Presentation Allowed, Failed Screen.</para>
57                                         </enum>
58                                         <enum name="allowed">
59                                                 <para>Presentation Allowed, Network Number.</para>
60                                         </enum>
61                                         <enum name="prohib_not_screened">
62                                                 <para>Presentation Prohibited, Not Screened.</para>
63                                         </enum>
64                                         <enum name="prohib_passed_screen">
65                                                 <para>Presentation Prohibited, Passed Screen.</para>
66                                         </enum>
67                                         <enum name="prohib_failed_screen">
68                                                 <para>Presentation Prohibited, Failed Screen.</para>
69                                         </enum>
70                                         <enum name="prohib">
71                                                 <para>Presentation Prohibited, Network Number.</para>
72                                         </enum>
73                                         <enum name="unavailable">
74                                                 <para>Number Unavailable.</para>
75                                         </enum>
76                                 </enumlist>
77                         </parameter>
78                 </syntax>
79                 <description>
80                         <para>Set Caller*ID presentation on a call.</para>
81                 </description>
82         </application>
83  ***/
84
85 static char *app2 = "SetCallerPres";
86
87 static int setcallerid_pres_exec(struct ast_channel *chan, const char *data)
88 {
89         int pres = -1;
90         static int deprecated = 0;
91
92         if (!deprecated) {
93                 deprecated = 1;
94                 ast_log(LOG_WARNING, "SetCallerPres is deprecated.  Please use Set(CALLERPRES()=%s) instead.\n", (char *)data);
95         }
96
97         /* For interface consistency, permit the argument to be specified as a number */
98         if (sscanf(data, "%30d", &pres) != 1 || pres < 0 || pres > 255 || (pres & 0x9c)) {
99                 pres = ast_parse_caller_presentation(data);
100         }
101
102         if (pres < 0) {
103                 ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
104                         (char *) data);
105                 return 0;
106         }
107         
108         chan->cid.cid_pres = pres;
109         return 0;
110 }
111
112 static int unload_module(void)
113 {
114         return ast_unregister_application(app2);
115 }
116
117 static int load_module(void)
118 {
119         return ast_register_application_xml(app2, setcallerid_pres_exec);
120 }
121
122 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Set CallerID Presentation Application");