Applications no longer need to call ast_module_user_add and ast_module_user_remove...
[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 <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35
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"
45
46 static char *app2 = "SetCallerPres";
47
48 static char *synopsis2 = "Set CallerID Presentation";
49
50
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"
65 ;
66
67 static int setcallerid_pres_exec(struct ast_channel *chan, void *data)
68 {
69         int pres = -1;
70         static int deprecated = 0;
71
72         if (!deprecated) {
73                 deprecated = 1;
74                 ast_log(LOG_WARNING, "SetCallerPres is deprecated.  Please use Set(CALLERPRES()=%s) instead.\n", (char *)data);
75         }
76         pres = ast_parse_caller_presentation(data);
77
78         if (pres < 0) {
79                 ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
80                         (char *) data);
81                 return 0;
82         }
83         
84         chan->cid.cid_pres = pres;
85         return 0;
86 }
87
88 static int unload_module(void)
89 {
90         return ast_unregister_application(app2);
91 }
92
93 static int load_module(void)
94 {
95         return ast_register_application(app2, setcallerid_pres_exec, synopsis2, descrip2);
96 }
97
98 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Set CallerID Presentation Application");