aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kde2/kioslave/kio_plp.cpp143
-rw-r--r--kde2/kioslave/kio_plp.h77
-rw-r--r--lib/plpdirent.cc25
-rw-r--r--lib/plpdirent.h26
-rw-r--r--lib/rfsv.cc45
-rw-r--r--lib/rfsv.h15
-rw-r--r--lib/rfsv16.cc140
-rw-r--r--lib/rfsv16.h3
-rw-r--r--lib/rfsv32.cc167
-rw-r--r--lib/rfsv32.h3
-rw-r--r--plpftp/ftp.cc47
-rw-r--r--plpnfsd/main.cc8
12 files changed, 368 insertions, 331 deletions
diff --git a/kde2/kioslave/kio_plp.cpp b/kde2/kioslave/kio_plp.cpp
index 587ef98..4e7dbf0 100644
--- a/kde2/kioslave/kio_plp.cpp
+++ b/kde2/kioslave/kio_plp.cpp
@@ -25,6 +25,7 @@
#include "kio_plp.h"
+#include <iomanip>
#include <stdio.h>
#include <sys/stat.h>
@@ -33,6 +34,7 @@
#include <kinstance.h>
#include <kdebug.h>
#include <klocale.h>
+#include <kconfig.h>
#include <rfsvfactory.h>
#include <bufferarray.h>
@@ -99,6 +101,10 @@ removeFirstPart(const QString& path, QString &removed) {
PLPProtocol::PLPProtocol (const QCString &pool, const QCString &app)
:SlaveBase("psion", pool, app), plpRfsv(0), plpRfsvSocket(0) {
+
+ kdDebug(PLP_DEBUGAREA) << "PLPProtocol::PLPProtocol(" << pool << ","
+ << app << ")" << endl;
+
currentHost = "";
struct servent *se = getservbyname("psion", "tcp");
endservent();
@@ -106,7 +112,45 @@ PLPProtocol::PLPProtocol (const QCString &pool, const QCString &app)
currentPort = ntohs(se->s_port);
else
currentPort = DPORT;
- kdDebug(PLP_DEBUGAREA) << "PLP::PLP: -" << pool << "-" << endl;
+
+ typedef QMap<QString,QString> UIDMap;
+ KConfig *cfg = new KConfig("kioslaverc");
+
+ UIDMap uids = cfg->entryMap("Psion/UIDmapping");
+ if (uids.isEmpty()) {
+ cfg->setGroup("Psion/UIDmapping");
+ // Builtin application types.
+ cfg->writeEntry("uid-10000037-1000006D-1000007F",
+ "application/x-psion-word");
+ cfg->writeEntry("uid-10000037-1000006D-10000088",
+ "application/x-psion-sheet");
+ cfg->writeEntry("uid-10000037-1000006D-1000006d",
+ "application/x-psion-record");
+ cfg->writeEntry("uid-10000037-1000006D-1000007d",
+ "application/x-psion-sketch");
+ cfg->writeEntry("uid-10000037-1000006D-10000085",
+ "application/x-psion-opl");
+ cfg->writeEntry("uid-10000050-1000006D-10000084",
+ "application/x-psion-agenda");
+ cfg->writeEntry("uid-10000050-1000006D-10000086",
+ "application/x-psion-data");
+ cfg->sync();
+ uids = cfg->entryMap("Psion/UIDmapping");
+ }
+ for (UIDMap::Iterator uit = uids.begin(); uit != uids.end(); ++uit) {
+ long u1, u2, u3;
+
+ sscanf(uit.key().data(), "uid-%08X-%08X-%08X", &u1, &u2, &u3);
+ puids.insert(PlpUID(u1, u2, u3), uit.data());
+ }
+#if 0
+ cout << "uids:" << endl;
+ for (UidMap::Iterator it = puids.begin(); it != puids.end(); it++) {
+ cout << "UID: " << hex << setw(8) << setfill('0') << it.key().uid[0]
+ << it.key().uid[1] << it.key().uid[2] << dec << "->" <<
+ it.data() << endl;
+ }
+#endif
}
PLPProtocol::~PLPProtocol() {
@@ -135,9 +179,9 @@ isDrive(const QString& path) {
for (QStringList::Iterator it = drives.begin(); it != drives.end(); it++) {
QString cmp = "/" + *it;
if (cmp == tmp)
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
bool PLPProtocol::
@@ -220,6 +264,19 @@ checkConnection() {
return (plpRfsv == 0);
}
+QString PLPProtocol::
+uid2mime(PlpDirent &e) {
+ QString tmp;
+ PlpUID u = e.getUID();
+ UidMap::Iterator it = puids.find(u);
+
+ if (it != puids.end())
+ tmp = it.data();
+ else
+ tmp.sprintf("application/x-psion-uid-%08X-%08X-%08X", u[0], u[1], u[2]);
+ return tmp;
+}
+
void PLPProtocol::
listDir(const KURL& _url) {
KURL url(_url);
@@ -268,6 +325,7 @@ listDir(const KURL& _url) {
UDSEntry entry;
for (int i = 0; i < files.size(); i++) {
UDSAtom atom;
+
PlpDirent e = files[i];
long attr = e.getAttr();
@@ -276,9 +334,13 @@ listDir(const KURL& _url) {
atom.m_str = e.getName();
entry.append(atom);
- if (rom)
- attr |= rfsv::PSI_A_RDONLY;
- completeUDSEntry(entry, attr, e.getSize(), e.getPsiTime().getTime());
+ if ((attr & rfsv::PSI_A_DIR) == 0) {
+ atom.m_uds = KIO::UDS_MIME_TYPE;
+ atom.m_str = uid2mime(e);
+ entry.append(atom);
+ }
+
+ completeUDSEntry(entry, e, rom);
listEntry(entry, false);
}
listEntry(entry, true); // ready
@@ -306,20 +368,17 @@ createVirtualDirEntry(UDSEntry & entry, bool rdonly) {
bool PLPProtocol::
emitTotalSize(QString &name) {
- long attr;
- long size;
- bool err;
- PsiTime time;
+ PlpDirent e;
- Enum<rfsv::errs> res = plpRfsv->fgeteattr(name, attr, size, time);
+ Enum<rfsv::errs> res = plpRfsv->fgeteattr(name, e);
if (checkForError(res))
return true;
- totalSize(size);
+ totalSize(e.getSize());
return false;
}
void PLPProtocol::
-stat( const KURL & url) {
+stat(const KURL & url) {
QString path(QFile::encodeName(url.path()));
UDSEntry entry;
UDSAtom atom;
@@ -351,33 +410,67 @@ stat( const KURL & url) {
return;
}
- long attr, size;
- PsiTime time;
- Enum<rfsv::errs> res = plpRfsv->fgeteattr(path, attr, size, time);
+ PlpDirent e;
+
+ Enum<rfsv::errs> res = plpRfsv->fgeteattr(path, e);
if (checkForError(res))
return;
- if (rom)
- attr |= rfsv::PSI_A_RDONLY;
atom.m_uds = KIO::UDS_NAME;
atom.m_str = fileName;
entry.append(atom);
- completeUDSEntry(entry, attr, size, time.getTime());
+ completeUDSEntry(entry, e, rom);
statEntry(entry);
finished();
}
void PLPProtocol::
-completeUDSEntry(UDSEntry& entry, const long attr, const long size, const time_t date) {
+mimetype(const KURL & url) {
+ QString path(QFile::encodeName(url.path()));
+ UDSEntry entry;
UDSAtom atom;
+ if (checkConnection())
+ return;
+
+ kdDebug(PLP_DEBUGAREA) << "mimetype(" << path << ")" << endl;
+ stripTrailingSlash(path);
+
+ if (isRoot(path) || isDrive(path)) {
+ mimeType("inode/directory");
+ finished();
+ return;
+ }
+ convertName(path);
+
+ if (path.isEmpty()) {
+ error(ERR_DOES_NOT_EXIST, path);
+ return;
+ }
+
+ PlpDirent e;
+ Enum<rfsv::errs> res = plpRfsv->fgeteattr(path, e);
+ if (checkForError(res))
+ return;
+ mimeType(uid2mime(e));
+ finished();
+}
+
+void PLPProtocol::
+completeUDSEntry(UDSEntry& entry, PlpDirent &e, bool rom) {
+ UDSAtom atom;
+ long attr = e.getAttr();
+
+ if (rom)
+ attr |= rfsv::PSI_A_RDONLY;
+
atom.m_uds = KIO::UDS_SIZE;
- atom.m_long = size;
+ atom.m_long = e.getSize();
entry.append(atom);
atom.m_uds = KIO::UDS_MODIFICATION_TIME;
- atom.m_long = date;
+ atom.m_long = e.getPsiTime().getTime();
entry.append(atom);
atom.m_uds = KIO::UDS_ACCESS;
@@ -392,7 +485,7 @@ completeUDSEntry(UDSEntry& entry, const long attr, const long size, const time_t
atom.m_long = (attr & rfsv::PSI_A_DIR) ? S_IFDIR : S_IFREG;
entry.append(atom);
-#if 0
+#if 1
KIO::UDSEntry::ConstIterator it = entry.begin();
for( ; it != entry.end(); it++ ) {
switch ((*it).m_uds) {
@@ -504,9 +597,9 @@ checkForError(Enum<rfsv::errs> res) {
error(ERR_UNKNOWN, text);
break;
}
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
void PLPProtocol::
diff --git a/kde2/kioslave/kio_plp.h b/kde2/kioslave/kio_plp.h
index 0112801..49176f0 100644
--- a/kde2/kioslave/kio_plp.h
+++ b/kde2/kioslave/kio_plp.h
@@ -28,50 +28,55 @@
#include <rfsv.h>
#include <ppsocket.h>
+typedef QMap<PlpUID,QString> UidMap;
+
class PLPProtocol : public KIO::SlaveBase
{
- public:
- PLPProtocol (const QCString &pool, const QCString &app );
- virtual ~PLPProtocol();
-
- virtual void openConnection();
- virtual void closeConnection();
+public:
+ PLPProtocol (const QCString &pool, const QCString &app);
+ virtual ~PLPProtocol();
+
+ virtual void openConnection();
+ virtual void closeConnection();
- virtual void setHost( const QString& host, int port, const QString& user, const QString& pass );
+ virtual void setHost(const QString& host, int port, const QString&, const QString&);
- virtual void put( const KURL& url, int _mode,bool _overwrite, bool _resume );
- virtual void get( const KURL& url );
- virtual void listDir( const KURL& url);
- virtual void stat( const KURL & url);
- virtual void mkdir( const KURL& url, int permissions );
- virtual void del( const KURL& url, bool isfile);
- virtual void chmod(const KURL& url, int permissions );
- virtual void rename(const KURL &src, const KURL &dest, bool overwrite);
- virtual void copy( const KURL& src, const KURL &dest, int mode, bool overwrite );
+ virtual void put(const KURL& url, int _mode,bool _overwrite, bool _resume);
+ virtual void get(const KURL& url);
+ virtual void listDir(const KURL& url);
+ virtual void stat(const KURL & url);
+ virtual void mimetype(const KURL & url);
+ virtual void mkdir(const KURL& url, int permissions);
+ virtual void del(const KURL& url, bool isfile);
+ virtual void chmod(const KURL& url, int permissions);
+ virtual void rename(const KURL &src, const KURL &dest, bool overwrite);
+ virtual void copy(const KURL& src, const KURL &dest, int mode, bool overwrite );
- void calcprogress(long total);
- private:
- bool checkConnection();
+ void calcprogress(long total);
+private:
+ bool checkConnection();
- char driveChar(const QString& path);
+ char driveChar(const QString& path);
- void createVirtualDirEntry(KIO::UDSEntry & entry, bool rdonly);
- void completeUDSEntry(KIO::UDSEntry& entry, const long attr, const long size, const time_t date);
- bool checkForError(Enum<rfsv::errs> res);
- bool isRomDrive(const QString& path);
- bool isDrive(const QString& path);
- bool isRoot(const QString& path);
- void convertName(QString &path);
- bool emitTotalSize(QString &name);
+ void createVirtualDirEntry(KIO::UDSEntry & entry, bool rdonly);
+ void completeUDSEntry(KIO::UDSEntry& entry, PlpDirent &e, bool rom);
+ bool checkForError(Enum<rfsv::errs> res);
+ bool isRomDrive(const QString& path);
+ bool isDrive(const QString& path);
+ bool isRoot(const QString& path);
+ void convertName(QString &path);
+ bool emitTotalSize(QString &name);
+ QString uid2mime(PlpDirent &e);
- rfsv *plpRfsv;
- ppsocket *plpRfsvSocket;
- QStringList drives;
- QMap<QString,char> drivechars;
- QString currentHost;
- int currentPort;
- time_t t_last;
- time_t t_start;
+ rfsv *plpRfsv;
+ ppsocket *plpRfsvSocket;
+ QStringList drives;
+ QMap<QString,char> drivechars;
+ UidMap puids;
+ QString currentHost;
+ int currentPort;
+ time_t t_last;
+ time_t t_start;
};
#endif
diff --git a/lib/plpdirent.cc b/lib/plpdirent.cc
index 345eac6..33e1a78 100644
--- a/lib/plpdirent.cc
+++ b/lib/plpdirent.cc
@@ -2,11 +2,25 @@
#include <stream.h>
#include <iomanip>
+PlpUID::PlpUID() {
+ memset(uid, 0, sizeof(uid));
+}
+
+PlpUID::PlpUID(const long u1, const long u2, const long u3) {
+ uid[0] = u1; uid[1] = u2; uid[2] = u3;
+}
+
+long PlpUID::
+operator[](int idx) {
+ assert ((idx > -1) && (idx < 3));
+ return uid[idx];
+}
+
PlpDirent::PlpDirent(const PlpDirent &e) {
size = e.size;
attr = e.attr;
time = e.time;
- memcpy(uid, e.uid, sizeof(uid));
+ UID = e.UID;
name = e.name;
attrstr = e.attrstr;
}
@@ -24,10 +38,15 @@ getAttr() {
long PlpDirent::
getUID(int uididx) {
if ((uididx >= 0) && (uididx < 4))
- return uid[uididx];
+ return UID[uididx];
return 0;
}
+PlpUID &PlpDirent::
+getUID() {
+ return UID;
+}
+
const char *PlpDirent::
getName() {
return name.c_str();
@@ -48,7 +67,7 @@ operator=(const PlpDirent &e) {
size = e.size;
attr = e.attr;
time = e.time;
- memcpy(uid, e.uid, sizeof(uid));
+ UID = e.UID;
name = e.name;
attrstr = e.attrstr;
return *this;
diff --git a/lib/plpdirent.h b/lib/plpdirent.h
index 808af37..d10c76a 100644
--- a/lib/plpdirent.h
+++ b/lib/plpdirent.h
@@ -5,6 +5,23 @@
#include <psitime.h>
#include <rfsv.h>
+class PlpUID
+{
+ friend inline bool operator<(const PlpUID &u1, const PlpUID &u2);
+public:
+ PlpUID();
+ PlpUID(const long u1, const long u2, const long u3);
+
+ long operator[](int idx);
+
+private:
+ long uid[3];
+};
+
+inline bool operator<(const PlpUID &u1, const PlpUID &u2) {
+ return (memcmp(u1.uid, u2.uid, sizeof(u1.uid)) < 0);
+}
+
/**
* A class, representing a directory entry of the Psion.
* Objects of this type are used by @ref rfsv::readdir and
@@ -58,6 +75,13 @@ public:
long getUID(int uididx);
/**
+ * Retrieves the @ref PlpUID object of a directory entry.
+ *
+ * @returns The PlpUID object.
+ */
+ PlpUID &getUID();
+
+ /**
* Retrieve the file name of a directory entry.
*
* @returns The name of the file.
@@ -102,7 +126,7 @@ public:
private:
long size;
long attr;
- long uid[3];
+ PlpUID UID;
PsiTime time;
string attrstr;
string name;
diff --git a/lib/rfsv.cc b/lib/rfsv.cc
index cd13cb3..68635d5 100644
--- a/lib/rfsv.cc
+++ b/lib/rfsv.cc
@@ -116,30 +116,35 @@ Enum<rfsv::errs> rfsv::getStatus(void) {
return status;
}
-// beware this returns static data
-const char * const rfsv::
+string rfsv::
+convertSlash(const string &name)
+{
+ string tmp = "";
+ for (const char *p = name.c_str(); *p; p++)
+ tmp += (*p == '/') ? '\\' : *p;
+ return tmp;
+}
+
+string rfsv::
attr2String(const long attr)
{
- static char buf[11];
- buf[0] = ((attr & PSI_A_DIR) ? 'd' : '-');
- buf[1] = ((attr & PSI_A_READ) ? 'r' : '-');
- buf[2] = ((attr & PSI_A_RDONLY) ? '-' : 'w');
- buf[3] = ((attr & PSI_A_HIDDEN) ? 'h' : '-');
- buf[4] = ((attr & PSI_A_SYSTEM) ? 's' : '-');
- buf[5] = ((attr & PSI_A_ARCHIVE) ? 'a' : '-');
- buf[6] = ((attr & PSI_A_VOLUME) ? 'v' : '-');
+ string tmp = "";
+ tmp += ((attr & PSI_A_DIR) ? 'd' : '-');
+ tmp += ((attr & PSI_A_READ) ? 'r' : '-');
+ tmp += ((attr & PSI_A_RDONLY) ? '-' : 'w');
+ tmp += ((attr & PSI_A_HIDDEN) ? 'h' : '-');
+ tmp += ((attr & PSI_A_SYSTEM) ? 's' : '-');
+ tmp += ((attr & PSI_A_ARCHIVE) ? 'a' : '-');
+ tmp += ((attr & PSI_A_VOLUME) ? 'v' : '-');
// EPOC
- buf[7] = ((attr & PSI_A_NORMAL) ? 'n' : '-');
- buf[8] = ((attr & PSI_A_TEMP) ? 't' : '-');
- buf[9] = ((attr & PSI_A_COMPRESSED) ? 'c' : '-');
-
+ tmp += ((attr & PSI_A_NORMAL) ? 'n' : '-');
+ tmp += ((attr & PSI_A_TEMP) ? 't' : '-');
+ tmp += ((attr & PSI_A_COMPRESSED) ? 'c' : '-');
// SIBO
- buf[7] = ((attr & PSI_A_EXEC) ? 'x' : buf[7]);
- buf[8] = ((attr & PSI_A_STREAM) ? 'b' : buf[8]);
- buf[9] = ((attr & PSI_A_TEXT) ? 't' : buf[9]);
-
- buf[10] = '\0';
- return (char *) (&buf);
+ tmp[7] = ((attr & PSI_A_EXEC) ? 'x' : tmp[7]);
+ tmp[8] = ((attr & PSI_A_STREAM) ? 'b' : tmp[8]);
+ tmp[9] = ((attr & PSI_A_TEXT) ? 't' : tmp[9]);
+ return tmp;
}
diff --git a/lib/rfsv.h b/lib/rfsv.h
index 79fbc68..fff8322 100644
--- a/lib/rfsv.h
+++ b/lib/rfsv.h
@@ -2,6 +2,7 @@
#define _rfsv_h_
#include <deque>
+#include <string>
#include "Enum.h"
#include "plpdirent.h"
#include "bufferstore.h"
@@ -291,13 +292,11 @@ class rfsv {
* Retrieves attributes, size and modification time of a file on the Psion.
*
* @param name The name of the file.
- * @param attr The file's attributes are returned here.
- * @param size The file's size in bytes is returned here.
- * @param time The file's modification time is returned here.
+ * @param e @ref PlpDirent object, filled with the information on return.
*
* @returns A Psion error code (One of enum @ref #errs ).
*/
- virtual Enum<errs> fgeteattr(const char * const name, long &attr, long &size, PsiTime &time) =0;
+ virtual Enum<errs> fgeteattr(const char * const name, PlpDirent &e) =0;
/**
* @param name
@@ -541,7 +540,7 @@ class rfsv {
* @returns Pointer to static textual representation of file attributes.
*
*/
- const char * const attr2String(const long attr);
+ string attr2String(const long attr);
/**
* Converts an open-mode (A combination of the PSI_O_ constants.)
@@ -553,6 +552,12 @@ class rfsv {
* @ref fopen , @ref fcreatefile and @freplacefile.
*/
virtual long opMode(const long mode) = 0;
+
+ /**
+ * Utility method, converts '/' to '\'.
+ */
+ static string convertSlash(const string &name);
+
protected:
/**
* Retrieves the PLP protocol name. Mainly internal use.
diff --git a/lib/rfsv16.cc b/lib/rfsv16.cc
index d42b270..c4798eb 100644
--- a/lib/rfsv16.cc
+++ b/lib/rfsv16.cc
@@ -30,7 +30,7 @@
#include <stream.h>
#include <stdlib.h>
#include <fstream.h>
-#include <iomanip.h>
+#include <iomanip>
#include <time.h>
#include <string>
@@ -50,55 +50,13 @@ rfsv16::rfsv16(ppsocket *_skt)
}
Enum<rfsv::errs> rfsv16::
-convertName(const char* orig, char *retVal)
-{
- int len = strlen(orig);
- char *temp = new char [len+1];
-
- // FIXME: need to return 1 if OOM?
- for (int i=0; i <= len; i++) {
- if (orig[i] == '/')
- temp[i] = '\\';
- else
- temp[i] = orig[i];
- }
-
- if (len == 0 || temp[1] != ':') {
- // We can automatically supply a drive letter
- strcpy(retVal, DDRIVE);
-
- if (len == 0 || temp[0] != '\\') {
- strcat(retVal, DBASEDIR);
- }
- else {
- retVal[strlen(retVal)-1] = 0;
- }
-
- strcat(retVal, temp);
- }
- else {
- strcpy(retVal, temp);
- }
-
- delete [] temp;
- cout << retVal << endl;
- return E_PSI_GEN_NONE;
-}
-
-Enum<rfsv::errs> rfsv16::
fopen(long attr, const char *name, long &handle)
{
bufferStore a;
- char realName[200];
- Enum<rfsv::errs> rv = convertName(name, realName);
- if (rv) return rv;
-
- // FIXME: anything that calls fopen should NOT do the name
- // conversion - it's just done here.
+ string realName = convertSlash(name);
a.addWord(attr & 0xFFFF);
- a.addString(realName);
- a.addByte(0x00); // Needs to be manually Null-Terminated.
+ a.addStringT(realName.c_str());
if (!sendCommand(FOPEN, a))
return E_PSI_FILE_DISC;
@@ -197,11 +155,11 @@ readdir(rfsvDirhandle &dH, PlpDirent &e) {
cerr << "dir: not version 2" << endl;
return E_PSI_GEN_FAIL;
}
- e.attr = attr2std((long)dH.b.getWord(2));
- e.size = dH.b.getDWord(4);
- e.time = PsiTime((time_t)dH.b.getDWord(8));
- e.name = dH.b.getString(16);
- e.uid[0] = e.uid[1] = e.uid[2] = 0;
+ e.attr = attr2std((long)dH.b.getWord(2));
+ e.size = dH.b.getDWord(4);
+ e.time = PsiTime((time_t)dH.b.getDWord(8));
+ e.name = dH.b.getString(16);
+ // e.UID = PlpUID(0,0,0);
e.attrstr = attr2String(e.attr);
dH.b.discardFirstBytes(17 + e.name.length());
@@ -295,11 +253,8 @@ fgetmtime(const char * const name, PsiTime &mtime)
cerr << "rfsv16::fgetmtime" << endl;
// NB: fgetattr, fgeteattr is almost identical...
bufferStore a;
- char realName[200];
- Enum<rfsv::errs> rv = convertName(name, realName);
- if (rv) return rv;
- a.addString(realName);
- a.addByte(0x00); // needs to be null-terminated,
+ string realName = convertSlash(name);
+ a.addStringT(realName.c_str());
// and this needs sending in the length word.
if (!sendCommand(FINFO, a))
return E_PSI_FILE_DISC;
@@ -310,10 +265,6 @@ cerr << "rfsv16::fgetmtime" << endl;
return res;
}
else if (a.getLen() == 16) {
- // struct timeval tv;
- // tv.tv_sec = a.getDWord(8);
- // tv.tv_usec = 0;
- // mtime.setUnixTime(&tv);
mtime.setUnixTime(a.getDWord(8));
return res;
}
@@ -335,11 +286,8 @@ fgetattr(const char * const name, long &attr)
{
// NB: fgetmtime, fgeteattr are almost identical...
bufferStore a;
- char realName[200];
- Enum<rfsv::errs> rv = convertName(name, realName);
- if (rv) return rv;
- a.addString(realName);
- a.addByte(0x00); // needs to be null-terminated,
+ string realName = convertSlash(name);
+ a.addStringT(realName.c_str());
// and this needs sending in the length word.
if (!sendCommand(FINFO, a))
return E_PSI_FILE_DISC;
@@ -358,28 +306,29 @@ fgetattr(const char * const name, long &attr)
}
Enum<rfsv::errs> rfsv16::
-fgeteattr(const char * const name, long &attr, long &size, PsiTime &time)
+fgeteattr(const char * const name, PlpDirent &e)
{
bufferStore a;
- char realName[200];
- Enum<rfsv::errs> rv = convertName(name, realName);
- if (rv) return rv;
- a.addString(realName);
- a.addByte(0x00); // needs to be null-terminated,
- // and this needs sending in the length word.
+ string realName = convertSlash(name);
+ a.addStringT(realName.c_str());
if (!sendCommand(FINFO, a))
return E_PSI_FILE_DISC;
-
Enum<rfsv::errs> res = getResponse(a);
if (res != 0) {
cerr << "fgeteattr: Error " << res << " on file " << name << endl;
return res;
}
else if (a.getLen() == 16) {
- attr = a.getWord(2);
- size = a.getDWord(4);
- time.setUnixTime(a.getDWord(8));
- //time = a.getDWord(8);
+ const char *p = strrchr(realName.c_str(), '\\');
+ if (p)
+ p++;
+ else
+ p = realName.c_str();
+ e.name = p;
+ e.attr = a.getWord(2);
+ e.size = a.getDWord(4);
+ e.time = PsiTime(a.getDWord(8));
+ e.UID = PlpUID(0,0,0);
return res;
}
cerr << "fgeteattr: Unknown response (" << name << ") " << a <<endl;
@@ -903,15 +852,11 @@ fseek(const long handle, const long pos, const long mode, long &resultpos)
Enum<rfsv::errs> rfsv16::
mkdir(const char* dirName)
{
- char realName[200];
- Enum<rfsv::errs> res = convertName(dirName, realName);
- if (res != E_PSI_GEN_NONE) return res;
+ string realName = convertSlash(dirName);
bufferStore a;
- a.addString(realName);
- a.addByte(0x00); // needs to be null-terminated,
- // and this needs sending in the length word.
+ a.addStringT(realName.c_str());
sendCommand(MKDIR, a);
- res = getResponse(a);
+ Enum<rfsv::errs> res = getResponse(a);
if (res == E_PSI_GEN_NONE) {
// Correct response
return res;
@@ -932,21 +877,14 @@ Enum<rfsv::errs> rfsv16::
rename(const char *oldName, const char *newName)
{
cerr << "rfsv16::rename ***" << endl;
- char realOldName[200];
- Enum<rfsv::errs> res = convertName(oldName, realOldName);
- if (res != E_PSI_GEN_NONE) return res;
- char realNewName[200];
- res = convertName(newName, realNewName);
- if (res != E_PSI_GEN_NONE) return res;
+
+ string realOldName = convertSlash(oldName);
+ string realNewName = convertSlash(newName);
bufferStore a;
- a.addString(realOldName);
- a.addByte(0x00); // needs to be null-terminated,
- // and this needs sending in the length word.
- a.addString(realNewName);
- a.addByte(0x00); // needs to be null-terminated,
- // and this needs sending in the length word.
+ a.addStringT(realOldName.c_str());
+ a.addStringT(realNewName.c_str());
sendCommand(RENAME, a);
- res = getResponse(a);
+ Enum<rfsv::errs> res = getResponse(a);
if (res == E_PSI_GEN_NONE) {
// Correct response
return res;
@@ -958,12 +896,10 @@ cerr << "rfsv16::rename ***" << endl;
Enum<rfsv::errs> rfsv16::
remove(const char* psionName)
{
- char realName[200];
- Enum<rfsv::errs> res = convertName(psionName, realName);
- if (res != E_PSI_GEN_NONE) return res;
+ Enum<rfsv::errs> res;
+ string realName = convertSlash(psionName);
bufferStore a;
- a.addString(realName);
- a.addByte(0x00); // needs to be null-terminated,
+ a.addStringT(realName.c_str());
// and this needs sending in the length word.
sendCommand(DELETE, a);
res = getResponse(a);
@@ -1054,5 +990,3 @@ std2attr(const long attr)
return res;
}
-
-
diff --git a/lib/rfsv16.h b/lib/rfsv16.h
index d0eda32..0b3bdab 100644
--- a/lib/rfsv16.h
+++ b/lib/rfsv16.h
@@ -16,7 +16,7 @@ public:
Enum<rfsv::errs> fgetmtime(const char * const, PsiTime &);
Enum<rfsv::errs> fsetmtime(const char * const, const PsiTime);
Enum<rfsv::errs> fgetattr(const char * const, long &);
- Enum<rfsv::errs> fgeteattr(const char * const, long &, long &, PsiTime &);
+ Enum<rfsv::errs> fgeteattr(const char * const, PlpDirent &);
Enum<rfsv::errs> fsetattr(const char * const, const long seta, const long unseta);
Enum<rfsv::errs> dircount(const char * const, long &);
Enum<rfsv::errs> devlist(long &);
@@ -99,7 +99,6 @@ private:
// Miscellaneous
- Enum<rfsv::errs> convertName(const char*, char *);
Enum<rfsv::errs> fopendir(const char * const, long &);
long attr2std(const long);
long std2attr(const long);
diff --git a/lib/rfsv32.cc b/lib/rfsv32.cc
index 8808879..0eb9911 100644
--- a/lib/rfsv32.cc
+++ b/lib/rfsv32.cc
@@ -44,25 +44,14 @@ rfsv32::rfsv32(ppsocket * _skt)
reset();
}
-char *rfsv32::
-convertSlash(const char *name)
-{
- char *n = strdup(name);
- for (char *p = n; *p; p++)
- if (*p == '/')
- *p = '\\';
- return n;
-}
-
Enum<rfsv::errs> rfsv32::
fopen(long attr, const char *name, long &handle)
{
bufferStore a;
- char *n = convertSlash(name);
+ string n = convertSlash(name);
a.addDWord(attr);
- a.addWord(strlen(n));
- a.addString(n);
- free(n);
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(OPEN_FILE, a))
return E_PSI_FILE_DISC;
Enum<rfsv::errs> res = getResponse(a);
@@ -91,11 +80,10 @@ Enum<rfsv::errs> rfsv32::
fcreatefile(long attr, const char *name, long &handle)
{
bufferStore a;
- char *n = convertSlash(name);
+ string n = convertSlash(name);
a.addDWord(attr);
- a.addWord(strlen(n));
- a.addString(n);
- free(n);
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(CREATE_FILE, a))
return E_PSI_FILE_DISC;
Enum<rfsv::errs> res = getResponse(a);
@@ -108,11 +96,10 @@ Enum<rfsv::errs> rfsv32::
freplacefile(const long attr, const char * const name, long &handle)
{
bufferStore a;
- char *n = convertSlash(name);
+ string n = convertSlash(name);
a.addDWord(attr);
- a.addWord(strlen(n));
- a.addString(n);
- free(n);
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(REPLACE_FILE, a))
return E_PSI_FILE_DISC;
Enum<rfsv::errs> res = getResponse(a);
@@ -125,11 +112,10 @@ Enum<rfsv::errs> rfsv32::
fopendir(const long attr, const char * const name, long &handle)
{
bufferStore a;
- char *n = convertSlash(name);
+ string n = convertSlash(name);
a.addDWord(attr | EPOC_ATTR_GETUID);
- a.addWord(strlen(n));
- a.addString(n);
- free(n);
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(OPEN_DIR, a))
return E_PSI_FILE_DISC;
Enum<rfsv::errs> res = getResponse(a);
@@ -177,11 +163,9 @@ readdir(rfsvDirhandle &dH, PlpDirent &e) {
long shortLen = dH.b.getDWord(0);
long longLen = dH.b.getDWord(32);
- e.attr = attr2std(dH.b.getDWord(4));
- e.size = dH.b.getDWord(8);
- e.uid[0] = dH.b.getDWord(20);
- e.uid[1] = dH.b.getDWord(24);
- e.uid[2] = dH.b.getDWord(28);
+ e.attr = attr2std(dH.b.getDWord(4));
+ e.size = dH.b.getDWord(8);
+ e.UID = PlpUID(dH.b.getDWord(20), dH.b.getDWord(24), dH.b.getDWord(28));
e.time = PsiTime(dH.b.getDWord(16), dH.b.getDWord(12));
e.name = "";
e.attrstr = string(attr2String(e.attr));
@@ -232,16 +216,14 @@ Enum<rfsv::errs> rfsv32::
fgetmtime(const char * const name, PsiTime &mtime)
{
bufferStore a;
- char *n = convertSlash(name);
- a.addWord(strlen(n));
- a.addString(n);
- free(n);
+ string n = convertSlash(name);
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(MODIFIED, a))
return E_PSI_FILE_DISC;
Enum<rfsv::errs> res = getResponse(a);
if (res != E_PSI_GEN_NONE)
return res;
- //mtime = micro2time(a.getDWord(4), a.getDWord(0));
mtime.setPsiTime(a.getDWord(4), a.getDWord(0));
return res;
}
@@ -250,14 +232,11 @@ Enum<rfsv::errs> rfsv32::
fsetmtime(const char * const name, PsiTime mtime)
{
bufferStore a;
- //unsigned long microLo, microHi;
- char *n = convertSlash(name);
- // time2micro(mtime, microHi, microLo);
+ string n = convertSlash(name);
a.addDWord(mtime.getPsiTimeLo());
a.addDWord(mtime.getPsiTimeHi());
- a.addWord(strlen(n));
- a.addString(n);
- free(n);
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(SET_MODIFIED, a))
return E_PSI_FILE_DISC;
return getResponse(a);
@@ -267,10 +246,9 @@ Enum<rfsv::errs> rfsv32::
fgetattr(const char * const name, long &attr)
{
bufferStore a;
- char *n = convertSlash(name);
- a.addWord(strlen(n));
- a.addString(n);
- free(n);
+ string n = convertSlash(name);
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(ATT, a))
return E_PSI_FILE_DISC;
Enum<rfsv::errs> res = getResponse(a);
@@ -281,29 +259,33 @@ fgetattr(const char * const name, long &attr)
}
Enum<rfsv::errs> rfsv32::
-fgeteattr(const char * const name, long &attr, long &size, PsiTime &time)
+fgeteattr(const char * const name, PlpDirent &e)
{
bufferStore a;
- char *n = convertSlash(name);
- a.addWord(strlen(n));
- a.addString(n);
- free(n);
+ string n = convertSlash(name);
+ a.addWord(n.size());
+ a.addString(n.c_str());
+ const char *p = strrchr(n.c_str(), '\\');
+ if (p)
+ p++;
+ else
+ p = n.c_str();
+ e.name = p;
+
if (!sendCommand(REMOTE_ENTRY, a))
return E_PSI_FILE_DISC;
Enum<rfsv::errs> res = getResponse(a);
if (res != E_PSI_GEN_NONE)
return res;
// long shortLen = a.getDWord(0);
- attr = attr2std(a.getDWord(4));
- size = a.getDWord(8);
- //unsigned long modLow = a.getDWord(12);
- //unsigned long modHi = a.getDWord(16);
- // long uid1 = a.getDWord(20);
- // long uid2 = a.getDWord(24);
- // long uid3 = a.getDWord(28);
// long longLen = a.getDWord(32);
- //time = micro2time(modHi, modLow);
- time.setPsiTime(a.getDWord(16), a.getDWord(12));
+
+ e.attr = attr2std(a.getDWord(4));
+ e.size = a.getDWord(8);
+ e.UID = PlpUID(a.getDWord(20), a.getDWord(24), a.getDWord(28));
+ e.time = PsiTime(a.getDWord(16), a.getDWord(12));
+ e.attrstr = string(attr2String(e.attr));
+
return res;
}
@@ -311,12 +293,11 @@ Enum<rfsv::errs> rfsv32::
fsetattr(const char * const name, const long seta, const long unseta)
{
bufferStore a;
- char *n = convertSlash(name);
+ string n = convertSlash(name);
a.addDWord(std2attr(seta));
a.addDWord(std2attr(unseta));
- a.addWord(strlen(n));
- a.addString(n);
- free(n);
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(SET_ATT, a))
return E_PSI_FILE_DISC;
return getResponse(a);
@@ -557,13 +538,10 @@ copyOnPsion(const char *from, const char *to, void *ptr, cpCallback_t cb)
{
long handle_from;
long handle_to;
- long attr;
- long from_size;
- long to_size;
- PsiTime time;
+ PlpDirent from_e;
Enum<rfsv::errs> res;
- if ((res = fgeteattr(from, attr, from_size, time)) != E_PSI_GEN_NONE)
+ if ((res = fgeteattr(from, from_e)) != E_PSI_GEN_NONE)
return res;
if ((res = fopen(EPOC_OMODE_SHARE_READERS | EPOC_OMODE_BINARY, from, handle_from))
!= E_PSI_GEN_NONE)
@@ -736,16 +714,11 @@ Enum<rfsv::errs> rfsv32::
mkdir(const char *name)
{
bufferStore a;
- char *n = convertSlash(name);
- if (strlen(n) && (n[strlen(n) - 1] != '\\')) {
- a.addWord(strlen(n) + 1);
- a.addString(n);
- a.addByte('\\');
- } else {
- a.addWord(strlen(n));
- a.addString(n);
- }
- free(n);
+ string n = convertSlash(name);
+ if (n.find_last_of('\\') == (n.size() - 1))
+ n += '\\';
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(MK_DIR_ALL, a))
return E_PSI_FILE_DISC;
return getResponse(a);
@@ -755,16 +728,11 @@ Enum<rfsv::errs> rfsv32::
rmdir(const char *name)
{
bufferStore a;
- char *n = convertSlash(name);
- if (strlen(n) && (n[strlen(n) - 1] != '\\')) {
- a.addWord(strlen(n) + 1);
- a.addString(n);
- a.addByte('\\');
- } else {
- a.addWord(strlen(n));
- a.addString(n);
- }
- free(n);
+ string n = convertSlash(name);
+ if (n.find_last_of('\\') == (n.size() - 1))
+ n += '\\';
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(RM_DIR, a))
return E_PSI_FILE_DISC;
return getResponse(a);
@@ -774,14 +742,12 @@ Enum<rfsv::errs> rfsv32::
rename(const char *oldname, const char *newname)
{
bufferStore a;
- char *on = convertSlash(oldname);
- char *nn = convertSlash(newname);
- a.addWord(strlen(on));
- a.addString(on);
- a.addWord(strlen(nn));
- a.addString(nn);
- free(on);
- free(nn);
+ string on = convertSlash(oldname);
+ string nn = convertSlash(newname);
+ a.addWord(on.size());
+ a.addString(on.c_str());
+ a.addWord(nn.size());
+ a.addString(nn.c_str());
if (!sendCommand(RENAME, a))
return E_PSI_FILE_DISC;
return getResponse(a);
@@ -791,10 +757,9 @@ Enum<rfsv::errs> rfsv32::
remove(const char *name)
{
bufferStore a;
- char *n = convertSlash(name);
- a.addWord(strlen(n));
- a.addString(n);
- free(n);
+ string n = convertSlash(name);
+ a.addWord(n.size());
+ a.addString(n.c_str());
if (!sendCommand(DELETE, a))
return E_PSI_FILE_DISC;
return getResponse(a);
diff --git a/lib/rfsv32.h b/lib/rfsv32.h
index 2ef584b..4a738da 100644
--- a/lib/rfsv32.h
+++ b/lib/rfsv32.h
@@ -19,7 +19,7 @@ public:
Enum<rfsv::errs> remove(const char * const);
Enum<rfsv::errs> rename(const char * const, const char * const);
Enum<rfsv::errs> mktemp(long &, char * const);
- Enum<rfsv::errs> fgeteattr(const char * const, long &, long &, PsiTime &);
+ Enum<rfsv::errs> fgeteattr(const char * const, PlpDirent &);
Enum<rfsv::errs> fgetattr(const char * const, long &);
Enum<rfsv::errs> fsetattr(const char * const, const long, const long);
Enum<rfsv::errs> fgetmtime(const char * const, PsiTime &);
@@ -159,7 +159,6 @@ private:
// Communication
bool sendCommand(enum commands, bufferStore &);
Enum<rfsv::errs> getResponse(bufferStore &);
- char *convertSlash(const char *);
// time-conversion
// unsigned long micro2time(unsigned long, unsigned long);
diff --git a/plpftp/ftp.cc b/plpftp/ftp.cc
index 837f668..222dd4e 100644
--- a/plpftp/ftp.cc
+++ b/plpftp/ftp.cc
@@ -328,17 +328,13 @@ session(rfsv & a, rpcs & r, int xargc, char **xargv)
continue;
}
if (!strcmp(argv[0], "test") && (argc == 2)) {
- long attr, size;
- PsiTime time;
+ PlpDirent e;
strcpy(f1, psionDir);
strcat(f1, argv[1]);
- if ((res = a.fgeteattr(f1, attr, size, time)) != rfsv::E_PSI_GEN_NONE)
+ if ((res = a.fgeteattr(f1, e)) != rfsv::E_PSI_GEN_NONE)
cerr << "Error: " << res << endl;
- else {
- cout << a.attr2String(attr);
- cout << " " << dec << setw(10) << setfill(' ') << size;
- cout << " " << time << " " << argv[1] << endl;
- }
+ else
+ cout << e << endl;
continue;
}
if (!strcmp(argv[0], "gattr") && (argc == 2)) {
@@ -993,49 +989,40 @@ static char *remote_dir_commands[] = {
static PlpDir comp_files;
static long maskAttr;
-static char tmpPath[1024];
static char cplPath[1024];
static char*
filename_generator(char *text, int state)
{
static int len;
-
+ string tmp;
if (!state) {
- char *p;
Enum<rfsv::errs> res;
len = strlen(text);
- strcpy(tmpPath, psionDir);
- strcat(tmpPath, cplPath);
- for (p = tmpPath; *p; p++)
- if (*p == '/')
- *p = '\\';
- if ((res = comp_a->dir(tmpPath, comp_files)) != rfsv::E_PSI_GEN_NONE) {
+ tmp = psionDir;
+ tmp += cplPath;
+ tmp = rfsv::convertSlash(tmp);
+ if ((res = comp_a->dir(tmp.c_str(), comp_files)) != rfsv::E_PSI_GEN_NONE) {
cerr << "Error: " << res << endl;
return NULL;
}
}
- for (int i = 0; i < comp_files.size(); i++) {
- PlpDirent e = comp_files[i];
+ while (!comp_files.empty()) {
+ PlpDirent e = comp_files.front();
long attr = e.getAttr();
- char *p;
+ comp_files.pop_front();
if ((attr & maskAttr) == 0)
continue;
- strcpy(tmpPath, cplPath);
- strcat(tmpPath, e.getName());
- for (p = tmpPath; *p; p++)
- if (*p == '\\')
- *p = '/';
- if (!(strncmp(tmpPath, text, len))) {
- char fnbuf[1024];
- strcpy(fnbuf, tmpPath);
+ tmp = cplPath;
+ tmp += e.getName();
+ if (!(strncmp(tmp.c_str(), text, len))) {
if (attr & rfsv::PSI_A_DIR) {
rl_completion_append_character = '\0';
- strcat(fnbuf, "/");
+ tmp += '/';
}
- return (strdup(fnbuf));
+ return (strdup(tmp.c_str()));
}
}
return NULL;
diff --git a/plpnfsd/main.cc b/plpnfsd/main.cc
index 96c2be4..d1e0337 100644
--- a/plpnfsd/main.cc
+++ b/plpnfsd/main.cc
@@ -393,12 +393,14 @@ long rfsv_setattr(const char *name, long sattr, long dattr) {
long rfsv_getattr(const char *name, long *attr, long *size, long *time) {
long res;
- PsiTime pt;
+ PlpDirent e;
if (!a)
return -1;
- res = a->fgeteattr(name, *attr, *size, pt);
- *time = pt.getTime();
+ res = a->fgeteattr(name, e);
+ *attr = e.getAttr();
+ *size = e.getSize();
+ *time = e.getPsiTime().getTime();
return res;
}