diff --git a/asterisk/ami.anubis b/asterisk/ami.anubis new file mode 100644 index 0000000..1e39e6e --- /dev/null +++ b/asterisk/ami.anubis @@ -0,0 +1,170 @@ +/* + * Created by PyramIDE. + * User: Totoro + * Date: 13/07/2013 + * Time: 02:07 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +read system/string.anubis +read tools/basis.anubis +read tools/connections.anubis + +read asterisk/ami_types.anubis +read asterisk/ami_commands.anubis +read web/CXM_http_get_common.anubis + + + + public define Result( + +define Maybe(One) + receive + ( + Bool print_dump, + Connection conn + )= + //TODO find the header and content-lenght to get full length of answer + + if read(conn, 16384, 5) is + { + error then println("Read error");failure, + timeout then println("Read timeout");failure, + ok(ba) then + with ami_response = to_string(ba), + // typed_response = xml_rpc_get_response(xml_response), + if print_dump then + + success(println("=== ASTERISK SERVER answer ==="+crlf +"["+ ami_response + "]" )) + //println("=== XML_RPC Anubis interpretation ==="); + + /* if typed_response is + { + failure then println("Interpretation error"), + success(result) then + if result is + { + ok(ok_res) then println(format_xml_rpc_parameters(ok_res,1)), + fault(fault) then println(format_xml_rpc_fault(fault,1)) + } + + } */ + + else success(unique) + } + . + +define Maybe(String) + _format_action + ( + String so_far, + List(Key_value) values + )= + if values is + { + [] then success(so_far+crlf), + [h . t] then + if h is key_value(key, value) then + _format_action(so_far+key+": "+value+crlf, t) + }. + + /** Format the AMI action + * + */ + +define Maybe(String) + format_action + ( + AMI_Action action + )= + if action is action(action_type, values_list) then + _format_action( "Action: "+action_type+crlf, + //"ActionID: "+ + values_list) + . + + + +public define Maybe(One) + send_action + ( + Asterisk_client client, + AMI_Action action + )= + if client is asterisk_client(conn, _, auth) then + + //format the action into string + if format_action(action) is + { + failure then failure + success(action_str) then + //send the action trough the connection to Asterisk + println("=== ACTION ==="); + print(action_str); + println("=== END ACTION ==="); + + if write(conn, to_byte_array(action_str)) is + { + failure then failure, + success(_) then receive(true, conn) + } + }. + +public define Maybe(Asterisk_client) + asterisk_new_client + ( + String server_name, + AMI_Auth auth + )= + if separate_name_port(server_name, 5038) is (name, server_port) then + // + // resolve server name and call 'https_get' with numeric server address: + // + with a = dns(name), + if a is ok(server_addr) then + println("TCP "+server_port+ " "+server_name); + if (Result(NetworkConnectError,RWStream))connect(server_addr, server_port) is + { + error(e) then failure, + ok(conn) then + if read_line(tcp(conn), 80, 10) is + { + error then failure, + timeout then failure, + eof then failure, + ok(str) then + println("=== ASTERISK SERVER answer ==="+crlf +"["+ str + "]" ); + //to ensure that it is an Asterisk server we test the returned string + if start_with(to_lower(str), "asterisk call manager") then + + with client = asterisk_client(tcp(conn), var(0), auth), + if send_action(client, ami_login(auth)) is + { + failure then failure, + success(_) then success(client) + } + else + failure + + } + + } + else + failure. + + +global define One + ami_test + ( + List(String) args + )= + if asterisk_new_client("192.168.3.20:5038", auth("admin","admin")) is + { + failure then println(" asterisk new client failure"), + success(ami_client) then unique + //forget(xml_rpc_client_execute(true, rpc_client, "/Settings", "list_domains", empty_param)) + //forget(xml_rpc_client_execute(true, rpc_client, "/Settings", "delete_domain", parameters([parameter[string("amisdefontainebleau.org")]]))) + //forget(xml_rpc_client_execute(true, rpc_client, "/Settings", "create_domain", empty_param)) + }. + diff --git a/asterisk/ami_commands.anubis b/asterisk/ami_commands.anubis new file mode 100644 index 0000000..359eb3a --- /dev/null +++ b/asterisk/ami_commands.anubis @@ -0,0 +1,25 @@ +/* + * Created by PyramIDE. + * User: Totoro + * Date: 14/07/2013 + * Time: 01:34 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +read asterisk/ami_types.anubis + +public define AMI_Action ami_login(String user, String password, Bool events) = + action("Login", [ + key_value("Username",user), + key_value("Secret", password), + key_value("Events", if events then "on" else "off") + ]). + +public define AMI_Action ami_login(String user, String password)= + ami_login(user, password, true). + +public define AMI_Action ami_login(AMI_Auth ami_auth) = + if ami_auth is auth(user, password) then + ami_login(user, password, true). + diff --git a/asterisk/ami_types.anubis b/asterisk/ami_types.anubis new file mode 100644 index 0000000..6bb6b07 --- /dev/null +++ b/asterisk/ami_types.anubis @@ -0,0 +1,33 @@ +/* + * Created by PyramIDE. + * User: Tototo + * Date: 13/07/2013 + * Time: 02:19 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +read tools/connections.anubis + +public type Key_value: + key_value(String key, String value). + +public type AMI_Response: + success(List(Key_value)), + error(List(Key_value)). + +public type AMI_Action: + action(String action_type, List(Key_value)). + +public type AMI_Event: + event(String event_type, List(Key_value)). + +public type AMI_Auth: + auth(String login, String pass). + +public type Asterisk_client: + asterisk_client( + Connection conn, + Var(Int) id, + AMI_Auth auth). + diff --git a/net_services/CXM_net_services.anubis b/net_services/CXM_net_services.anubis index d797a3d..b326155 100644 --- a/net_services/CXM_net_services.anubis +++ b/net_services/CXM_net_services.anubis @@ -48,17 +48,23 @@ define Maybe(NetService) find_service ( List(NetService) services_list, - Word32 service_id, - Word32 service_version + Word32 service_id, + Word32 service_version, + String domain )= if services_list is { [] then failure, [h . t] then if h.id = service_id & h.version >=+ service_version then - success(h) + if domain = "" then + success(h) + else if domain:h.domains then //this writing (a:b) means, is a belonging to b where b is list of type a + success(h) + else + find_service(t, service_id, service_version, domain) else - find_service(t, service_id, service_version) + find_service(t, service_id, service_version, domain) }. /** Check if the muscle message msg has the correct fields for requesting a net_services @@ -83,7 +89,13 @@ define Maybe(NetService) if find_int32(msg, "version") is { failure then send_ACK_error(queue, _CXM_REQUEST_FOR_SERVICE);failure, - success(service_version) then find_service(net_services, service_id, service_version) + success(service_version) then + //if DOMAIN field exists, this mean we want to target only this domain + if find_string(msg, "DOMAIN") is + { + failure then find_service(net_services, service_id, service_version,""), + success(domain) then find_service(net_services, service_id, service_version, domain) + } } } @@ -91,7 +103,13 @@ define Maybe(NetService) if find_int32(msg, "VERSION") is { failure then send_ACK_error(queue, _CXM_REQUEST_FOR_SERVICE);failure, - success(service_version) then find_service(net_services, service_id, service_version) + success(service_version) then + //if DOMAIN field exists, this mean we want to target only this domain + if find_string(msg, "DOMAIN") is + { + failure then find_service(net_services, service_id, service_version,""), + success(domain) then find_service(net_services, service_id, service_version, domain) + } } }. diff --git a/obj/unit_test.aproj.FileListAbsolute.txt b/obj/unit_test.aproj.FileListAbsolute.txt new file mode 100644 index 0000000..b116676 --- /dev/null +++ b/obj/unit_test.aproj.FileListAbsolute.txt @@ -0,0 +1,2 @@ +D:\Documents and Settings\david\Mes documents\Calexium\icalldroid\calexium_lib\bin\Debug\xml_rpc.unit_test.adm +D:\Documents and Settings\david\Mes documents\Calexium\icalldroid\calexium_lib\obj\Debug\xml_rpc.unit_test.adm diff --git a/unit_test.aproj b/unit_test.aproj new file mode 100644 index 0000000..f1d21c2 --- /dev/null +++ b/unit_test.aproj @@ -0,0 +1,532 @@ + + + {F4319F29-A930-4597-A742-F7C7E6B701A2} + Debug + AnyCPU + Exe + xml_rpc.ut + xml_rpc.unit_test + unit_test\xml_rpc.unit_test.anubis + False + False + False + C:\Program Files\Anubis\ + ./ + + + bin\Debug\ + True + Full + False + + + bin\Release\ + False + None + True + -tab:2 -pre -O + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/unit_test.ide b/unit_test.ide new file mode 100644 index 0000000..b6874fc --- /dev/null +++ b/unit_test.ide @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +# SharpDevelop 1.0.12.108 +Project("{B6712916-30DE-4a3e-A54C-2A79AC984AEE}") = "unit_test", "unit_test.aproj", "{F4319F29-A930-4597-A742-F7C7E6B701A2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F4319F29-A930-4597-A742-F7C7E6B701A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F4319F29-A930-4597-A742-F7C7E6B701A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F4319F29-A930-4597-A742-F7C7E6B701A2}.Release|Any CPU.Build.0 = Release|Any CPU + {F4319F29-A930-4597-A742-F7C7E6B701A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/unit_test/xml_rpc.unit_test.anubis b/unit_test/xml_rpc.unit_test.anubis new file mode 100644 index 0000000..fe5bd54 --- /dev/null +++ b/unit_test/xml_rpc.unit_test.anubis @@ -0,0 +1,4 @@ + +read web/CXM_xml_rpc.anubis +read asterisk/ami.anubis + -- libgit2 0.21.4