Applications no longer need to call ast_module_user_add and ast_module_user_remove...
[asterisk/asterisk.git] / apps / app_image.c
old mode 100755 (executable)
new mode 100644 (file)
index 0e43e2a..655bbcf
 /*! \file
  *
  * \brief App to transmit an image
+ *
+ * \author Mark Spencer <markster@digium.com>
  * 
+ * \ingroup applications
  */
  
-#include <string.h>
-#include <stdlib.h>
-
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "asterisk/lock.h"
 #include "asterisk/file.h"
 #include "asterisk/logger.h"
@@ -37,80 +41,64 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/module.h"
 #include "asterisk/translate.h"
 #include "asterisk/image.h"
-
-static char *tdesc = "Image Transmission Application";
+#include "asterisk/app.h"
+#include "asterisk/options.h"
 
 static char *app = "SendImage";
 
 static char *synopsis = "Send an image file";
 
 static char *descrip = 
-"  SendImage(filename): Sends an image on a channel. If the channel\n"
-"does not support  image transport, and there exists  a  step  with\n"
-"priority n + 101, then  execution  will  continue  at  that  step.\n"
-"Otherwise,  execution  will continue at  the  next priority level.\n"
-"SendImage only  returns  0 if  the  image was sent correctly or if\n"
-"the channel does not support image transport, and -1 otherwise.\n";
-
-STANDARD_LOCAL_USER;
+"  SendImage(filename): Sends an image on a channel. \n"
+"If the channel supports image transport but the image send\n"
+"fails, the channel will be hung up. Otherwise, the dialplan\n"
+"continues execution.\n"
+"This application sets the following channel variable upon completion:\n"
+"      SENDIMAGESTATUS         The status is the result of the attempt as a text string, one of\n"
+"              OK | NOSUPPORT \n";                     
 
-LOCAL_USER_DECL;
 
 static int sendimage_exec(struct ast_channel *chan, void *data)
 {
        int res = 0;
-       struct localuser *u;
+       char *parse;
+       AST_DECLARE_APP_ARGS(args,
+               AST_APP_ARG(filename);
+               AST_APP_ARG(options);
+       );
        
-       if (ast_strlen_zero(data)) {
-               ast_log(LOG_WARNING, "SendImage requires an argument (filename)\n");
+       parse = ast_strdupa(data);
+
+       AST_STANDARD_APP_ARGS(args, parse);
+
+       if (ast_strlen_zero(args.filename)) {
+               ast_log(LOG_WARNING, "SendImage requires an argument (filename[|options])\n");
                return -1;
        }
 
-       LOCAL_USER_ADD(u);
+       if (args.options) {
+       }
 
        if (!ast_supports_images(chan)) {
                /* Does not support transport */
-               ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
-               LOCAL_USER_REMOVE(u);
+               pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "NOSUPPORT");
                return 0;
        }
 
-       res = ast_send_image(chan, data);
-       
-       LOCAL_USER_REMOVE(u);
-       
+       if (!(res = ast_send_image(chan, args.filename)))
+               pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "OK");
+               
        return res;
 }
 
-int unload_module(void)
+static int unload_module(void)
 {
-       int res;
-
-       res = ast_unregister_application(app);
-
-       STANDARD_HANGUP_LOCALUSERS;
-
-       return res; 
+       return ast_unregister_application(app);
 }
 
-int load_module(void)
+static int load_module(void)
 {
        return ast_register_application(app, sendimage_exec, synopsis, descrip);
 }
 
-char *description(void)
-{
-       return tdesc;
-}
-
-int usecount(void)
-{
-       int res;
-       STANDARD_USECOUNT(res);
-       return res;
-}
-
-char *key()
-{
-       return ASTERISK_GPL_KEY;
-}
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Image Transmission Application");