d9c6dc5f81d18f341a7d30e57b1fc3a688f0812c
[asterisk/asterisk.git] / apps / app_settransfercapability.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * App to set the ISDN Transfer Capability
5  * 
6  * Copyright (C) 2005, Frank Sautter, levigo holding gmbh, www.levigo.de
7  *
8  * Frank Sautter - asterisk+at+sautter+dot+com 
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13  
14 #include <string.h>
15 #include <stdlib.h>
16
17 #include "asterisk.h"
18
19 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
20
21 #include "asterisk/logger.h"
22 #include "asterisk/channel.h"
23 #include "asterisk/pbx.h"
24 #include "asterisk/module.h"
25 #include "asterisk/options.h"
26 #include "asterisk/transcap.h"
27
28
29 static char *app = "SetTransferCapability";
30
31 static char *synopsis = "Set ISDN Transfer Capability";
32
33 STANDARD_LOCAL_USER;
34
35 LOCAL_USER_DECL;
36
37 static struct { int val; char *name; } transcaps[] = {
38         { AST_TRANS_CAP_SPEECH,                         "SPEECH" },
39         { AST_TRANS_CAP_DIGITAL,                        "DIGITAL" },
40         { AST_TRANS_CAP_RESTRICTED_DIGITAL,     "RESTRICTED_DIGITAL" },
41         { AST_TRANS_CAP_3_1K_AUDIO,                     "3K1AUDIO" },
42         { AST_TRANS_CAP_DIGITAL_W_TONES,        "DIGITAL_W_TONES" },
43         { AST_TRANS_CAP_VIDEO,                          "VIDEO" },
44 };
45
46 static char *descrip = 
47 "  SetTransferCapability(transfercapability): Set the ISDN Transfer \n"
48 "Capability of a call to a new value.\n"
49 "Always returns 0.  Valid Transfer Capabilities are:\n"
50 "\n"
51 "  SPEECH             : 0x00 - Speech (default, voice calls)\n"
52 "  DIGITAL            : 0x08 - Unrestricted digital information (data calls)\n"
53 "  RESTRICTED_DIGITAL : 0x09 - Restricted digital information\n"
54 "  3K1AUDIO           : 0x10 - 3.1kHz Audio (fax calls)\n"
55 "  DIGITAL_W_TONES    : 0x11 - Unrestricted digital information with tones/announcements\n"
56 "  VIDEO              : 0x18 - Video:\n"
57 "\n"
58 ;
59
60 static int settransfercapability_exec(struct ast_channel *chan, void *data)
61 {
62         char tmp[256] = "";
63         struct localuser *u;
64         int x;
65         char *opts;
66         int transfercapability = -1;
67         
68         if (data)
69                 strncpy(tmp, (char *)data, sizeof(tmp) - 1);
70         opts = strchr(tmp, '|');
71         if (opts)
72                 *opts = '\0';
73         for (x=0;x<sizeof(transcaps) / sizeof(transcaps[0]);x++) {
74                 if (!strcasecmp(transcaps[x].name, tmp)) {
75                         transfercapability = transcaps[x].val;
76                         break;
77                 }
78         }
79         if (transfercapability < 0) {
80                 ast_log(LOG_WARNING, "'%s' is not a valid transfer capability (see 'show application SetTransferCapability')\n", tmp);
81                 return 0;
82         } else {
83                 LOCAL_USER_ADD(u);
84                 chan->transfercapability = (unsigned short)transfercapability;
85                 LOCAL_USER_REMOVE(u);
86                 if (option_verbose > 2)
87                         ast_verbose(VERBOSE_PREFIX_3 "Setting transfer capability to: 0x%.2x - %s.\n", transfercapability, tmp);                        
88                 return 0;
89         }
90 }
91
92
93 int unload_module(void)
94 {
95         STANDARD_HANGUP_LOCALUSERS;
96         return ast_unregister_application(app);
97 }
98
99 int load_module(void)
100 {
101         return ast_register_application(app, settransfercapability_exec, synopsis, descrip);
102 }
103
104 char *description(void)
105 {
106         return synopsis;
107 }
108
109 int usecount(void)
110 {
111         int res;
112         STANDARD_USECOUNT(res);
113         return res;
114 }
115
116 char *key()
117 {
118         return ASTERISK_GPL_KEY;
119 }