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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* App to transmit a text message
|
|
|
|
*
|
2004-04-07 17:19:25 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
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"
|
2004-04-07 17:19:25 +00:00
|
|
|
|
2005-08-22 21:55:46 +00:00
|
|
|
static const char *tdesc = "Send Text Applications";
|
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 =
|
|
|
|
" SendText(text): Sends text to current channel (callee).\n"
|
|
|
|
"Otherwise, execution will continue at the next priority level.\n"
|
|
|
|
"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"
|
|
|
|
"Old deprecated behavior: \n"
|
|
|
|
" SendText only returns 0 if the text was sent correctly or if\n"
|
|
|
|
" the channel does not support text transport.\n"
|
|
|
|
" If the client does not support text transport, and there exists a\n"
|
|
|
|
" step with priority n + 101, then execution will continue at that step.\n";
|
2004-04-07 17:19:25 +00:00
|
|
|
|
|
|
|
STANDARD_LOCAL_USER;
|
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
|
|
|
static int sendtext_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
struct localuser *u;
|
2005-08-22 21:55:46 +00:00
|
|
|
char *status = "UNSUPPORTED";
|
2005-10-19 18:19:02 +00:00
|
|
|
|
|
|
|
if (!data || ast_strlen_zero(data)) {
|
2004-04-07 17:19:25 +00:00
|
|
|
ast_log(LOG_WARNING, "SendText requires an argument (text)\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2004-04-07 17:19:25 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2004-04-07 17:19:25 +00:00
|
|
|
ast_mutex_lock(&chan->lock);
|
2005-03-04 06:47:24 +00:00
|
|
|
if (!chan->tech->send_text) {
|
2004-04-07 17:19:25 +00:00
|
|
|
ast_mutex_unlock(&chan->lock);
|
|
|
|
/* Does not support transport */
|
2005-08-22 21:55:46 +00:00
|
|
|
if (option_priority_jumping)
|
|
|
|
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
|
2004-04-07 17:19:25 +00:00
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-08-22 21:55:46 +00:00
|
|
|
status = "FAILURE";
|
2004-04-07 17:19:25 +00:00
|
|
|
ast_mutex_unlock(&chan->lock);
|
|
|
|
res = ast_sendtext(chan, (char *)data);
|
2005-08-22 21:55:46 +00:00
|
|
|
if (!res)
|
|
|
|
status = "SUCCESS";
|
|
|
|
pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
|
2004-04-07 17:19:25 +00:00
|
|
|
LOCAL_USER_REMOVE(u);
|
2005-08-22 21:55:46 +00:00
|
|
|
return 0;
|
2004-04-07 17:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int unload_module(void)
|
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_unregister_application(app);
|
|
|
|
|
2004-04-07 17:19:25 +00:00
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int load_module(void)
|
|
|
|
{
|
|
|
|
return ast_register_application(app, sendtext_exec, synopsis, descrip);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *description(void)
|
|
|
|
{
|
2005-08-22 21:55:46 +00:00
|
|
|
return (char *) tdesc;
|
2004-04-07 17:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int usecount(void)
|
|
|
|
{
|
|
|
|
int res;
|
2005-08-22 21:55:46 +00:00
|
|
|
|
2004-04-07 17:19:25 +00:00
|
|
|
STANDARD_USECOUNT(res);
|
2005-08-22 21:55:46 +00:00
|
|
|
|
2004-04-07 17:19:25 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *key()
|
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|