Commit 1d4718c6245b9e270425dace0512dbda5157b265

Authored by David RENÉ
1 parent 239531ee

finish the get_file independent command command based on long time ago FTP_* protocol

net_services/CXM_generic_protocol.anubis
@@ -188,7 +188,7 @@ public define Bool @@ -188,7 +188,7 @@ public define Bool
188 ok_msg(msg) then true 188 ok_msg(msg) then true
189 }. 189 }.
190 190
191 -public define Bool 191 + public define Bool
192 get_file_ref 192 get_file_ref
193 ( 193 (
194 MessageQueue mQ, 194 MessageQueue mQ,
net_services/get_file.anubis
@@ -10,14 +10,16 @@ @@ -10,14 +10,16 @@
10 read calexium_lib/CXM_message_constants.anubis 10 read calexium_lib/CXM_message_constants.anubis
11 read calexium_lib/net_services/CXM_generic_protocol.anubis 11 read calexium_lib/net_services/CXM_generic_protocol.anubis
12 read calexium_lib/net_services/CXM_generic_client.anubis //for get_ip 12 read calexium_lib/net_services/CXM_generic_client.anubis //for get_ip
  13 +read calexium_lib/types/generated/file_ref.anubis
13 read system/message_queue.anubis 14 read system/message_queue.anubis
14 read system/message_transceiver.anubis 15 read system/message_transceiver.anubis
15 read system/muscle.anubis 16 read system/muscle.anubis
16 read system/files.anubis 17 read system/files.anubis
  18 +read system/logger.anubis
17 read tools/basis.anubis 19 read tools/basis.anubis
18 read network/dns.anubis 20 read network/dns.anubis
19 21
20 -define Maybe(One) 22 +define Bool
21 receive_data 23 receive_data
22 ( 24 (
23 MessageQueue mQ, 25 MessageQueue mQ,
@@ -28,24 +30,24 @@ define Maybe(One) @@ -28,24 +30,24 @@ define Maybe(One)
28 //println("receive_data "); 30 //println("receive_data ");
29 if mQ.get_next_received_Message(30) is 31 if mQ.get_next_received_Message(30) is
30 { 32 {
31 - timeout then failure,  
32 - closed then failure, 33 + timeout then false,
  34 + closed then false,
33 msg(_msg) then 35 msg(_msg) then
34 with last_block = if find_bool(_msg, "End") is {failure then false, success(r) then r}, 36 with last_block = if find_bool(_msg, "End") is {failure then false, success(r) then r},
35 if find_raw(_msg, "Data") is 37 if find_raw(_msg, "Data") is
36 { 38 {
37 - failure then println("Can't find raw Data"); send_ACK_error(mQ, _CXM_FTP_DATA); failure, 39 + failure then println("Can't find raw Data"); send_ACK_error(mQ, _CXM_FTP_DATA); false,
38 success(data) then 40 success(data) then
39 if write(fd, data) is 41 if write(fd, data) is
40 { 42 {
41 - failure then println("Can't write into file"); send_ACK_error(mQ, _CXM_FTP_DATA);failure, 43 + failure then println("Can't write into file"); send_ACK_error(mQ, _CXM_FTP_DATA);false,
42 success(len) then 44 success(len) then
43 send_ACK_ok(mQ, _CXM_FTP_DATA); 45 send_ACK_ok(mQ, _CXM_FTP_DATA);
44 if last_block then 46 if last_block then
45 println("File received successfully"); 47 println("File received successfully");
46 //TODO this is a big hack, we must check if all data are sent from the mQ 48 //TODO this is a big hack, we must check if all data are sent from the mQ
47 sleep(10000); 49 sleep(10000);
48 - success(unique) 50 + true
49 else 51 else
50 // println("Bytes received : " + (so_far + len)); 52 // println("Bytes received : " + (so_far + len));
51 receive_data(mQ, fd, so_far + len, left_read - len) 53 receive_data(mQ, fd, so_far + len, left_read - len)
@@ -54,17 +56,18 @@ define Maybe(One) @@ -54,17 +56,18 @@ define Maybe(One)
54 } 56 }
55 . 57 .
56 58
57 -define Maybe(One) 59 +define Bool
58 start_get_file_transtert 60 start_get_file_transtert
59 ( 61 (
60 - MessageQueue mQ,  
61 - String local_file,  
62 - Int size 62 + MessageQueue mQ,
  63 + String local_file,
  64 + Int size,
  65 + (LogLevel, String) -> One logger
63 )= 66 )=
64 make_directories(local_file); 67 make_directories(local_file);
65 if file(local_file, new) is 68 if file(local_file, new) is
66 { 69 {
67 - failure then println("Can't create \""+local_file+"\" file"); failure, 70 + failure then logger(logError, "start_get_file_transtert Can't create \""+local_file+"\" file"); false,
68 success(fd) then //the local file is open 71 success(fd) then //the local file is open
69 with start = message(_CXM_FTP_START_TRANSFERT), 72 with start = message(_CXM_FTP_START_TRANSFERT),
70 mQ.add_Message_to_send(start); 73 mQ.add_Message_to_send(start);
@@ -72,7 +75,7 @@ define Maybe(One) @@ -72,7 +75,7 @@ define Maybe(One)
72 } 75 }
73 . 76 .
74 77
75 -define Bool 78 +public define Bool
76 get_file_ref 79 get_file_ref
77 ( 80 (
78 MessageQueue mQ, 81 MessageQueue mQ,
@@ -85,22 +88,22 @@ define Bool @@ -85,22 +88,22 @@ define Bool
85 forget(add_message(get_file_msg, "GET_FILE_REF", to_Message(f_ref))); 88 forget(add_message(get_file_msg, "GET_FILE_REF", to_Message(f_ref)));
86 89
87 mQ.add_Message_to_send(get_file_msg); 90 mQ.add_Message_to_send(get_file_msg);
88 - if wait_for_reply(mQ, _CXM_FTP_GET_FILE, 30) is 91 + if wait_for_reply(mQ, _CXM_GET_FILE_REF, 30) is
89 { 92 {
90 - failure then println("get_file failure");failure,  
91 - timeout then println("get_file timeout");failure,  
92 - unknow_cmd then println("get_file unknow_cmd");failure,  
93 - error then println("get_file remote error msg");failure,  
94 - error(c,m) then println("get_file remote error [" + c + "] msg '" + m + "'");failure,  
95 - ok then println("get_file ok");failure, 93 + failure then println("get_file failure");false,
  94 + timeout then logger(logError, "get_file timeout");false,
  95 + unknow_cmd then logger(logWarning,"get_file unknow_cmd");false,
  96 + error then println("get_file remote error msg");false,
  97 + error(c,m) then println("get_file remote error [" + c + "] msg '" + m + "'");false,
  98 + ok then println("get_file ok");false,
96 ok_msg(msg)then 99 ok_msg(msg)then
97 - 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_}},  
98 - start_get_file_transtert(mQ, target_file, size) 100 + 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_}},
  101 + start_get_file_transtert(mQ, target_file, size, logger)
99 } 102 }
100 . 103 .
101 104
102 105
103 -define Bool 106 + define Bool
104 request_for_service 107 request_for_service
105 ( 108 (
106 MessageQueue queue 109 MessageQueue queue
@@ -125,7 +128,7 @@ define Bool @@ -125,7 +128,7 @@ define Bool
125 } 128 }
126 }. 129 }.
127 130
128 -public define Maybe(One) 131 + public define Maybe(One)
129 ftp_get_file 132 ftp_get_file
130 ( 133 (
131 String server, 134 String server,
@@ -158,7 +161,7 @@ public define Maybe(One) @@ -158,7 +161,7 @@ public define Maybe(One)
158 * The last argument set to false (no ftp directory on the remote, pickup on collection dir) 161 * The last argument set to false (no ftp directory on the remote, pickup on collection dir)
159 */ 162 */
160 163
161 -public define Maybe(One) 164 + public define Maybe(One)
162 ftp_get_file 165 ftp_get_file
163 ( 166 (
164 String server, 167 String server,