revert my pass through the tree to remove checks of the result of ast_strdupa
[asterisk/asterisk.git] / apps / app_image.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief App to transmit an image
22  *
23  * \author Mark Spencer <markster@digium.com>
24  * 
25  * \ingroup applications
26  */
27  
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "asterisk.h"
33
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35
36 #include "asterisk/lock.h"
37 #include "asterisk/file.h"
38 #include "asterisk/logger.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/pbx.h"
41 #include "asterisk/module.h"
42 #include "asterisk/translate.h"
43 #include "asterisk/image.h"
44 #include "asterisk/app.h"
45 #include "asterisk/options.h"
46
47 static char *tdesc = "Image Transmission Application";
48
49 static char *app = "SendImage";
50
51 static char *synopsis = "Send an image file";
52
53 static char *descrip = 
54 "  SendImage(filename): Sends an image on a channel. \n"
55 "If the channel supports image transport but the image send\n"
56 "fails, the channel will be hung up. Otherwise, the dialplan\n"
57 "continues execution.\n"
58 "The option string may contain the following character:\n"
59 "       'j' -- jump to priority n+101 if the channel doesn't support image transport\n"
60 "This application sets the following channel variable upon completion:\n"
61 "       SENDIMAGESTATUS         The status is the result of the attempt as a text string, one of\n"
62 "               OK | NOSUPPORT \n";                     
63
64 STANDARD_LOCAL_USER;
65
66 LOCAL_USER_DECL;
67
68 static int sendimage_exec(struct ast_channel *chan, void *data)
69 {
70         int res = 0;
71         struct localuser *u;
72         char *parse;
73         int priority_jump = 0;
74         AST_DECLARE_APP_ARGS(args,
75                 AST_APP_ARG(filename);
76                 AST_APP_ARG(options);
77         );
78         
79         LOCAL_USER_ADD(u);
80
81         if (!(parse = ast_strdupa(data))) {
82                 ast_log(LOG_WARNING, "Memory Error!\n");
83                 LOCAL_USER_REMOVE(u);
84                 return -1;
85         }
86
87         AST_STANDARD_APP_ARGS(args, parse);
88
89         if (ast_strlen_zero(args.filename)) {
90                 ast_log(LOG_WARNING, "SendImage requires an argument (filename[|options])\n");
91                 return -1;
92         }
93
94         if (args.options) {
95                 if (strchr(args.options, 'j'))
96                         priority_jump = 1;
97         }
98
99         if (!ast_supports_images(chan)) {
100                 /* Does not support transport */
101                 if (priority_jump || ast_opt_priority_jumping)
102                         ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
103                 pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "NOSUPPORT");
104                 LOCAL_USER_REMOVE(u);
105                 return 0;
106         }
107
108         res = ast_send_image(chan, args.filename);
109         
110         if (!res)
111                 pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "OK");
112         
113         LOCAL_USER_REMOVE(u);
114         
115         return res;
116 }
117
118 int unload_module(void)
119 {
120         int res;
121
122         res = ast_unregister_application(app);
123
124         STANDARD_HANGUP_LOCALUSERS;
125
126         return res; 
127 }
128
129 int load_module(void)
130 {
131         return ast_register_application(app, sendimage_exec, synopsis, descrip);
132 }
133
134 char *description(void)
135 {
136         return tdesc;
137 }
138
139 int usecount(void)
140 {
141         int res;
142         STANDARD_USECOUNT(res);
143         return res;
144 }
145
146 char *key()
147 {
148         return ASTERISK_GPL_KEY;
149 }