/* Returns 0 if a normal slot is available and was allocated. Returns 1 if a * free slot was granted (either for a filelist, small file or an extra granted * slot). Returns -1 if no slot was available. */ slot_state_t hub_request_upload_slot(hub_t *hub, const char *nick, const char *filename, uint64_t size) { if(filename == NULL || is_filelist(filename) || size < 64*1024) { INFO("allowing free upload slot for file %s", filename); return SLOT_FREE; } if(extra_slots_get_for_user(nick) > 0) { INFO("allowing extra upload slot for nick %s", nick); return SLOT_EXTRA; } if(used_slots >= total_slots) { INFO("no free slots left"); return SLOT_NONE; } used_slots++; INFO("allocating one upload slot for file %s: %d used, %d free", filename, used_slots, total_slots - used_slots); return SLOT_NORMAL; }
void TransportSSH::recv(std::string target) { if (_uri._host == "") throw std::string (STRING_TRANSPORT_SSH_URI); // Is there more than one file to transfer? // Then target has to end with a '/' if (is_filelist(_uri._path) && !is_directory(target)) throw format (STRING_TRANSPORT_URI_NODIR, target); // cmd line is: scp [-p port] [user@]host:path if (_uri._port != "") { _arguments.push_back ("-P"); _arguments.push_back (_uri._port); } // We do not do {} expansion of the URI, as ssh servers do that for us. if (_uri._user != "") { _arguments.push_back (_uri._user + "@" + _uri._host + ":" + escape (_uri._path, ' ')); } else { _arguments.push_back (_uri._host + ":" + escape (_uri._path, ' ')); } _arguments.push_back (target); if (execute ()) throw std::string (STRING_TRANSPORT_SSH_FAIL); }
void TransportCurl::send(const std::string& source) { if (_uri._host == "") throw std::string (STRING_TRANSPORT_CURL_URI); if (_uri._user != "") { _arguments.push_back("--user"); _arguments.push_back(_uri._user); } if (is_filelist(source)) { std::string::size_type pos; pos = source.find("{"); if (pos == std::string::npos) throw std::string (STRING_TRANSPORT_CURL_WILDCD); if (!_uri.is_directory()) throw format (STRING_TRANSPORT_URI_NODIR, _uri._path); _arguments.push_back ("-T"); _arguments.push_back ("\"" + escape (source, ' ') + "\""); } else { _arguments.push_back ("-T"); _arguments.push_back (escape (source, ' ')); } // cmd line is: curl -T source protocol://host:port/path if (_uri._port != "") { _arguments.push_back (_uri._protocol + "://" + _uri._host + ":" + _uri._port + "/" + _uri._path); } else { _arguments.push_back (_uri._protocol + "://" + _uri._host + "/" + _uri._path); } int result = execute(); if (result) { if (result == 127) // command not found throw std::string (STRING_TRANSPORT_CURL_NORUN); else throw std::string (STRING_TRANSPORT_CURL_FAIL); } }
void TransportCurl::send(const std::string& source) { if (uri.host == "") throw std::string ("when using the 'curl' protocol, the uri must contain a hostname."); if (uri.user != "") { arguments.push_back("--user"); arguments.push_back(uri.user); } if (is_filelist(source)) { std::string::size_type pos; pos = source.find("{"); if (pos == std::string::npos) throw std::string ("When using the 'curl' protocol, wildcards are not supported."); if (!uri.is_directory()) throw std::string ("The uri '") + uri.path + "' does not appear to be a directory."; arguments.push_back ("-T"); arguments.push_back ("\"" + source + "\""); } else { arguments.push_back ("-T"); arguments.push_back (source); } // cmd line is: curl -T source protocol://host:port/path if (uri.port != "") { arguments.push_back (uri.protocol + "://" + uri.host + ":" + uri.port + "/" + uri.path); } else { arguments.push_back (uri.protocol + "://" + uri.host + "/" + uri.path); } int result = execute(); if (result) { if (result == 127) // command not found throw std::string ("Could not run curl. Is it installed, and available in $PATH?"); else throw std::string ("Curl failed, see output above."); } }
void TransportSSH::send(const std::string& source) { std::vector<std::string> sourcelist; std::vector<std::string>::const_iterator source_iter; if (_uri._host == "") throw std::string (STRING_TRANSPORT_SSH_URI); // cmd line is: scp [-p port] [user@]host:path if (_uri._port != "") { _arguments.push_back ("-P"); _arguments.push_back (_uri._port); } if (is_filelist (source)) { expand_braces (source, _uri._data, sourcelist); // Is there more than one source? // Then path has to end with a '/' if (sourcelist.size () > 1 && !_uri.is_directory ()) throw format (STRING_TRANSPORT_URI_NODIR, _uri); for (source_iter = sourcelist.begin (); source_iter != sourcelist.end (); ++source_iter) { _arguments.push_back (*source_iter); } } else { _arguments.push_back (source); } if (_uri._user != "") { _arguments.push_back (_uri._user + "@" + _uri._host + ":" + escape (_uri._path, ' ')); } else { _arguments.push_back (_uri._host + ":" + escape (_uri._path, ' ')); } if (execute ()) throw std::string (STRING_TRANSPORT_SSH_FAIL); }
void TransportCurl::recv(std::string target) { if (uri.host == "") throw std::string ("when using the 'curl' protocol, the uri must contain a hostname."); if (uri.user != "") { arguments.push_back("--user"); arguments.push_back(uri.user); } if (is_filelist(uri.path)) { std::string::size_type pos; pos = uri.path.find("{"); if (pos == std::string::npos) throw std::string ("When using the 'curl' protocol, wildcards are not supported."); if (!is_directory(target)) throw std::string ("The uri '") + target + "' does not appear to be a directory."; std::string toSplit; std::string suffix; std::string prefix = target; std::vector<std::string> splitted; toSplit = uri.path.substr (pos+1); pos = toSplit.find ("}"); suffix = toSplit.substr (pos+1); split (splitted, toSplit.substr(0, pos), ','); target = ""; foreach (file, splitted) { target += " -o " + prefix + *file + suffix; }
void TransportCurl::recv(std::string target) { if (_uri._host == "") throw std::string (STRING_TRANSPORT_CURL_URI); if (_uri._user != "") { _arguments.push_back("--user"); _arguments.push_back(_uri._user); } std::vector<std::string> targetargs; if (is_filelist(_uri._path)) { std::string::size_type pos; pos = _uri._path.find("{"); if (pos == std::string::npos) throw std::string (STRING_TRANSPORT_CURL_WILDCD); if (!is_directory(target)) throw format (STRING_TRANSPORT_URI_NODIR, target); std::string toSplit; std::string suffix; std::string prefix = target; std::vector<std::string> splitted; toSplit = _uri._path.substr (pos+1); pos = toSplit.find ("}"); suffix = toSplit.substr (pos+1); split (splitted, toSplit.substr(0, pos), ','); std::vector <std::string>::iterator file; for (file = splitted.begin (); file != splitted.end (); ++file) { targetargs.push_back ("-o"); targetargs.push_back (prefix + *file + suffix); } } else { targetargs.push_back ("-o"); targetargs.push_back (target); } // cmd line is: curl protocol://host:port/path/to/source/file -o path/to/target/file if (_uri._port != "") { _arguments.push_back (_uri._protocol + "://" + _uri._host + ":" + _uri._port + "/" + _uri._path); } else { _arguments.push_back (_uri._protocol + "://" + _uri._host + "/" + _uri._path); } _arguments.insert (_arguments.end (), targetargs.begin (), targetargs.end ()); int result = execute(); if (result) { if (result == 127) // command not found throw std::string (STRING_TRANSPORT_CURL_NORUN); else throw std::string (STRING_TRANSPORT_CURL_FAIL); } }