Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:47:48 2009

## Asterisk developer's documentation

# app_sendtext.c

Go to the documentation of this file.

    00001 /*
    00002  * Asterisk -- An open source telephony toolkit.
    00003  *
    00004  * Copyright (C) 1999 - 2005, Digium, Inc.
    00005  *
    00006  * Mark Spencer <markster@digium.com>
    00007  *
    00008  * See http://www.asterisk.org for more information about
    00009  * the Asterisk project. Please do not directly contact
    00010  * any of the maintainers of this project for assistance;
    00011  * the project provides a web site, mailing lists and IRC
    00012  * channels for your use.
    00013  *
    00014  * This program is free software, distributed under the terms of
    00015  * the GNU General Public License Version 2. See the LICENSE file
    00016  * at the top of the source tree.
    00017  */
    00018
    00019 /*! \file
    00020  *
    00021  * \brief App to transmit a text message
    00022  *
    00023  * Requires support of sending text messages from channel driver
    00024  *
    00025  * \ingroup applications
    00026  */
    00027
    00028 #include <stdlib.h>
    00029 #include <stdio.h>
    00030 #include <string.h>
    00031
    00032 #include "asterisk.h"
    00033
    00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
    00035
    00036 #include "asterisk/lock.h"
    00037 #include "asterisk/file.h"
    00038 #include "asterisk/logger.h"
    00039 #include "asterisk/channel.h"
    00040 #include "asterisk/pbx.h"
    00041 #include "asterisk/module.h"
    00042 #include "asterisk/translate.h"
    00043 #include "asterisk/image.h"
    00044 #include "asterisk/options.h"
    00045 #include "asterisk/app.h"
    00046
    00047 static const char *tdesc = "Send Text Applications";
    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 STANDARD_LOCAL_USER;
    00067
    00068 LOCAL_USER_DECL;
    00069
    00070 static int sendtext_exec(struct ast_channel *chan, void *data)
    00071 {
    00072    int res = 0;
    00073    struct localuser *u;
    00074    char *status = "UNSUPPORTED";
    00075    char *parse = NULL;
    00076    int priority_jump = 0;
    00077    AST_DECLARE_APP_ARGS(args,
    00078       AST_APP_ARG(text);
    00079       AST_APP_ARG(options);
    00080    );
    00081
    00082    LOCAL_USER_ADD(u);
    00083
    00084    if (ast_strlen_zero(data)) {
    00085       ast_log(LOG_WARNING, "SendText requires an argument (text[|options])\n");
    00086       LOCAL_USER_REMOVE(u);
    00087       return -1;
    00088    } else {
    00089       parse = ast_strdupa(data);
    00090       if (!parse) {
    00091          ast_log(LOG_ERROR, "Out of memory!\n");
    00092          LOCAL_USER_REMOVE(u);
    00093          return -1;
    00094       }
    00095    }
    00096
    00097    AST_STANDARD_APP_ARGS(args, parse);
    00098
    00099    if (args.options) {
    00100       if (strchr(args.options, 'j'))
    00101          priority_jump = 1;
    00102    }
    00103
    00104    ast_mutex_lock(&chan->lock);
    00105    if (!chan->tech->send_text) {
    00106       ast_mutex_unlock(&chan->lock);
    00107       /* Does not support transport */
    00108       if (priority_jump || option_priority_jumping)
    00109          ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
    00110       LOCAL_USER_REMOVE(u);
    00111       return 0;
    00112    }
    00113    status = "FAILURE";
    00114    ast_mutex_unlock(&chan->lock);
    00115    res = ast_sendtext(chan, args.text);
    00116    if (!res)
    00117       status = "SUCCESS";
    00118    pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
    00119    LOCAL_USER_REMOVE(u);
    00120    return 0;
    00121 }
    00122
    00123 int unload_module(void)
    00124 {
    00125    int res;
    00126
    00127    res = ast_unregister_application(app);
    00128
    00129    STANDARD_HANGUP_LOCALUSERS;
    00130
    00131    return res;
    00132 }
    00133
    00134 int load_module(void)
    00135 {
    00136    return ast_register_application(app, sendtext_exec, synopsis, descrip);
    00137 }
    00138
    00139 char *description(void)
    00140 {
    00141    return (char *) tdesc;
    00142 }
    00143
    00144 int usecount(void)
    00145 {
    00146    int res;
    00147
    00148    STANDARD_USECOUNT(res);
    00149
    00150    return res;
    00151 }
    00152
    00153 char *key()
    00154 {
    00155    return ASTERISK_GPL_KEY;
    00156 }