app_url.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 a URL
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. *
  24. * \ingroup applications
  25. */
  26. /*** MODULEINFO
  27. <support_level>extended</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include "asterisk/pbx.h"
  32. #include "asterisk/module.h"
  33. #include "asterisk/app.h"
  34. #include "asterisk/channel.h"
  35. /*** DOCUMENTATION
  36. <application name="SendURL" language="en_US">
  37. <synopsis>
  38. Send a URL.
  39. </synopsis>
  40. <syntax>
  41. <parameter name="URL" required="true" />
  42. <parameter name="option">
  43. <optionlist>
  44. <option name="w">
  45. <para>Execution will wait for an acknowledgement that the
  46. URL has been loaded before continuing.</para>
  47. </option>
  48. </optionlist>
  49. </parameter>
  50. </syntax>
  51. <description>
  52. <para>Requests client go to <replaceable>URL</replaceable> (IAX2) or sends the
  53. URL to the client (other channels).</para>
  54. <para>Result is returned in the <variable>SENDURLSTATUS</variable> channel variable:</para>
  55. <variablelist>
  56. <variable name="SENDURLSTATUS">
  57. <value name="SUCCESS">
  58. URL successfully sent to client.
  59. </value>
  60. <value name="FAILURE">
  61. Failed to send URL.
  62. </value>
  63. <value name="NOLOAD">
  64. Client failed to load URL (wait enabled).
  65. </value>
  66. <value name="UNSUPPORTED">
  67. Channel does not support URL transport.
  68. </value>
  69. </variable>
  70. </variablelist>
  71. <para>SendURL continues normally if the URL was sent correctly or if the channel
  72. does not support HTML transport. Otherwise, the channel is hung up.</para>
  73. </description>
  74. <see-also>
  75. <ref type="application">SendImage</ref>
  76. <ref type="application">SendText</ref>
  77. </see-also>
  78. </application>
  79. ***/
  80. static char *app = "SendURL";
  81. enum option_flags {
  82. OPTION_WAIT = (1 << 0),
  83. };
  84. AST_APP_OPTIONS(app_opts,{
  85. AST_APP_OPTION('w', OPTION_WAIT),
  86. });
  87. static int sendurl_exec(struct ast_channel *chan, const char *data)
  88. {
  89. int res = 0;
  90. char *tmp;
  91. struct ast_frame *f;
  92. char *status = "FAILURE";
  93. char *opts[0];
  94. struct ast_flags flags = { 0 };
  95. AST_DECLARE_APP_ARGS(args,
  96. AST_APP_ARG(url);
  97. AST_APP_ARG(options);
  98. );
  99. if (ast_strlen_zero(data)) {
  100. ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
  101. pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
  102. return -1;
  103. }
  104. tmp = ast_strdupa(data);
  105. AST_STANDARD_APP_ARGS(args, tmp);
  106. if (args.argc == 2)
  107. ast_app_parse_options(app_opts, &flags, opts, args.options);
  108. if (!ast_channel_supports_html(chan)) {
  109. /* Does not support transport */
  110. pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
  111. return 0;
  112. }
  113. res = ast_channel_sendurl(chan, args.url);
  114. if (res == -1) {
  115. pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "FAILURE");
  116. return res;
  117. }
  118. status = "SUCCESS";
  119. if (ast_test_flag(&flags, OPTION_WAIT)) {
  120. for(;;) {
  121. /* Wait for an event */
  122. res = ast_waitfor(chan, -1);
  123. if (res < 0)
  124. break;
  125. f = ast_read(chan);
  126. if (!f) {
  127. res = -1;
  128. status = "FAILURE";
  129. break;
  130. }
  131. if (f->frametype == AST_FRAME_HTML) {
  132. switch (f->subclass.integer) {
  133. case AST_HTML_LDCOMPLETE:
  134. res = 0;
  135. ast_frfree(f);
  136. status = "NOLOAD";
  137. goto out;
  138. break;
  139. case AST_HTML_NOSUPPORT:
  140. /* Does not support transport */
  141. status = "UNSUPPORTED";
  142. res = 0;
  143. ast_frfree(f);
  144. goto out;
  145. break;
  146. default:
  147. ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass.integer);
  148. };
  149. }
  150. ast_frfree(f);
  151. }
  152. }
  153. out:
  154. pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
  155. return res;
  156. }
  157. static int unload_module(void)
  158. {
  159. return ast_unregister_application(app);
  160. }
  161. static int load_module(void)
  162. {
  163. return ast_register_application_xml(app, sendurl_exec);
  164. }
  165. AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Send URL Applications");