| 1 |
/* |
| 2 |
* This File is part of Davix, The IO library for HTTP based protocols |
| 3 |
* Copyright (C) CERN 2013 |
| 4 |
* Author: Adrien Devresse <[email protected]> |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2.1 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef DAVIX_TOOL_UTIL_HPP |
| 23 |
#define DAVIX_TOOL_UTIL_HPP |
| 24 |
|
| 25 |
#include <davix.hpp> |
| 26 |
#include <davix_internal.hpp> |
| 27 |
#include <tools/davix_tool_params.hpp> |
| 28 |
|
| 29 |
|
| 30 |
namespace Davix{ |
| 31 |
|
| 32 |
namespace Tool{ |
| 33 |
|
| 34 |
dav_ssize_t writeToFd(int fd, const void* buffer, dav_size_t s_buff); |
| 35 |
|
| 36 |
dav_ssize_t writeToFd(int fd, const std::string & str); |
| 37 |
|
| 38 |
int configureAuth(OptParams & opts); |
| 39 |
|
| 40 |
bool checkProtocolSanity(OptParams &opts, const std::string &url, DavixError **err); |
| 41 |
|
| 42 |
void configureContext(Context &context, const OptParams & opts); |
| 43 |
|
| 44 |
void errorPrint(DavixError ** err); |
| 45 |
|
| 46 |
void writeConsoleLine(int fd, char symbol, const std::string & msg); |
| 47 |
|
| 48 |
int authCallbackLoginPassword(void* userdata, const SessionInfo & info, std::string & login, std::string & password, |
| 49 |
int count, DavixError** err); |
| 50 |
|
| 51 |
int authCallbackCert(void* userdata, const SessionInfo & info, X509Credential* cert, DavixError** err); |
| 52 |
|
| 53 |
// return output file descriptor |
| 54 |
int getOutFd(const Tool::OptParams & opts, const std::string & scope, DavixError** err); |
| 55 |
|
| 56 |
// return output file descriptor |
| 57 |
int getInFd(const Tool::OptParams & opts, const std::string & scope, DavixError** err); |
| 58 |
|
| 59 |
// string utils |
| 60 |
std::string string_from_mode(mode_t mode); |
| 61 |
std::string string_from_ptime(const time_t &t); |
| 62 |
|
| 63 |
// print a string in a minimum of size_string char, fill it with white-space if inferior to this |
| 64 |
std::string string_from_size_t(size_t number, size_t size_string); |
| 65 |
|
| 66 |
std::string filename_from_uri(const std::string & current_dir, const Uri & uri); |
| 67 |
|
| 68 |
// shell related utils |
| 69 |
bool isShell(int fd); |
| 70 |
void flushFinalLineShell(int fd); |
| 71 |
|
| 72 |
// replace '~' at front of string with env HOME if found |
| 73 |
std::string SanitiseTildedPath(const char * path); |
| 74 |
|
| 75 |
bool is_number(const std::string& s); |
| 76 |
|
| 77 |
void TransferMonitor(const Uri & url, Transfer::Type op_type, dav_ssize_t bytes_transfered, dav_size_t total_size, Transfer::Type tool_type); |
| 78 |
|
| 79 |
void printProgressBar(int out_fd, int percent, dav_ssize_t bytes_transfered, dav_size_t total_size, dav_size_t baudrate); |
| 80 |
|
| 81 |
int configureMonitorCB(OptParams & opts, Transfer::Type type); |
| 82 |
|
| 83 |
void tokeniseUrl(std::string url, std::deque<std::string>& dirVec); |
| 84 |
|
| 85 |
// mkdir -p, discard front and back entries if trim is true |
| 86 |
int mkdirP(std::string dirPath, bool trim); |
| 87 |
int mkdirP(std::deque<std::string>& dirVec, bool trim); |
| 88 |
|
| 89 |
void batchTransferMonitor(std::string dirPath, std::string msg, int entryCount, int totalEntry); |
| 90 |
|
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
#endif // DAVIX_TOOL_UTIL_HPP |