Merge "BuildSystem: For consistency, avoid double-checking via if clauses."
[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 /*** MODULEINFO
29         <support_level>extended</support_level>
30  ***/
31
32 #include "asterisk.h"
33
34 #include "asterisk/pbx.h"
35 #include "asterisk/module.h"
36 #include "asterisk/image.h"
37
38 static char *app = "SendImage";
39
40 /*** DOCUMENTATION
41         <application name="SendImage" language="en_US">
42                 <synopsis>
43                         Sends an image file.
44                 </synopsis>
45                 <syntax>
46                         <parameter name="filename" required="true">
47                                 <para>Path of the filename (image) to send.</para>
48                         </parameter>
49                 </syntax>
50                 <description>
51                         <para>Send an image file on a channel supporting it.</para>
52                         <para>Result of transmission will be stored in <variable>SENDIMAGESTATUS</variable></para>
53                         <variablelist>
54                                 <variable name="SENDIMAGESTATUS">
55                                         <value name="SUCCESS">
56                                                 Transmission succeeded.
57                                         </value>
58                                         <value name="FAILURE">
59                                                 Transmission failed.
60                                         </value>
61                                         <value name="UNSUPPORTED">
62                                                 Image transmission not supported by channel.
63                                         </value>
64                                 </variable>
65                         </variablelist>
66                 </description>
67                 <see-also>
68                         <ref type="application">SendText</ref>
69                         <ref type="application">SendURL</ref>
70                 </see-also>
71         </application>
72  ***/
73
74 static int sendimage_exec(struct ast_channel *chan, const char *data)
75 {
76
77         if (ast_strlen_zero(data)) {
78                 ast_log(LOG_WARNING, "SendImage requires an argument (filename)\n");
79                 return -1;
80         }
81
82         if (!ast_supports_images(chan)) {
83                 /* Does not support transport */
84                 pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "UNSUPPORTED");
85                 return 0;
86         }
87
88         if (!ast_send_image(chan, data)) {
89                 pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "SUCCESS");
90         } else {
91                 pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "FAILURE");
92         }
93
94         return 0;
95 }
96
97 static int unload_module(void)
98 {
99         return ast_unregister_application(app);
100 }
101
102 static int load_module(void)
103 {
104         return ast_register_application_xml(app, sendimage_exec);
105 }
106
107 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Image Transmission Application");