app_originate.c File Reference

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"
#include "asterisk/format_cache.h"

Include dependency graph for app_originate.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int load_module (void)
static int originate_exec (struct ast_channel *chan, const char *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Originate call" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static const char app_originate [] = "Originate"
static struct ast_module_infoast_module_info = &__mod_info


Detailed Description

Originate application.

Author:
Roberto Casas <roberto.casas@diaple.com>

Russell Bryant <russell@digium.com>

Todo:
Make a way to be able to set variables (and functions) on the outbound channel, similar to the Variable headers for the AMI Originate, and the Set options for call files.

Definition in file app_originate.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 246 of file app_originate.c.

static void __unreg_module ( void   )  [static]

Definition at line 246 of file app_originate.c.

static int load_module ( void   )  [static]

static int originate_exec ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 100 of file app_originate.c.

References ao2_cleanup, 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_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_slin, ast_format_slin12, ast_format_slin16, ast_format_slin192, ast_format_slin24, ast_format_slin32, ast_format_slin44, ast_format_slin48, ast_format_slin96, ast_log, ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, exten, LOG_ERROR, LOG_NOTICE, LOG_WARNING, NULL, parse(), pbx_builtin_setvar_helper(), S_OR, strsep(), timeout, and type.

Referenced by load_module().

00101 {
00102    AST_DECLARE_APP_ARGS(args,
00103       AST_APP_ARG(tech_data);
00104       AST_APP_ARG(type);
00105       AST_APP_ARG(arg1);
00106       AST_APP_ARG(arg2);
00107       AST_APP_ARG(arg3);
00108       AST_APP_ARG(timeout);
00109    );
00110    char *parse;
00111    char *chantech, *chandata;
00112    int res = -1;
00113    int outgoing_status = 0;
00114    unsigned int timeout = 30;
00115    static const char default_exten[] = "s";
00116    struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
00117 
00118    ast_autoservice_start(chan);
00119    if (!cap_slin) {
00120       goto return_cleanup;
00121    }
00122 
00123    ast_format_cap_append(cap_slin, ast_format_slin, 0);
00124    ast_format_cap_append(cap_slin, ast_format_slin12, 0);
00125    ast_format_cap_append(cap_slin, ast_format_slin16, 0);
00126    ast_format_cap_append(cap_slin, ast_format_slin24, 0);
00127    ast_format_cap_append(cap_slin, ast_format_slin32, 0);
00128    ast_format_cap_append(cap_slin, ast_format_slin44, 0);
00129    ast_format_cap_append(cap_slin, ast_format_slin48, 0);
00130    ast_format_cap_append(cap_slin, ast_format_slin96, 0);
00131    ast_format_cap_append(cap_slin, ast_format_slin192, 0);
00132 
00133    if (ast_strlen_zero(data)) {
00134       ast_log(LOG_ERROR, "Originate() requires arguments\n");
00135       goto return_cleanup;
00136    }
00137 
00138    parse = ast_strdupa(data);
00139 
00140    AST_STANDARD_APP_ARGS(args, parse);
00141 
00142    if (args.argc < 3) {
00143       ast_log(LOG_ERROR, "Incorrect number of arguments\n");
00144       goto return_cleanup;
00145    }
00146 
00147    if (!ast_strlen_zero(args.timeout)) {
00148       if(sscanf(args.timeout, "%u", &timeout) != 1) {
00149          ast_log(LOG_NOTICE, "Invalid timeout: '%s'. Setting timeout to 30 seconds\n", args.timeout);
00150          timeout = 30;
00151       }
00152    }
00153 
00154    chandata = ast_strdupa(args.tech_data);
00155    chantech = strsep(&chandata, "/");
00156 
00157    if (ast_strlen_zero(chandata) || ast_strlen_zero(chantech)) {
00158       ast_log(LOG_ERROR, "Channel Tech/Data invalid: '%s'\n", args.tech_data);
00159       goto return_cleanup;
00160    }
00161 
00162    if (!strcasecmp(args.type, "exten")) {
00163       int priority = 1; /* Initialized in case priority not specified */
00164       const char *exten = args.arg2;
00165 
00166       if (args.argc == 5) {
00167          /* Context/Exten/Priority all specified */
00168          if (sscanf(args.arg3, "%30d", &priority) != 1) {
00169             ast_log(LOG_ERROR, "Invalid priority: '%s'\n", args.arg3);
00170             goto return_cleanup;
00171          }
00172       } else if (args.argc == 3) {
00173          /* Exten not specified */
00174          exten = default_exten;
00175       }
00176 
00177       ast_debug(1, "Originating call to '%s/%s' and connecting them to extension %s,%s,%d\n",
00178             chantech, chandata, args.arg1, exten, priority);
00179 
00180       ast_pbx_outgoing_exten(chantech, cap_slin, chandata,
00181             timeout * 1000, args.arg1, exten, priority, &outgoing_status, 1, NULL,
00182             NULL, NULL, NULL, NULL, 0, NULL);
00183    } else if (!strcasecmp(args.type, "app")) {
00184       ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
00185             chantech, chandata, args.arg1, S_OR(args.arg2, ""));
00186 
00187       ast_pbx_outgoing_app(chantech, cap_slin, chandata,
00188             timeout * 1000, args.arg1, args.arg2, &outgoing_status, 1, NULL,
00189             NULL, NULL, NULL, NULL, NULL);
00190    } else {
00191       ast_log(LOG_ERROR, "Incorrect type, it should be 'exten' or 'app': %s\n",
00192             args.type);
00193       goto return_cleanup;
00194    }
00195 
00196    res = 0;
00197 
00198 return_cleanup:
00199    if (res) {
00200       pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "FAILED");
00201    } else {
00202       switch (outgoing_status) {
00203       case 0:
00204       case AST_CONTROL_ANSWER:
00205          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "SUCCESS");
00206          break;
00207       case AST_CONTROL_BUSY:
00208          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "BUSY");
00209          break;
00210       case AST_CONTROL_CONGESTION:
00211          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "CONGESTION");
00212          break;
00213       case AST_CONTROL_HANGUP:
00214          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "HANGUP");
00215          break;
00216       case AST_CONTROL_RINGING:
00217          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "RINGING");
00218          break;
00219       default:
00220          ast_log(LOG_WARNING, "Unknown originate status result of '%d'\n",
00221                outgoing_status);
00222          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "UNKNOWN");
00223          break;
00224       }
00225    }
00226    ao2_cleanup(cap_slin);
00227    ast_autoservice_stop(chan);
00228 
00229    return res;
00230 }

static int unload_module ( void   )  [static]

Definition at line 232 of file app_originate.c.

References ast_unregister_application().

00233 {
00234    return ast_unregister_application(app_originate);
00235 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Originate call" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 246 of file app_originate.c.

const char app_originate[] = "Originate" [static]

Definition at line 50 of file app_originate.c.

Definition at line 246 of file app_originate.c.


Generated on Thu Apr 16 06:28:36 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6