This rather large commit changes the way modules are loaded.
[asterisk/asterisk.git] / apps / app_sendtext.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 transmit a text message
22  *
23  * \author Mark Spencer <markster@digium.com>
24  * 
25  * \note Requires support of sending text messages from channel driver
26  *
27  * \ingroup applications
28  */
29  
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33
34 #include "asterisk.h"
35
36 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
37
38 #include "asterisk/lock.h"
39 #include "asterisk/file.h"
40 #include "asterisk/logger.h"
41 #include "asterisk/channel.h"
42 #include "asterisk/pbx.h"
43 #include "asterisk/module.h"
44 #include "asterisk/translate.h"
45 #include "asterisk/image.h"
46 #include "asterisk/options.h"
47 #include "asterisk/app.h"
48
49 static const char *app = "SendText";
50
51 static const char *synopsis = "Send a Text Message";
52
53 static const char *descrip = 
54 "  SendText(text[|options]): Sends text to current channel (callee).\n"
55 "Result of transmission will be stored in the SENDTEXTSTATUS\n"
56 "channel variable:\n"
57 "      SUCCESS      Transmission succeeded\n"
58 "      FAILURE      Transmission failed\n"
59 "      UNSUPPORTED  Text transmission not supported by channel\n"
60 "\n"
61 "At this moment, text is supposed to be 7 bit ASCII in most channels.\n"
62 "The option string many contain the following character:\n"
63 "'j' -- jump to n+101 priority if the channel doesn't support\n"
64 "       text transport\n";
65
66 LOCAL_USER_DECL;
67
68 static int sendtext_exec(struct ast_channel *chan, void *data)
69 {
70         int res = 0;
71         struct localuser *u;
72         char *status = "UNSUPPORTED";
73         char *parse = NULL;
74         int priority_jump = 0;
75         AST_DECLARE_APP_ARGS(args,
76                 AST_APP_ARG(text);
77                 AST_APP_ARG(options);
78         );
79                 
80         LOCAL_USER_ADD(u);      
81
82         if (ast_strlen_zero(data)) {
83                 ast_log(LOG_WARNING, "SendText requires an argument (text[|options])\n");
84                 LOCAL_USER_REMOVE(u);
85                 return -1;
86         } else {
87                 if (!(parse = ast_strdupa(data))) {
88                         LOCAL_USER_REMOVE(u);
89                         return -1;
90                 }
91         }
92         
93         AST_STANDARD_APP_ARGS(args, parse);
94
95         if (args.options) {
96                 if (strchr(args.options, 'j'))
97                         priority_jump = 1;
98         }
99
100         ast_mutex_lock(&chan->lock);
101         if (!chan->tech->send_text) {
102                 ast_mutex_unlock(&chan->lock);
103                 /* Does not support transport */
104                 if (priority_jump || ast_opt_priority_jumping)
105                         ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
106                 LOCAL_USER_REMOVE(u);
107                 return 0;
108         }
109         status = "FAILURE";
110         ast_mutex_unlock(&chan->lock);
111         res = ast_sendtext(chan, args.text);
112         if (!res)
113                 status = "SUCCESS";
114         pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
115         LOCAL_USER_REMOVE(u);
116         return 0;
117 }
118
119 static int unload_module(void *mod)
120 {
121         int res;
122         
123         res = ast_unregister_application(app);
124         
125         STANDARD_HANGUP_LOCALUSERS;
126
127         return res;     
128 }
129
130 static int load_module(void *mod)
131 {
132         return ast_register_application(app, sendtext_exec, synopsis, descrip);
133 }
134
135 static const char *description(void)
136 {
137         return "Send Text Applications";
138 }
139
140 static const char *key(void)
141 {
142         return ASTERISK_GPL_KEY;
143 }
144
145 STD_MOD1;