diff --git a/net_services/CXM_generic_protocol.anubis b/net_services/CXM_generic_protocol.anubis index 7d45254..1220e3e 100644 --- a/net_services/CXM_generic_protocol.anubis +++ b/net_services/CXM_generic_protocol.anubis @@ -188,7 +188,7 @@ public define Bool ok_msg(msg) then true }. -public define Bool + public define Bool get_file_ref ( MessageQueue mQ, diff --git a/net_services/get_file.anubis b/net_services/get_file.anubis index 0e2ff80..025eda2 100644 --- a/net_services/get_file.anubis +++ b/net_services/get_file.anubis @@ -10,14 +10,16 @@ read calexium_lib/CXM_message_constants.anubis read calexium_lib/net_services/CXM_generic_protocol.anubis read calexium_lib/net_services/CXM_generic_client.anubis //for get_ip +read calexium_lib/types/generated/file_ref.anubis read system/message_queue.anubis read system/message_transceiver.anubis read system/muscle.anubis read system/files.anubis +read system/logger.anubis read tools/basis.anubis read network/dns.anubis -define Maybe(One) +define Bool receive_data ( MessageQueue mQ, @@ -28,24 +30,24 @@ define Maybe(One) //println("receive_data "); if mQ.get_next_received_Message(30) is { - timeout then failure, - closed then failure, + timeout then false, + closed then false, msg(_msg) then with last_block = if find_bool(_msg, "End") is {failure then false, success(r) then r}, if find_raw(_msg, "Data") is { - failure then println("Can't find raw Data"); send_ACK_error(mQ, _CXM_FTP_DATA); failure, + failure then println("Can't find raw Data"); send_ACK_error(mQ, _CXM_FTP_DATA); false, success(data) then if write(fd, data) is { - failure then println("Can't write into file"); send_ACK_error(mQ, _CXM_FTP_DATA);failure, + failure then println("Can't write into file"); send_ACK_error(mQ, _CXM_FTP_DATA);false, success(len) then send_ACK_ok(mQ, _CXM_FTP_DATA); if last_block then println("File received successfully"); //TODO this is a big hack, we must check if all data are sent from the mQ sleep(10000); - success(unique) + true else // println("Bytes received : " + (so_far + len)); receive_data(mQ, fd, so_far + len, left_read - len) @@ -54,17 +56,18 @@ define Maybe(One) } . -define Maybe(One) +define Bool start_get_file_transtert ( - MessageQueue mQ, - String local_file, - Int size + MessageQueue mQ, + String local_file, + Int size, + (LogLevel, String) -> One logger )= make_directories(local_file); if file(local_file, new) is { - failure then println("Can't create \""+local_file+"\" file"); failure, + failure then logger(logError, "start_get_file_transtert Can't create \""+local_file+"\" file"); false, success(fd) then //the local file is open with start = message(_CXM_FTP_START_TRANSFERT), mQ.add_Message_to_send(start); @@ -72,7 +75,7 @@ define Maybe(One) } . -define Bool +public define Bool get_file_ref ( MessageQueue mQ, @@ -85,22 +88,22 @@ define Bool forget(add_message(get_file_msg, "GET_FILE_REF", to_Message(f_ref))); mQ.add_Message_to_send(get_file_msg); - if wait_for_reply(mQ, _CXM_FTP_GET_FILE, 30) is + if wait_for_reply(mQ, _CXM_GET_FILE_REF, 30) is { - failure then println("get_file failure");failure, - timeout then println("get_file timeout");failure, - unknow_cmd then println("get_file unknow_cmd");failure, - error then println("get_file remote error msg");failure, - error(c,m) then println("get_file remote error [" + c + "] msg '" + m + "'");failure, - ok then println("get_file ok");failure, + failure then println("get_file failure");false, + timeout then logger(logError, "get_file timeout");false, + unknow_cmd then logger(logWarning,"get_file unknow_cmd");false, + error then println("get_file remote error msg");false, + error(c,m) then println("get_file remote error [" + c + "] msg '" + m + "'");false, + ok then println("get_file ok");false, ok_msg(msg)then - with size = if find_string(rmsg, "SIZE") is {failure then f_ref.size, success(size_str) then if decimal_scan(size_str) is { failure then should_not_happen(0), success(_size_) then _size_}}, - start_get_file_transtert(mQ, target_file, size) + with size = if find_string(msg, "SIZE") is {failure then f_ref.size, success(size_str) then if decimal_scan(size_str) is { failure then should_not_happen(0), success(_size_) then _size_}}, + start_get_file_transtert(mQ, target_file, size, logger) } . -define Bool + define Bool request_for_service ( MessageQueue queue @@ -125,7 +128,7 @@ define Bool } }. -public define Maybe(One) + public define Maybe(One) ftp_get_file ( String server, @@ -158,7 +161,7 @@ public define Maybe(One) * The last argument set to false (no ftp directory on the remote, pickup on collection dir) */ -public define Maybe(One) + public define Maybe(One) ftp_get_file ( String server, -- libgit2 0.21.4