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
00033
00034
00035
00036 #include "asterisk.h"
00037
00038 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 354495 $")
00039
00040 #include "asterisk/file.h"
00041 #include "asterisk/channel.h"
00042 #include "asterisk/pbx.h"
00043 #include "asterisk/module.h"
00044 #include "asterisk/features.h"
00045 #include "asterisk/say.h"
00046 #include "asterisk/lock.h"
00047 #include "asterisk/utils.h"
00048 #include "asterisk/app.h"
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
00087
00088
00089
00090 static char *app = "ParkAndAnnounce";
00091
00092 static int parkandannounce_exec(struct ast_channel *chan, const char *data)
00093 {
00094 int res = -1;
00095 int lot, timeout = 0, dres;
00096 char *dialtech, *tmp[100], buf[13];
00097 int looptemp, i;
00098 char *s;
00099 struct ast_party_id caller_id;
00100
00101 struct ast_channel *dchan;
00102 struct outgoing_helper oh = { 0, };
00103 int outstate;
00104 AST_DECLARE_APP_ARGS(args,
00105 AST_APP_ARG(template);
00106 AST_APP_ARG(timeout);
00107 AST_APP_ARG(dial);
00108 AST_APP_ARG(return_context);
00109 );
00110 if (ast_strlen_zero(data)) {
00111 ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce_template,timeout,dial,[return_context])\n");
00112 return -1;
00113 }
00114
00115 s = ast_strdupa(data);
00116 AST_STANDARD_APP_ARGS(args, s);
00117
00118 if (args.timeout)
00119 timeout = atoi(args.timeout) * 1000;
00120
00121 if (ast_strlen_zero(args.dial)) {
00122 ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or DAHDI/g1/5551212\n");
00123 return -1;
00124 }
00125
00126 dialtech = strsep(&args.dial, "/");
00127 ast_verb(3, "Dial Tech,String: (%s,%s)\n", dialtech, args.dial);
00128
00129 if (!ast_strlen_zero(args.return_context)) {
00130 ast_clear_flag(chan, AST_FLAG_IN_AUTOLOOP);
00131 ast_parseable_goto(chan, args.return_context);
00132 }
00133
00134 ast_verb(3, "Return Context: (%s,%s,%d) ID: %s\n", chan->context, chan->exten,
00135 chan->priority,
00136 S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, ""));
00137 if (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority,
00138 S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
00139 ast_verb(3, "Warning: Return Context Invalid, call will return to default|s\n");
00140 }
00141
00142
00143 ast_party_id_init(&caller_id);
00144 ast_channel_lock(chan);
00145 ast_party_id_copy(&caller_id, &chan->caller.id);
00146 ast_channel_unlock(chan);
00147
00148
00149
00150
00151 res = ast_masq_park_call(chan, NULL, timeout, &lot);
00152 if (res) {
00153
00154 ast_party_id_free(&caller_id);
00155 return -1;
00156 }
00157
00158 ast_verb(3, "Call parked in space: %d, timeout: %d, return-context: %s\n",
00159 lot, timeout, args.return_context ? args.return_context : "");
00160
00161
00162
00163 snprintf(buf, sizeof(buf), "%d", lot);
00164 oh.parent_channel = chan;
00165 oh.vars = ast_variable_new("_PARKEDAT", buf, "");
00166 dchan = __ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, chan, args.dial, 30000,
00167 &outstate,
00168 S_COR(caller_id.number.valid, caller_id.number.str, NULL),
00169 S_COR(caller_id.name.valid, caller_id.name.str, NULL),
00170 &oh);
00171 ast_variables_destroy(oh.vars);
00172 ast_party_id_free(&caller_id);
00173 if (dchan) {
00174 if (dchan->_state == AST_STATE_UP) {
00175 ast_verb(4, "Channel %s was answered.\n", dchan->name);
00176 } else {
00177 ast_verb(4, "Channel %s was never answered.\n", dchan->name);
00178 ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", dchan->name);
00179 ast_hangup(dchan);
00180 return -1;
00181 }
00182 } else {
00183 ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n");
00184 return -1;
00185 }
00186
00187 ast_stopstream(dchan);
00188
00189
00190
00191 ast_verb(4, "Announce Template:%s\n", args.template);
00192
00193 for (looptemp = 0; looptemp < ARRAY_LEN(tmp); looptemp++) {
00194 if ((tmp[looptemp] = strsep(&args.template, ":")) != NULL)
00195 continue;
00196 else
00197 break;
00198 }
00199
00200 for (i = 0; i < looptemp; i++) {
00201 ast_verb(4, "Announce:%s\n", tmp[i]);
00202 if (!strcmp(tmp[i], "PARKED")) {
00203 ast_say_digits(dchan, lot, "", dchan->language);
00204 } else {
00205 dres = ast_streamfile(dchan, tmp[i], dchan->language);
00206 if (!dres) {
00207 dres = ast_waitstream(dchan, "");
00208 } else {
00209 ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], dchan->name);
00210 }
00211 }
00212 }
00213
00214 ast_stopstream(dchan);
00215 ast_hangup(dchan);
00216
00217 return res;
00218 }
00219
00220 static int unload_module(void)
00221 {
00222 return ast_unregister_application(app);
00223 }
00224
00225 static int load_module(void)
00226 {
00227
00228 return ast_register_application_xml(app, parkandannounce_exec);
00229 }
00230
00231 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Call Parking and Announce Application");