app_url.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * App to transmit a URL
  5. *
  6. * Copyright (C) 1999, Mark Spencer
  7. *
  8. * Mark Spencer <markster@linux-support.net>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. #include <asterisk/lock.h>
  14. #include <asterisk/file.h>
  15. #include <asterisk/logger.h>
  16. #include <asterisk/channel.h>
  17. #include <asterisk/pbx.h>
  18. #include <asterisk/module.h>
  19. #include <asterisk/translate.h>
  20. #include <asterisk/image.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. static char *tdesc = "Send URL Applications";
  24. static char *app = "SendURL";
  25. static char *synopsis = "Send a URL";
  26. static char *descrip =
  27. " SendURL(URL[|option]): Requests client go to URL. If the client\n"
  28. "does not support html transport, and there exists a step with\n"
  29. "priority n + 101, then execution will continue at that step.\n"
  30. "Otherwise, execution will continue at the next priority level.\n"
  31. "SendURL only returns 0 if the URL was sent correctly or if\n"
  32. "the channel does not support HTML transport, and -1 otherwise.\n"
  33. "If the option 'wait' is specified, execution will wait for an\n"
  34. "acknowledgement that the URL has been loaded before continuing\n"
  35. "and will return -1 if the peer is unable to load the URL\n";
  36. STANDARD_LOCAL_USER;
  37. LOCAL_USER_DECL;
  38. static int sendurl_exec(struct ast_channel *chan, void *data)
  39. {
  40. int res = 0;
  41. struct localuser *u;
  42. char tmp[256];
  43. char *options;
  44. int option_wait=0;
  45. struct ast_frame *f;
  46. char *stringp=NULL;
  47. if (!data || !strlen((char *)data)) {
  48. ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
  49. return -1;
  50. }
  51. strncpy(tmp, (char *)data, sizeof(tmp)-1);
  52. stringp=tmp;
  53. strsep(&stringp, "|");
  54. options = strsep(&stringp, "|");
  55. if (options && !strcasecmp(options, "wait"))
  56. option_wait = 1;
  57. LOCAL_USER_ADD(u);
  58. if (!ast_channel_supports_html(chan)) {
  59. /* Does not support transport */
  60. if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
  61. chan->priority += 100;
  62. LOCAL_USER_REMOVE(u);
  63. return 0;
  64. }
  65. res = ast_channel_sendurl(chan, tmp);
  66. if (res > -1) {
  67. if (option_wait) {
  68. for(;;) {
  69. /* Wait for an event */
  70. res = ast_waitfor(chan, -1);
  71. if (res < 0)
  72. break;
  73. f = ast_read(chan);
  74. if (!f) {
  75. res = -1;
  76. break;
  77. }
  78. if (f->frametype == AST_FRAME_HTML) {
  79. switch(f->subclass) {
  80. case AST_HTML_LDCOMPLETE:
  81. res = 0;
  82. ast_frfree(f);
  83. goto out;
  84. break;
  85. case AST_HTML_NOSUPPORT:
  86. /* Does not support transport */
  87. if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
  88. chan->priority += 100;
  89. res = 0;
  90. goto out;
  91. break;
  92. default:
  93. ast_log(LOG_WARNING, "Don't know what to do with HTML subclass %d\n", f->subclass);
  94. };
  95. }
  96. ast_frfree(f);
  97. }
  98. }
  99. }
  100. out:
  101. LOCAL_USER_REMOVE(u);
  102. return res;
  103. }
  104. int unload_module(void)
  105. {
  106. STANDARD_HANGUP_LOCALUSERS;
  107. return ast_unregister_application(app);
  108. }
  109. int load_module(void)
  110. {
  111. return ast_register_application(app, sendurl_exec, synopsis, descrip);
  112. }
  113. char *description(void)
  114. {
  115. return tdesc;
  116. }
  117. int usecount(void)
  118. {
  119. int res;
  120. STANDARD_USECOUNT(res);
  121. return res;
  122. }
  123. char *key()
  124. {
  125. return ASTERISK_GPL_KEY;
  126. }