ftp.h
来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C头文件 代码 · 共 599 行 · 第 1/2 页
H
599 行
// -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*-/* This file is part of the KDE libraries Copyright (C) 2000 David Faure <faure@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/// $Id: ftp.h 465272 2005-09-29 09:47:40Z mueller $#ifndef __ftp_h__#define __ftp_h__#include <config.h>#include <sys/types.h>#include <sys/socket.h>#include <qcstring.h>#include <qstring.h>#include <kurl.h>#include <kio/slavebase.h>#include <kextsock.h>#include <ksocks.h>struct FtpEntry{ QString name; QString owner; QString group; QString link; KIO::filesize_t size; mode_t type; mode_t access; time_t date;};//===============================================================================// FtpTextReader A helper class to read text lines from a socket//===============================================================================#ifdef KIO_FTP_PRIVATE_INCLUDEclass FtpSocket;class FtpTextReader{public: FtpTextReader() { textClear(); }/** * Resets the status of the object, also called from xtor */ void textClear();/** * Read a line from the socket into m_szText. Only the first RESP_READ_LIMIT * characters are copied. If the server response is longer all extra data up to * the new-line gets discarded. An ending CR gets stripped. The number of chars * in the buffer is returned. Use textToLong() to check for truncation! */ int textRead(FtpSocket *pSock);/** * An accessor to the data read by textRead() */ const char* textLine() const { return m_szText; }/** * Returns true if the last textRead() resulted in a truncated line */ bool textTooLong() const { return m_bTextTruncated; }/** * Returns true if the last textRead() got an EOF or an error */ bool textEOF() const { return m_bTextEOF; } enum { /** * This is the physical size of m_szText. Only up to textReadLimit * characters are used to store a server reply. If the server reply * is longer, the stored line gets truncated - see textTooLong()! */ textReadBuffer = 2048,/** * Max number of chars returned from textLine(). If the server * sends more all chars until the next new-line are discarded. */ textReadLimit = 1024 };private: /** * textRead() sets this true on trucation (e.g. line too long) */ bool m_bTextTruncated; /** * textRead() sets this true if the read returns 0 bytes or error */ bool m_bTextEOF; /** * textRead() fills this buffer with data */ char m_szText[textReadBuffer]; /** * the number of bytes in the current response line */ int m_iTextLine; /** * the number of bytes in the response buffer (includes m_iRespLine) */ int m_iTextBuff;};#endif // KIO_FTP_PRIVATE_INCLUDE//===============================================================================// FtpSocket Helper Class for Data or Control Connections//===============================================================================#ifdef KIO_FTP_PRIVATE_INCLUDEclass FtpSocket : public FtpTextReader, public KExtendedSocket{private: // hide the default xtor FtpSocket() {}public:/** * The one and only public xtor. The string data passed to the * xtor must remain valid during the object's lifetime - it is * used in debug messages to identify the socket instance. */ FtpSocket(const char* pszName) { m_pszName = pszName; m_server = -1; } ~FtpSocket() { closeSocket(); }/** * Resets the status of the object, also called from xtor */ void closeSocket();/** * We may have a server connection socket if not in passive mode. This * routine returns the server socket set by setServer. The sock() * function will return the server socket - if it is set. */ int server() const { return m_server; }/** * Set the server socket if arg >= 0, otherwise clear it. */ void setServer(int i) { m_server = (i >= 0) ? i : -1; }/** * returns the effective socket that user used for read/write. See server() */ int sock() const { return (m_server != -1) ? m_server : fd(); }/** * output an debug message via kdDebug */ void debugMessage(const char* pszMsg) const;/** * output an error message via kdError, returns iErrorCode */ int errorMessage(int iErrorCode, const char* pszMsg) const;/** * connect socket and set some options (reuse, keepalive, linger) */ int connectSocket(int iTimeOutSec, bool bControl);/** * utility to simplify calls to ::setsockopt(). Uses sock(). */ bool setSocketOption(int opt, char*arg, socklen_t len) const;/** * utility to read data from the effective socket, see sock() */ long read(void* pData, long iMaxlen) { return KSocks::self()->read(sock(), pData, iMaxlen); }/** * utility to write data to the effective socket, see sock() */ long write(void* pData, long iMaxlen) { return KSocks::self()->write(sock(), pData, iMaxlen); }/** * Use the inherited FtpTextReader to read a line from the socket */ int textRead() { return FtpTextReader::textRead(this); }private: const char* m_pszName; // set by the xtor, used for debug output int m_server; // socket override, see setSock()};#else class FtpSocket;#endif // KIO_FTP_PRIVATE_INCLUDE//===============================================================================// Ftp//===============================================================================class Ftp : public KIO::SlaveBase{ // Ftp() {}public: Ftp( const QCString &pool, const QCString &app ); virtual ~Ftp(); virtual void setHost( const QString& host, int port, const QString& user, const QString& pass ); /** * Connects to a ftp server and logs us in * m_bLoggedOn is set to true if logging on was successful. * It is set to false if the connection becomes closed. * */ virtual void openConnection(); /** * Closes the connection */ virtual void closeConnection(); virtual void stat( const KURL &url ); virtual void listDir( const KURL & url ); virtual void mkdir( const KURL & url, int permissions ); virtual void rename( const KURL & src, const KURL & dst, bool overwrite ); virtual void del( const KURL & url, bool isfile ); virtual void chmod( const KURL & url, int permissions ); virtual void get( const KURL& url ); virtual void put( const KURL& url, int permissions, bool overwrite, bool resume); //virtual void mimetype( const KURL& url ); virtual void slave_status(); /** * Handles the case that one side of the job is a local file */ virtual void copy( const KURL &src, const KURL &dest, int permissions, bool overwrite );private: // ------------------------------------------------------------------------ // All the methods named ftpXyz are lowlevel methods that are not exported. // The implement functionality used by the public high-level methods. Some // low-level methods still use error() to emit errors. This behaviour is not // recommended - please return a boolean status or an error code instead! // ------------------------------------------------------------------------ /** * Status Code returned from ftpPut() and ftpGet(), used to select * source or destination url for error messages */ typedef enum { statusSuccess, statusClientError, statusServerError } StatusCode; /** * Login Mode for ftpOpenConnection */ typedef enum { loginDefered,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?