AsteriskOfAmiYou can refer to this article if you need to extend the APIs.
I. ExpansionAsteriskOfAmiInterface
Involved files:Main/manager. c
1, Function Registration
AddMyoriginateInterface
In the FunctionInt _ init_manager (int reload)Add the followingCode:
Ast_manager_register_xml ("Myoriginate", Event_flag_originate, action_myoriginate );//Add by Mike
2, Function implementation:
View code
// Add by Mike Static Int Action_myoriginate (Struct Mansession * s, Const Struct Message * M ){ Const Char * Name = astman_get_header (m, " Channel " ); Const Char * Exten = astman_get_header (m, " Exten " ); Const Char * Context = astman_get_header (m, " Context " ); Const Char * Priority = astman_get_header (m, " Priority " ); Const Char * Timeout = astman_get_header (m," Timeout " ); Const Char * Callerid = astman_get_header (m, " Callerid " ); Char TMP [ 256 ]; Int I = 0 ; Sprintf (TMP, " % LD _ % s " , Time (null), name ); Int Tmplen = Strlen (TMP ); For (I = 0 ; I <tmplen; ++ I ){ If (Isalnum (TMP [I]) Continue ; TMP [I] = ' _ ' ;} Char Filename [ 1024 ] = { 0 }; Sprintf (filename, " /Var/spool/asterisk/outgoing/% S. Call " , TMP ); // File * fp = fopen ("/var/spool/asterisk/outgoing/1. Call", "W "); File * fp = fopen (filename, " W " ); Char Buf [ 1024 ] = { 0 }; Sprintf (TMP, " Channel: % s \ r \ n " , Name); strcpy (BUF, TMP); sprintf (TMP, " Callerid: % s \ r \ n " , Callerid); strcat (BUF, TMP); strcat (BUF, " Maxretries: 1 \ r \ n " ); Strcat (BUF, " Retrytime: 1 \ r \ n " ); // Sprintf (TMP, "waittime: % s \ r \ n", timeout ); Sprintf (TMP, " Waittime: % s \ r \ n " , " 30 " ); Strcat (BUF, TMP); sprintf (TMP, " Context: % s \ r \ n " , Context); strcat (BUF, TMP); sprintf (TMP, " Extension: % s \ r \ n " , Exten); strcat (BUF, TMP); sprintf (TMP, " Extension: % s \ r \ n " , Exten); strcat (BUF, TMP); fwrite (( Void *) BUF, strlen (BUF ), 1 , FP); fclose (FP ); Return 0 ;}
Ii. ConfigurationAsterisk
1, Compilation and Installation
Make & make install
2, AddDialing Scheme
In the file/Etc/asterisk/extension. confAdd the following code:
[Dlpn_meetingwithoutrecord]
Exten
=> _ 63xx , 1 , Answer ()
Exten
=> _ 63xx , N , Meetme ( $ {Exten} , MW, 1234)
Exten
=> _ 63xx , N , Hangup ()
III,AmiCall test (Python):
View code
# ! /Usr/bin/Python Import Socket Def Strlogin (USR, PWD): msg = " Action: Login \ r \ n " MSG + = " Events: off \ r \ n " MSG + = " Username: " + USR + " \ R \ n " MSG + = " Secret: " + PWD + " \ R \ n " MSG + = " \ R \ n " Return MSG Def Strcall (strnum, strcallid): msg =" Action: myoriginate \ r \ n " MSG + = " Channel: SIP/ " + Strnum + " \ R \ n " MSG + = " Waittime: 1 \ r \ n " MSG + = " Callerid: " + Strcallid + " \ R \ n " MSG + = " Exten: " + Strcallid + " \ R \ n " MSG + = " Context: dlpn_meetingwithoutrecord \ r \ n " MSG + = " Priority: 1 \ r \ n " MSG + = " \ R \ n " Return MSG Def Strlogoff (): Return " Action: logoff \ r \ n " Def Strhangup (strnum): msg = " Action: hangup \ r \ n " MSG + = " Channel: SIP/ " + Strnum Return MSG Def Main (): S =Socket. socket (socket. af_inet, socket. sock_stream) S. Connect (raw_input ( " IP: " ), 5038 )) If Not S: Print " Connect fail! " Return Else : Print " Connect success! " Strnum = Raw_input ( " Input number to dail: " ) Strcallerid = Raw_input ( " Input caller ID: " ) Msg = "" MSG + = Strlogin (raw_input ( " Username: " ), Raw_input ( " Password " ) Msg + = Strcall (strnum, strcallerid) msg + = Strlogoff () S. Send (MSG) While True: Data = S. Recv (1024 ) If Not Data: Break Else : Print Data S. Close () If _ Name __ = ' _ Main __ ' : Main () # Raw_input ("press enter to continue ")
Okay, that's all. I hope it will help you.