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 #include "asterisk.h"
00036
00037 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 211580 $")
00038
00039 #include "asterisk/file.h"
00040 #include "asterisk/channel.h"
00041 #include "asterisk/pbx.h"
00042 #include "asterisk/module.h"
00043 #include "asterisk/app.h"
00044
00045 static const char app_originate[] = "Originate";
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
00087
00088
00089
00090
00091
00092 static int originate_exec(struct ast_channel *chan, void *data)
00093 {
00094 AST_DECLARE_APP_ARGS(args,
00095 AST_APP_ARG(tech_data);
00096 AST_APP_ARG(type);
00097 AST_APP_ARG(arg1);
00098 AST_APP_ARG(arg2);
00099 AST_APP_ARG(arg3);
00100 );
00101 char *parse;
00102 char *chantech, *chandata;
00103 int res = -1;
00104 int outgoing_res = 0;
00105 int outgoing_status = 0;
00106 static const unsigned int timeout = 30;
00107 static const char default_exten[] = "s";
00108
00109 ast_autoservice_start(chan);
00110
00111 if (ast_strlen_zero(data)) {
00112 ast_log(LOG_ERROR, "Originate() requires arguments\n");
00113 goto return_cleanup;
00114 }
00115
00116 parse = ast_strdupa(data);
00117
00118 AST_STANDARD_APP_ARGS(args, parse);
00119
00120 if (args.argc < 3) {
00121 ast_log(LOG_ERROR, "Incorrect number of arguments\n");
00122 goto return_cleanup;
00123 }
00124
00125 chandata = ast_strdupa(args.tech_data);
00126 chantech = strsep(&chandata, "/");
00127
00128 if (ast_strlen_zero(chandata) || ast_strlen_zero(chantech)) {
00129 ast_log(LOG_ERROR, "Channel Tech/Data invalid: '%s'\n", args.tech_data);
00130 goto return_cleanup;
00131 }
00132
00133 if (!strcasecmp(args.type, "exten")) {
00134 int priority = 1;
00135 const char *exten = args.arg2;
00136
00137 if (args.argc == 5) {
00138
00139 if (sscanf(args.arg3, "%30d", &priority) != 1) {
00140 ast_log(LOG_ERROR, "Invalid priority: '%s'\n", args.arg3);
00141 goto return_cleanup;
00142 }
00143 } else if (args.argc == 3) {
00144
00145 exten = default_exten;
00146 }
00147
00148 ast_debug(1, "Originating call to '%s/%s' and connecting them to extension %s,%s,%d\n",
00149 chantech, chandata, args.arg1, exten, priority);
00150
00151 outgoing_res = ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata,
00152 timeout * 1000, args.arg1, exten, priority, &outgoing_status, 0, NULL,
00153 NULL, NULL, NULL, NULL);
00154 } else if (!strcasecmp(args.type, "app")) {
00155 ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
00156 chantech, chandata, args.arg1, S_OR(args.arg2, ""));
00157
00158 outgoing_res = ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata,
00159 timeout * 1000, args.arg1, args.arg2, &outgoing_status, 0, NULL,
00160 NULL, NULL, NULL, NULL);
00161 } else {
00162 ast_log(LOG_ERROR, "Incorrect type, it should be 'exten' or 'app': %s\n",
00163 args.type);
00164 goto return_cleanup;
00165 }
00166
00167 res = 0;
00168
00169 return_cleanup:
00170 if (res) {
00171 pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "FAILED");
00172 } else {
00173 switch (outgoing_status) {
00174 case 0:
00175 case AST_CONTROL_ANSWER:
00176 pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "SUCCESS");
00177 break;
00178 case AST_CONTROL_BUSY:
00179 pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "BUSY");
00180 break;
00181 case AST_CONTROL_CONGESTION:
00182 pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "CONGESTION");
00183 break;
00184 case AST_CONTROL_HANGUP:
00185 pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "HANGUP");
00186 break;
00187 case AST_CONTROL_RINGING:
00188 pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "RINGING");
00189 break;
00190 default:
00191 ast_log(LOG_WARNING, "Unknown originate status result of '%d'\n",
00192 outgoing_status);
00193 pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "UNKNOWN");
00194 break;
00195 }
00196 }
00197
00198 ast_autoservice_stop(chan);
00199
00200 return res;
00201 }
00202
00203 static int unload_module(void)
00204 {
00205 return ast_unregister_application(app_originate);
00206 }
00207
00208 static int load_module(void)
00209 {
00210 int res;
00211
00212 res = ast_register_application_xml(app_originate, originate_exec);
00213
00214 return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
00215 }
00216
00217 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Originate call");