make app_queue 1.2 jump compliant (issue #5580)
[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  * \ingroup applications
24  */
25  
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29
30 #include "asterisk.h"
31
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33
34 #include "asterisk/lock.h"
35 #include "asterisk/file.h"
36 #include "asterisk/logger.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/pbx.h"
39 #include "asterisk/module.h"
40 #include "asterisk/translate.h"
41 #include "asterisk/image.h"
42 #include "asterisk/app.h"
43 #include "asterisk/options.h"
44
45 static char *tdesc = "Image Transmission Application";
46
47 static char *app = "SendImage";
48
49 static char *synopsis = "Send an image file";
50
51 static char *descrip = 
52 "  SendImage(filename): Sends an image on a channel. \n"
53 "If the channel supports image transport but the image send\n"
54 "fails, the channel will be hung up. Otherwise, the dialplan\n"
55 "continues execution.\n"
56 "The option string may contain the following character:\n"
57 "       'j' -- jump to priority n+101 if the channel doesn't support image transport\n"
58 "This application sets the following channel variable upon completion:\n"
59 "       SENDIMAGESTATUS         The status is the result of the attempt as a text string, one of\n"
60 "               OK | NOSUPPORT \n";                     
61
62 STANDARD_LOCAL_USER;
63
64 LOCAL_USER_DECL;
65
66 static int sendimage_exec(struct ast_channel *chan, void *data)
67 {
68         int res = 0;
69         struct localuser *u;
70         char *parse;
71         int priority_jump = 0;
72         AST_DECLARE_APP_ARGS(args,
73                 AST_APP_ARG(filename);
74                 AST_APP_ARG(options);
75         );
76         
77         LOCAL_USER_ADD(u);
78
79         if (!(parse = ast_strdupa(data))) {
80                 ast_log(LOG_WARNING, "Memory Error!\n");
81                 LOCAL_USER_REMOVE(u);
82                 return -1;
83         }
84
85         AST_STANDARD_APP_ARGS(args, parse);
86
87         if (ast_strlen_zero(args.filename)) {
88                 ast_log(LOG_WARNING, "SendImage requires an argument (filename[|options])\n");
89                 return -1;
90         }
91
92         if (args.options) {
93                 if (strchr(args.options, 'j'))
94                         priority_jump = 1;
95         }
96
97         if (!ast_supports_images(chan)) {
98                 /* Does not support transport */
99                 if (priority_jump || option_priority_jumping)
100                         ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
101                 pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "NOSUPPORT");
102                 LOCAL_USER_REMOVE(u);
103                 return 0;
104         }
105
106         res = ast_send_image(chan, args.filename);
107         
108         if (!res)
109                 pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "OK");
110         
111         LOCAL_USER_REMOVE(u);
112         
113         return res;
114 }
115
116 int unload_module(void)
117 {
118         int res;
119
120         res = ast_unregister_application(app);
121
122         STANDARD_HANGUP_LOCALUSERS;
123
124         return res; 
125 }
126
127 int load_module(void)
128 {
129         return ast_register_application(app, sendimage_exec, synopsis, descrip);
130 }
131
132 char *description(void)
133 {
134         return tdesc;
135 }
136
137 int usecount(void)
138 {
139         int res;
140         STANDARD_USECOUNT(res);
141         return res;
142 }
143
144 char *key()
145 {
146         return ASTERISK_GPL_KEY;
147 }