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