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