app_sendtext.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief App to transmit a text message
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. *
  24. * \note Requires support of sending text messages from channel driver
  25. *
  26. * \ingroup applications
  27. */
  28. /*** MODULEINFO
  29. <support_level>core</support_level>
  30. ***/
  31. #include "asterisk.h"
  32. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  33. #include "asterisk/file.h"
  34. #include "asterisk/channel.h"
  35. #include "asterisk/pbx.h"
  36. #include "asterisk/module.h"
  37. #include "asterisk/app.h"
  38. /*** DOCUMENTATION
  39. <application name="SendText" language="en_US">
  40. <synopsis>
  41. Send a Text Message.
  42. </synopsis>
  43. <syntax>
  44. <parameter name="text" required="true" />
  45. </syntax>
  46. <description>
  47. <para>Sends <replaceable>text</replaceable> to current channel (callee).</para>
  48. <para>Result of transmission will be stored in the <variable>SENDTEXTSTATUS</variable></para>
  49. <variablelist>
  50. <variable name="SENDTEXTSTATUS">
  51. <value name="SUCCESS">
  52. Transmission succeeded.
  53. </value>
  54. <value name="FAILURE">
  55. Transmission failed.
  56. </value>
  57. <value name="UNSUPPORTED">
  58. Text transmission not supported by channel.
  59. </value>
  60. </variable>
  61. </variablelist>
  62. <note><para>At this moment, text is supposed to be 7 bit ASCII in most channels.</para></note>
  63. </description>
  64. <see-also>
  65. <ref type="application">SendImage</ref>
  66. <ref type="application">SendURL</ref>
  67. </see-also>
  68. </application>
  69. ***/
  70. static const char * const app = "SendText";
  71. static int sendtext_exec(struct ast_channel *chan, const char *data)
  72. {
  73. char *status = "UNSUPPORTED";
  74. struct ast_str *str;
  75. /* NOT ast_strlen_zero, because some protocols (e.g. SIP) MUST be able to
  76. * send a zero-length message. */
  77. if (!data) {
  78. ast_log(LOG_WARNING, "SendText requires an argument (text)\n");
  79. return -1;
  80. }
  81. if (!(str = ast_str_alloca(strlen(data) + 1))) {
  82. return -1;
  83. }
  84. ast_str_get_encoded_str(&str, -1, data);
  85. ast_channel_lock(chan);
  86. if (!ast_channel_tech(chan)->send_text) {
  87. ast_channel_unlock(chan);
  88. /* Does not support transport */
  89. pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
  90. return 0;
  91. }
  92. status = "FAILURE";
  93. if (!ast_sendtext(chan, ast_str_buffer(str))) {
  94. status = "SUCCESS";
  95. }
  96. ast_channel_unlock(chan);
  97. pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
  98. return 0;
  99. }
  100. static int unload_module(void)
  101. {
  102. return ast_unregister_application(app);
  103. }
  104. static int load_module(void)
  105. {
  106. return ast_register_application_xml(app, sendtext_exec);
  107. }
  108. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");