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