app_image.c 3.2 KB

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