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$")
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 if (ast_strlen_zero(data)) {
00082 ast_log(LOG_WARNING, "SendText requires an argument (text[|options])\n");
00083 ast_module_user_remove(u);
00084 return -1;
00085 } else
00086 parse = ast_strdupa(data);
00087
00088 AST_STANDARD_APP_ARGS(args, parse);
00089
00090 if (args.options) {
00091 if (strchr(args.options, 'j'))
00092 priority_jump = 1;
00093 }
00094
00095 ast_channel_lock(chan);
00096 if (!chan->tech->send_text) {
00097 ast_channel_unlock(chan);
00098 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00099
00100 if (priority_jump || ast_opt_priority_jumping)
00101 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00102 ast_module_user_remove(u);
00103 return 0;
00104 }
00105 status = "FAILURE";
00106 ast_channel_unlock(chan);
00107 res = ast_sendtext(chan, args.text);
00108 if (!res)
00109 status = "SUCCESS";
00110 pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
00111 ast_module_user_remove(u);
00112 return 0;
00113 }
00114
00115 static int unload_module(void)
00116 {
00117 int res;
00118
00119 res = ast_unregister_application(app);
00120
00121 ast_module_user_hangup_all();
00122
00123 return res;
00124 }
00125
00126 static int load_module(void)
00127 {
00128 return ast_register_application(app, sendtext_exec, synopsis, descrip);
00129 }
00130
00131 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");