File indexing completed on 2024-04-28 04:58:02

0001 /////////////////////////////////////////////////////////////////////////////
0002 //
0003 // Project:     SMB kioworker for KDE2
0004 //
0005 // File:        smburl.h
0006 //
0007 // Abstract:    Utility classes used by SMBWorker
0008 //
0009 // Author(s):   Matthew Peterson <mpeterson@caldera.com>
0010 //              Frank Schwanz <schwanz@fh-brandenburg.de>
0011 //---------------------------------------------------------------------------
0012 //
0013 // SPDX-FileCopyrightText: 2000 Caldera Systems Inc.
0014 //
0015 // This program is free software; you can redistribute it and/or modify it
0016 // under the terms of the GNU General Public License as published by the
0017 // Free Software Foundation; either version 2.1 of the License, or
0018 // (at your option) any later version.
0019 //
0020 //     This program is distributed in the hope that it will be useful,
0021 //     but WITHOUT ANY WARRANTY; without even the implied warranty of
0022 //     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0023 //     GNU Lesser General Public License for more details.
0024 //
0025 //     You should have received a copy of the GNU General Public License
0026 //     along with this program; see the file COPYING.  If not, please obtain
0027 //     a copy from https://www.gnu.org/copyleft/gpl.html
0028 //
0029 /////////////////////////////////////////////////////////////////////////////
0030 
0031 #ifndef KIO_SMB_INTERNAL_H_INCLUDED
0032 #define KIO_SMB_INTERNAL_H_INCLUDED
0033 
0034 #include <QByteArray>
0035 #include <QUrl>
0036 
0037 /**
0038  *   Types of a SMBURL :
0039  *   SMBURLTYPE_UNKNOWN  - Type could not be determined. Bad SMB Url.
0040  *   SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network
0041  *   SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver"
0042  *   SMBURLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir"
0043  *   SMBURLTYPE_PRINTER - "smb://host/printer?kio-printer=true"
0044  */
0045 enum SMBUrlType {
0046     SMBURLTYPE_UNKNOWN = 0,
0047     SMBURLTYPE_ENTIRE_NETWORK = 1,
0048     SMBURLTYPE_WORKGROUP_OR_SERVER = 2,
0049     SMBURLTYPE_SHARE_OR_PATH = 3,
0050     SMBURLTYPE_PRINTER,
0051 };
0052 
0053 /**
0054  * Class to handle URL's
0055  * it can convert QUrl to smbUrl
0056  * and Handle UserInfo
0057  * it also check the correctness of the URL
0058  */
0059 class SMBUrl : public QUrl
0060 {
0061 public:
0062     SMBUrl();
0063     SMBUrl(const SMBUrl &);
0064     SMBUrl(const QUrl &kurl);
0065     ~SMBUrl();
0066 
0067     SMBUrl &operator=(const SMBUrl &);
0068 
0069     /**
0070      * Appends the specified file and dir to this SMBUrl
0071      * "smb://server/share" --> "smb://server/share/filedir"
0072      */
0073     void addPath(const QString &filedir);
0074 
0075     void cdUp();
0076 
0077     /**
0078      *   Returns the type of this SMBUrl:
0079      *   SMBURLTYPE_UNKNOWN  - Type could not be determined. Bad SMB Url.
0080      *   SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network
0081      *   SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver"
0082      *   URLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir"
0083      */
0084     SMBUrlType getType() const;
0085 
0086     void setPass(const QString &_txt)
0087     {
0088         QUrl::setPassword(_txt);
0089         updateCache();
0090     }
0091     void setUser(const QString &_txt)
0092     {
0093         QUrl::setUserName(_txt);
0094         updateCache();
0095     }
0096     void setHost(const QString &_txt)
0097     {
0098         QUrl::setHost(_txt);
0099         updateCache();
0100     }
0101     void setPath(const QString &_txt)
0102     {
0103         QUrl::setPath(_txt);
0104         updateCache();
0105     }
0106 
0107     /**
0108      * Return a URL that is suitable for libsmbclient
0109      */
0110     QByteArray toSmbcUrl() const
0111     {
0112         return m_surl;
0113     }
0114 
0115     /**
0116      * Returns the partial URL.
0117      */
0118     SMBUrl partUrl() const;
0119 
0120 private:
0121     void updateCache();
0122     QByteArray m_surl;
0123 
0124     /**
0125      * Type of URL
0126      * @see _SMBUrlType
0127      */
0128     mutable SMBUrlType m_type = SMBURLTYPE_UNKNOWN;
0129 };
0130 
0131 #endif