Sat Aug 6 00:39:34 2011

Asterisk developer's documentation


app_channelredirect.c File Reference

ChannelRedirect application. More...

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/features.h"
#include "asterisk/options.h"

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int asyncgoto_exec (struct ast_channel *chan, void *data)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Channel Redirect" , .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, }
static char * app = "ChannelRedirect"
static const struct ast_module_infoast_module_info = &__mod_info
static char * descrip
static char * synopsis = "Redirects given channel to a dialplan target."


Detailed Description

ChannelRedirect application.

Author:
Sergey Basmanov <sergey_basmanov@mail.ru>

Definition in file app_channelredirect.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 145 of file app_channelredirect.c.

static void __unreg_module ( void   )  [static]

Definition at line 145 of file app_channelredirect.c.

static int asyncgoto_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 52 of file app_channelredirect.c.

References AST_APP_ARG, ast_async_goto_if_exists(), ast_channel_lock, ast_channel_unlock, AST_DECLARE_APP_ARGS, ast_findlabel_extension(), AST_FLAG_BRIDGE_HANGUP_DONT, ast_get_channel_by_name_locked(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_mutex_unlock(), ast_set_flag, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_channel::cid, ast_callerid::cid_num, ast_channel::context, context, ast_channel::exten, exten, ast_channel::lock, LOG_DEBUG, LOG_WARNING, option_debug, ast_channel::pbx, quit, and S_OR.

Referenced by load_module().

00053 {
00054    int res = -1;
00055    struct ast_module_user *u;
00056    char *info, *context, *exten, *priority;
00057    int prio = 1;
00058    struct ast_channel *chan2 = NULL;
00059 
00060    AST_DECLARE_APP_ARGS(args,
00061       AST_APP_ARG(channel);
00062       AST_APP_ARG(label);
00063    );
00064 
00065    if (ast_strlen_zero(data)) {
00066       ast_log(LOG_WARNING, "%s requires an argument (channel|[[context|]exten|]priority)\n", app);
00067       return -1;
00068    }
00069 
00070    u = ast_module_user_add(chan);
00071 
00072    info = ast_strdupa(data);
00073    AST_STANDARD_APP_ARGS(args, info);
00074 
00075    if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.label)) {
00076       ast_log(LOG_WARNING, "%s requires an argument (channel|[[context|]exten|]priority)\n", app);
00077       goto quit;
00078    }
00079 
00080    chan2 = ast_get_channel_by_name_locked(args.channel);
00081    if (!chan2) {
00082       ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
00083       goto quit;
00084    }
00085 
00086    /* Parsed right to left, so standard parsing won't work */
00087    context = strsep(&args.label, "|");
00088    exten = strsep(&args.label, "|");
00089    if (exten) {
00090       priority = strsep(&args.label, "|");
00091       if (!priority) {
00092          priority = exten;
00093          exten = context;
00094          context = NULL;
00095       }
00096    } else {
00097       priority = context;
00098       context = NULL;
00099    }
00100 
00101    /* ast_findlabel_extension does not convert numeric priorities; it only does a lookup */
00102    if (!(prio = atoi(priority)) && !(prio = ast_findlabel_extension(chan2, S_OR(context, chan2->context),
00103                            S_OR(exten, chan2->exten), priority, chan2->cid.cid_num))) {
00104       ast_log(LOG_WARNING, "'%s' is not a known priority or label\n", priority);
00105       goto chanquit;
00106    }
00107 
00108    if (option_debug > 1)
00109       ast_log(LOG_DEBUG, "Attempting async goto (%s) to %s|%s|%d\n", args.channel, S_OR(context, chan2->context), S_OR(exten, chan2->exten), prio);
00110 
00111    if (chan2->pbx) {
00112       ast_channel_lock(chan2);
00113       ast_set_flag(chan2, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */
00114       ast_channel_unlock(chan2);
00115    }
00116    if (ast_async_goto_if_exists(chan2, S_OR(context, chan2->context), S_OR(exten, chan2->exten), prio))
00117       ast_log(LOG_WARNING, "%s failed for %s\n", app, args.channel);
00118    else
00119       res = 0;
00120 
00121  chanquit:
00122    ast_mutex_unlock(&chan2->lock);
00123  quit:
00124    ast_module_user_remove(u);
00125 
00126    return res;
00127 }

static int load_module ( void   )  [static]

Definition at line 140 of file app_channelredirect.c.

References ast_register_application(), and asyncgoto_exec().

00141 {
00142    return ast_register_application(app, asyncgoto_exec, synopsis, descrip);
00143 }

static int unload_module ( void   )  [static]

Definition at line 129 of file app_channelredirect.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00130 {
00131    int res;
00132 
00133    res = ast_unregister_application(app);
00134 
00135    ast_module_user_hangup_all();
00136 
00137    return res; 
00138 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Channel Redirect" , .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 145 of file app_channelredirect.c.

char* app = "ChannelRedirect" [static]

Definition at line 45 of file app_channelredirect.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 145 of file app_channelredirect.c.

char* descrip [static]

Initial value:

 
"ChannelRedirect(channel|[[context|]extension|]priority):\n"
"  Sends the specified channel to the specified extension priority\n"

Definition at line 47 of file app_channelredirect.c.

char* synopsis = "Redirects given channel to a dialplan target." [static]

Definition at line 46 of file app_channelredirect.c.


Generated on Sat Aug 6 00:39:34 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7