when a new activity is added, don't move more than necessary to show it
[kdebase.git] / runtime / kioslave / smb / kio_smb.h
bloba1404f8591c484999a15988509781dc4ba4c50f7
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // Project: SMB kioslave for KDE
4 //
5 // File: kio_smb.h
6 //
7 // Abstract: The main kio slave class declaration. For convenience,
8 // in concurrent devlopment, the implementation for this class
9 // is separated into several .cpp files -- the file containing
10 // the implementation should be noted in the comments for each
11 // member function.
13 // Author(s): Matthew Peterson <mpeterson@caldera.com>
15 //---------------------------------------------------------------------------
17 // Copyright (c) 2000 Caldera Systems, Inc.
19 // This program is free software; you can redistribute it and/or modify it
20 // under the terms of the GNU General Public License as published by the
21 // Free Software Foundation; either version 2.1 of the License, or
22 // (at your option) any later version.
24 // This program is distributed in the hope that it will be useful,
25 // but WITHOUT ANY WARRANTY; without even the implied warranty of
26 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 // GNU Lesser General Public License for more details.
29 // You should have received a copy of the GNU General Public License
30 // along with this program; see the file COPYING. If not, please obtain
31 // a copy from http://www.gnu.org/copyleft/gpl.html
33 /////////////////////////////////////////////////////////////////////////////
36 #ifndef KIO_SMB_H_INCLUDED
37 #define KIO_SMB_H_INCLUDED
39 #include "config-smb.h"
41 //-------------
42 // QT includes
43 //-------------
45 #include <Qt3Support/Q3PtrList>
46 #include <QTextStream>
47 #include <Qt3Support/Q3StrIList>
48 //Added by qt3to4:
49 #include <QByteArray>
51 //--------------
52 // KDE includes
53 //--------------
54 #include <kdebug.h>
55 #include <kio/global.h>
56 #include <kio/slavebase.h>
57 #include <kurl.h>
58 #include <klocale.h>
60 //-----------------------------
61 // Standard C library includes
62 //-----------------------------
63 #include <stdlib.h>
64 #include <sys/stat.h>
65 #include <sys/ioctl.h>
66 #include <sys/socket.h>
67 #include <netinet/in.h>
68 #include <net/if.h>
69 #include <arpa/inet.h>
70 #include <stdio.h>
71 #include <errno.h>
72 #include <time.h>
73 #include <QObject>
75 //-------------------------------
76 // Samba client library includes
77 //-------------------------------
78 extern "C"
80 #include <libsmbclient.h>
83 //---------------------------
84 // kio_smb internal includes
85 //---------------------------
86 #include "kio_smb_internal.h"
88 #define MAX_XFER_BUF_SIZE 16348
89 #define KIO_SMB 7106
91 using namespace KIO;
92 class K3Process;
94 //===========================================================================
97 class SMBSlave : public QObject, public KIO::SlaveBase
99 Q_OBJECT
101 private:
102 //---------------------------------------------------------------------
103 // please make sure your private data does not duplicate existing data
104 //---------------------------------------------------------------------
105 bool m_initialized_smbc;
108 * From Controlcenter
110 QString m_default_user;
111 // QString m_default_workgroup; //currently unused, Alex <neundorf@kde.org>
112 QString m_default_password;
113 QString m_default_encoding;
116 * we store the current url, it's needed for
117 * callback authorisation method
119 SMBUrl m_current_url;
122 * From Controlcenter, show SHARE$ or not
124 // bool m_showHiddenShares; //currently unused, Alex <neundorf@kde.org>
127 * libsmbclient need global variables to store in,
128 * else it crashes on exit next method after use cache_stat,
129 * looks like gcc (C/C++) failure
131 struct stat st;
133 protected:
134 //---------------------------------------------
135 // Authentication functions (kio_smb_auth.cpp)
136 //---------------------------------------------
137 // (please prefix functions with auth)
141 * Description : Initilizes the libsmbclient
142 * Return : true on success false with errno set on error
144 bool auth_initialize_smbc();
146 bool checkPassword(SMBUrl &url);
149 //---------------------------------------------
150 // Cache functions (kio_smb_auth.cpp)
151 //---------------------------------------------
153 //Stat methods
155 //-----------------------------------------
156 // Browsing functions (kio_smb_browse.cpp)
157 //-----------------------------------------
158 // (please prefix functions with browse)
161 * Description : Return a stat of given SMBUrl. Calls cache_stat and
162 * pack it in UDSEntry. UDSEntry will not be cleared
163 * Parameter : SMBUrl the url to stat
164 * ignore_errors do not call error(), but warning()
165 * Return : false if any error occurred (errno), else true
167 bool browse_stat_path(const SMBUrl& url, UDSEntry& udsentry, bool ignore_errors);
170 * Description : call smbc_stat and return stats of the url
171 * Parameter : SMBUrl the url to stat
172 * Return : stat* of the url
173 * Note : it has some problems with stat in method, looks like
174 * something leave(or removed) on the stack. If your
175 * method segfault on returning try to change the stat*
176 * variable
178 int cache_stat( const SMBUrl& url, struct stat* st );
180 //---------------------------------------------
181 // Configuration functions (kio_smb_config.cpp)
182 //---------------------------------------------
183 // (please prefix functions with config)
186 //---------------------------------------
187 // Directory functions (kio_smb_dir.cpp)
188 //---------------------------------------
189 // (please prefix functions with dir)
192 //--------------------------------------
193 // File IO functions (kio_smb_file.cpp)
194 //--------------------------------------
195 // (please prefix functions with file)
197 //----------------------------
198 // Misc functions (this file)
199 //----------------------------
203 * Description : correct a given URL
204 * valid URL's are
206 * smb://[[domain;]user[:password]@]server[:port][/share[/path[/file]]]
207 * smb:/[[domain;]user[:password]@][group/[server[/share[/path[/file]]]]]
208 * domain = workgroup(domain) of the user
209 * user = username
210 * password = password of useraccount
211 * group = workgroup(domain) of server
212 * server = host to connect
213 * share = a share of the server (host)
214 * path = a path of the share
215 * Parameter : KUrl the url to check
216 * Return : new KUrl if its corrected. else the same KUrl
218 KUrl checkURL(const KUrl& kurl) const;
220 void reportError(const SMBUrl &kurl, const int &errNum);
222 public:
224 //-----------------------------------------------------------------------
225 // smbclient authentication callback (note that this is called by the
226 // global ::auth_smbc_get_data() call.
227 void auth_smbc_get_data(const char *server,const char *share,
228 char *workgroup, int wgmaxlen,
229 char *username, int unmaxlen,
230 char *password, int pwmaxlen);
233 //-----------------------------------------------------------------------
234 // Overwritten functions from the base class that define the operation of
235 // this slave. (See the base class headerfile slavebase.h for more
236 // details)
237 //-----------------------------------------------------------------------
239 // Functions overwritten in kio_smb.cpp
240 SMBSlave(const QByteArray& pool, const QByteArray& app);
241 virtual ~SMBSlave();
243 // Functions overwritten in kio_smb_browse.cpp
244 virtual void listDir( const KUrl& url );
245 virtual void stat( const KUrl& url );
247 // Functions overwritten in kio_smb_config.cpp
248 virtual void reparseConfiguration();
250 // Functions overwritten in kio_smb_dir.cpp
251 virtual void copy( const KUrl& src, const KUrl &dest, int permissions, KIO::JobFlags flags );
252 virtual void del( const KUrl& kurl, bool isfile);
253 virtual void mkdir( const KUrl& kurl, int permissions );
254 virtual void rename( const KUrl& src, const KUrl& dest, KIO::JobFlags flags );
256 // Functions overwritten in kio_smb_file.cpp
257 virtual void get( const KUrl& kurl );
258 virtual void put( const KUrl& kurl, int permissions, KIO::JobFlags flags );
259 virtual void open( const KUrl& kurl, QIODevice::OpenMode mode );
260 virtual void read( KIO::filesize_t bytesRequested );
261 virtual void write( const QByteArray &fileData );
262 virtual void seek( KIO::filesize_t offset );
263 virtual void close();
265 // Functions not implemented (yet)
266 //virtual void setHost(const QString& host, int port, const QString& user, const QString& pass);
267 //virtual void openConnection();
268 //virtual void closeConnection();
269 //virtual void slave_status();
270 virtual void special( const QByteArray & );
272 private Q_SLOTS:
273 void readOutput(K3Process *proc, char *buffer, int buflen);
274 void readStdErr(K3Process *proc, char *buffer, int buflen);
276 private:
277 QString mybuf, mystderr;
279 * Used in open(), read(), write(), and close()
280 * FIXME Placing these in the private section above causes m_openUrl = kurl
281 * to fail in SMBSlave::open. Need to find out why this is.
283 int m_openFd;
284 SMBUrl m_openUrl;
287 //==========================================================================
288 // the global libsmbclient authentication callback function
289 extern "C"
292 void auth_smbc_get_data(SMBCCTX * context,
293 const char *server,const char *share,
294 char *workgroup, int wgmaxlen,
295 char *username, int unmaxlen,
296 char *password, int pwmaxlen);
301 //===========================================================================
302 // Main slave entrypoint (see kio_smb.cpp)
303 extern "C"
306 int kdemain( int argc, char **argv );
311 #endif //#endif KIO_SMB_H_INCLUDED