"Fossies" - the Fresh Open Source Software Archive

Member "filezilla-3.48.1/src/include/server.h" (29 Apr 2020, 7669 Bytes) of package /linux/misc/FileZilla_3.48.1_src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "server.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.48.0_vs_3.48.1.

    1 #ifndef FILEZILLA_ENGINE_SERVER_HEADER
    2 #define FILEZILLA_ENGINE_SERVER_HEADER
    3 
    4 #include <map>
    5 #include <memory>
    6 #include <vector>
    7 
    8 enum ServerProtocol
    9 {
   10     // Never change any existing values or user's saved sites will become
   11     // corrupted
   12     UNKNOWN = -1,
   13     FTP, // FTP, attempts AUTH TLS
   14     SFTP,
   15     HTTP,
   16     FTPS, // Implicit SSL
   17     FTPES, // Explicit SSL
   18     HTTPS,
   19     INSECURE_FTP, // Insecure, as the name suggests
   20 
   21     S3, // Amazon S3 or compatible
   22 
   23     STORJ,
   24 
   25     WEBDAV,
   26 
   27     AZURE_FILE,
   28     AZURE_BLOB,
   29 
   30     SWIFT,
   31 
   32     GOOGLE_CLOUD,
   33     GOOGLE_DRIVE,
   34 
   35     DROPBOX,
   36 
   37     ONEDRIVE,
   38 
   39     B2,
   40 
   41     BOX,
   42 
   43     INSECURE_WEBDAV,
   44 
   45     MAX_VALUE = INSECURE_WEBDAV
   46 };
   47 
   48 enum ServerType
   49 {
   50     DEFAULT,
   51     UNIX,
   52     VMS,
   53     DOS, // Backslashes as preferred separator
   54     MVS,
   55     VXWORKS,
   56     ZVM,
   57     HPNONSTOP,
   58     DOS_VIRTUAL,
   59     CYGWIN,
   60     DOS_FWD_SLASHES, // Forwardslashes as preferred separator
   61 
   62     SERVERTYPE_MAX
   63 };
   64 
   65 enum PasvMode
   66 {
   67     MODE_DEFAULT,
   68     MODE_ACTIVE,
   69     MODE_PASSIVE
   70 };
   71 
   72 enum class ServerFormat
   73 {
   74     host_only,
   75     with_optional_port,
   76     with_user_and_optional_port,
   77     url,
   78     url_with_password
   79 };
   80 
   81 enum CharsetEncoding
   82 {
   83     ENCODING_AUTO,
   84     ENCODING_UTF8,
   85     ENCODING_CUSTOM
   86 };
   87 
   88 enum class ProtocolFeature
   89 {
   90     DataTypeConcept,        // Some protocol distinguish between ASCII and binary files for line-ending conversion.
   91     TransferMode,
   92     PreserveTimestamp,
   93     Charset,
   94     ServerType,
   95     EnterCommand,
   96     DirectoryRename,
   97     PostLoginCommands,
   98     S3Lifecycle,
   99     RecursiveDelete,
  100     ServerAssignedHome,
  101     TemporaryUrl,
  102     S3Sse,
  103     Security, // Encryption, integrity protection and authentication
  104     UnixChmod
  105 };
  106 
  107 enum class CaseSensitivity
  108 {
  109     unspecified,
  110     yes,
  111     no
  112 };
  113 
  114 CaseSensitivity GetCaseSensitivity(ServerProtocol protocol);
  115 
  116 class Credentials;
  117 class CServerPath;
  118 class CServer final
  119 {
  120 public:
  121 
  122     // No error checking is done in the constructors
  123     CServer() = default;
  124     CServer(ServerProtocol protocol, ServerType type, std::wstring const& host, unsigned int);
  125 
  126     CServer(CServer const&) = default;
  127     CServer& operator=(CServer const&) = default;
  128 
  129     CServer(CServer &&) noexcept = default;
  130     CServer& operator=(CServer &&) noexcept = default;
  131 
  132     void clear();
  133 
  134     void SetType(ServerType type);
  135 
  136     ServerProtocol GetProtocol() const;
  137     ServerType GetType() const;
  138     std::wstring GetHost() const;
  139     unsigned int GetPort() const;
  140     std::wstring GetUser() const;
  141     int GetTimezoneOffset() const;
  142     PasvMode GetPasvMode() const;
  143     int MaximumMultipleConnections() const;
  144     bool GetBypassProxy() const;
  145 
  146     void SetProtocol(ServerProtocol serverProtocol);
  147     bool SetHost(std::wstring const& host, unsigned int port);
  148 
  149     void SetUser(std::wstring const& user);
  150 
  151     bool operator==(const CServer &op) const;
  152     bool operator<(const CServer &op) const;
  153     bool operator!=(const CServer &op) const;
  154 
  155     // Returns whether the argument refers to the same resource.
  156     // Compares things like protocol and hostname, but excludes things like the name or the timezone offset.
  157     bool SameResource(CServer const& other) const;
  158 
  159     // Stricter than SameResource, also compares things like the encoding.
  160     // Can be used as key comparator in content caches
  161     bool SameContent(CServer const& other) const;
  162 
  163     bool SetTimezoneOffset(int minutes);
  164     void SetPasvMode(PasvMode pasvMode);
  165     void MaximumMultipleConnections(int maximum);
  166 
  167     std::wstring Format(ServerFormat formatType) const;
  168     std::wstring Format(ServerFormat formatType, Credentials const& credentials) const;
  169 
  170     bool SetEncodingType(CharsetEncoding type, std::wstring const& encoding = std::wstring());
  171     CharsetEncoding GetEncodingType() const;
  172     std::wstring GetCustomEncoding() const;
  173 
  174     static unsigned int GetDefaultPort(ServerProtocol protocol);
  175     static ServerProtocol GetProtocolFromPort(unsigned int port, bool defaultOnly = false);
  176 
  177     static std::wstring GetProtocolName(ServerProtocol protocol);
  178     static ServerProtocol GetProtocolFromName(std::wstring const& name);
  179 
  180     static ServerProtocol GetProtocolFromPrefix(std::wstring const& prefix, ServerProtocol const hint = UNKNOWN);
  181     static std::wstring GetPrefixFromProtocol(ServerProtocol const protocol);
  182     static std::vector<ServerProtocol> const& GetDefaultProtocols();
  183 
  184     bool HasFeature(ProtocolFeature const feature) const;
  185     static bool ProtocolHasFeature(ServerProtocol const protocol, ProtocolFeature const feature);
  186 
  187     CaseSensitivity GetCaseSensitivity() const;
  188 
  189     // These commands will be executed after a successful login.
  190     std::vector<std::wstring> const& GetPostLoginCommands() const { return m_postLoginCommands; }
  191     bool SetPostLoginCommands(std::vector<std::wstring> const& postLoginCommands);
  192 
  193     void SetBypassProxy(bool val);
  194 
  195     static std::wstring GetNameFromServerType(ServerType type);
  196     static ServerType GetServerTypeFromName(std::wstring const& name);
  197 
  198     bool empty() const { return m_host.empty(); }
  199     explicit operator bool() const { return !empty(); }
  200 
  201     void ClearExtraParameters();
  202     std::wstring GetExtraParameter(std::string_view const& name) const;
  203     std::map<std::string, std::wstring, std::less<>> const& GetExtraParameters() const;
  204     bool HasExtraParameter(std::string_view const& name) const;
  205     void SetExtraParameter(std::string_view const& name, std::wstring const& value);
  206     void ClearExtraParameter(std::string_view const& name);
  207 
  208 protected:
  209     ServerProtocol m_protocol{UNKNOWN};
  210     ServerType m_type{DEFAULT};
  211     std::wstring m_host;
  212     unsigned int m_port{21};
  213     std::wstring m_user;
  214     int m_timezoneOffset{};
  215     PasvMode m_pasvMode{MODE_DEFAULT};
  216     int m_maximumMultipleConnections{};
  217     CharsetEncoding m_encodingType{ENCODING_AUTO};
  218     std::wstring m_customEncoding;
  219 
  220     std::vector<std::wstring> m_postLoginCommands;
  221     bool m_bypassProxy{};
  222 
  223     std::map<std::string, std::wstring, std::less<>> extraParameters_;
  224 };
  225 
  226 
  227 enum class LogonType
  228 {
  229     anonymous,
  230     normal,
  231     ask, // ask should not be sent to the engine, it's intended to be used by the interface
  232     interactive,
  233     account,
  234     key,
  235 
  236     count
  237 };
  238 std::wstring GetNameFromLogonType(LogonType type);
  239 LogonType GetLogonTypeFromName(std::wstring const& name);
  240 
  241 std::vector<LogonType> GetSupportedLogonTypes(ServerProtocol protocol);
  242 
  243 
  244 namespace ParameterSection {
  245     enum type {
  246         host,
  247         user,
  248         credentials,
  249         extra,
  250         custom,
  251 
  252         section_count
  253     };
  254 }
  255 
  256 struct ParameterTraits
  257 {
  258     std::string name_;
  259 
  260     ParameterSection::type section_;
  261 
  262     enum flags : unsigned char {
  263         optional = 0x01,
  264         numeric = 0x02
  265     };
  266     unsigned char flags_;
  267     std::wstring default_;
  268     std::wstring hint_;
  269 };
  270 
  271 std::vector<ParameterTraits> const& ExtraServerParameterTraits(ServerProtocol protocol);
  272 
  273 std::tuple<std::wstring, std::wstring> GetDefaultHost(ServerProtocol protocol);
  274 
  275 bool ProtocolHasUser(ServerProtocol protocol);
  276 
  277 class Credentials
  278 {
  279 public:
  280     virtual ~Credentials() = default;
  281 
  282     bool operator==(Credentials const& rhs) const {
  283         return
  284             logonType_ == rhs.logonType_ &&
  285             password_ == rhs.password_ &&
  286             account_ == rhs.account_ &&
  287             keyFile_ == rhs.keyFile_;
  288     }
  289 
  290     void SetPass(std::wstring const& password);
  291     std::wstring GetPass() const;
  292 
  293     LogonType logonType_{LogonType::anonymous};
  294     std::wstring account_;
  295     std::wstring keyFile_;
  296 
  297     void ClearExtraParameters();
  298     std::wstring GetExtraParameter(std::string_view const& name) const;
  299     std::map<std::string, std::wstring, std::less<>> const& GetExtraParameters() const;
  300     bool HasExtraParameter(std::string_view const& name) const;
  301     void SetExtraParameter(ServerProtocol protocol, std::string_view const& name, std::wstring const& value);
  302 
  303 protected:
  304     std::wstring password_;
  305     std::map<std::string, std::wstring, std::less<>> extraParameters_;
  306 };
  307 
  308 struct ServerHandleData {
  309 protected:
  310     ServerHandleData() = default;
  311     virtual ~ServerHandleData() = default;
  312     ServerHandleData(ServerHandleData const&) = default;
  313     ServerHandleData& operator=(ServerHandleData const&) = default;
  314 };
  315 typedef std::weak_ptr<ServerHandleData> ServerHandle;
  316 
  317 #endif