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.
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
32 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
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"
49 static const char *app
= "SendText";
51 static const char *synopsis
= "Send a Text Message";
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"
57 " SUCCESS Transmission succeeded\n"
58 " FAILURE Transmission failed\n"
59 " UNSUPPORTED Text transmission not supported by channel\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"
67 static int sendtext_exec(struct ast_channel
*chan
, void *data
)
70 struct ast_module_user
*u
;
71 char *status
= "UNSUPPORTED";
73 int priority_jump
= 0;
74 AST_DECLARE_APP_ARGS(args
,
79 u
= ast_module_user_add(chan
);
81 if (ast_strlen_zero(data
)) {
82 ast_log(LOG_WARNING
, "SendText requires an argument (text[|options])\n");
83 ast_module_user_remove(u
);
86 parse
= ast_strdupa(data
);
88 AST_STANDARD_APP_ARGS(args
, parse
);
91 if (strchr(args
.options
, 'j'))
95 ast_channel_lock(chan
);
96 if (!chan
->tech
->send_text
) {
97 ast_channel_unlock(chan
);
98 /* Does not support transport */
99 if (priority_jump
|| ast_opt_priority_jumping
)
100 ast_goto_if_exists(chan
, chan
->context
, chan
->exten
, chan
->priority
+ 101);
101 ast_module_user_remove(u
);
105 ast_channel_unlock(chan
);
106 res
= ast_sendtext(chan
, args
.text
);
109 pbx_builtin_setvar_helper(chan
, "SENDTEXTSTATUS", status
);
110 ast_module_user_remove(u
);
114 static int unload_module(void)
118 res
= ast_unregister_application(app
);
120 ast_module_user_hangup_all();
125 static int load_module(void)
127 return ast_register_application(app
, sendtext_exec
, synopsis
, descrip
);
130 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Send Text Applications");