2004-04-07 17:19:25 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2004-04-07 17:19:25 +00:00
|
|
|
*
|
2005-01-21 07:06:25 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
2004-04-07 17:19:25 +00:00
|
|
|
*
|
2004-10-02 00:58:31 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
2004-04-07 17:19:25 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
2004-04-07 17:19:25 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief App to transmit a text message
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-12-30 21:18:06 +00:00
|
|
|
* \note Requires support of sending text messages from channel driver
|
2005-11-06 15:09:47 +00:00
|
|
|
*
|
|
|
|
* \ingroup applications
|
2004-04-07 17:19:25 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/translate.h"
|
|
|
|
#include "asterisk/image.h"
|
2005-08-22 21:55:46 +00:00
|
|
|
#include "asterisk/options.h"
|
2005-11-07 22:55:34 +00:00
|
|
|
#include "asterisk/app.h"
|
2004-04-07 17:19:25 +00:00
|
|
|
|
2005-08-22 21:55:46 +00:00
|
|
|
static const char *app = "SendText";
|
2004-04-07 17:19:25 +00:00
|
|
|
|
2005-08-22 21:55:46 +00:00
|
|
|
static const char *synopsis = "Send a Text Message";
|
2004-04-07 17:19:25 +00:00
|
|
|
|
2005-08-22 21:55:46 +00:00
|
|
|
static const char *descrip =
|
2005-11-07 22:55:34 +00:00
|
|
|
" SendText(text[|options]): Sends text to current channel (callee).\n"
|
2005-08-22 21:55:46 +00:00
|
|
|
"Result of transmission will be stored in the SENDTEXTSTATUS\n"
|
|
|
|
"channel variable:\n"
|
|
|
|
" SUCCESS Transmission succeeded\n"
|
|
|
|
" FAILURE Transmission failed\n"
|
|
|
|
" UNSUPPORTED Text transmission not supported by channel\n"
|
|
|
|
"\n"
|
|
|
|
"At this moment, text is supposed to be 7 bit ASCII in most channels.\n"
|
2005-11-07 22:55:34 +00:00
|
|
|
"The option string many contain the following character:\n"
|
|
|
|
"'j' -- jump to n+101 priority if the channel doesn't support\n"
|
|
|
|
" text transport\n";
|
2004-04-07 17:19:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int sendtext_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
int res = 0;
|
2006-08-21 02:11:39 +00:00
|
|
|
struct ast_module_user *u;
|
2005-08-22 21:55:46 +00:00
|
|
|
char *status = "UNSUPPORTED";
|
2005-11-07 22:55:34 +00:00
|
|
|
char *parse = NULL;
|
|
|
|
int priority_jump = 0;
|
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(text);
|
|
|
|
AST_APP_ARG(options);
|
|
|
|
);
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
u = ast_module_user_add(chan);
|
2005-11-07 22:55:34 +00:00
|
|
|
|
2005-10-26 19:48:14 +00:00
|
|
|
if (ast_strlen_zero(data)) {
|
2005-11-07 22:55:34 +00:00
|
|
|
ast_log(LOG_WARNING, "SendText requires an argument (text[|options])\n");
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_remove(u);
|
2004-04-07 17:19:25 +00:00
|
|
|
return -1;
|
2006-05-10 13:22:15 +00:00
|
|
|
} else
|
|
|
|
parse = ast_strdupa(data);
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2005-11-07 22:55:34 +00:00
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
|
|
|
|
|
|
|
if (args.options) {
|
|
|
|
if (strchr(args.options, 'j'))
|
|
|
|
priority_jump = 1;
|
|
|
|
}
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2006-05-10 15:30:59 +00:00
|
|
|
ast_channel_lock(chan);
|
2005-03-04 06:47:24 +00:00
|
|
|
if (!chan->tech->send_text) {
|
2006-05-10 15:30:59 +00:00
|
|
|
ast_channel_unlock(chan);
|
2004-04-07 17:19:25 +00:00
|
|
|
/* Does not support transport */
|
2005-12-04 20:40:46 +00:00
|
|
|
if (priority_jump || ast_opt_priority_jumping)
|
2005-08-22 21:55:46 +00:00
|
|
|
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_remove(u);
|
2004-04-07 17:19:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-08-22 21:55:46 +00:00
|
|
|
status = "FAILURE";
|
2006-05-10 15:30:59 +00:00
|
|
|
ast_channel_unlock(chan);
|
2005-11-07 22:55:34 +00:00
|
|
|
res = ast_sendtext(chan, args.text);
|
2005-08-22 21:55:46 +00:00
|
|
|
if (!res)
|
|
|
|
status = "SUCCESS";
|
|
|
|
pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_remove(u);
|
2005-08-22 21:55:46 +00:00
|
|
|
return 0;
|
2004-04-07 17:19:25 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2004-04-07 17:19:25 +00:00
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_unregister_application(app);
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_hangup_all();
|
2005-08-22 21:55:46 +00:00
|
|
|
|
2005-10-18 22:52:21 +00:00
|
|
|
return res;
|
2004-04-07 17:19:25 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2004-04-07 17:19:25 +00:00
|
|
|
{
|
|
|
|
return ast_register_application(app, sendtext_exec, synopsis, descrip);
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");
|