Merged revisions 126573 via svnmerge from
[asterisk-bristuff.git] / apps / app_sendtext.c
blobe55c59528da3910f5585e5cf8eac22d6e5fc2dcb
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
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.
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.
19 /*! \file
21 * \brief App to transmit a text message
23 * \author Mark Spencer <markster@digium.com>
25 * \note Requires support of sending text messages from channel driver
27 * \ingroup applications
30 #include "asterisk.h"
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
34 #include "asterisk/file.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/module.h"
38 #include "asterisk/app.h"
40 static const char *app = "SendText";
42 static const char *synopsis = "Send a Text Message";
44 static const char *descrip =
45 " SendText(text[,options]): Sends text to current channel (callee).\n"
46 "Result of transmission will be stored in the SENDTEXTSTATUS\n"
47 "channel variable:\n"
48 " SUCCESS Transmission succeeded\n"
49 " FAILURE Transmission failed\n"
50 " UNSUPPORTED Text transmission not supported by channel\n"
51 "\n"
52 "At this moment, text is supposed to be 7 bit ASCII in most channels.\n";
54 static int sendtext_exec(struct ast_channel *chan, void *data)
56 int res = 0;
57 char *status = "UNSUPPORTED";
58 char *parse = NULL;
59 AST_DECLARE_APP_ARGS(args,
60 AST_APP_ARG(text);
61 AST_APP_ARG(options);
64 if (ast_strlen_zero(data)) {
65 ast_log(LOG_WARNING, "SendText requires an argument (text[,options])\n");
66 return -1;
67 } else
68 parse = ast_strdupa(data);
70 AST_STANDARD_APP_ARGS(args, parse);
72 if (args.options) {
75 ast_channel_lock(chan);
76 if (!chan->tech->send_text) {
77 ast_channel_unlock(chan);
78 /* Does not support transport */
79 return 0;
81 status = "FAILURE";
82 ast_channel_unlock(chan);
83 res = ast_sendtext(chan, args.text);
84 if (!res)
85 status = "SUCCESS";
86 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
87 return 0;
90 static int unload_module(void)
92 return ast_unregister_application(app);
95 static int load_module(void)
97 return ast_register_application(app, sendtext_exec, synopsis, descrip);
100 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");