00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 239712 $")
00031
00032 #include "asterisk/file.h"
00033 #include "asterisk/channel.h"
00034 #include "asterisk/pbx.h"
00035 #include "asterisk/module.h"
00036 #include "asterisk/lock.h"
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 static char *app = "WaitForRing";
00055
00056 static int waitforring_exec(struct ast_channel *chan, const char *data)
00057 {
00058 struct ast_frame *f;
00059 struct ast_silence_generator *silgen = NULL;
00060 int res = 0;
00061 double s;
00062 int ms;
00063
00064 if (!data || (sscanf(data, "%30lg", &s) != 1)) {
00065 ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n");
00066 return 0;
00067 }
00068
00069 if (ast_opt_transmit_silence) {
00070 silgen = ast_channel_start_silence_generator(chan);
00071 }
00072
00073 ms = s * 1000.0;
00074 while (ms > 0) {
00075 ms = ast_waitfor(chan, ms);
00076 if (ms < 0) {
00077 res = ms;
00078 break;
00079 }
00080 if (ms > 0) {
00081 f = ast_read(chan);
00082 if (!f) {
00083 res = -1;
00084 break;
00085 }
00086 if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_RING)) {
00087 ast_verb(3, "Got a ring but still waiting for timeout\n");
00088 }
00089 ast_frfree(f);
00090 }
00091 }
00092
00093 if (!res) {
00094 ms = 99999999;
00095 while(ms > 0) {
00096 ms = ast_waitfor(chan, ms);
00097 if (ms < 0) {
00098 res = ms;
00099 break;
00100 }
00101 if (ms > 0) {
00102 f = ast_read(chan);
00103 if (!f) {
00104 res = -1;
00105 break;
00106 }
00107 if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_RING)) {
00108 ast_verb(3, "Got a ring after the timeout\n");
00109 ast_frfree(f);
00110 break;
00111 }
00112 ast_frfree(f);
00113 }
00114 }
00115 }
00116
00117 if (silgen) {
00118 ast_channel_stop_silence_generator(chan, silgen);
00119 }
00120
00121 return res;
00122 }
00123
00124 static int unload_module(void)
00125 {
00126 return ast_unregister_application(app);
00127 }
00128
00129 static int load_module(void)
00130 {
00131 return ast_register_application_xml(app, waitforring_exec);
00132 }
00133
00134 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Waits until first ring after time");