|
21 | 21 | * \brief App to transmit a text message
|
22 | 22 | *
|
23 | 23 | * \author Mark Spencer <markster@digium.com>
|
| 24 | + * \author Naveen Albert <asterisk@phreaknet.org> |
24 | 25 | *
|
25 | 26 | * \note Requires support of sending text messages from channel driver
|
26 | 27 | *
|
|
140 | 141 | <see-also>
|
141 | 142 | <ref type="application">SendImage</ref>
|
142 | 143 | <ref type="application">SendURL</ref>
|
| 144 | + <ref type="application">ReceiveText</ref> |
| 145 | + </see-also> |
| 146 | + </application> |
| 147 | + <application name="ReceiveText" language="en_US"> |
| 148 | + <synopsis> |
| 149 | + Receive a Text Message on a channel. |
| 150 | + </synopsis> |
| 151 | + <syntax> |
| 152 | + <parameter name="timeout" required="false"> |
| 153 | + <para>Time in seconds to wait for text. Default is 0 (forever).</para> |
| 154 | + </parameter> |
| 155 | + </syntax> |
| 156 | + <description> |
| 157 | + <para>Waits for <replaceable>timeout</replaceable> seconds on the current channel |
| 158 | + to receive text.</para> |
| 159 | + <para>Result of transmission will be stored in the following variables:</para> |
| 160 | + <variablelist> |
| 161 | + <variable name="RECEIVETEXTMESSAGE"> |
| 162 | + <para>The received text message.</para> |
| 163 | + </variable> |
| 164 | + <variable name="RECEIVETEXTSTATUS"> |
| 165 | + <value name="SUCCESS"> |
| 166 | + Transmission succeeded. |
| 167 | + </value> |
| 168 | + <value name="FAILURE"> |
| 169 | + Transmission failed or timed out. |
| 170 | + </value> |
| 171 | + </variable> |
| 172 | + </variablelist> |
| 173 | + <example title="Receive message on channel"> |
| 174 | + same => n,ReceiveText() |
| 175 | + same => n,NoOp(${RECEIVETEXTMESSAGE}) |
| 176 | + </example> |
| 177 | + </description> |
| 178 | + <see-also> |
| 179 | + <ref type="application">SendText</ref> |
| 180 | + <ref type="application">SendImage</ref> |
| 181 | + <ref type="application">SendURL</ref> |
143 | 182 | </see-also>
|
144 | 183 | </application>
|
145 | 184 | ***/
|
146 | 185 |
|
147 | 186 | static const char * const app = "SendText";
|
| 187 | +static const char * const app2 = "ReceiveText"; |
148 | 188 |
|
149 | 189 | static int sendtext_exec(struct ast_channel *chan, const char *data)
|
150 | 190 | {
|
@@ -237,14 +277,55 @@ static int sendtext_exec(struct ast_channel *chan, const char *data)
|
237 | 277 | return rc;
|
238 | 278 | }
|
239 | 279 |
|
| 280 | +static int recvtext_exec(struct ast_channel *chan, const char *data) |
| 281 | +{ |
| 282 | + double timeout = 0, timeout_ms = 0; |
| 283 | + char *parse, *buf; |
| 284 | + |
| 285 | + AST_DECLARE_APP_ARGS(args, |
| 286 | + AST_APP_ARG(timeout); |
| 287 | + ); |
| 288 | + |
| 289 | + parse = ast_strdupa(data); |
| 290 | + |
| 291 | + AST_STANDARD_APP_ARGS(args, parse); |
| 292 | + |
| 293 | + if (!ast_strlen_zero(args.timeout)) { |
| 294 | + if (sscanf(args.timeout, "%30lg", &timeout) != 1) { |
| 295 | + ast_log(LOG_WARNING, "Invalid timeout provided: %s. No timeout set.\n", args.timeout); |
| 296 | + return -1; |
| 297 | + } |
| 298 | + timeout_ms = timeout * 1000.0; |
| 299 | + } |
| 300 | + |
| 301 | + buf = ast_recvtext(chan, timeout_ms); |
| 302 | + pbx_builtin_setvar_helper(chan, "RECEIVETEXTSTATUS", buf ? "SUCCESS" : "FAILURE"); |
| 303 | + if (buf) { |
| 304 | + pbx_builtin_setvar_helper(chan, "RECEIVETEXTMESSAGE", buf); |
| 305 | + ast_free(buf); |
| 306 | + } |
| 307 | + |
| 308 | + return 0; |
| 309 | +} |
| 310 | + |
240 | 311 | static int unload_module(void)
|
241 | 312 | {
|
242 |
| - return ast_unregister_application(app); |
| 313 | + int res; |
| 314 | + |
| 315 | + res = ast_unregister_application(app); |
| 316 | + res |= ast_unregister_application(app2); |
| 317 | + |
| 318 | + return res; |
243 | 319 | }
|
244 | 320 |
|
245 | 321 | static int load_module(void)
|
246 | 322 | {
|
247 |
| - return ast_register_application_xml(app, sendtext_exec); |
| 323 | + int res; |
| 324 | + |
| 325 | + res = ast_register_application_xml(app, sendtext_exec); |
| 326 | + res |= ast_register_application_xml(app2, recvtext_exec); |
| 327 | + |
| 328 | + return res; |
248 | 329 | }
|
249 | 330 |
|
250 |
| -AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications"); |
| 331 | +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send and Receive Text Applications"); |
0 commit comments