Commit 03f679013033b5da64d2de9d8c3d7aa01030e059
1 parent
e119b779
add the management of FTP_DIR into ftp protocol
Add get_ip as public for resolving ip or URL
Showing
2 changed files
with
80 additions
and
4 deletions
Show diff stats
calexium_lib/net_services/CXM_generic_client.anubis
| @@ -196,7 +196,59 @@ public define Maybe($T) | @@ -196,7 +196,59 @@ public define Maybe($T) | ||
| 196 | queue.quit(unique); | 196 | queue.quit(unique); |
| 197 | result | 197 | result |
| 198 | }. | 198 | }. |
| 199 | + | ||
| 200 | +define Word32 | ||
| 201 | + get_ip | ||
| 202 | + ( | ||
| 203 | + String url_or_ip, | ||
| 204 | + (String) -> One logger | ||
| 205 | + ) = | ||
| 206 | + //logInfo(debug_log,"Try to resolve URL [" + url_or_ip+ "]."); | ||
| 207 | + if ip_address(url_or_ip) is success(ip) then | ||
| 208 | + //logInfo(debug_log,"Try to resolve URL OK ip"+ip); | ||
| 209 | + ip | ||
| 210 | + else if dns(url_or_ip) is ok(ip_adr) then | ||
| 211 | + //logInfo(debug_log,"Try to resolve URL OK dns"+ip_adr); | ||
| 212 | + ip_adr | ||
| 213 | + else | ||
| 214 | + logger("Can't resolve URL [" + url_or_ip+ "]. Using localhost."); | ||
| 215 | + ip_address((127,0,0,1)). | ||
| 199 | 216 | ||
| 217 | + | ||
| 218 | +public define Maybe(Word32) | ||
| 219 | + get_ip | ||
| 220 | + ( | ||
| 221 | + String url_or_ip | ||
| 222 | + ) = | ||
| 223 | + //logInfo(debug_log,"Try to resolve URL [" + url_or_ip+ "]."); | ||
| 224 | + if ip_address(url_or_ip) is success(ip) then | ||
| 225 | + //logInfo(debug_log,"Try to resolve URL OK ip"+ip); | ||
| 226 | + success(ip) | ||
| 227 | + else if dns(url_or_ip) is ok(ip_adr) then | ||
| 228 | + //logInfo(debug_log,"Try to resolve URL OK dns"+ip_adr); | ||
| 229 | + success(ip_adr) | ||
| 230 | + else | ||
| 231 | + println("Can't resolve URL [" + url_or_ip+ "]. Using localhost."); | ||
| 232 | + failure. | ||
| 233 | + | ||
| 234 | + /* Same version as above, but server is string containing IP or URL | ||
| 235 | + * It's resolve by get_ip and call generic_connect_to_net_service with IP | ||
| 236 | + */ | ||
| 237 | + | ||
| 238 | +public define Maybe($T) | ||
| 239 | + generic_connect_to_net_service | ||
| 240 | + ( | ||
| 241 | + String queue_name, | ||
| 242 | + String server, | ||
| 243 | + Word32 port, | ||
| 244 | + Word32 service_id, | ||
| 245 | + Word32 service_version, | ||
| 246 | + (MessageQueue, String) -> Maybe($T) handler, | ||
| 247 | + (String) -> One logger | ||
| 248 | + ) | ||
| 249 | + = generic_connect_to_net_service(queue_name, get_ip(server, logger), port, service_id, service_version, handler, logger). | ||
| 250 | + | ||
| 251 | + | ||
| 200 | public define Maybe($T) | 252 | public define Maybe($T) |
| 201 | generic_connect_to_net_service_SSL | 253 | generic_connect_to_net_service_SSL |
| 202 | ( | 254 | ( |
calexium_lib/net_services_protocols/ftp_client.anubis
| @@ -10,6 +10,7 @@ | @@ -10,6 +10,7 @@ | ||
| 10 | 10 | ||
| 11 | read calexium_lib/CXM_message_constants.anubis | 11 | read calexium_lib/CXM_message_constants.anubis |
| 12 | read calexium_lib/net_services/CXM_generic_protocol.anubis | 12 | read calexium_lib/net_services/CXM_generic_protocol.anubis |
| 13 | +read calexium_lib/net_services/CXM_generic_client.anubis //for get_ip | ||
| 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 |
| @@ -77,13 +78,20 @@ define Maybe(One) | @@ -77,13 +78,20 @@ define Maybe(One) | ||
| 77 | ( | 78 | ( |
| 78 | MessageQueue mQ, | 79 | MessageQueue mQ, |
| 79 | String remote_file, | 80 | String remote_file, |
| 80 | - String local_file | 81 | + String local_file, |
| 82 | + Bool ftp | ||
| 81 | )= | 83 | )= |
| 82 | with get_file_msg = message(_CXM_FTP_GET_FILE), | 84 | with get_file_msg = message(_CXM_FTP_GET_FILE), |
| 83 | if add_string(get_file_msg, "FileName", remote_file) is | 85 | if add_string(get_file_msg, "FileName", remote_file) is |
| 84 | { | 86 | { |
| 85 | failure then failure, | 87 | failure then failure, |
| 86 | success(_) then | 88 | success(_) then |
| 89 | + ( if ftp then | ||
| 90 | + println("get_file FTP_DIR"); | ||
| 91 | + forget(add_bool(get_file_msg, "FTP_DIR", true)) | ||
| 92 | + else | ||
| 93 | + unique | ||
| 94 | + ); | ||
| 87 | mQ.add_Message_to_send(get_file_msg); | 95 | mQ.add_Message_to_send(get_file_msg); |
| 88 | if wait_for_reply(mQ, _CXM_FTP_GET_FILE, 30) is | 96 | if wait_for_reply(mQ, _CXM_FTP_GET_FILE, 30) is |
| 89 | { | 97 | { |
| @@ -135,17 +143,19 @@ public define Maybe(One) | @@ -135,17 +143,19 @@ public define Maybe(One) | ||
| 135 | String server, | 143 | String server, |
| 136 | Word32 ip_port, | 144 | Word32 ip_port, |
| 137 | String remote_file, | 145 | String remote_file, |
| 138 | - String local_file | 146 | + String local_file, |
| 147 | + Bool ftp, | ||
| 139 | ) = | 148 | ) = |
| 140 | - if resolve_address(server) is success(ip_adr) then | 149 | + if get_ip(server) is success(ip_adr) then |
| 141 | if connect( ip_adr, ip_port) is | 150 | if connect( ip_adr, ip_port) is |
| 142 | { | 151 | { |
| 143 | error(_) then println("can't connect to ftp server"); failure, | 152 | error(_) then println("can't connect to ftp server"); failure, |
| 144 | ok(conn) then | 153 | ok(conn) then |
| 145 | with queue = create_MessageQueue("ftp_get_file"), | 154 | with queue = create_MessageQueue("ftp_get_file"), |
| 146 | message_transceiver(conn, queue); | 155 | message_transceiver(conn, queue); |
| 156 | + println("request for ftp service"); | ||
| 147 | if request_for_service(queue) then | 157 | if request_for_service(queue) then |
| 148 | - with result = get_file(queue, remote_file, local_file), | 158 | + with result = get_file(queue, remote_file, local_file, ftp), |
| 149 | queue.quit(unique);result | 159 | queue.quit(unique);result |
| 150 | else | 160 | else |
| 151 | queue.quit(unique); | 161 | queue.quit(unique); |
| @@ -154,4 +164,18 @@ public define Maybe(One) | @@ -154,4 +164,18 @@ public define Maybe(One) | ||
| 154 | else | 164 | else |
| 155 | println("server "+server+" DNS error");failure | 165 | println("server "+server+" DNS error");failure |
| 156 | . | 166 | . |
| 167 | + | ||
| 168 | + /* Exists for backward compatibility. | ||
| 169 | + * The last argument set to false (no ftp directory on the remote, pickup on collection dir) | ||
| 170 | + */ | ||
| 157 | 171 | ||
| 172 | +public define Maybe(One) | ||
| 173 | + ftp_get_file | ||
| 174 | + ( | ||
| 175 | + String server, | ||
| 176 | + Word32 ip_port, | ||
| 177 | + String remote_file, | ||
| 178 | + String local_file, | ||
| 179 | + ) = | ||
| 180 | + ftp_get_file(server, ip_port, remote_file, local_file, false). | ||
| 181 | + |