/* * Asterisk -- A telephony toolkit for Linux. * * Switch call application through a CLI command * * Copyright (C) 2003, Thomas Häger * * Thomas Häger * * This program is free software, distributed under the terms of * the GNU General Public License */ #include #include #include #include #include #include #include #include #include #include #include static char *tdesc = "Make two calls from within Asterisk and switch them together"; static char *app = "Switch call"; static int switch_call(char *dialtech1,char *dialtech2,char *dialstr1,char *dialstr2) { int res=0; struct ast_channel *c1; struct ast_channel *c2; int reason; struct ast_frame *f; struct ast_channel *who; c1=ast_request_and_dial(dialtech1, AST_FORMAT_SLINEAR, dialstr1,10000, &reason,"1234"); if (!c1) { ast_log(LOG_WARNING,"Can't create channel 1!\n"); return -1; } ast_log(LOG_NOTICE, "Reason: [%d]\n",c1->_state); if (c1->_state==AST_STATE_UP) { ast_log(LOG_NOTICE, "First channel connected!\n"); c2=ast_request_and_dial(dialtech2, AST_FORMAT_SLINEAR, dialstr2,10000, &reason, "5678"); if (!c2) { ast_log(LOG_WARNING,"Can't create channel 2!\n"); return -1; } if (c2->_state==AST_STATE_UP) { ast_log(LOG_NOTICE, "Both channels connected!\n"); ast_channel_make_compatible(c1, c2); res=ast_channel_bridge(c1, c2,AST_BRIDGE_REC_CHANNEL_0 + AST_BRIDGE_REC_CHANNEL_1, &f, &who); if (res) ast_log(LOG_NOTICE, "Call switched between [%s] <-> [%s]\n",c1->name,c2->name); else ast_log(LOG_WARNING, "Bridge failed on channels %s and %s\n", c1->name, c2->name); } } else { ast_log(LOG_NOTICE, "Wrong call state!\n"); ast_softhangup(c1,AST_SOFTHANGUP_EXPLICIT); } ast_hangup(c2); ast_hangup(c1); return res; } static int init_call(char *dialtech,char *dialstr,char *context,char *exten ,char *prio) { int res=0; int reason; struct ast_frame *f; struct ast_channel *who; struct ast_channel *c; int pri=atoi(prio); c=ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, dialstr,10000, &reason,"1234"); if (!c) { ast_log(LOG_WARNING,"Can't create channel!\n"); return -1; } if (c->_state==AST_STATE_UP) { ast_log(LOG_NOTICE,"Context: %s\tExten: %s\tPrio: %s\n",context,exten,prio); ast_async_goto_by_name(c,context,exten,pri); } } static int start_switch(int fd,int argc, char *argv[]) { int res=0; char *dialtech1, *dialstr1,*dialtech2, *dialstr2; if (argc!=4) return RESULT_SHOWUSAGE; dialtech1=strsep(&argv[2], "/"); dialstr1=argv[2]; dialtech2=strsep(&argv[3], "/"); dialstr2=argv[3]; ast_log (LOG_NOTICE,"start switch ..."); res=switch_call(dialtech1,dialtech2,dialstr1,dialstr2); return RESULT_SUCCESS; } static int make_call(int fd,int argc, char *argv[]) { int res=0; char *dialtech, *dialstr ; if (argc!=6) return RESULT_SHOWUSAGE; dialtech=strsep(&argv[2], "/"); dialstr=argv[2]; init_call(dialtech,dialstr,argv[3],argv[4],argv[5]); return RESULT_SUCCESS; } static char show_switch_usage[] = "Usage: switch call <[Techn1]/[Address1]> <[Techn2]/[Address2]>\n" " Make two calls with the two given technologies and switch them together\n"; static char show_make_call_usage[] = "Usage: make call <[Techn]/[Address]> \n" " Make two calls with the two given technologies and switch them together\n"; static struct ast_cli_entry cli_switch_call = { { "switch", "call", NULL, NULL }, start_switch, "Switch Test", show_switch_usage }; static struct ast_cli_entry cli_make_call = { { "make", "call", NULL, NULL ,NULL, NULL}, make_call, "Switch Test", show_make_call_usage }; int unload_module(void) { ast_cli_unregister(&cli_switch_call); ast_cli_unregister(&cli_make_call); return 0; } int load_module(void) { ast_cli_register(&cli_switch_call); ast_cli_register(&cli_make_call); return 0; } char *description(void) { return tdesc; } int usecount(void) { return 0; } char *key() { return ASTERISK_GPL_KEY; }