Sat Aug 6 00:39:20 2011

Asterisk developer's documentation


app_image.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 an image
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \ingroup applications
00026  */
00027  
00028 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 40722 $")
00031 
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <string.h>
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/app.h"
00045 #include "asterisk/options.h"
00046 
00047 static char *app = "SendImage";
00048 
00049 static char *synopsis = "Send an image file";
00050 
00051 static char *descrip = 
00052 "  SendImage(filename): Sends an image on a channel. \n"
00053 "If the channel supports image transport but the image send\n"
00054 "fails, the channel will be hung up. Otherwise, the dialplan\n"
00055 "continues execution.\n"
00056 "The option string may contain the following character:\n"
00057 "  'j' -- jump to priority n+101 if the channel doesn't support image transport\n"
00058 "This application sets the following channel variable upon completion:\n"
00059 "  SENDIMAGESTATUS      The status is the result of the attempt as a text string, one of\n"
00060 "     OK | NOSUPPORT \n";        
00061 
00062 
00063 static int sendimage_exec(struct ast_channel *chan, void *data)
00064 {
00065    int res = 0;
00066    struct ast_module_user *u;
00067    char *parse;
00068    int priority_jump = 0;
00069    AST_DECLARE_APP_ARGS(args,
00070       AST_APP_ARG(filename);
00071       AST_APP_ARG(options);
00072    );
00073    
00074    u = ast_module_user_add(chan);
00075 
00076    parse = ast_strdupa(data);
00077 
00078    AST_STANDARD_APP_ARGS(args, parse);
00079 
00080    if (ast_strlen_zero(args.filename)) {
00081       ast_log(LOG_WARNING, "SendImage requires an argument (filename[|options])\n");
00082       return -1;
00083    }
00084 
00085    if (args.options) {
00086       if (strchr(args.options, 'j'))
00087          priority_jump = 1;
00088    }
00089 
00090    if (!ast_supports_images(chan)) {
00091       /* Does not support transport */
00092       if (priority_jump || ast_opt_priority_jumping)
00093          ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00094       pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "NOSUPPORT");
00095       ast_module_user_remove(u);
00096       return 0;
00097    }
00098 
00099    res = ast_send_image(chan, args.filename);
00100    
00101    if (!res)
00102       pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "OK");
00103    
00104    ast_module_user_remove(u);
00105    
00106    return res;
00107 }
00108 
00109 static int unload_module(void)
00110 {
00111    int res;
00112 
00113    res = ast_unregister_application(app);
00114 
00115    ast_module_user_hangup_all();
00116 
00117    return res; 
00118 }
00119 
00120 static int load_module(void)
00121 {
00122    return ast_register_application(app, sendimage_exec, synopsis, descrip);
00123 }
00124 
00125 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Image Transmission Application");

Generated on Sat Aug 6 00:39:20 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7