📄 cagi.c
字号:
// @param string $class//int AGITool_set_music(AGI_TOOLS *tool, AGI_CMD_RESULT *res, int enabled, char *class){ return AGITool_sendcmd(tool, res, "SET MUSIC %s %s\n", enabled?"ON":"OFF", class);}//// Still need to translate some from PHP to C//// *********************************************************************************************************// ** APPLICATIONS **// *********************************************************************************************************//// Set absolute maximum time of call//// Note that the timeout is set from the current time forward, not counting the number of seconds the call has already been up. // Each time you call AbsoluteTimeout(), all previous absolute timeouts are cancelled. // Will return the call to the T extension so that you can playback an explanatory note to the calling party (the called party // will not hear that)//// @link http://www.voip-info.org/wiki-Asterisk+-+documentation+of+application+commands// @link http://www.dynx.net/ASTERISK/AGI/ccard/agi-ccard.agi// @param seconds allowed, 0 disables timeout//int AGITool_exec_absolutetimeout(AGI_TOOLS *tool, AGI_CMD_RESULT *res, int seconds){ char secbuf[30]; snprintf(secbuf,sizeof(secbuf),"%d",seconds); return AGITool_exec(tool, res, "AbsoluteTimeout", secbuf);}// /**// * Executes an AGI compliant application// *// * @param string $command// * @return array, see evaluate for return information. ['result'] is -1 on hangup or if application requested hangup, or 0 on non-hangup exit.// * @param string $args// */// int AGITool_exec_agi(AGI_TOOLS *tool, AGI_CMD_RESULT *res,$command, $args)// {// return $this->exec("AGI $command", $args);// }//// /**// * Set Language // *// * @param string $language code// * @return array, see evaluate for return information.// */int AGITool_exec_setlanguage(AGI_TOOLS *tool, AGI_CMD_RESULT *res, char *language){ if (!language) { language="en"; } return AGITool_exec(tool, res, "SetLanguage", language);}// /**// * Do ENUM Lookup// *// * Note: to retrieve the result, use// * get_variable('ENUM');// *// * @param $exten// * @return array, see evaluate for return information.// */// int AGITool_exec_enumlookup(AGI_TOOLS *tool, AGI_CMD_RESULT *res,$exten)// {// return $this->exec('EnumLookup', $exten);// }/*** Dial** @link http://www.voip-info.org/wiki-Asterisk+cmd+Dial* @param string type* @param string destnum* @param string gateway* @param integer dialtimeout* @param integer sessiontimeout* @return result code*/int AGITool_exec_dial(AGI_TOOLS *tool, AGI_CMD_RESULT *res, char *type, char *destnum, char *gateway, int dialtimeout, int sessiontimeout){ return AGITool_sendcmd(tool, res, "EXEC Dial %s/%s@%s|%d|L(%d:80000:20000)\n", type, destnum, gateway, dialtimeout, sessiontimeout); }/*** Goto** This function takes three arguments: context,extension, and priority, but the leading arguments* are optional, not the trailing arguments. Thuse goto($z) sets the priority to $z.** @param string a* @param string b;* @param string c;* @return result code*/int AGITool_exec_goto(AGI_TOOLS *tool, AGI_CMD_RESULT *res, char *context, char *extension, char *priority){ char buf[255],*ptr; snprintf(buf, sizeof(buf), "%s|%s|%s", context?context:"",extension?extension:"",priority); ptr=buf; while (ptr[0]=='|') { ptr++; } return AGITool_exec(tool, res, "Goto", ptr);}// // *********************************************************************************************************// // ** DERIVED **// // *********************************************************************************************************//// /**// * Goto - Set context, extension and priority// *// * @param string $context// * @param string $extension// * @param string $priority// */// int AGITool_goto(AGI_TOOLS *tool, AGI_CMD_RESULT *res,$context, $extension='s', $priority=1)// {// $this->set_context($context);// $this->set_extension($extension);// $this->set_priority($priority);// }//// /**// * Parse caller id// *// * @example examples/dtmf.php Get DTMF tones from the user and say the digits// * @example examples/input.php Get text input from the user and say it back// *// * "name" <proto:user@server:port>// *// * @param string $callerid// * @return array('Name'=>$name, 'Number'=>$number)// */// int AGITool_parse_callerid(AGI_TOOLS *tool, AGI_CMD_RESULT *res,$callerid=NULL)// {// if(is_null($callerid))// $callerid = $this->request['agi_callerid'];//// $ret = array('name'=>'', 'protocol'=>'', 'username'=>'', 'host'=>'', 'port'=>'');// $callerid = trim($callerid);//// if($callerid{0} == '"' || $callerid{0} == "'")// {// $d = $callerid{0};// $callerid = explode($d, substr($callerid, 1));// $ret['name'] = array_shift($callerid);// $callerid = join($d, $callerid);// }//// $callerid = explode('@', trim($callerid, '<> '));// $username = explode(':', array_shift($callerid));// if(count($username) == 1)// $ret['username'] = $username[0];// else// {// $ret['protocol'] = array_shift($username);// $ret['username'] = join(':', $username);// }//// $callerid = join('@', $callerid);// $host = explode(':', $callerid);// if(count($host) == 1)// $ret['host'] = $host[0];// else// {// $ret['host'] = array_shift($host);// $ret['port'] = join(':', $host);// }//// return $ret;// }////// Use festival to read text//// @example examples/dtmf.php Get DTMF tones from the user and say the digits// @example examples/input.php Get text input from the user and say it back// @example examples/ping.php Ping an IP address//// @link http://www.cstr.ed.ac.uk/projects/festival/// @param string $text// @param string $escape_digits// @param integer $frequency - default 8000//int AGITool_text2wav(AGI_TOOLS *agi, AGI_CMD_RESULT *res, char *text, char *escape_digits, int frequency){ int ret=-1; char fname[MAXPATH], command[MAXPATH*2]; FILE *p; if(!strlen(text)) return 1; if (frequency <= 0) frequency=8000; // create the wave file snprintf(fname,sizeof(fname),"%s%ctxt2wav_%s", AGITool_ListGetVal(agi->settings,"tmpdir"), DIRECTORY_SEPARATOR, AGITool_ListGetVal(agi->agi_vars,"agi_uniqueid")); snprintf(command,sizeof(command),"%s -F %d -o %s.wav", AGITool_ListGetVal(agi->settings,"festival_text2wave"), frequency, fname); p = popen(command, "w"); if (p) { fputs(text, p); pclose(p); // stream it ret = AGITool_stream_file(agi,res,fname, escape_digits,0); // destroy it strcat(fname,".wav"); if(FileExists(fname)) unlink(fname); } return ret;}// /**// * Use Cepstral Swift to read text// *// * @link http://www.cepstral.com/// * @param string $text// * @param string $escape_digits// * @param integer $frequency// * @return array, see evaluate for return information.// */// int AGITool_swift(AGI_TOOLS *tool, AGI_CMD_RESULT *res,$text, $escape_digits='', $frequency=8000, $voice=NULL)// {// $text = trim($text);// if($text == '') return true;//// if(!is_null($voice))// $voice = "-n $voice";// elseif(isset($this->config['cepstral']['voice']))// $voice = "-n {$this->config['cepstral']['voice']}";//// // create the wave file// $fname = $this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR;// $fname .= str_replace('.', '_', 'swift_' . $this->request['agi_uniqueid']);// $p = popen("{$this->config['cepstral']['swift']} -p audio/channels=1,audio/sampling-rate=$frequency $voice -o $fname.wav -f -", 'w');// fputs($p, $text);// pclose($p);//// // stream it// $ret = $this->stream_file($fname, $escape_digits);//// // destroy it// if(file_exists($fname . '.wav'))// unlink($fname . '.wav');//// return $ret;// }//// /**// * Text Input// *// * Based on ideas found at http://www.voip-info.org/wiki-Asterisk+cmd+DTMFToText// *// * Example:// * UC H LC i , SP h o w SP a r e SP y o u ?// * $string = '*8'.'44*'.'*5'.'444*'.'00*'.'0*'.'44*'.'666*'.'9*'.'0*'.'2*'.'777*'.'33*'.'0*'.'999*'.'666*'.'88*'.'0000*';// *// * @link http://www.voip-info.org/wiki-Asterisk+cmd+DTMFToText// * @example examples/input.php Get text input from the user and say it back// *// * @return string// */// int AGITool_text_input(AGI_TOOLS *tool, AGI_CMD_RESULT *res,$mode='NUMERIC')// {// $alpha = array( 'k0'=>' ', 'k00'=>',', 'k000'=>'.', 'k0000'=>'?', 'k00000'=>'0',// 'k1'=>'!', 'k11'=>':', 'k111'=>';', 'k1111'=>'#', 'k11111'=>'1',// 'k2'=>'A', 'k22'=>'B', 'k222'=>'C', 'k2222'=>'2',// 'k3'=>'D', 'k33'=>'E', 'k333'=>'F', 'k3333'=>'3',// 'k4'=>'G', 'k44'=>'H', 'k444'=>'I', 'k4444'=>'4',// 'k5'=>'J', 'k55'=>'K', 'k555'=>'L', 'k5555'=>'5',// 'k6'=>'M', 'k66'=>'N', 'k666'=>'O', 'k6666'=>'6',// 'k7'=>'P', 'k77'=>'Q', 'k777'=>'R', 'k7777'=>'S', 'k77777'=>'7',// 'k8'=>'T', 'k88'=>'U', 'k888'=>'V', 'k8888'=>'8',// 'k9'=>'W', 'k99'=>'X', 'k999'=>'Y', 'k9999'=>'Z', 'k99999'=>'9');// $symbol = array('k0'=>'=',// 'k1'=>'<', 'k11'=>'(', 'k111'=>'[', 'k1111'=>'{', 'k11111'=>'1',// 'k2'=>'@', 'k22'=>'$', 'k222'=>'&', 'k2222'=>'%', 'k22222'=>'2',// 'k3'=>'>', 'k33'=>')', 'k333'=>']', 'k3333'=>'}', 'k33333'=>'3',// 'k4'=>'+', 'k44'=>'-', 'k444'=>'*', 'k4444'=>'/', 'k44444'=>'4',// 'k5'=>"'", 'k55'=>'`', 'k555'=>'5',// 'k6'=>'"', 'k66'=>'6',// 'k7'=>'^', 'k77'=>'7',// 'k8'=>"\\",'k88'=>'|', 'k888'=>'8',// 'k9'=>'_', 'k99'=>'~', 'k999'=>'9');// $text = '';// do// {// $command = false;// $result = $this->get_data('beep');// foreach(explode('*', $result['result']) as $code)// {// if($command)// {// switch($code{0})// {// case '2': $text = substr($text, 0, strlen($text) - 1); break; // backspace// case '5': $mode = 'LOWERCASE'; break;// case '6': $mode = 'NUMERIC'; break;// case '7': $mode = 'SYMBOL'; break;// case '8': $mode = 'UPPERCASE'; break;// case '9': $text = explode(' ', $text); unset($text[count($text)-1]); $text = join(' ', $text); break; // backspace a word// }// $code = substr($code, 1);// $command = false;// }// if($code == '')// $command = true;// elseif($mode == 'NUMERIC')// $text .= $code;// elseif($mode == 'UPPERCASE' && isset($alpha['k'.$code]))// $text .= $alpha['k'.$code];// elseif($mode == 'LOWERCASE' && isset($alpha['k'.$code]))// $text .= strtolower($alpha['k'.$code]);// elseif($mode == 'SYMBOL' && isset($symbol['k'.$code]))// $text .= $symbol['k'.$code];// }// $this->say_punctuation($text);// } while(substr($result['result'], -2) == '**');// return $text;// }//// /**// * Say Puncutation in a string// *// * @param string $text// * @param string $escape_digits// * @param integer $frequency// * @return array, see evaluate for return information.// */// int AGITool_say_punctuation(AGI_TOOLS *tool, AGI_CMD_RESULT *res,$text, $escape_digits='', $frequency=8000)// {// for($i = 0; $i < strlen($text); $i++)// {// switch($text{$i})// {// case ' ': $ret .= 'SPACE ';// case ',': $ret .= 'COMMA '; break;// case '.': $ret .= 'PERIOD '; break;// case '?': $ret .= 'QUESTION MARK '; break;// case '!': $ret .= 'EXPLANATION POINT '; break;// case ':': $ret .= 'COLON '; break;// case ';': $ret .= 'SEMICOLON '; break;// case '#': $ret .= 'POUND '; break;// case '=': $ret .= 'EQUALS '; break;// case '<': $ret .= 'LESS THAN '; break;// case '(': $ret .= 'LEFT PARENTHESIS '; break;// case '[': $ret .= 'LEFT BRACKET '; break;// case '{': $ret .= 'LEFT BRACE '; break;// case '@': $ret .= 'AT '; break;// case '$': $ret .= 'DOLLAR SIGN '; break;// case '&': $ret .= 'AMPERSAND '; break;// case '%': $ret .= 'PERCENT '; break;// case '>': $ret .= 'GREATER THAN '; break;// case ')': $ret .= 'RIGHT PARENTHESIS '; break;// case ']': $ret .= 'RIGHT BRACKET '; break;// case '}': $ret .= 'RIGHT BRACE '; break;// case '+': $ret .= 'PLUS '; break;// case '-': $ret .= 'MINUS '; break;// case '*': $ret .= 'ASTERISK '; break;// case '/': $ret .= 'SLASH '; break;// case "'": $ret .= 'SINGLE QUOTE '; break;// case '`': $ret .= 'BACK TICK '; break;// case '"': $ret .= 'QUOTE '; break;// case '^': $ret .= 'CAROT '; break;// case "\\": $ret .= 'BACK SLASH '; break;// case '|': $ret .= 'BAR '; break;// case '_': $ret .= 'UNDERSCORE '; break;// case '~': $ret .= 'TILDE '; break;// default: $ret .= $text{$i} . ' '; break;// }// }// return $this->text2wav($ret, $escape_digits, $frequency);// }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -