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: 152133 $")
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): 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 );
00068
00069 if (ast_strlen_zero((char *)data)) {
00070 ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
00071 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00072 return 0;
00073 } else
00074 parse = ast_strdupa(data);
00075
00076 AST_STANDARD_APP_ARGS(args, parse);
00077
00078 dest = args.dest;
00079
00080 if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
00081 tech = dest;
00082 dest = slash + 1;
00083
00084 if (strncasecmp(chan->tech->type, tech, len)) {
00085 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
00086 return 0;
00087 }
00088 }
00089
00090
00091 if (!chan->tech->transfer) {
00092 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
00093 return 0;
00094 }
00095
00096 res = ast_transfer(chan, dest);
00097
00098 if (res < 0) {
00099 status = "FAILURE";
00100 res = 0;
00101 } else {
00102 status = "SUCCESS";
00103 res = 0;
00104 }
00105
00106 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
00107
00108 return res;
00109 }
00110
00111 static int unload_module(void)
00112 {
00113 return ast_unregister_application(app);
00114 }
00115
00116 static int load_module(void)
00117 {
00118 return ast_register_application(app, transfer_exec, synopsis, descrip);
00119 }
00120
00121 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Transfers a caller to another extension");