app_softhangup.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * SoftHangup application
  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 <sys/types.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/lock.h>
  20. #include <stdlib.h>
  21. #include <unistd.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. static char *synopsis = "Soft Hangup Application";
  25. static char *tdesc = "Hangs up the requested channel";
  26. static char *desc = " SoftHangup(Technology/resource)\n"
  27. "Hangs up the requested channel. Always returns 0\n";
  28. static char *app = "SoftHangup";
  29. STANDARD_LOCAL_USER;
  30. LOCAL_USER_DECL;
  31. static int softhangup_exec(struct ast_channel *chan, void *data)
  32. {
  33. struct localuser *u;
  34. struct ast_channel *c=NULL;
  35. if (!data) {
  36. ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
  37. return 0;
  38. }
  39. LOCAL_USER_ADD(u);
  40. c = ast_channel_walk_locked(NULL);
  41. while (c) {
  42. if (!strcasecmp(c->name, data)) {
  43. ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
  44. ast_mutex_unlock(&c->lock);
  45. break;
  46. }
  47. ast_mutex_unlock(&c->lock);
  48. c = ast_channel_walk_locked(c);
  49. }
  50. LOCAL_USER_REMOVE(u);
  51. return 0;
  52. }
  53. int unload_module(void)
  54. {
  55. STANDARD_HANGUP_LOCALUSERS;
  56. return ast_unregister_application(app);
  57. }
  58. int load_module(void)
  59. {
  60. return ast_register_application(app, softhangup_exec, synopsis, desc);
  61. }
  62. char *description(void)
  63. {
  64. return tdesc;
  65. }
  66. int usecount(void)
  67. {
  68. int res;
  69. STANDARD_USECOUNT(res);
  70. return res;
  71. }
  72. char *key()
  73. {
  74. return ASTERISK_GPL_KEY;
  75. }