app_sendtext.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "asterisk.h"
00031
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 305888 $")
00033
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <string.h>
00037
00038 #include "asterisk/lock.h"
00039 #include "asterisk/file.h"
00040 #include "asterisk/logger.h"
00041 #include "asterisk/channel.h"
00042 #include "asterisk/pbx.h"
00043 #include "asterisk/module.h"
00044 #include "asterisk/translate.h"
00045 #include "asterisk/image.h"
00046 #include "asterisk/options.h"
00047 #include "asterisk/app.h"
00048
00049 static const char *app = "SendText";
00050
00051 static const char *synopsis = "Send a Text Message";
00052
00053 static const char *descrip =
00054 " SendText(text[|options]): Sends text to current channel (callee).\n"
00055 "Result of transmission will be stored in the SENDTEXTSTATUS\n"
00056 "channel variable:\n"
00057 " SUCCESS Transmission succeeded\n"
00058 " FAILURE Transmission failed\n"
00059 " UNSUPPORTED Text transmission not supported by channel\n"
00060 "\n"
00061 "At this moment, text is supposed to be 7 bit ASCII in most channels.\n"
00062 "The option string many contain the following character:\n"
00063 "'j' -- jump to n+101 priority if the channel doesn't support\n"
00064 " text transport\n";
00065
00066
00067 static int sendtext_exec(struct ast_channel *chan, void *data)
00068 {
00069 int res = 0;
00070 struct ast_module_user *u;
00071 char *status = "UNSUPPORTED";
00072 char *parse = NULL;
00073 int priority_jump = 0;
00074 AST_DECLARE_APP_ARGS(args,
00075 AST_APP_ARG(text);
00076 AST_APP_ARG(options);
00077 );
00078
00079 u = ast_module_user_add(chan);
00080
00081
00082
00083 if (!data) {
00084 ast_log(LOG_WARNING, "SendText requires an argument (text[|options])\n");
00085 ast_module_user_remove(u);
00086 return -1;
00087 } else
00088 parse = ast_strdupa(data);
00089
00090 AST_STANDARD_APP_ARGS(args, parse);
00091
00092 if (args.options) {
00093 if (strchr(args.options, 'j'))
00094 priority_jump = 1;
00095 }
00096
00097 ast_channel_lock(chan);
00098 if (!chan->tech->send_text) {
00099 ast_channel_unlock(chan);
00100 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00101
00102 if (priority_jump || ast_opt_priority_jumping)
00103 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00104 ast_module_user_remove(u);
00105 return 0;
00106 }
00107 status = "FAILURE";
00108 res = ast_sendtext(chan, args.text);
00109 if (!res)
00110 status = "SUCCESS";
00111 ast_channel_unlock(chan);
00112 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00113 ast_module_user_remove(u);
00114 return 0;
00115 }
00116
00117 static int unload_module(void)
00118 {
00119 int res;
00120
00121 res = ast_unregister_application(app);
00122
00123 ast_module_user_hangup_all();
00124
00125 return res;
00126 }
00127
00128 static int load_module(void)
00129 {
00130 return ast_register_application(app, sendtext_exec, synopsis, descrip);
00131 }
00132
00133 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");