1 /////////////////////////////////////////////////////////////////////////////
3 // Project: SMB kioslave for KDE
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
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"
45 #include <kio/global.h>
46 #include <kio/slavebase.h>
50 //-----------------------------
51 // Standard C library includes
52 //-----------------------------
55 #include <sys/ioctl.h>
56 #include <sys/socket.h>
57 #include <netinet/in.h>
59 #include <arpa/inet.h>
65 //-------------------------------
66 // Samba client library includes
67 //-------------------------------
70 #include <libsmbclient.h>
73 //---------------------------
74 // kio_smb internal includes
75 //---------------------------
76 #include "kio_smb_internal.h"
78 #define MAX_XFER_BUF_SIZE 16348
84 //===========================================================================
87 class SMBSlave
: public QObject
, public KIO::SlaveBase
92 //---------------------------------------------------------------------
93 // please make sure your private data does not duplicate existing data
94 //---------------------------------------------------------------------
95 bool m_initialized_smbc
;
100 QString m_default_user
;
101 // QString m_default_workgroup; //currently unused, Alex <neundorf@kde.org>
102 QString m_default_password
;
103 QString m_default_encoding
;
106 * we store the current url, it's needed for
107 * callback authorisation method
109 SMBUrl m_current_url
;
112 * From Controlcenter, show SHARE$ or not
114 // bool m_showHiddenShares; //currently unused, Alex <neundorf@kde.org>
117 * libsmbclient need global variables to store in,
118 * else it crashes on exit next method after use cache_stat,
119 * looks like gcc (C/C++) failure
124 //---------------------------------------------
125 // Authentication functions (kio_smb_auth.cpp)
126 //---------------------------------------------
127 // (please prefix functions with auth)
131 * Description : Initilizes the libsmbclient
132 * Return : true on success false with errno set on error
134 bool auth_initialize_smbc();
136 bool checkPassword(SMBUrl
&url
);
139 //---------------------------------------------
140 // Cache functions (kio_smb_auth.cpp)
141 //---------------------------------------------
145 //-----------------------------------------
146 // Browsing functions (kio_smb_browse.cpp)
147 //-----------------------------------------
148 // (please prefix functions with browse)
151 * Description : Return a stat of given SMBUrl. Calls cache_stat and
152 * pack it in UDSEntry. UDSEntry will not be cleared
153 * Parameter : SMBUrl the url to stat
154 * ignore_errors do not call error(), but warning()
155 * Return : false if any error occurred (errno), else true
157 bool browse_stat_path(const SMBUrl
& url
, UDSEntry
& udsentry
, bool ignore_errors
);
160 * Description : call smbc_stat and return stats of the url
161 * Parameter : SMBUrl the url to stat
162 * Return : stat* of the url
163 * Note : it has some problems with stat in method, looks like
164 * something leave(or removed) on the stack. If your
165 * method segfault on returning try to change the stat*
168 int cache_stat( const SMBUrl
& url
, struct stat
* st
);
170 //---------------------------------------------
171 // Configuration functions (kio_smb_config.cpp)
172 //---------------------------------------------
173 // (please prefix functions with config)
176 //---------------------------------------
177 // Directory functions (kio_smb_dir.cpp)
178 //---------------------------------------
179 // (please prefix functions with dir)
182 //--------------------------------------
183 // File IO functions (kio_smb_file.cpp)
184 //--------------------------------------
185 // (please prefix functions with file)
187 //----------------------------
188 // Misc functions (this file)
189 //----------------------------
193 * Description : correct a given URL
196 * smb://[[domain;]user[:password]@]server[:port][/share[/path[/file]]]
197 * smb:/[[domain;]user[:password]@][group/[server[/share[/path[/file]]]]]
198 * domain = workgroup(domain) of the user
200 * password = password of useraccount
201 * group = workgroup(domain) of server
202 * server = host to connect
203 * share = a share of the server (host)
204 * path = a path of the share
205 * Parameter : KUrl the url to check
206 * Return : new KUrl if its corrected. else the same KUrl
208 KUrl
checkURL(const KUrl
& kurl
) const;
210 void reportError(const SMBUrl
&kurl
, const int &errNum
);
214 //-----------------------------------------------------------------------
215 // smbclient authentication callback (note that this is called by the
216 // global ::auth_smbc_get_data() call.
217 void auth_smbc_get_data(const char *server
,const char *share
,
218 char *workgroup
, int wgmaxlen
,
219 char *username
, int unmaxlen
,
220 char *password
, int pwmaxlen
);
223 //-----------------------------------------------------------------------
224 // Overwritten functions from the base class that define the operation of
225 // this slave. (See the base class headerfile slavebase.h for more
227 //-----------------------------------------------------------------------
229 // Functions overwritten in kio_smb.cpp
230 SMBSlave(const QByteArray
& pool
, const QByteArray
& app
);
233 // Functions overwritten in kio_smb_browse.cpp
234 virtual void listDir( const KUrl
& url
);
235 virtual void stat( const KUrl
& url
);
237 // Functions overwritten in kio_smb_config.cpp
238 virtual void reparseConfiguration();
240 // Functions overwritten in kio_smb_dir.cpp
241 virtual void copy( const KUrl
& src
, const KUrl
&dest
, int permissions
, KIO::JobFlags flags
);
242 virtual void del( const KUrl
& kurl
, bool isfile
);
243 virtual void mkdir( const KUrl
& kurl
, int permissions
);
244 virtual void rename( const KUrl
& src
, const KUrl
& dest
, KIO::JobFlags flags
);
246 // Functions overwritten in kio_smb_file.cpp
247 virtual void get( const KUrl
& kurl
);
248 virtual void put( const KUrl
& kurl
, int permissions
, KIO::JobFlags flags
);
249 virtual void open( const KUrl
& kurl
, QIODevice::OpenMode mode
);
250 virtual void read( KIO::filesize_t bytesRequested
);
251 virtual void write( const QByteArray
&fileData
);
252 virtual void seek( KIO::filesize_t offset
);
253 virtual void close();
255 // Functions not implemented (yet)
256 //virtual void setHost(const QString& host, int port, const QString& user, const QString& pass);
257 //virtual void openConnection();
258 //virtual void closeConnection();
259 //virtual void slave_status();
260 virtual void special( const QByteArray
& );
263 void readOutput(K3Process
*proc
, char *buffer
, int buflen
);
264 void readStdErr(K3Process
*proc
, char *buffer
, int buflen
);
267 QString mybuf
, mystderr
;
269 * Used in open(), read(), write(), and close()
270 * FIXME Placing these in the private section above causes m_openUrl = kurl
271 * to fail in SMBSlave::open. Need to find out why this is.
277 //==========================================================================
278 // the global libsmbclient authentication callback function
282 void auth_smbc_get_data(SMBCCTX
* context
,
283 const char *server
,const char *share
,
284 char *workgroup
, int wgmaxlen
,
285 char *username
, int unmaxlen
,
286 char *password
, int pwmaxlen
);
291 //===========================================================================
292 // Main slave entrypoint (see kio_smb.cpp)
296 int kdemain( int argc
, char **argv
);
301 #endif //#endif KIO_SMB_H_INCLUDED