app_url.c 3.3 KB

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