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