app_sendtext.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * App to transmit a text message
  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/channel_pvt.h>
  18. #include <asterisk/pbx.h>
  19. #include <asterisk/module.h>
  20. #include <asterisk/translate.h>
  21. #include <asterisk/image.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. static char *tdesc = "Send Text Applications";
  25. static char *app = "SendText";
  26. static char *synopsis = "Send a Text Message";
  27. static char *descrip =
  28. " SendText(text): Sends text to client. If the client\n"
  29. "does not support text 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. "SendText only returns 0 if the text was sent correctly or if\n"
  33. "the channel does not support text transport, and -1 otherwise.\n";
  34. STANDARD_LOCAL_USER;
  35. LOCAL_USER_DECL;
  36. static int sendtext_exec(struct ast_channel *chan, void *data)
  37. {
  38. int res = 0;
  39. struct localuser *u;
  40. if (!data || !strlen((char *)data)) {
  41. ast_log(LOG_WARNING, "SendText requires an argument (text)\n");
  42. return -1;
  43. }
  44. LOCAL_USER_ADD(u);
  45. ast_mutex_lock(&chan->lock);
  46. if (!chan->pvt->send_text) {
  47. ast_mutex_unlock(&chan->lock);
  48. /* Does not support transport */
  49. if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
  50. chan->priority += 100;
  51. LOCAL_USER_REMOVE(u);
  52. return 0;
  53. }
  54. ast_mutex_unlock(&chan->lock);
  55. res = ast_sendtext(chan, (char *)data);
  56. LOCAL_USER_REMOVE(u);
  57. return res;
  58. }
  59. int unload_module(void)
  60. {
  61. STANDARD_HANGUP_LOCALUSERS;
  62. return ast_unregister_application(app);
  63. }
  64. int load_module(void)
  65. {
  66. return ast_register_application(app, sendtext_exec, synopsis, descrip);
  67. }
  68. char *description(void)
  69. {
  70. return tdesc;
  71. }
  72. int usecount(void)
  73. {
  74. int res;
  75. STANDARD_USECOUNT(res);
  76. return res;
  77. }
  78. char *key()
  79. {
  80. return ASTERISK_GPL_KEY;
  81. }