Fix a typo in the non-DEBUG_THREADS version of the recently added DEADLOCK_AVOIDANCE()
[asterisk-bristuff.git] / apps / app_sendtext.c
blob6828e3f76d46d45352308a3f724c3cf4653a8d4a
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 <stdlib.h>
35 #include <stdio.h>
36 #include <string.h>
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"
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";
67 static int sendtext_exec(struct ast_channel *chan, void *data)
69 int res = 0;
70 struct ast_module_user *u;
71 char *status = "UNSUPPORTED";
72 char *parse = NULL;
73 int priority_jump = 0;
74 AST_DECLARE_APP_ARGS(args,
75 AST_APP_ARG(text);
76 AST_APP_ARG(options);
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);
84 return -1;
85 } else
86 parse = ast_strdupa(data);
88 AST_STANDARD_APP_ARGS(args, parse);
90 if (args.options) {
91 if (strchr(args.options, 'j'))
92 priority_jump = 1;
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);
102 return 0;
104 status = "FAILURE";
105 ast_channel_unlock(chan);
106 res = ast_sendtext(chan, args.text);
107 if (!res)
108 status = "SUCCESS";
109 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
110 ast_module_user_remove(u);
111 return 0;
114 static int unload_module(void)
116 int res;
118 res = ast_unregister_application(app);
120 ast_module_user_hangup_all();
122 return res;
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");