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 #include "asterisk.h"
00031
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89522 $")
00033
00034 #include "asterisk/pbx.h"
00035 #include "asterisk/module.h"
00036 #include "asterisk/app.h"
00037 #include "asterisk/channel.h"
00038
00039
00040 static const char *app = "Transfer";
00041
00042 static const char *synopsis = "Transfer caller to remote extension";
00043
00044 static const char *descrip =
00045 " Transfer([Tech/]dest[,options]): Requests the remote caller be transferred\n"
00046 "to a given destination. If TECH (SIP, IAX2, LOCAL etc) is used, only\n"
00047 "an incoming call with the same channel technology will be transfered.\n"
00048 "Note that for SIP, if you transfer before call is setup, a 302 redirect\n"
00049 "SIP message will be returned to the caller.\n"
00050 "\nThe result of the application will be reported in the TRANSFERSTATUS\n"
00051 "channel variable:\n"
00052 " SUCCESS Transfer succeeded\n"
00053 " FAILURE Transfer failed\n"
00054 " UNSUPPORTED Transfer unsupported by channel driver\n";
00055
00056 static int transfer_exec(struct ast_channel *chan, void *data)
00057 {
00058 int res;
00059 int len;
00060 char *slash;
00061 char *tech = NULL;
00062 char *dest = NULL;
00063 char *status;
00064 char *parse;
00065 AST_DECLARE_APP_ARGS(args,
00066 AST_APP_ARG(dest);
00067 AST_APP_ARG(options);
00068 );
00069
00070 if (ast_strlen_zero((char *)data)) {
00071 ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination[,options])\n");
00072 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00073 return 0;
00074 } else
00075 parse = ast_strdupa(data);
00076
00077 AST_STANDARD_APP_ARGS(args, parse);
00078
00079 if (args.options) {
00080 }
00081
00082 dest = args.dest;
00083
00084 if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
00085 tech = dest;
00086 dest = slash + 1;
00087
00088 if (strncasecmp(chan->tech->type, tech, len)) {
00089 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00090 return 0;
00091 }
00092 }
00093
00094
00095 if (!chan->tech->transfer) {
00096 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
00097 return 0;
00098 }
00099
00100 res = ast_transfer(chan, dest);
00101
00102 if (res < 0) {
00103 status = "FAILURE";
00104 res = 0;
00105 } else {
00106 status = "SUCCESS";
00107 res = 0;
00108 }
00109
00110 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
00111
00112 return res;
00113 }
00114
00115 static int unload_module(void)
00116 {
00117 return ast_unregister_application(app);
00118 }
00119
00120 static int load_module(void)
00121 {
00122 return ast_register_application(app, transfer_exec, synopsis, descrip);
00123 }
00124
00125 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Transfers a caller to another extension");