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: 170047 $")
00035
00036 #include "asterisk/file.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/module.h"
00040 #include "asterisk/features.h"
00041 #include "asterisk/say.h"
00042 #include "asterisk/lock.h"
00043 #include "asterisk/utils.h"
00044 #include "asterisk/app.h"
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 static char *app = "ParkAndAnnounce";
00087
00088 static int parkandannounce_exec(struct ast_channel *chan, void *data)
00089 {
00090 int res = -1;
00091 int lot, timeout = 0, dres;
00092 char *dialtech, *tmp[100], buf[13];
00093 int looptemp, i;
00094 char *s;
00095
00096 struct ast_channel *dchan;
00097 struct outgoing_helper oh = { 0, };
00098 int outstate;
00099 AST_DECLARE_APP_ARGS(args,
00100 AST_APP_ARG(template);
00101 AST_APP_ARG(timeout);
00102 AST_APP_ARG(dial);
00103 AST_APP_ARG(return_context);
00104 );
00105 if (ast_strlen_zero(data)) {
00106 ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce:template|timeout|dial|[return_context])\n");
00107 return -1;
00108 }
00109
00110 s = ast_strdupa(data);
00111 AST_STANDARD_APP_ARGS(args, s);
00112
00113 if (args.timeout)
00114 timeout = atoi(args.timeout) * 1000;
00115
00116 if (ast_strlen_zero(args.dial)) {
00117 ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or DAHDI/g1/5551212\n");
00118 return -1;
00119 }
00120
00121 dialtech = strsep(&args.dial, "/");
00122 ast_verb(3, "Dial Tech,String: (%s,%s)\n", dialtech, args.dial);
00123
00124 if (!ast_strlen_zero(args.return_context)) {
00125 ast_clear_flag(chan, AST_FLAG_IN_AUTOLOOP);
00126 ast_parseable_goto(chan, args.return_context);
00127 }
00128
00129 ast_verb(3, "Return Context: (%s,%s,%d) ID: %s\n", chan->context, chan->exten, chan->priority, chan->cid.cid_num);
00130 if (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
00131 ast_verb(3, "Warning: Return Context Invalid, call will return to default|s\n");
00132 }
00133
00134
00135
00136
00137 res = ast_masq_park_call(chan, NULL, timeout, &lot);
00138 if (res == -1)
00139 return res;
00140
00141 ast_verb(3, "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, args.return_context);
00142
00143
00144
00145 snprintf(buf, sizeof(buf), "%d", lot);
00146 oh.parent_channel = chan;
00147 oh.vars = ast_variable_new("_PARKEDAT", buf, "");
00148 dchan = __ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, args.dial, 30000, &outstate, chan->cid.cid_num, chan->cid.cid_name, &oh);
00149
00150 if (dchan) {
00151 if (dchan->_state == AST_STATE_UP) {
00152 ast_verb(4, "Channel %s was answered.\n", dchan->name);
00153 } else {
00154 ast_verb(4, "Channel %s was never answered.\n", dchan->name);
00155 ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", dchan->name);
00156 ast_hangup(dchan);
00157 return -1;
00158 }
00159 } else {
00160 ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n");
00161 return -1;
00162 }
00163
00164 ast_stopstream(dchan);
00165
00166
00167
00168 ast_verb(4, "Announce Template:%s\n", args.template);
00169
00170 for (looptemp = 0; looptemp < ARRAY_LEN(tmp); looptemp++) {
00171 if ((tmp[looptemp] = strsep(&args.template, ":")) != NULL)
00172 continue;
00173 else
00174 break;
00175 }
00176
00177 for (i = 0; i < looptemp; i++) {
00178 ast_verb(4, "Announce:%s\n", tmp[i]);
00179 if (!strcmp(tmp[i], "PARKED")) {
00180 ast_say_digits(dchan, lot, "", dchan->language);
00181 } else {
00182 dres = ast_streamfile(dchan, tmp[i], dchan->language);
00183 if (!dres) {
00184 dres = ast_waitstream(dchan, "");
00185 } else {
00186 ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], dchan->name);
00187 dres = 0;
00188 }
00189 }
00190 }
00191
00192 ast_stopstream(dchan);
00193 ast_hangup(dchan);
00194
00195 return res;
00196 }
00197
00198 static int unload_module(void)
00199 {
00200 return ast_unregister_application(app);
00201 }
00202
00203 static int load_module(void)
00204 {
00205
00206 return ast_register_application_xml(app, parkandannounce_exec);
00207 }
00208
00209 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Call Parking and Announce Application");