ensure that the private structure for pseudo channels is created without 'leaking...
[asterisk-bristuff.git] / apps / app_sendtext.c
blobaf4fcade5320503bfe7f0a6782dea209838f0981
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 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
99 /* Does not support transport */
100 if (priority_jump || ast_opt_priority_jumping)
101 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
102 ast_module_user_remove(u);
103 return 0;
105 status = "FAILURE";
106 ast_channel_unlock(chan);
107 res = ast_sendtext(chan, args.text);
108 if (!res)
109 status = "SUCCESS";
110 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
111 ast_module_user_remove(u);
112 return 0;
115 static int unload_module(void)
117 int res;
119 res = ast_unregister_application(app);
121 ast_module_user_hangup_all();
123 return res;
126 static int load_module(void)
128 return ast_register_application(app, sendtext_exec, synopsis, descrip);
131 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");