LIB_EXPORT rc_t CC ascp_locate(const char **ascp_bin, const char **private_file, bool use_config, bool status) { static const char *bin = NULL; static const char *key = NULL; rc_t rc = 0; KConfig *cfg = NULL; bool found = false; if (ascp_bin == NULL || private_file == NULL) { return RC(rcNS, rcFile, rcCopying, rcParam, rcNull); } *ascp_bin = *private_file = NULL; rc = returnAscp(bin, key, ascp_bin, private_file, &found); if (rc != 0 || found) { return rc; } rc = KConfigMake(&cfg, NULL); if (rc != 0) { return rc; } if (_KConfigAscpDisabled(cfg, status)) { if (status) { STSMSG(STS_INFO, ("Use of Aspera transfer is disabled " "by the configuration, using HTTP transfer")); } } else { KDirectory *dir = NULL; rc = _KConfigGetAscp(cfg, &bin, &key); if (bin != NULL) { assert(key && !rc); RELEASE(KConfig, cfg); rc = returnAscp(bin, key, ascp_bin, private_file, &found); if (rc != 0 || found) { return rc; } } rc = KDirectoryNativeDir(&dir); if (rc != 0) { return rc; } while (ascp_path(&bin, &key)) { if (_SystemHelp(bin, status)) { if (_KDirectoryFileFound(dir, key, status)) { break; } } } RELEASE(KDirectory, dir); } RELEASE(KConfig, cfg); rc = returnAscp(bin, key, ascp_bin, private_file, &found); if (rc != 0 || found) { return rc; } else { return RC(rcNS, rcFile, rcCopying, rcFile, rcNotFound); } }
LIB_EXPORT rc_t CC ascp_locate(const char **ascp_bin, const char **private_file, bool use_config, bool status) { rc_t rc = 0; KConfig *cfg = NULL; if (ascp_bin == NULL || private_file == NULL) { return RC(rcNS, rcFile, rcCopying, rcParam, rcNull); } *ascp_bin = *private_file = NULL; rc = KConfigMake(&cfg, NULL); if (rc != 0) { return rc; } if (_KConfigAscpDisabled(cfg, status)) { if (status) { STSMSG(STS_INFO, ("Use of Aspera transfer is disabled " "by the configuration, using HTTP transfer")); } } else { KDirectory *dir = NULL; const char *bin = NULL; const char *key = NULL; rc = _KConfigGetAscp(cfg, ascp_bin, private_file); if (*ascp_bin != NULL) { assert(*private_file && !rc); RELEASE(KConfig, cfg); return 0; } rc = KDirectoryNativeDir(&dir); if (rc != 0) { return rc; } while (ascp_path(&bin, &key)) { if (_SystemHelp(bin, status)) { if (_KDirectoryFileFound(dir, key, status)) { *ascp_bin = string_dup_measure(bin, NULL); *private_file = string_dup_measure(key, NULL); if (*ascp_bin == NULL || *private_file == NULL) { free((void*)*ascp_bin); free((void*)*private_file); *ascp_bin = *private_file = NULL; return RC(rcNS, rcStorage, rcAllocating, rcMemory, rcExhausted); } break; } } } RELEASE(KDirectory, dir); } RELEASE(KConfig, cfg); return rc; }