app_transfer.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * Transfer a caller
  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 <stdlib.h>
  20. #include <unistd.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. static char *tdesc = "Transfer";
  24. static char *app = "Transfer";
  25. static char *synopsis = "Transfer caller to remote extension";
  26. static char *descrip =
  27. " Transfer(exten): Requests the remote caller be transferred to\n"
  28. "a given extension. Returns -1 on hangup, or 0 on completion\n"
  29. "regardless of whether the transfer was successful. If the transfer\n"
  30. "was *not* supported or successful and there exists a priority n + 101,\n"
  31. "then that priority will be taken next.\n" ;
  32. STANDARD_LOCAL_USER;
  33. LOCAL_USER_DECL;
  34. static int transfer_exec(struct ast_channel *chan, void *data)
  35. {
  36. int res=0;
  37. struct localuser *u;
  38. if (!data || !strlen(data)) {
  39. ast_log(LOG_WARNING, "Transfer requires an argument (destination)\n");
  40. res = 1;
  41. }
  42. LOCAL_USER_ADD(u);
  43. if (!res) {
  44. res = ast_transfer(chan, data);
  45. }
  46. if (!res) {
  47. /* Look for a "busy" place */
  48. if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
  49. chan->priority += 100;
  50. }
  51. if (res > 0)
  52. res = 0;
  53. LOCAL_USER_REMOVE(u);
  54. return res;
  55. }
  56. int unload_module(void)
  57. {
  58. STANDARD_HANGUP_LOCALUSERS;
  59. return ast_unregister_application(app);
  60. }
  61. int load_module(void)
  62. {
  63. return ast_register_application(app, transfer_exec, synopsis, descrip);
  64. }
  65. char *description(void)
  66. {
  67. return tdesc;
  68. }
  69. int usecount(void)
  70. {
  71. int res;
  72. STANDARD_USECOUNT(res);
  73. return res;
  74. }
  75. char *key()
  76. {
  77. return ASTERISK_GPL_KEY;
  78. }