You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
262 lines
9.2 KiB
262 lines
9.2 KiB
15 years ago
|
/***************************************************************************
|
||
|
sftpfileattr.h - description
|
||
|
-------------------
|
||
|
begin : Sat Jun 30 2001
|
||
|
copyright : (C) 2001 by Lucas Fisher
|
||
|
email : ljfisher@iastate.edu
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License as published by *
|
||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
|
#ifndef SFTPFILEATTR_H
|
||
|
#define SFTPFILEATTR_H
|
||
|
|
||
|
#include <sys/types.h>
|
||
|
|
||
15 years ago
|
#include <tqglobal.h>
|
||
|
#include <tqstring.h>
|
||
|
#include <tqdatastream.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeio/global.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
|
||
|
#include "sftp.h"
|
||
|
|
||
|
/**
|
||
|
*@author Lucas Fisher
|
||
|
*/
|
||
|
|
||
|
class KRemoteEncoding;
|
||
|
|
||
|
class sftpFileAttr {
|
||
|
|
||
|
private: // Private attributes
|
||
|
/** Name of file. */
|
||
15 years ago
|
TQString mFilename;
|
||
15 years ago
|
|
||
|
/** Specifies which fields of the file attribute are available. */
|
||
14 years ago
|
TQ_UINT32 mFlags;
|
||
15 years ago
|
|
||
|
/** Size of the file in bytes. Should be 64 bit safe. */
|
||
13 years ago
|
TQ_ULLONG mSize;
|
||
15 years ago
|
|
||
|
/** User id of the owner of the file. */
|
||
|
uid_t mUid;
|
||
|
|
||
|
/** Group id of the group to which the file belongs. */
|
||
|
gid_t mGid;
|
||
|
|
||
|
/** POSIX permissions of the file. */
|
||
|
mode_t mPermissions;
|
||
|
|
||
|
/** Last access time of the file in seconds from Jan 1, 1970. */
|
||
|
time_t mAtime;
|
||
|
|
||
|
/** Last modification time of file in seconds since Jan. 1, 1970. */
|
||
|
time_t mMtime;
|
||
|
|
||
|
/** Number of file attribute extensions.
|
||
|
Not currently implemented */
|
||
14 years ago
|
TQ_UINT32 mExtendedCount;
|
||
15 years ago
|
|
||
|
/** Longname of the file as found in a SSH_FXP_NAME sftp packet.
|
||
|
These contents are parse to return the file's owner name and
|
||
|
gr oup name. */
|
||
15 years ago
|
TQCString mLongname;
|
||
15 years ago
|
|
||
15 years ago
|
TQString mUserName;
|
||
|
TQString mGroupName;
|
||
15 years ago
|
|
||
14 years ago
|
/** If file is a link, contains the destination of the link */
|
||
15 years ago
|
TQString mLinkDestination;
|
||
15 years ago
|
|
||
14 years ago
|
/** If resource is a link, contains the type the link,e.g. file,dir... */
|
||
15 years ago
|
mode_t mLinkType;
|
||
|
|
||
|
/** Whether >> operator should read filename and longname from the stream. */
|
||
|
bool mDirAttrs;
|
||
|
|
||
|
/** Holds the encoding of the remote host */
|
||
|
KRemoteEncoding* mEncoding;
|
||
|
|
||
|
public:
|
||
|
sftpFileAttr();
|
||
|
|
||
|
sftpFileAttr(KRemoteEncoding* encoding);
|
||
|
|
||
|
~sftpFileAttr();
|
||
|
|
||
|
/** Constructor to initialize the file attributes on declaration. */
|
||
13 years ago
|
sftpFileAttr(TQ_ULLONG size_, uid_t uid_, gid_t gid_, mode_t permissions_,
|
||
14 years ago
|
time_t atime_, time_t mtime_, TQ_UINT32 extendedCount_ = 0);
|
||
15 years ago
|
|
||
|
/** Return the size of the sftp attribute not including filename or longname*/
|
||
14 years ago
|
TQ_UINT32 size() const;
|
||
15 years ago
|
|
||
|
/** Clear all attributes and flags. */
|
||
|
void clear();
|
||
|
|
||
|
/** Set the size of the file. */
|
||
13 years ago
|
void setFileSize(TQ_ULLONG s)
|
||
15 years ago
|
{ mSize = s; mFlags |= SSH2_FILEXFER_ATTR_SIZE; }
|
||
|
|
||
|
/** The size file attribute will not be included in the UDSEntry
|
||
|
or when the file attribute is written to the sftp packet. */
|
||
|
void clearFileSize()
|
||
|
{ mSize = 0; mFlags &= ~SSH2_FILEXFER_ATTR_SIZE; }
|
||
|
|
||
|
/** Returns the size of the file. */
|
||
13 years ago
|
TQ_ULLONG fileSize() const { return mSize; }
|
||
15 years ago
|
|
||
|
/** Sets the POSIX permissions of the file. */
|
||
|
void setPermissions(mode_t p)
|
||
|
{ mPermissions = p; mFlags |= SSH2_FILEXFER_ATTR_PERMISSIONS; }
|
||
|
|
||
|
/** The permissions file attribute will not be included in the UDSEntry
|
||
|
or when the file attribute is written to the sftp packet. */
|
||
|
void clearPermissions()
|
||
|
{ mPermissions = 0; mFlags &= ~SSH2_FILEXFER_ATTR_PERMISSIONS; }
|
||
|
|
||
|
/** Returns the POSIX permissons of the file. */
|
||
|
mode_t permissions() const { return mPermissions; }
|
||
|
|
||
|
/** Sets the group id of the file. */
|
||
|
void setGid(gid_t id)
|
||
|
{ mGid = id; mFlags |= SSH2_FILEXFER_ATTR_UIDGID; }
|
||
|
|
||
|
/** Neither the gid or uid file attributes will not be included in the UDSEntry
|
||
|
or when the file attribute is written to the sftp packet. This is
|
||
|
equivalent to clearUid() */
|
||
|
void clearGid()
|
||
|
{ mGid = 0; mFlags &= SSH2_FILEXFER_ATTR_UIDGID; }
|
||
|
|
||
|
/** Returns the group id of the file. */
|
||
|
gid_t gid() const { return mGid; }
|
||
|
|
||
|
/** Sets the uid of the file. */
|
||
|
void setUid(uid_t id)
|
||
|
{ mUid = id; mFlags |= SSH2_FILEXFER_ATTR_UIDGID; }
|
||
|
|
||
|
/** Neither the gid or uid file attributes will not be included in the UDSEntry
|
||
|
or when the file attribute is written to the sftp packet. This is
|
||
|
equivalent to clearGid() */
|
||
|
void clearUid()
|
||
|
{ mUid = 0; mFlags &= SSH2_FILEXFER_ATTR_UIDGID; }
|
||
|
|
||
|
/** Returns the user id of the file. */
|
||
|
gid_t uid() const { return mUid; }
|
||
|
|
||
|
/** Set the modificatoin time of the file in seconds since Jan. 1, 1970. */
|
||
|
void setMtime(time_t t)
|
||
|
{ mMtime = t; mFlags |= SSH2_FILEXFER_ATTR_ACMODTIME; }
|
||
|
|
||
|
/** Neither the mtime or atime file attributes will not be included in the UDSEntry
|
||
|
or when the file attribute is written to the sftp packet. This is
|
||
|
equivalent to clearAtime() */
|
||
|
void clearMtime()
|
||
|
{ mMtime = 0; mFlags &= SSH2_FILEXFER_ATTR_ACMODTIME; }
|
||
|
|
||
|
/** Returns the modification time of the file in seconds since Jan. 1, 1970. */
|
||
|
time_t mtime() const { return mMtime; }
|
||
|
|
||
|
/** Sets the access time of the file in seconds since Jan. 1, 1970. */
|
||
|
void setAtime(time_t t)
|
||
|
{ mAtime = t; mFlags |= SSH2_FILEXFER_ATTR_ACMODTIME; }
|
||
|
|
||
|
/** Neither the atime or mtime file attributes will not be included in the UDSEntry
|
||
|
or when the file attribute is written to the sftp packet. This is
|
||
|
equivalent to clearMtime() */
|
||
|
void clearAtime()
|
||
|
{ mAtime = 0; mFlags &= SSH2_FILEXFER_ATTR_ACMODTIME; }
|
||
|
|
||
|
/** Returns the last access time of the file in seconds since Jan. 1, 1970. */
|
||
|
time_t atime() const { return mAtime; }
|
||
|
|
||
|
/** Sets the number of file attribute extensions. */
|
||
|
void setExtendedCount(unsigned int c)
|
||
|
{ mExtendedCount = c; mFlags |= SSH2_FILEXFER_ATTR_EXTENDED; }
|
||
|
|
||
|
/** No extensions will be included when the file attribute is written
|
||
|
to a sftp packet. */
|
||
|
void clearExtensions()
|
||
|
{ mExtendedCount = 0; mFlags &= ~SSH2_FILEXFER_ATTR_EXTENDED; }
|
||
|
|
||
|
/** Returns the number of file attribute extentsions. */
|
||
|
unsigned int extendedCount() const { return mExtendedCount; }
|
||
|
|
||
|
/** Returns the flags for the sftp file attributes. */
|
||
|
unsigned int flags() const { return mFlags; }
|
||
|
|
||
|
/** Sets file's longname. See sftpFileAttr::longname. */
|
||
15 years ago
|
void setLongname(TQString l) { mLongname = l.latin1(); }
|
||
15 years ago
|
|
||
|
/** Returns a string describing the file attributes. The format is specific
|
||
|
to the implementation of the sftp server. In most cases (ie OpenSSH)
|
||
|
this is similar to the long output of 'ls'. */
|
||
15 years ago
|
TQString longname() const { return mLongname; }
|
||
15 years ago
|
|
||
15 years ago
|
void setLinkDestination(const TQString& target)
|
||
15 years ago
|
{ mLinkDestination = target; }
|
||
|
|
||
15 years ago
|
TQString linkDestination()
|
||
15 years ago
|
{ return mLinkDestination; }
|
||
|
|
||
|
/** Sets the actual type a symbolic link points to. */
|
||
|
void setLinkType (mode_t type) { mLinkType = type; }
|
||
|
|
||
|
mode_t linkType() const { return mLinkType; }
|
||
|
|
||
|
/** No descriptions */
|
||
15 years ago
|
void setFilename(const TQString& fn)
|
||
15 years ago
|
{ mFilename = fn; }
|
||
|
|
||
15 years ago
|
TQString filename() const
|
||
15 years ago
|
{ return mFilename; }
|
||
|
|
||
|
/** Returns a UDSEntry describing the file.
|
||
|
The UDSEntry is generated from the sftp file attributes. */
|
||
12 years ago
|
TDEIO::UDSEntry entry();
|
||
15 years ago
|
|
||
|
/** Use to output the file attributes to a sftp packet
|
||
|
This will only write the sftp ATTR structure to the stream.
|
||
|
It will never write the filename and longname because the client
|
||
|
never sends those to the server. */
|
||
15 years ago
|
friend TQDataStream& operator<< (TQDataStream&, const sftpFileAttr&);
|
||
15 years ago
|
|
||
|
/** Use to read a file attribute from a sftp packet.
|
||
|
Read this carefully! If the DirAttrs flag is true, this will
|
||
|
read the filename, longname, and file attributes from the stream.
|
||
|
This is for use with listing directories.
|
||
|
If the DirAttrs flag is false, this will only read file attributes
|
||
|
from the stream.
|
||
|
BY DEFAULT, A NEW INSTANCE HAS DirAttrs == false */
|
||
15 years ago
|
friend TQDataStream& operator>> (TQDataStream&, sftpFileAttr&);
|
||
15 years ago
|
|
||
|
/** Parse longname for the owner and group names. */
|
||
|
void getUserGroupNames();
|
||
|
|
||
|
/** Sets the DirAttrs flag. This flag affects how the >> operator works on data streams. */
|
||
|
void setDirAttrsFlag(bool flag){ mDirAttrs = flag; }
|
||
|
|
||
|
/** Gets the DirAttrs flag. */
|
||
|
bool getDirAttrsFlag() const { return mDirAttrs; }
|
||
|
|
||
|
friend kdbgstream& operator<< (kdbgstream& s, sftpFileAttr& a);
|
||
|
friend kndbgstream& operator<< (kndbgstream& s, sftpFileAttr& a);
|
||
|
|
||
|
/** Returns the file type as determined from the file permissions */
|
||
|
mode_t fileType() const;
|
||
|
|
||
|
/** Set the encoding of the remote file system */
|
||
|
void setEncoding( KRemoteEncoding* encoding );
|
||
|
};
|
||
|
|
||
|
#endif
|