aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Enum.cc94
-rw-r--r--lib/Enum.h380
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/bufferarray.cc185
-rw-r--r--lib/bufferarray.h289
-rw-r--r--lib/bufferstore.cc225
-rw-r--r--lib/bufferstore.h421
-rw-r--r--lib/iowatch.cc110
-rw-r--r--lib/iowatch.h101
-rw-r--r--lib/log.cc59
-rw-r--r--lib/log.h102
-rw-r--r--lib/plpdirent.cc197
-rw-r--r--lib/plpdirent.h577
-rw-r--r--lib/ppsocket.cc884
-rw-r--r--lib/ppsocket.h389
-rw-r--r--lib/psitime.cc291
-rw-r--r--lib/psitime.h513
-rw-r--r--lib/rfsv.cc253
-rw-r--r--lib/rfsv.h1091
-rw-r--r--lib/rfsv16.cc1409
-rw-r--r--lib/rfsv16.h231
-rw-r--r--lib/rfsv32.cc1320
-rw-r--r--lib/rfsv32.h346
-rw-r--r--lib/rfsvfactory.cc140
-rw-r--r--lib/rfsvfactory.h124
-rw-r--r--lib/rpcs.cc469
-rw-r--r--lib/rpcs.h706
-rw-r--r--lib/rpcs16.cc74
-rw-r--r--lib/rpcs16.h44
-rw-r--r--lib/rpcs32.cc347
-rw-r--r--lib/rpcs32.h75
-rw-r--r--lib/rpcsfactory.cc138
-rw-r--r--lib/rpcsfactory.h114
33 files changed, 6193 insertions, 5507 deletions
diff --git a/lib/Enum.cc b/lib/Enum.cc
index 8abce8b..74fc2e3 100644
--- a/lib/Enum.cc
+++ b/lib/Enum.cc
@@ -1,57 +1,75 @@
-/*--*-c++-*-------------------------------------------------------------
- * $Id$
- *---------------------------------------------------------------------*/
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 2000 Henner Zeller <hzeller@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#include "Enum.h"
void EnumBase::i2sMapper::add(long i, const char* s) {
- stringMap.insert(pair<long, const char* const>(i, s));
+ stringMap.insert(pair<long, const char* const>(i, s));
}
string EnumBase::i2sMapper::lookup (long i) const {
- i2s_map_t::const_iterator searchPtr = stringMap.find(i);
+ i2s_map_t::const_iterator searchPtr = stringMap.find(i);
- if (searchPtr == stringMap.end())
- return "[OUT-OF-RANGE]";
- /*
- * now combine the probably the multiple strings belonging to this
- * integer
- */
- string result;
- for (i = stringMap.count(i); i > 0 ; --i, ++searchPtr) {
- // this should be the case:
- assert(searchPtr != stringMap.end());
- if (result.length() != 0)
- result += string(",");
- result += string(searchPtr->second);
- }
- return result;
+ if (searchPtr == stringMap.end())
+ return "[OUT-OF-RANGE]";
+ /*
+ * now combine the probably the multiple strings belonging to this
+ * integer
+ */
+ string result;
+ for (i = stringMap.count(i); i > 0 ; --i, ++searchPtr) {
+ // this should be the case:
+ assert(searchPtr != stringMap.end());
+ if (result.length() != 0)
+ result += string(",");
+ result += string(searchPtr->second);
+ }
+ return result;
}
long EnumBase::i2sMapper::lookup (const char *s) const {
- /*
- * lookup a specific string.
- * Since speed does not matter, we just do an exhaustive
- * search.
- * Otherwise we would have to maintain another map
- * mapping strings to ints .. but its not worth the memory
- */
- i2s_map_t::const_iterator run = stringMap.begin();
- while (run != stringMap.end() && strcmp(s, run->second)) {
- ++run;
- }
- if (run == stringMap.end())
- return -1; // FIXME .. maybe throw an exception ?
- return run->first;
+ /*
+ * lookup a specific string.
+ * Since speed does not matter, we just do an exhaustive
+ * search.
+ * Otherwise we would have to maintain another map
+ * mapping strings to ints .. but its not worth the memory
+ */
+ i2s_map_t::const_iterator run = stringMap.begin();
+ while (run != stringMap.end() && strcmp(s, run->second)) {
+ ++run;
+ }
+ if (run == stringMap.end())
+ return -1; // FIXME .. maybe throw an exception ?
+ return run->first;
}
bool EnumBase::i2sMapper::inRange (long i) const {
- return (stringMap.find(i) != stringMap.end());
+ return (stringMap.find(i) != stringMap.end());
}
-/*
+/*
* Local variables:
- * c-basic-offset: 8
+ * c-basic-offset: 4
* End:
*/
diff --git a/lib/Enum.h b/lib/Enum.h
index 8dcaa1b..a106f5a 100644
--- a/lib/Enum.h
+++ b/lib/Enum.h
@@ -1,10 +1,36 @@
-/*--*-c++-*-------------------------------------------------------------
- * $Id$
- *---------------------------------------------------------------------*/
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 2000 Henner Zeller <hzeller@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifndef _ENUM_H_
#define _ENUM_H_
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_LIBINTL_H
+#include <intl.h>
+#endif
+
#include <map>
#include <string>
@@ -18,69 +44,69 @@
*/
class EnumBase {
protected:
+ /**
+ * maps integers (typically: enumeration values) to
+ * Strings. Takes care of the fact, that an Integer may map
+ * to multiple strings (sometimes multiple enumeration values
+ * represent the same integer).
+ *
+ * Provides a means to get the string representation of an
+ * integer and vice versa.
+ *
+ * @author Henner Zeller
+ */
+ class i2sMapper {
+ private:
/**
- * maps integers (typically: enumeration values) to
- * Strings. Takes care of the fact, that an Integer may map
- * to multiple strings (sometimes multiple enumeration values
- * represent the same integer).
- *
- * Provides a means to get the string representation of an
- * integer and vice versa.
- *
- * @author Henner Zeller
- */
- class i2sMapper {
- private:
- /**
- * there can be one value, mapping to multiple
- * strings. Therefore, we need a multimap.
- */
- typedef multimap<long, const char*> i2s_map_t;
-
- /**
- * just for the record. Mapping back a string to the
- * Integer value in question. Since Symbols must be unique,
- * there is only a 1:1 relation as opposed to i2s_map_t. So
- * we can use a normal map here.
- *
- * Since in the usual application, mapping a string back
- * to its value is not important performance wise (typically
- * in a frontend), so it is implemented as exhaustive search,
- * not as extra map. Saves some bits of memrory ..
- */
- //typedef map<const char*, long> s2i_map_t;
+ * there can be one value, mapping to multiple
+ * strings. Therefore, we need a multimap.
+ */
+ typedef multimap<long, const char*> i2s_map_t;
- i2s_map_t stringMap;
- public:
- /**
- * adds a new int -> string mapping
- * Does NOT take over responsibility for the
- * pointer (i.e. it is not freed), so it is save
- * to add constant strings provided in the program code.
- */
- void add(long, const char*);
+ /**
+ * just for the record. Mapping back a string to the
+ * Integer value in question. Since Symbols must be unique,
+ * there is only a 1:1 relation as opposed to i2s_map_t. So
+ * we can use a normal map here.
+ *
+ * Since in the usual application, mapping a string back
+ * to its value is not important performance wise (typically
+ * in a frontend), so it is implemented as exhaustive search,
+ * not as extra map. Saves some bits of memrory ..
+ */
+ //typedef map<const char*, long> s2i_map_t;
- /**
- * returns the string representation for this integer.
- * If there are multiple strings for this integer,
- * return a comma delimited list.
- */
- string lookup(long) const;
+ i2s_map_t stringMap;
+ public:
+ /**
+ * adds a new int -> string mapping
+ * Does NOT take over responsibility for the
+ * pointer (i.e. it is not freed), so it is save
+ * to add constant strings provided in the program code.
+ */
+ void add(long, const char*);
+
+ /**
+ * returns the string representation for this integer.
+ * If there are multiple strings for this integer,
+ * return a comma delimited list.
+ */
+ string lookup(long) const;
- /**
- * returns the integer associated with the
- * given string or -1 if the value
- * is not found (XXX: this should throw
- * an exception).
- */
- long lookup (const char *) const;
+ /**
+ * returns the integer associated with the
+ * given string or -1 if the value
+ * is not found (XXX: this should throw
+ * an exception).
+ */
+ long lookup (const char *) const;
- /**
- * returns true, if we have an representation for
- * the given integer.
- */
- bool inRange(long) const;
- };
+ /**
+ * returns true, if we have an representation for
+ * the given integer.
+ */
+ bool inRange(long) const;
+ };
};
/**
@@ -89,7 +115,7 @@ protected:
*
* The string representation capability is needed to provide a
* generic input frontend for any Enumeration because text labels
- * are needed in GUIs, and, of course, aids debugging, because you
+ * are needed in GUIs, and, of course, aids debugging, because you
* can provide a readable presentation of an entry if something
* goes wrong.
*
@@ -115,118 +141,124 @@ protected:
template<typename E>
class Enum : private EnumBase {
private:
- struct sdata {
- /**
- * The constructor of the static data part.
- * You've to provide a constructor for each Enumeration
- * you want to wrap with this class. Initializes
- * the string Representation map, the readable name
- * of this Enumeration and a default value.
- *
- * The constructor is called automatically on definition,
- * so this makes sure, that the static part is initialized
- * properly before the program starts.
- */
- sdata();
- i2sMapper stringRep;
- string name;
- E defaultValue;
- };
- static sdata staticData;
-
+ struct sdata {
/**
- * The actual value hold by this instance
+ * The constructor of the static data part.
+ * You've to provide a constructor for each Enumeration
+ * you want to wrap with this class. Initializes
+ * the string Representation map, the readable name
+ * of this Enumeration and a default value.
+ *
+ * The constructor is called automatically on definition,
+ * so this makes sure, that the static part is initialized
+ * properly before the program starts.
*/
- E value;
+ sdata();
+ i2sMapper stringRep;
+ string name;
+ E defaultValue;
+ };
+ static sdata staticData;
+
+ /**
+ * The actual value hold by this instance
+ */
+ E value;
public:
- /**
- * default constructor.
- * Initialize with default value.
- */
- Enum() : value(staticData.defaultValue) {}
-
- /**
- * initialize with Enumeration given.
- */
- Enum(E init) : value(init){
- // if this hits you and you're sure, that the
- // value is right .. is this Enum proper
- // initialized in the Enum<E>::sdata::sdata() ?
- assert(inRange(init));
- }
-
- /**
- * initialize with the string representation
- * XXX: throw Exception if not found ?
- */
- Enum(const string& s) : value(getValueFor(s)) {
- assert(inRange(value));
- }
+ /**
+ * default constructor.
+ * Initialize with default value.
+ */
+ Enum() : value(staticData.defaultValue) {}
- /**
- * assign an Enumeration of this type. In debug
- * version, assert, that it is really in the Range of
- * this Enumeration.
- */
- inline Enum& operator = (E setval) {
- value = setval;
- assert(inRange(setval));
- return *this;
- }
+ /**
+ * initialize with Enumeration given.
+ */
+ Enum(E init) : value(init){
+ // if this hits you and you're sure, that the
+ // value is right .. is this Enum proper
+ // initialized in the Enum<E>::sdata::sdata() ?
+ assert(inRange(init));
+ }
- /**
- * returns the enumeration value hold with this
- * enum.
- */
- inline operator E () const { return value; }
+ /**
+ * initialize with the string representation
+ * XXX: throw Exception if not found ?
+ */
+ Enum(const string& s) : value(getValueFor(s)) {
+ assert(inRange(value));
+ }
- /**
- * returns the String representation for the value
- * represented by this instance.
- */
- string toString() const { return getStringFor(value); }
+ /**
+ * assign an Enumeration of this type. In debug
+ * version, assert, that it is really in the Range of
+ * this Enumeration.
+ */
+ inline Enum& operator = (E setval) {
+ value = setval;
+ assert(inRange(setval));
+ return *this;
+ }
- /**
- * This static member returns true, if the integer value
- * given fits int the range of this Enumeration. Use this
- * to verify input/output.
- * Fitting in the range of Enumeration here means, that
- * there actually exists a String representation for it,
- * so this Enumeration is needed to be initialized properly
- * in its Enum<E>::sdata::sdata() constructor, you've to
- * provide. For convenience, use the ENUM_DEFINITION() macro
- * for this.
- */
- static bool inRange(long i) {
- return (staticData.stringRep.inRange(i));
- }
+ /**
+ * returns the enumeration value hold with this
+ * enum.
+ */
+ inline operator E () const { return value; }
- /**
- * returns the Name for this enumeration. Useful for
- * error reporting.
- */
- static string getEnumName() { return staticData.name; }
-
- /**
- * gives the String represenatation of a specific
- * value of this Enumeration.
- */
- static string getStringFor(E e) {
- return staticData.stringRep.lookup((long) e);
- }
-
- /**
- * returns the Value for a specific String.
- * XXX: throw OutOfRangeException ?
- */
- static E getValueFor(const string &s) {
- return (E) staticData.stringRep.lookup(s.getCStr());
- }
+ /**
+ * returns the String representation for the value
+ * represented by this instance.
+ */
+ string toString() const { return getStringFor(value); }
+
+ /**
+ * returns the C string representation for the value
+ * represented by this instance.
+ */
+ operator const char *() const { return toString().c_str(); }
+
+ /**
+ * This static member returns true, if the integer value
+ * given fits int the range of this Enumeration. Use this
+ * to verify input/output.
+ * Fitting in the range of Enumeration here means, that
+ * there actually exists a String representation for it,
+ * so this Enumeration is needed to be initialized properly
+ * in its Enum<E>::sdata::sdata() constructor, you've to
+ * provide. For convenience, use the ENUM_DEFINITION() macro
+ * for this.
+ */
+ static bool inRange(long i) {
+ return (staticData.stringRep.inRange(i));
+ }
+
+ /**
+ * returns the Name for this enumeration. Useful for
+ * error reporting.
+ */
+ static string getEnumName() { return staticData.name; }
+
+ /**
+ * gives the String represenatation of a specific
+ * value of this Enumeration.
+ */
+ static string getStringFor(E e) {
+ return staticData.stringRep.lookup((long) e);
+ }
+
+ /**
+ * returns the Value for a specific String.
+ * XXX: throw OutOfRangeException ?
+ */
+ static E getValueFor(const string &s) {
+ return (E) staticData.stringRep.lookup(s.getCStr());
+ }
};
/**
- * Helper macro to construct an enumeration wrapper Enum<E> for
+ * Helper macro to construct an enumeration wrapper Enum<E> for
* a specific enum type.
*
* It defines the static variable holding the static
@@ -237,7 +269,7 @@ public:
*
* usage example:
* <pre>
- * // declaration of enumeration; somewhere
+ * // declaration of enumeration; somewhere
* class rfsv {
* [...]
* enum PSI_ERROR_CODES { E_PSI_GEN_NONE, E_PSI_GEN_FAIL, E_PSI_GEN_ARG };
@@ -260,30 +292,30 @@ public:
* @author Henner Zeller
*/
#define ENUM_DEFINITION(EnumName, initWith) \
- /** \
+/** \
* The definition of the static variable holding the static \
* data for this Enumeration wrapper. \
*/ \
- Enum<EnumName>::sdata Enum<EnumName>::staticData; \
- /** \
+Enum<EnumName>::sdata Enum<EnumName>::staticData; \
+/** \
* actual definition of the constructor for the static data. \
* This is called implicitly by the definition above. \
*/ \
- Enum<EnumName>::sdata::sdata() : \
- name(#EnumName),defaultValue(initWith)
+Enum<EnumName>::sdata::sdata() : \
+name(#EnumName),defaultValue(initWith)
/**
* Writes enumeration's string representation.
*/
template <typename E>
inline ostream& operator << (ostream& out, const Enum<E> &e) {
- return out << e.toString();
+ return out << gettext(e.toString().c_str());
}
-/*
+#endif /* _ENUM_H_ */
+
+/*
* Local variables:
- * c-basic-offset: 8
+ * c-basic-offset: 4
* End:
*/
-
-#endif /* _ENUM_H_ */
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7e56949..505b19d 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,5 +1,7 @@
# $Id$
#
+INCLUDES += -I$(top_srcdir)/intl
+
lib_LTLIBRARIES = libplp.la
libplp_la_LDFLAGS = $(LIBDEBUG) -version-info $(LIBVERSION)
diff --git a/lib/bufferarray.cc b/lib/bufferarray.cc
index 953ec8f..65f2acf 100644
--- a/lib/bufferarray.cc
+++ b/lib/bufferarray.cc
@@ -1,25 +1,26 @@
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-// extensions Copyright (C) 2000 Fritz Elfert <felfert@to.com>
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 2000, 2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#include <stream.h>
#include <iomanip.h>
@@ -29,136 +30,142 @@
bufferArray::bufferArray()
{
- len = 0;
- lenAllocd = ALLOC_MIN;
- buff = new bufferStore[lenAllocd];
+ len = 0;
+ lenAllocd = ALLOC_MIN;
+ buff = new bufferStore[lenAllocd];
}
bufferArray::bufferArray(const bufferArray & a)
{
- len = a.len;
- lenAllocd = a.lenAllocd;
- buff = new bufferStore[lenAllocd];
- for (int i = 0; i < len; i++)
- buff[i] = a.buff[i];
+ len = a.len;
+ lenAllocd = a.lenAllocd;
+ buff = new bufferStore[lenAllocd];
+ for (int i = 0; i < len; i++)
+ buff[i] = a.buff[i];
}
bufferArray::~bufferArray()
{
- delete []buff;
+ delete []buff;
}
bufferStore bufferArray::
pop()
{
- bufferStore ret;
- if (len > 0) {
- ret = buff[0];
- len--;
- for (long i = 0; i < len; i++) {
- buff[i] = buff[i + 1];
- }
+ bufferStore ret;
+ if (len > 0) {
+ ret = buff[0];
+ len--;
+ for (long i = 0; i < len; i++) {
+ buff[i] = buff[i + 1];
}
- return ret;
+ }
+ return ret;
}
void bufferArray::
append(const bufferStore & b)
{
- if (len == lenAllocd) {
- lenAllocd += ALLOC_MIN;
- bufferStore *nb = new bufferStore[lenAllocd];
- for (long i = 0; i < len; i++) {
- nb[i] = buff[i];
- }
- delete []buff;
- buff = nb;
+ if (len == lenAllocd) {
+ lenAllocd += ALLOC_MIN;
+ bufferStore *nb = new bufferStore[lenAllocd];
+ for (long i = 0; i < len; i++) {
+ nb[i] = buff[i];
}
- buff[len++] = b;
+ delete []buff;
+ buff = nb;
+ }
+ buff[len++] = b;
}
void bufferArray::
push(const bufferStore & b)
{
- if (len == lenAllocd)
- lenAllocd += ALLOC_MIN;
- bufferStore *nb = new bufferStore[lenAllocd];
- for (long i = len; i > 0; i--) {
- nb[i] = buff[i - 1];
- }
- nb[0] = b;
- delete[]buff;
- buff = nb;
- len++;
+ if (len == lenAllocd)
+ lenAllocd += ALLOC_MIN;
+ bufferStore *nb = new bufferStore[lenAllocd];
+ for (long i = len; i > 0; i--) {
+ nb[i] = buff[i - 1];
+ }
+ nb[0] = b;
+ delete[]buff;
+ buff = nb;
+ len++;
}
long bufferArray::
length(void)
{
- return len;
+ return len;
}
void bufferArray::
clear(void)
{
- len = 0;
- lenAllocd = ALLOC_MIN;
- delete []buff;
- buff = new bufferStore[lenAllocd];
+ len = 0;
+ lenAllocd = ALLOC_MIN;
+ delete []buff;
+ buff = new bufferStore[lenAllocd];
}
bufferArray &bufferArray::
operator =(const bufferArray & a)
{
- delete []buff;
- len = a.len;
- lenAllocd = a.lenAllocd;
- buff = new bufferStore[lenAllocd];
- for (int i = 0; i < len; i++)
- buff[i] = a.buff[i];
- return *this;
+ delete []buff;
+ len = a.len;
+ lenAllocd = a.lenAllocd;
+ buff = new bufferStore[lenAllocd];
+ for (int i = 0; i < len; i++)
+ buff[i] = a.buff[i];
+ return *this;
}
bufferStore &bufferArray::
operator [](const unsigned long index)
{
- return buff[index];
+ return buff[index];
}
bufferArray bufferArray::
operator +(const bufferStore &s)
{
- bufferArray res = *this;
- res += s;
- return res;
+ bufferArray res = *this;
+ res += s;
+ return res;
}
bufferArray bufferArray::
operator +(const bufferArray &a)
{
- bufferArray res = *this;
- res += a;
- return res;
+ bufferArray res = *this;
+ res += a;
+ return res;
}
bufferArray &bufferArray::
operator +=(const bufferArray &a)
{
- lenAllocd += a.lenAllocd;
- bufferStore *nb = new bufferStore[lenAllocd];
- for (int i = 0; i < len; i++)
- nb[len + i] = buff[i];
- for (int i = 0; i < a.len; i++)
- nb[len + i] = a.buff[i];
- len += a.len;
- delete []buff;
- buff = nb;
- return *this;
+ lenAllocd += a.lenAllocd;
+ bufferStore *nb = new bufferStore[lenAllocd];
+ for (int i = 0; i < len; i++)
+ nb[len + i] = buff[i];
+ for (int i = 0; i < a.len; i++)
+ nb[len + i] = a.buff[i];
+ len += a.len;
+ delete []buff;
+ buff = nb;
+ return *this;
}
bufferArray &bufferArray::
operator +=(const bufferStore &s)
{
- append(s);
- return *this;
+ append(s);
+ return *this;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/bufferarray.h b/lib/bufferarray.h
index 358d428..59554e3 100644
--- a/lib/bufferarray.h
+++ b/lib/bufferarray.h
@@ -1,5 +1,28 @@
-#ifndef _bufferarray_h
-#define _bufferarray_h
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _BUFFERARRAY_H_
+#define _BUFFERARRAY_H_
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -11,138 +34,144 @@ class bufferStore;
*/
class bufferArray {
public:
- /**
- * constructs a new bufferArray.
- * A minimum of @ref ALLOC_MIN
- * elements is allocated.
- */
- bufferArray();
-
- /**
- * Constructs a new bufferArray.
- *
- * @param a The initial contents for this array.
- */
- bufferArray(const bufferArray &a);
-
- /**
- * Destroys the bufferArray.
- */
- ~bufferArray();
-
- /**
- * Copys the bufferArray.
- */
- bufferArray &operator =(const bufferArray &a);
-
- /**
- * Checks if this bufferArray is empty.
- *
- * @return true if the bufferArray is empty.
- */
- bool empty() const;
-
- /**
- * Retrieves the bufferStore at given index.
- *
- * @return The bufferStore at index.
- */
- bufferStore &operator [](const unsigned long index);
-
- /**
- * Appends a bufferStore to a bufferArray.
- *
- * @param s The bufferStore to be appended.
- *
- * @returns A new bufferArray with bufferStore appended to.
- */
- bufferArray operator +(const bufferStore &s);
-
- /**
- * Concatenates two bufferArrays.
- *
- * @param a The bufferArray to be appended.
- *
- * @returns A new bufferArray consisting with a appended.
- */
- bufferArray operator +(const bufferArray &a);
-
- /**
- * Appends a bufferStore to current instance.
- *
- * @param s The bufferStore to append.
- *
- * @returns A reference to the current instance with s appended.
- */
- bufferArray &operator +=(const bufferStore &s);
-
- /**
- * Appends a bufferArray to current instance.
- *
- * @param a The bufferArray to append.
- *
- * @returns A reference to the current instance with a appended.
- */
- bufferArray &operator +=(const bufferArray &a);
-
- /**
- * Removes the first bufferStore.
- *
- * @return The removed bufferStore.
- */
- bufferStore pop(void);
-
- /**
- * Inserts a bufferStore at index 0.
- *
- * @param b The bufferStore to be inserted.
- */
- void push(const bufferStore& b);
-
- /**
- * Appends a bufferStore.
- *
- * @param b The bufferStore to be appended.
- */
- void append(const bufferStore& b);
-
- /**
- * Evaluates the current length.
- *
- * @return The current number of bufferStores
- */
- long length(void);
-
- /**
- * Empties the bufferArray.
- */
- void clear(void);
+ /**
+ * constructs a new bufferArray.
+ * A minimum of @ref ALLOC_MIN
+ * elements is allocated.
+ */
+ bufferArray();
+
+ /**
+ * Constructs a new bufferArray.
+ *
+ * @param a The initial contents for this array.
+ */
+ bufferArray(const bufferArray &a);
+
+ /**
+ * Destroys the bufferArray.
+ */
+ ~bufferArray();
+
+ /**
+ * Copys the bufferArray.
+ */
+ bufferArray &operator =(const bufferArray &a);
+
+ /**
+ * Checks if this bufferArray is empty.
+ *
+ * @return true if the bufferArray is empty.
+ */
+ bool empty() const;
+
+ /**
+ * Retrieves the bufferStore at given index.
+ *
+ * @return The bufferStore at index.
+ */
+ bufferStore &operator [](const unsigned long index);
+
+ /**
+ * Appends a bufferStore to a bufferArray.
+ *
+ * @param s The bufferStore to be appended.
+ *
+ * @returns A new bufferArray with bufferStore appended to.
+ */
+ bufferArray operator +(const bufferStore &s);
+
+ /**
+ * Concatenates two bufferArrays.
+ *
+ * @param a The bufferArray to be appended.
+ *
+ * @returns A new bufferArray consisting with a appended.
+ */
+ bufferArray operator +(const bufferArray &a);
+
+ /**
+ * Appends a bufferStore to current instance.
+ *
+ * @param s The bufferStore to append.
+ *
+ * @returns A reference to the current instance with s appended.
+ */
+ bufferArray &operator +=(const bufferStore &s);
+
+ /**
+ * Appends a bufferArray to current instance.
+ *
+ * @param a The bufferArray to append.
+ *
+ * @returns A reference to the current instance with a appended.
+ */
+ bufferArray &operator +=(const bufferArray &a);
+
+ /**
+ * Removes the first bufferStore.
+ *
+ * @return The removed bufferStore.
+ */
+ bufferStore pop(void);
+
+ /**
+ * Inserts a bufferStore at index 0.
+ *
+ * @param b The bufferStore to be inserted.
+ */
+ void push(const bufferStore& b);
+
+ /**
+ * Appends a bufferStore.
+ *
+ * @param b The bufferStore to be appended.
+ */
+ void append(const bufferStore& b);
+
+ /**
+ * Evaluates the current length.
+ *
+ * @return The current number of bufferStores
+ */
+ long length(void);
+
+ /**
+ * Empties the bufferArray.
+ */
+ void clear(void);
private:
- /**
- * Minimum number of bufferStores to
- * allocate.
- */
- static const long ALLOC_MIN = 5;
-
- /**
- * The current number of bufferStores in
- * this bufferArray.
- */
- long len;
-
- /**
- * The current number of bufferStores
- * allocated.
- */
- long lenAllocd;
-
- /**
- * The content.
- */
- bufferStore* buff;
+ /**
+ * Minimum number of bufferStores to
+ * allocate.
+ */
+ static const long ALLOC_MIN = 5;
+
+ /**
+ * The current number of bufferStores in
+ * this bufferArray.
+ */
+ long len;
+
+ /**
+ * The current number of bufferStores
+ * allocated.
+ */
+ long lenAllocd;
+
+ /**
+ * The content.
+ */
+ bufferStore* buff;
};
inline bool bufferArray::empty() const { return len == 0; }
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/bufferstore.cc b/lib/bufferstore.cc
index 35bea26..8d7ed45 100644
--- a/lib/bufferstore.cc
+++ b/lib/bufferstore.cc
@@ -1,27 +1,30 @@
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
-#include <stream.h>
-// That should be iostream.h, but it won't build on Sun WorkShop C++ 5.0
-#include <iomanip.h>
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 2000, 2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <stream.h>
+// Should be iostream.h, but won't build on Sun WorkShop C++ 5.0
+#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@@ -29,158 +32,164 @@
#include "bufferstore.h"
bufferStore::bufferStore() {
- lenAllocd = 0;
- buff = 0L;
- len = 0;
- start = 0;
+ lenAllocd = 0;
+ buff = 0L;
+ len = 0;
+ start = 0;
}
bufferStore::bufferStore(const bufferStore &a) {
- lenAllocd = (a.getLen() > MIN_LEN) ? a.getLen() : MIN_LEN;
- buff = (unsigned char *)malloc(lenAllocd);
- len = a.getLen();
- memcpy(buff, a.getString(0), len);
- start = 0;
+ lenAllocd = (a.getLen() > MIN_LEN) ? a.getLen() : MIN_LEN;
+ buff = (unsigned char *)malloc(lenAllocd);
+ len = a.getLen();
+ memcpy(buff, a.getString(0), len);
+ start = 0;
}
bufferStore::bufferStore(const unsigned char *_buff, long _len) {
- lenAllocd = (_len > MIN_LEN) ? _len : MIN_LEN;
- buff = (unsigned char *)malloc(lenAllocd);
- len = _len;
- memcpy(buff, _buff, len);
- start = 0;
+ lenAllocd = (_len > MIN_LEN) ? _len : MIN_LEN;
+ buff = (unsigned char *)malloc(lenAllocd);
+ len = _len;
+ memcpy(buff, _buff, len);
+ start = 0;
}
bufferStore &bufferStore::operator =(const bufferStore &a) {
- checkAllocd(a.getLen());
- len = a.getLen();
- memcpy(buff, a.getString(0), len);
- start = 0;
- return *this;
+ checkAllocd(a.getLen());
+ len = a.getLen();
+ memcpy(buff, a.getString(0), len);
+ start = 0;
+ return *this;
}
void bufferStore::init() {
- start = 0;
- len = 0;
+ start = 0;
+ len = 0;
}
void bufferStore::init(const unsigned char *_buff, long _len) {
- checkAllocd(_len);
- start = 0;
- len = _len;
- memcpy(buff, _buff, len);
+ checkAllocd(_len);
+ start = 0;
+ len = _len;
+ memcpy(buff, _buff, len);
}
bufferStore::~bufferStore() {
- if (buff != 0L)
- free(buff);
+ if (buff != 0L)
+ free(buff);
}
unsigned long bufferStore::getLen() const {
- return (start > len) ? 0 : len - start;
+ return (start > len) ? 0 : len - start;
}
unsigned char bufferStore::getByte(long pos) const {
- return buff[pos+start];
+ return buff[pos+start];
}
u_int16_t bufferStore::getWord(long pos) const {
- return buff[pos+start] + (buff[pos+start+1] << 8);
+ return buff[pos+start] + (buff[pos+start+1] << 8);
}
u_int32_t bufferStore::getDWord(long pos) const {
- return buff[pos+start] +
- (buff[pos+start+1] << 8) +
- (buff[pos+start+2] << 16) +
- (buff[pos+start+3] << 24);
+ return buff[pos+start] +
+ (buff[pos+start+1] << 8) +
+ (buff[pos+start+2] << 16) +
+ (buff[pos+start+3] << 24);
}
const char * bufferStore::getString(long pos) const {
- return (const char *)buff + pos + start;
+ return (const char *)buff + pos + start;
}
ostream &operator<<(ostream &s, const bufferStore &m) {
- // save stream flags
- ostream::fmtflags old = s.flags();
+ // save stream flags
+ ostream::fmtflags old = s.flags();
- for (int i = m.start; i < m.len; i++)
- s << hex << setw(2) << setfill('0') << (int)m.buff[i] << " ";
+ for (int i = m.start; i < m.len; i++)
+ s << hex << setw(2) << setfill('0') << (int)m.buff[i] << " ";
- // restore stream flags
- s.flags(old);
- s << "(";
+ // restore stream flags
+ s.flags(old);
+ s << "(";
- for (int i = m.start; i < m.len; i++) {
- unsigned char c = m.buff[i];
- s << (unsigned char)(isprint(c) ? c : '.');
- }
+ for (int i = m.start; i < m.len; i++) {
+ unsigned char c = m.buff[i];
+ s << (unsigned char)(isprint(c) ? c : '.');
+ }
- return s << ")";
+ return s << ")";
}
void bufferStore::discardFirstBytes(int n) {
- start += n;
- if (start > len) start = len;
+ start += n;
+ if (start > len) start = len;
}
void bufferStore::checkAllocd(long newLen) {
- if (newLen >= lenAllocd) {
- do {
- lenAllocd = (lenAllocd < MIN_LEN) ? MIN_LEN : (lenAllocd * 2);
- } while (newLen >= lenAllocd);
- buff = (unsigned char *)realloc(buff, lenAllocd);
- }
+ if (newLen >= lenAllocd) {
+ do {
+ lenAllocd = (lenAllocd < MIN_LEN) ? MIN_LEN : (lenAllocd * 2);
+ } while (newLen >= lenAllocd);
+ buff = (unsigned char *)realloc(buff, lenAllocd);
+ }
}
void bufferStore::addByte(unsigned char cc) {
- checkAllocd(len + 1);
- buff[len++] = cc;
+ checkAllocd(len + 1);
+ buff[len++] = cc;
}
void bufferStore::addString(const char *s) {
- int l = strlen(s);
- checkAllocd(len + l);
- memcpy(&buff[len], s, l);
- len += l;
+ int l = strlen(s);
+ checkAllocd(len + l);
+ memcpy(&buff[len], s, l);
+ len += l;
}
void bufferStore::addStringT(const char *s) {
- addString(s);
- addByte(0);
+ addString(s);
+ addByte(0);
}
void bufferStore::addBytes(const unsigned char *s, int l) {
- checkAllocd(len + l);
- memcpy(&buff[len], s, l);
- len += l;
+ checkAllocd(len + l);
+ memcpy(&buff[len], s, l);
+ len += l;
}
void bufferStore::addBuff(const bufferStore &s, long maxLen) {
- long l = s.getLen();
- checkAllocd(len + l);
- if ((maxLen >= 0) && (maxLen < l))
- l = maxLen;
- if (l > 0) {
- memcpy(&buff[len], s.getString(0), l);
- len += l;
- }
+ long l = s.getLen();
+ checkAllocd(len + l);
+ if ((maxLen >= 0) && (maxLen < l))
+ l = maxLen;
+ if (l > 0) {
+ memcpy(&buff[len], s.getString(0), l);
+ len += l;
+ }
}
void bufferStore::addWord(int a) {
- checkAllocd(len + 2);
- buff[len++] = a & 0xff;
- buff[len++] = (a>>8) & 0xff;
+ checkAllocd(len + 2);
+ buff[len++] = a & 0xff;
+ buff[len++] = (a>>8) & 0xff;
}
void bufferStore::addDWord(long a) {
- checkAllocd(len + 4);
- buff[len++] = a & 0xff;
- buff[len++] = (a>>8) & 0xff;
- buff[len++] = (a>>16) & 0xff;
- buff[len++] = (a>>24) & 0xff;
+ checkAllocd(len + 4);
+ buff[len++] = a & 0xff;
+ buff[len++] = (a>>8) & 0xff;
+ buff[len++] = (a>>16) & 0xff;
+ buff[len++] = (a>>24) & 0xff;
}
void bufferStore::truncate(long newLen) {
- if (newLen < len)
- len = newLen;
+ if (newLen < len)
+ len = newLen;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/bufferstore.h b/lib/bufferstore.h
index a018e81..3a69159 100644
--- a/lib/bufferstore.h
+++ b/lib/bufferstore.h
@@ -1,5 +1,28 @@
-#ifndef _bufferstore_h
-#define _bufferstore_h
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _BUFFERSTORE_H_
+#define _BUFFERSTORE_H_
#include <sys/types.h>
@@ -13,208 +36,214 @@ class ostream;
*/
class bufferStore {
public:
- /**
- * Constructs a new bufferStore.
- */
- bufferStore();
-
- /**
- * Constructs a new bufferStore and
- * initializes its content.
- *
- * @param buf Pointer to data for initialization.
- * @param len Length of data for initialization.
- */
- bufferStore(const unsigned char *, long);
-
- /**
- * Destroys a bufferStore instance.
- */
- ~bufferStore();
-
- /**
- * Constructs a new bufferStore and
- * initializes its content.
- *
- * @param b A bufferStore, whose content is
- * used for initialization.
- */
- bufferStore(const bufferStore &);
-
- /**
- * Copies a bufferStore.
- */
- bufferStore &operator =(const bufferStore &);
-
- /**
- * Retrieves the length of a bufferStore.
- *
- * @returns The current length of the contents
- * in bytes.
- */
- unsigned long getLen() const;
-
- /**
- * Retrieves the byte at index <em>pos</em>.
- *
- * @param pos The index of the byte to retrieve.
- *
- * @returns The value of the byte at index <em>pos</em>
- */
- unsigned char getByte(long pos = 0) const;
-
- /**
- * Retrieves the word at index <em>pos</em>.
- *
- * @param pos The index of the word to retrieve.
- *
- * @returns The value of the word at index <em>pos</em>
- */
- u_int16_t getWord(long pos = 0) const;
-
- /**
- * Retrieves the dword at index <em>pos</em>.
- *
- * @param pos The index of the dword to retrieve.
- *
- * @returns The value of the dword at index <em>pos</em>
- */
- u_int32_t getDWord(long pos = 0) const;
-
- /**
- * Retrieves the characters at index <em>pos</em>.
- *
- * @param pos The index of the characters to retrieve.
- *
- * @returns A pointer to characters at index <em>pos</em>
- */
- const char * getString(long pos = 0) const;
-
- /**
- * Removes bytes from the start of the buffer.
- *
- * @param len Number of bytes to remove.
- */
- void discardFirstBytes(int len = 0);
-
- /**
- * Prints a dump of the content.
- *
- * Mainly used for debugging purposes.
- *
- * @param s The stream to write to.
- * @param b The bufferStore do be dumped.
- *
- * @returns The stream.
- */
- friend ostream &operator<<(ostream &, const bufferStore &);
-
- /**
- * Tests if the bufferStore is empty.
- *
- * @returns true, if the bufferStore is empty.
- * false, if it contains data.
- */
- bool empty() const;
-
- /**
- * Initializes the bufferStore.
- *
- * All data is removed, the length is
- * reset to 0.
- */
- void init();
-
- /**
- * Initializes the bufferStore with
- * a given data.
- *
- * @param buf Pointer to data to initialize from.
- * @param len Length of data.
- */
- void init(const unsigned char * buf, long len);
-
- /**
- * Appends a byte to the content of this instance.
- *
- * @param c The byte to append.
- */
- void addByte(unsigned char c);
-
- /**
- * Appends a word to the content of this instance.
- *
- * @param w The word to append.
- */
- void addWord(int);
-
- /**
- * Appends a dword to the content of this instance.
- *
- * @param dw The dword to append.
- */
- void addDWord(long dw);
-
- /**
- * Appends a string to the content of this instance.
- *
- * The trailing zero byte is <em>not</em> copied
- * to the content.
- *
- * @param s The string to append.
- */
- void addString(const char *s);
-
- /**
- * Appends a string to the content of this instance.
- *
- * The trailing zero byte <em>is</em> copied
- * to the content.
- *
- * @param s The string to append.
- */
- void addStringT(const char *s);
-
- /**
- * Appends data to the content of this instance.
- *
- * @param buf The data to append.
- * @param len Length of data.
- */
- void addBytes(const unsigned char *buf, int len);
-
- /**
- * Appends data to the content of this instance.
- *
- * @param b The bufferStore whose content to append.
- * @param maxLen Length of content to append. If
- * @p maxLen is less than 0 or greater than
- * the current length of @p b , then the
- * whole content of @p b is appended.
- */
- void addBuff(const bufferStore &b, long maxLen = -1);
+ /**
+ * Constructs a new bufferStore.
+ */
+ bufferStore();
+
+ /**
+ * Constructs a new bufferStore and
+ * initializes its content.
+ *
+ * @param buf Pointer to data for initialization.
+ * @param len Length of data for initialization.
+ */
+ bufferStore(const unsigned char *, long);
+
+ /**
+ * Destroys a bufferStore instance.
+ */
+ ~bufferStore();
+
+ /**
+ * Constructs a new bufferStore and
+ * initializes its content.
+ *
+ * @param b A bufferStore, whose content is
+ * used for initialization.
+ */
+ bufferStore(const bufferStore &);
+
+ /**
+ * Copies a bufferStore.
+ */
+ bufferStore &operator =(const bufferStore &);
+
+ /**
+ * Retrieves the length of a bufferStore.
+ *
+ * @returns The current length of the contents
+ * in bytes.
+ */
+ unsigned long getLen() const;
+
+ /**
+ * Retrieves the byte at index <em>pos</em>.
+ *
+ * @param pos The index of the byte to retrieve.
+ *
+ * @returns The value of the byte at index <em>pos</em>
+ */
+ unsigned char getByte(long pos = 0) const;
+
+ /**
+ * Retrieves the word at index <em>pos</em>.
+ *
+ * @param pos The index of the word to retrieve.
+ *
+ * @returns The value of the word at index <em>pos</em>
+ */
+ u_int16_t getWord(long pos = 0) const;
+
+ /**
+ * Retrieves the dword at index <em>pos</em>.
+ *
+ * @param pos The index of the dword to retrieve.
+ *
+ * @returns The value of the dword at index <em>pos</em>
+ */
+ u_int32_t getDWord(long pos = 0) const;
+
+ /**
+ * Retrieves the characters at index <em>pos</em>.
+ *
+ * @param pos The index of the characters to retrieve.
+ *
+ * @returns A pointer to characters at index <em>pos</em>
+ */
+ const char * getString(long pos = 0) const;
+
+ /**
+ * Removes bytes from the start of the buffer.
+ *
+ * @param len Number of bytes to remove.
+ */
+ void discardFirstBytes(int len = 0);
+
+ /**
+ * Prints a dump of the content.
+ *
+ * Mainly used for debugging purposes.
+ *
+ * @param s The stream to write to.
+ * @param b The bufferStore do be dumped.
+ *
+ * @returns The stream.
+ */
+ friend ostream &operator<<(ostream &, const bufferStore &);
+
+ /**
+ * Tests if the bufferStore is empty.
+ *
+ * @returns true, if the bufferStore is empty.
+ * false, if it contains data.
+ */
+ bool empty() const;
+
+ /**
+ * Initializes the bufferStore.
+ *
+ * All data is removed, the length is
+ * reset to 0.
+ */
+ void init();
+
+ /**
+ * Initializes the bufferStore with
+ * a given data.
+ *
+ * @param buf Pointer to data to initialize from.
+ * @param len Length of data.
+ */
+ void init(const unsigned char * buf, long len);
+
+ /**
+ * Appends a byte to the content of this instance.
+ *
+ * @param c The byte to append.
+ */
+ void addByte(unsigned char c);
+
+ /**
+ * Appends a word to the content of this instance.
+ *
+ * @param w The word to append.
+ */
+ void addWord(int);
+
+ /**
+ * Appends a dword to the content of this instance.
+ *
+ * @param dw The dword to append.
+ */
+ void addDWord(long dw);
+
+ /**
+ * Appends a string to the content of this instance.
+ *
+ * The trailing zero byte is <em>not</em> copied
+ * to the content.
+ *
+ * @param s The string to append.
+ */
+ void addString(const char *s);
+
+ /**
+ * Appends a string to the content of this instance.
+ *
+ * The trailing zero byte <em>is</em> copied
+ * to the content.
+ *
+ * @param s The string to append.
+ */
+ void addStringT(const char *s);
+
+ /**
+ * Appends data to the content of this instance.
+ *
+ * @param buf The data to append.
+ * @param len Length of data.
+ */
+ void addBytes(const unsigned char *buf, int len);
+
+ /**
+ * Appends data to the content of this instance.
+ *
+ * @param b The bufferStore whose content to append.
+ * @param maxLen Length of content to append. If
+ * @p maxLen is less than 0 or greater than
+ * the current length of @p b , then the
+ * whole content of @p b is appended.
+ */
+ void addBuff(const bufferStore &b, long maxLen = -1);
- /**
- * Truncates the buffer.
- * If the buffer is smaller, does nothing.
- *
- * @param newLen The new length of the buffer.
- */
- void truncate(long newLen);
+ /**
+ * Truncates the buffer.
+ * If the buffer is smaller, does nothing.
+ *
+ * @param newLen The new length of the buffer.
+ */
+ void truncate(long newLen);
private:
- void checkAllocd(long newLen);
+ void checkAllocd(long newLen);
- long len;
- long lenAllocd;
- long start;
- unsigned char * buff;
+ long len;
+ long lenAllocd;
+ long start;
+ unsigned char * buff;
- enum c { MIN_LEN = 300 };
+ enum c { MIN_LEN = 300 };
};
inline bool bufferStore::empty() const {
- return (len - start) == 0;
+ return (len - start) == 0;
}
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/iowatch.cc b/lib/iowatch.cc
index e3c86fc..50c03a6 100644
--- a/lib/iowatch.cc
+++ b/lib/iowatch.cc
@@ -1,24 +1,26 @@
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 2000, 2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
@@ -29,46 +31,52 @@
#include "iowatch.h"
IOWatch::IOWatch() {
- num = 0;
- io = new int [FD_SETSIZE];
+ num = 0;
+ io = new int [FD_SETSIZE];
}
IOWatch::~IOWatch() {
- delete [] io;
+ delete [] io;
}
void IOWatch::addIO(const int fd) {
- int pos;
- for (pos = 0; pos < num && fd < io[pos]; pos++);
- if (io[pos] == fd)
- return;
- for (int i = num; i > pos; i--)
- io[i] = io[i-1];
- io[pos] = fd;
- num++;
+ int pos;
+ for (pos = 0; pos < num && fd < io[pos]; pos++);
+ if (io[pos] == fd)
+ return;
+ for (int i = num; i > pos; i--)
+ io[i] = io[i-1];
+ io[pos] = fd;
+ num++;
}
void IOWatch::remIO(const int fd) {
- int pos;
- for (pos = 0; pos < num && fd != io[pos]; pos++);
- if (pos != num) {
- num--;
- for (int i = pos; i <num; i++) io[i] = io[i+1];
- }
+ int pos;
+ for (pos = 0; pos < num && fd != io[pos]; pos++);
+ if (pos != num) {
+ num--;
+ for (int i = pos; i <num; i++) io[i] = io[i+1];
+ }
}
bool IOWatch::watch(const long secs, const long usecs) {
- if (num > 0) {
- fd_set iop;
- FD_ZERO(&iop);
- for (int i = 0; i < num; i++)
- FD_SET(io[i], &iop);
- struct timeval t;
- t.tv_usec = usecs;
- t.tv_sec = secs;
- return (select(io[0]+1, &iop, NULL, NULL, &t) > 0);
- }
- sleep(secs);
- usleep(usecs);
- return false;
+ if (num > 0) {
+ fd_set iop;
+ FD_ZERO(&iop);
+ for (int i = 0; i < num; i++)
+ FD_SET(io[i], &iop);
+ struct timeval t;
+ t.tv_usec = usecs;
+ t.tv_sec = secs;
+ return (select(io[0]+1, &iop, NULL, NULL, &t) > 0);
+ }
+ sleep(secs);
+ usleep(usecs);
+ return false;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/iowatch.h b/lib/iowatch.h
index 12abb1f..0d025f3 100644
--- a/lib/iowatch.h
+++ b/lib/iowatch.h
@@ -1,5 +1,28 @@
-#ifndef _iowatch_h
-#define _iowatch_h
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _IOWATCH_H_
+#define _IOWATCH_H_
/**
* A simple wrapper for select()
@@ -12,46 +35,52 @@
*/
class IOWatch {
public:
- /**
- * Creates a new instance.
- */
- IOWatch();
+ /**
+ * Creates a new instance.
+ */
+ IOWatch();
- /**
- * Destroys an instance.
- */
- ~IOWatch();
+ /**
+ * Destroys an instance.
+ */
+ ~IOWatch();
- /**
- * Adds a file descriptor to
- * the set of descriptors.
- *
- * @param fd The file descriptor to add.
- */
- void addIO(const int fd);
+ /**
+ * Adds a file descriptor to
+ * the set of descriptors.
+ *
+ * @param fd The file descriptor to add.
+ */
+ void addIO(const int fd);
- /**
- * Removes a file descriptor from the
- * set of descriptors.
- *
- * @param fd The file descriptor to remove.
- */
- void remIO(const int fd);
+ /**
+ * Removes a file descriptor from the
+ * set of descriptors.
+ *
+ * @param fd The file descriptor to remove.
+ */
+ void remIO(const int fd);
- /**
- * Performs a select() call.
- *
- * @param secs Number of seconds to wait.
- * @param usecs Number of microseconds to wait.
- *
- * @return true, if any of the descriptors is
- * readable.
- */
- bool watch(const long secs, const long usecs);
+ /**
+ * Performs a select() call.
+ *
+ * @param secs Number of seconds to wait.
+ * @param usecs Number of microseconds to wait.
+ *
+ * @return true, if any of the descriptors is
+ * readable.
+ */
+ bool watch(const long secs, const long usecs);
private:
- int num;
- int *io;
+ int num;
+ int *io;
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/log.cc b/lib/log.cc
index 2f7a795..48b07d8 100644
--- a/lib/log.cc
+++ b/lib/log.cc
@@ -1,23 +1,52 @@
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#include "log.h"
logbuf::logbuf(int _level) {
- ptr = buf;
- len = 0;
- level = _level;
+ ptr = buf;
+ len = 0;
+ level = _level;
}
int logbuf::overflow(int c) {
- if (c == '\n') {
- *ptr++ = '\n';
- *ptr = '\0';
- syslog(level, buf);
- ptr = buf;
- len = 0;
- return 0;
- }
- if ((len + 2) >= sizeof(buf))
- return EOF;
- *ptr++ = c;
- len++;
+ if (c == '\n') {
+ *ptr++ = '\n';
+ *ptr = '\0';
+ syslog(level, buf);
+ ptr = buf;
+ len = 0;
return 0;
+ }
+ if ((len + 2) >= sizeof(buf))
+ return EOF;
+ *ptr++ = c;
+ len++;
+ return 0;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/log.h b/lib/log.h
index 708631f..9067ae1 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -1,8 +1,28 @@
-/* $Id$
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
*/
-
-#ifndef _log_h_
-#define _log_h_
+#ifndef _LOG_H_
+#define _LOG_H_
#include <ostream.h>
#include <syslog.h>
@@ -27,47 +47,53 @@
* </PRE>
*/
class logbuf : public streambuf {
- public:
+public:
- /**
- * Constructs a new instance.
- *
- * @param level The log level for this instance.
- * see syslog(3) for symbolic names to use.
- */
- logbuf(int level);
+ /**
+ * Constructs a new instance.
+ *
+ * @param level The log level for this instance.
+ * see syslog(3) for symbolic names to use.
+ */
+ logbuf(int level);
- /**
- * Called by the associated
- * ostream to write a character.
- * Stores the character in a buffer
- * and calls syslog(level, buffer)
- * whenever a LF is seen.
- */
- int overflow(int c = EOF);
+ /**
+ * Called by the associated
+ * ostream to write a character.
+ * Stores the character in a buffer
+ * and calls syslog(level, buffer)
+ * whenever a LF is seen.
+ */
+ int overflow(int c = EOF);
- private:
+private:
- /**
- * Pointer to next char in buffer.
- */
- char *ptr;
+ /**
+ * Pointer to next char in buffer.
+ */
+ char *ptr;
- /**
- * Current length of buffer.
- */
- unsigned int len;
+ /**
+ * Current length of buffer.
+ */
+ unsigned int len;
- /**
- * The log level to use with syslog.
- */
- int level;
+ /**
+ * The log level to use with syslog.
+ */
+ int level;
- /**
- * The internal buffer for holding
- * messages.
- */
- char buf[1024];
+ /**
+ * The internal buffer for holding
+ * messages.
+ */
+ char buf[1024];
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/plpdirent.cc b/lib/plpdirent.cc
index 9695480..d78260c 100644
--- a/lib/plpdirent.cc
+++ b/lib/plpdirent.cc
@@ -1,87 +1,110 @@
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#include <plpdirent.h>
#include <stream.h>
#include <iomanip>
PlpUID::PlpUID() {
- memset(uid, 0, sizeof(uid));
+ 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;
+ uid[0] = u1; uid[1] = u2; uid[2] = u3;
}
long PlpUID::
operator[](int idx) {
- assert ((idx > -1) && (idx < 3));
- return uid[idx];
+ assert ((idx > -1) && (idx < 3));
+ return uid[idx];
}
PlpDirent::PlpDirent(const PlpDirent &e) {
- size = e.size;
- attr = e.attr;
- time = e.time;
- UID = e.UID;
- name = e.name;
- attrstr = e.attrstr;
+ size = e.size;
+ attr = e.attr;
+ time = e.time;
+ UID = e.UID;
+ name = e.name;
+ attrstr = e.attrstr;
}
long PlpDirent::
getSize() {
- return size;
+ return size;
}
long PlpDirent::
getAttr() {
- return attr;
+ return attr;
}
long PlpDirent::
getUID(int uididx) {
- if ((uididx >= 0) && (uididx < 4))
- return UID[uididx];
- return 0;
+ if ((uididx >= 0) && (uididx < 4))
+ return UID[uididx];
+ return 0;
}
PlpUID &PlpDirent::
getUID() {
- return UID;
+ return UID;
}
const char *PlpDirent::
getName() {
- return name.c_str();
+ return name.c_str();
}
PsiTime PlpDirent::
getPsiTime() {
- return time;
+ return time;
}
void PlpDirent::
setName(const char *str) {
- name = str;
+ name = str;
}
PlpDirent &PlpDirent::
operator=(const PlpDirent &e) {
- size = e.size;
- attr = e.attr;
- time = e.time;
- UID = e.UID;
- name = e.name;
- attrstr = e.attrstr;
- return *this;
+ size = e.size;
+ attr = e.attr;
+ time = e.time;
+ UID = e.UID;
+ name = e.name;
+ attrstr = e.attrstr;
+ return *this;
}
ostream &
operator<<(ostream &o, const PlpDirent &e) {
- ostream::fmtflags old = o.flags();
+ ostream::fmtflags old = o.flags();
- o << e.attrstr << " " << dec << setw(10)
- << setfill(' ') << e.size << " " << e.time
- << " " << e.name;
- o.flags(old);
- return o;
+ o << e.attrstr << " " << dec << setw(10)
+ << setfill(' ') << e.size << " " << e.time
+ << " " << e.name;
+ o.flags(old);
+ return o;
}
PlpDrive::PlpDrive() {
@@ -92,132 +115,138 @@ PlpDrive::PlpDrive(const PlpDrive &other) {
void PlpDrive::
setMediaType(u_int32_t type) {
- mediatype = type;
+ mediatype = type;
}
void PlpDrive::
setDriveAttribute(u_int32_t attr) {
- driveattr = attr;
+ driveattr = attr;
}
void PlpDrive::
setMediaAttribute(u_int32_t attr) {
- mediaattr = attr;
+ mediaattr = attr;
}
void PlpDrive::
setUID(u_int32_t attr) {
- uid = attr;
+ uid = attr;
}
void PlpDrive::
setSize(u_int32_t sizeLo, u_int32_t sizeHi) {
- size = ((unsigned long long)sizeHi << 32) + sizeLo;
+ size = ((unsigned long long)sizeHi << 32) + sizeLo;
}
void PlpDrive::
setSpace(u_int32_t spaceLo, u_int32_t spaceHi) {
- space = ((unsigned long long)spaceHi << 32) + spaceLo;
+ space = ((unsigned long long)spaceHi << 32) + spaceLo;
}
void PlpDrive::
setName(char drive, const char * const volname) {
- drivechar = drive;
- name = "";
- name += volname;
+ drivechar = drive;
+ name = "";
+ name += volname;
}
u_int32_t PlpDrive::
getMediaType() {
- return mediatype;
+ return mediatype;
}
static const char * const media_types[] = {
- "Not present",
- "Unknown",
- "Floppy",
- "Disk",
- "CD-ROM",
- "RAM",
- "Flash Disk",
- "ROM",
- "Remote",
+ N_("Not present"),
+ N_("Unknown"),
+ N_("Floppy"),
+ N_("Disk"),
+ N_("CD-ROM"),
+ N_("RAM"),
+ N_("Flash Disk"),
+ N_("ROM"),
+ N_("Remote"),
};
void PlpDrive::
getMediaType(string &ret) {
- ret = media_types[mediatype];
+ ret = media_types[mediatype];
}
u_int32_t PlpDrive::
getDriveAttribute() {
- return driveattr;
+ return driveattr;
}
static void
appendWithDelim(string &s1, const char * const s2) {
- if (!s1.empty())
- s1 += ',';
- s1 += s2;
+ if (!s1.empty())
+ s1 += ',';
+ s1 += s2;
}
void PlpDrive::
getDriveAttribute(string &ret) {
- ret = "";
- if (driveattr & 1)
- appendWithDelim(ret, "local");
- if (driveattr & 2)
- appendWithDelim(ret, "ROM");
- if (driveattr & 4)
- appendWithDelim(ret, "redirected");
- if (driveattr & 8)
- appendWithDelim(ret, "substituted");
- if (driveattr & 16)
- appendWithDelim(ret, "internal");
- if (driveattr & 32)
- appendWithDelim(ret, "removable");
+ ret = "";
+ if (driveattr & 1)
+ appendWithDelim(ret, _("local"));
+ if (driveattr & 2)
+ appendWithDelim(ret, _("ROM"));
+ if (driveattr & 4)
+ appendWithDelim(ret, _("redirected"));
+ if (driveattr & 8)
+ appendWithDelim(ret, _("substituted"));
+ if (driveattr & 16)
+ appendWithDelim(ret, _("internal"));
+ if (driveattr & 32)
+ appendWithDelim(ret, _("removable"));
}
u_int32_t PlpDrive::
getMediaAttribute() {
- return mediaattr;
+ return mediaattr;
}
void PlpDrive::
getMediaAttribute(string &ret) {
- ret = "";
+ ret = "";
- if (mediaattr & 1)
- appendWithDelim(ret, "variable size");
- if (mediaattr & 2)
- appendWithDelim(ret, "dual density");
- if (mediaattr & 4)
- appendWithDelim(ret, "formattable");
- if (mediaattr & 8)
- appendWithDelim(ret, "write protected");
+ if (mediaattr & 1)
+ appendWithDelim(ret, _("variable size"));
+ if (mediaattr & 2)
+ appendWithDelim(ret, _("dual density"));
+ if (mediaattr & 4)
+ appendWithDelim(ret, _("formattable"));
+ if (mediaattr & 8)
+ appendWithDelim(ret, _("write protected"));
}
u_int32_t PlpDrive::
getUID() {
- return uid;
+ return uid;
}
u_int64_t PlpDrive::
getSize() {
- return size;
+ return size;
}
u_int64_t PlpDrive::
getSpace() {
- return space;
+ return space;
}
string PlpDrive::
getName() {
- return name;
+ return name;
}
char PlpDrive::
getDrivechar() {
- return drivechar;
+ return drivechar;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/plpdirent.h b/lib/plpdirent.h
index c567a9b..3c9fb40 100644
--- a/lib/plpdirent.h
+++ b/lib/plpdirent.h
@@ -1,5 +1,27 @@
-#ifndef _PLP_DIRENT_H_
-#define _PLP_DIRENT_H_
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _PLPDIRENT_H_
+#define _PLPDIRENT_H_
#include <string>
#include "psitime.h"
@@ -16,33 +38,33 @@
*/
class PlpUID
{
- friend inline bool operator<(const PlpUID &u1, const PlpUID &u2);
+ friend inline bool operator<(const PlpUID &u1, const PlpUID &u2);
public:
- /**
- * Default constructor.
- */
- PlpUID();
-
- /**
- * Constructor.
- * Create an instance, presetting all thre uid values.
- */
- PlpUID(const long u1, const long u2, const long u3);
-
- /**
- * Retrieve a UID value.
- *
- * @param idx The index of the desired UID. Range must be (0..2),
- * otherwise an assertion is triggered.
- */
- long operator[](int idx);
+ /**
+ * Default constructor.
+ */
+ PlpUID();
+
+ /**
+ * Constructor.
+ * Create an instance, presetting all thre uid values.
+ */
+ PlpUID(const long u1, const long u2, const long u3);
+
+ /**
+ * Retrieve a UID value.
+ *
+ * @param idx The index of the desired UID. Range must be (0..2),
+ * otherwise an assertion is triggered.
+ */
+ long operator[](int idx);
private:
- long uid[3];
+ long uid[3];
};
inline bool operator<(const PlpUID &u1, const PlpUID &u2) {
- return (memcmp(u1.uid, u2.uid, sizeof(u1.uid)) < 0);
+ return (memcmp(u1.uid, u2.uid, sizeof(u1.uid)) < 0);
}
/**
@@ -54,108 +76,108 @@ inline bool operator<(const PlpUID &u1, const PlpUID &u2) {
* @author Fritz Elfert <felfert@to.com>
*/
class PlpDirent {
- friend class rfsv32;
- friend class rfsv16;
+ friend class rfsv32;
+ friend class rfsv16;
public:
- /**
- * Default constructor
- */
- PlpDirent() : size(0), attr(0), name(""), time(0L), attrstr("") { };
-
- /**
- * A copy constructor.
- * Mainly used by STL container classes.
- *
- * @param d The object to be used as initializer.
- */
- PlpDirent(const PlpDirent &d);
-
- /**
- * Default destructor.
- */
- ~PlpDirent() {};
-
- /**
- * Retrieves the file size of a directory entry.
- *
- * @returns The file size in bytes.
- */
- long getSize();
-
- /**
- * Retrieves the file attributes of a directory entry.
- *
- * @returns The generic attributes ( @ref rfsv:file_attribs ).
- */
- long getAttr();
-
- /**
- * Retrieves the UIDs of a directory entry.
- * This method returns always 0 with a Series3.
- *
- * @param uididx The index of the UID to retrieve (0 .. 2).
- *
- * @returns The selected UID or 0 if the index is out of range.
- */
- 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.
- */
- const char *getName();
-
- /**
- * Retrieve the modification time of a directory entry.
- *
- * @returns A @ref PsiTime object, representing the time.
- */
- PsiTime getPsiTime();
-
- /**
- * Set the file name of a directory entry.
- * This is currently used in plpbackup only for
- * changing the name to the full path. It does NOT
- * change the name of the corresponding file on
- * the Psion.
- *
- * @param str The new name of the file.
- */
- void setName(const char *str);
-
- /**
- * Assignment operator
- * Mainly used by STL container classes.
- *
- * @param e The new value to assign.
- *
- * @returns The modified object.
- */
- PlpDirent &operator=(const PlpDirent &e);
-
- /**
- * Prints the object contents.
- * The output is in human readable similar to the
- * output of a "ls" command.
- */
- friend ostream &operator<<(ostream &o, const PlpDirent &e);
+ /**
+ * Default constructor
+ */
+ PlpDirent() : size(0), attr(0), name(""), time(0L), attrstr("") { };
+
+ /**
+ * A copy constructor.
+ * Mainly used by STL container classes.
+ *
+ * @param d The object to be used as initializer.
+ */
+ PlpDirent(const PlpDirent &d);
+
+ /**
+ * Default destructor.
+ */
+ ~PlpDirent() {};
+
+ /**
+ * Retrieves the file size of a directory entry.
+ *
+ * @returns The file size in bytes.
+ */
+ long getSize();
+
+ /**
+ * Retrieves the file attributes of a directory entry.
+ *
+ * @returns The generic attributes ( @ref rfsv:file_attribs ).
+ */
+ long getAttr();
+
+ /**
+ * Retrieves the UIDs of a directory entry.
+ * This method returns always 0 with a Series3.
+ *
+ * @param uididx The index of the UID to retrieve (0 .. 2).
+ *
+ * @returns The selected UID or 0 if the index is out of range.
+ */
+ 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.
+ */
+ const char *getName();
+
+ /**
+ * Retrieve the modification time of a directory entry.
+ *
+ * @returns A @ref PsiTime object, representing the time.
+ */
+ PsiTime getPsiTime();
+
+ /**
+ * Set the file name of a directory entry.
+ * This is currently used in plpbackup only for
+ * changing the name to the full path. It does NOT
+ * change the name of the corresponding file on
+ * the Psion.
+ *
+ * @param str The new name of the file.
+ */
+ void setName(const char *str);
+
+ /**
+ * Assignment operator
+ * Mainly used by STL container classes.
+ *
+ * @param e The new value to assign.
+ *
+ * @returns The modified object.
+ */
+ PlpDirent &operator=(const PlpDirent &e);
+
+ /**
+ * Prints the object contents.
+ * The output is in human readable similar to the
+ * output of a "ls" command.
+ */
+ friend ostream &operator<<(ostream &o, const PlpDirent &e);
private:
- long size;
- long attr;
- PlpUID UID;
- PsiTime time;
- string attrstr;
- string name;
+ long size;
+ long attr;
+ PlpUID UID;
+ PsiTime time;
+ string attrstr;
+ string name;
};
/**
@@ -167,158 +189,165 @@ private:
* @author Fritz Elfert <felfert@to.com>
*/
class PlpDrive {
- friend rfsv32;
- friend rfsv16;
-
- public:
- /**
- * Default constructor.
- */
- PlpDrive();
-
- /**
- * Copy constructor
- */
- PlpDrive(const PlpDrive &other);
-
- /**
- * Retrieve the media type of the drive.
- *
- * @returns The media type of the probed drive.
- * <pre>
- * Media types are encoded by a number
- * in the range 0 .. 8 with the following
- * meaning:
- *
- * 0 = Not present
- * 1 = Unknown
- * 2 = Floppy
- * 3 = Disk
- * 4 = CD-ROM
- * 5 = RAM
- * 6 = Flash Disk
- * 7 = ROM
- * 8 = Remote
- * </pre>
- */
- u_int32_t getMediaType();
-
- /**
- * Retrieve the media type of the drive.
- * Just like the above function, but returns
- * the media type as human readable string.
- *
- * @param ret The string is returned here.
- */
- void getMediaType(string &ret);
-
- /**
- * Retrieve the attributes of the drive.
- *
- * @returns The attributes of the probed drive.
- * <pre>
- * Drive attributes are encoded by a number
- * in the range 0 .. 63. The bits have the
- * the following meaning:
- *
- * bit 0 = local
- * bit 1 = ROM
- * bit 2 = redirected
- * bit 3 = substituted
- * bit 4 = internal
- * bit 5 = removable
- * </pre>
- */
- u_int32_t getDriveAttribute();
-
- /**
- * Retrieve the attributes of the drive.
- * Just like the above function, but returns
- * the attributes as human readable string.
- *
- * @param ret The string is returned here.
- */
- void getDriveAttribute(string &ret);
-
- /**
- * Retrieve the attributes of the media.
- *
- * @returns The attributes of the probed media.
- * <pre>
- * Media attributes are encoded by a number
- * in the range 0 .. 15. The bits have the
- * following meaning:
- *
- * bit 0 = variable size
- * bit 1 = dual density
- * bit 2 = formattable
- * bit 3 = write protected
- * </pre>
- */
- u_int32_t getMediaAttribute();
-
- /**
- * Retrieve the attributes of the media.
- * Just like the above function, but returns
- * the attributes as human readable string.
- *
- * @param ret The string is returned here.
- */
- void getMediaAttribute(string &ret);
-
- /**
- * Retrieve the UID of the drive.
- * Each drive, except the ROM drive on a Psion has
- * a unique ID which can be retrieved here.
- *
- * @returns The UID of the probed drive.
- */
- u_int32_t getUID();
-
- /**
- * Retrieve the total capacity of the drive.
- *
- * @returns The capacity of the probed drive in bytes.
- */
- u_int64_t getSize();
-
- /**
- * Retrieve the free capacity on the drive.
- *
- * @returns The free space on the probed drive in bytes.
- */
- u_int64_t getSpace();
-
- /**
- * Retrieve the volume name of the drive.
- *
- * returns The volume name of the drive.
- */
- string getName();
-
- /**
- * Retrieve the drive letter of the drive.
- *
- * returns The letter of the probed drive.
- */
- char getDrivechar();
-
- private:
- void setMediaType(u_int32_t type);
- void setDriveAttribute(u_int32_t attr);
- void setMediaAttribute(u_int32_t attr);
- void setUID(u_int32_t uid);
- void setSize(u_int32_t sizeLo, u_int32_t sizeHi);
- void setSpace(u_int32_t spaceLo, u_int32_t spaceHi);
- void setName(char drive, const char * const volname);
-
- u_int32_t mediatype;
- u_int32_t driveattr;
- u_int32_t mediaattr;
- u_int32_t uid;
- u_int64_t size;
- u_int64_t space;
- char drivechar;
- string name;
+ friend rfsv32;
+ friend rfsv16;
+
+public:
+ /**
+ * Default constructor.
+ */
+ PlpDrive();
+
+ /**
+ * Copy constructor
+ */
+ PlpDrive(const PlpDrive &other);
+
+ /**
+ * Retrieve the media type of the drive.
+ *
+ * @returns The media type of the probed drive.
+ * <pre>
+ * Media types are encoded by a number
+ * in the range 0 .. 8 with the following
+ * meaning:
+ *
+ * 0 = Not present
+ * 1 = Unknown
+ * 2 = Floppy
+ * 3 = Disk
+ * 4 = CD-ROM
+ * 5 = RAM
+ * 6 = Flash Disk
+ * 7 = ROM
+ * 8 = Remote
+ * </pre>
+ */
+ u_int32_t getMediaType();
+
+ /**
+ * Retrieve the media type of the drive.
+ * Just like the above function, but returns
+ * the media type as human readable string.
+ *
+ * @param ret The string is returned here.
+ */
+ void getMediaType(string &ret);
+
+ /**
+ * Retrieve the attributes of the drive.
+ *
+ * @returns The attributes of the probed drive.
+ * <pre>
+ * Drive attributes are encoded by a number
+ * in the range 0 .. 63. The bits have the
+ * the following meaning:
+ *
+ * bit 0 = local
+ * bit 1 = ROM
+ * bit 2 = redirected
+ * bit 3 = substituted
+ * bit 4 = internal
+ * bit 5 = removable
+ * </pre>
+ */
+ u_int32_t getDriveAttribute();
+
+ /**
+ * Retrieve the attributes of the drive.
+ * Just like the above function, but returns
+ * the attributes as human readable string.
+ *
+ * @param ret The string is returned here.
+ */
+ void getDriveAttribute(string &ret);
+
+ /**
+ * Retrieve the attributes of the media.
+ *
+ * @returns The attributes of the probed media.
+ * <pre>
+ * Media attributes are encoded by a number
+ * in the range 0 .. 15. The bits have the
+ * following meaning:
+ *
+ * bit 0 = variable size
+ * bit 1 = dual density
+ * bit 2 = formattable
+ * bit 3 = write protected
+ * </pre>
+ */
+ u_int32_t getMediaAttribute();
+
+ /**
+ * Retrieve the attributes of the media.
+ * Just like the above function, but returns
+ * the attributes as human readable string.
+ *
+ * @param ret The string is returned here.
+ */
+ void getMediaAttribute(string &ret);
+
+ /**
+ * Retrieve the UID of the drive.
+ * Each drive, except the ROM drive on a Psion has
+ * a unique ID which can be retrieved here.
+ *
+ * @returns The UID of the probed drive.
+ */
+ u_int32_t getUID();
+
+ /**
+ * Retrieve the total capacity of the drive.
+ *
+ * @returns The capacity of the probed drive in bytes.
+ */
+ u_int64_t getSize();
+
+ /**
+ * Retrieve the free capacity on the drive.
+ *
+ * @returns The free space on the probed drive in bytes.
+ */
+ u_int64_t getSpace();
+
+ /**
+ * Retrieve the volume name of the drive.
+ *
+ * returns The volume name of the drive.
+ */
+ string getName();
+
+ /**
+ * Retrieve the drive letter of the drive.
+ *
+ * returns The letter of the probed drive.
+ */
+ char getDrivechar();
+
+private:
+ void setMediaType(u_int32_t type);
+ void setDriveAttribute(u_int32_t attr);
+ void setMediaAttribute(u_int32_t attr);
+ void setUID(u_int32_t uid);
+ void setSize(u_int32_t sizeLo, u_int32_t sizeHi);
+ void setSpace(u_int32_t spaceLo, u_int32_t spaceHi);
+ void setName(char drive, const char * const volname);
+
+ u_int32_t mediatype;
+ u_int32_t driveattr;
+ u_int32_t mediaattr;
+ u_int32_t uid;
+ u_int64_t size;
+ u_int64_t space;
+ char drivechar;
+ string name;
};
+
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/ppsocket.cc b/lib/ppsocket.cc
index 9b0a33d..49e02be 100644
--- a/lib/ppsocket.cc
+++ b/lib/ppsocket.cc
@@ -1,24 +1,26 @@
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -45,563 +47,569 @@
ppsocket::ppsocket(const ppsocket & another)
{
- m_Socket = another.m_Socket;
- m_HostAddr = another.m_HostAddr;
- m_PeerAddr = another.m_PeerAddr;
- m_Bound = another.m_Bound;
- m_LastError = another.m_LastError;
- myWatch = another.myWatch;
+ m_Socket = another.m_Socket;
+ m_HostAddr = another.m_HostAddr;
+ m_PeerAddr = another.m_PeerAddr;
+ m_Bound = another.m_Bound;
+ m_LastError = another.m_LastError;
+ myWatch = another.myWatch;
}
ppsocket::ppsocket()
{
- m_Socket = INVALID_SOCKET;
+ m_Socket = INVALID_SOCKET;
- memset(&m_HostAddr, 0, sizeof(m_HostAddr));
- memset(&m_PeerAddr, 0, sizeof(m_PeerAddr));
+ memset(&m_HostAddr, 0, sizeof(m_HostAddr));
+ memset(&m_PeerAddr, 0, sizeof(m_PeerAddr));
- ((struct sockaddr_in *) &m_HostAddr)->sin_family = AF_INET;
- ((struct sockaddr_in *) &m_PeerAddr)->sin_family = AF_INET;
+ ((struct sockaddr_in *) &m_HostAddr)->sin_family = AF_INET;
+ ((struct sockaddr_in *) &m_PeerAddr)->sin_family = AF_INET;
- m_Bound = false;
- m_LastError = 0;
- myWatch = 0L;
+ m_Bound = false;
+ m_LastError = 0;
+ myWatch = 0L;
}
ppsocket::~ppsocket()
{
- if (m_Socket != INVALID_SOCKET) {
- if (myWatch)
- myWatch->remIO(m_Socket);
- shutdown(m_Socket, SHUT_RDWR);
- ::close(m_Socket);
- }
+ if (m_Socket != INVALID_SOCKET) {
+ if (myWatch)
+ myWatch->remIO(m_Socket);
+ shutdown(m_Socket, SHUT_RDWR);
+ ::close(m_Socket);
+ }
}
void ppsocket::
setWatch(IOWatch *watch) {
- if (watch)
- myWatch = watch;
+ if (watch)
+ myWatch = watch;
}
bool ppsocket::
reconnect()
{
- if (m_Socket != INVALID_SOCKET) {
- if (myWatch)
- myWatch->remIO(m_Socket);
- shutdown(m_Socket, SHUT_RDWR);
- ::close(m_Socket);
- }
- m_Socket = INVALID_SOCKET;
- if (!createSocket())
- return (false);
- m_LastError = 0;
- m_Bound = false;
- if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) != 0) {
- m_LastError = errno;
- return (false);
- }
- if (::connect(m_Socket, &m_PeerAddr, sizeof(m_PeerAddr)) != 0) {
- m_LastError = errno;
- return (false);
- }
+ if (m_Socket != INVALID_SOCKET) {
if (myWatch)
- myWatch->addIO(m_Socket);
- return (true);
+ myWatch->remIO(m_Socket);
+ shutdown(m_Socket, SHUT_RDWR);
+ ::close(m_Socket);
+ }
+ m_Socket = INVALID_SOCKET;
+ if (!createSocket())
+ return (false);
+ m_LastError = 0;
+ m_Bound = false;
+ if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) != 0) {
+ m_LastError = errno;
+ return (false);
+ }
+ if (::connect(m_Socket, &m_PeerAddr, sizeof(m_PeerAddr)) != 0) {
+ m_LastError = errno;
+ return (false);
+ }
+ if (myWatch)
+ myWatch->addIO(m_Socket);
+ return (true);
}
string ppsocket::
toString()
{
- string ret = "";
- char nbuf[10];
- char *tmp = 0L;
- int port;
-
- tmp = inet_ntoa(((struct sockaddr_in *) &m_HostAddr)->sin_addr);
- ret += tmp ? tmp : "none:none";
- if (tmp) {
- ret += ':';
- sprintf(nbuf, "%d", ntohs(((struct sockaddr_in *) &m_HostAddr)->sin_port));
- ret += nbuf;
- }
- ret += " -> ";
- tmp = inet_ntoa(((struct sockaddr_in *) &m_PeerAddr)->sin_addr);
- ret += tmp ? tmp : "none:none";
- if (tmp) {
- ret += ':';
- sprintf(nbuf, "%d", ntohs(((struct sockaddr_in *) &m_PeerAddr)->sin_port));
- ret += nbuf;
- }
- return ret;
+ string ret = "";
+ char nbuf[10];
+ char *tmp = 0L;
+ int port;
+
+ tmp = inet_ntoa(((struct sockaddr_in *) &m_HostAddr)->sin_addr);
+ ret += tmp ? tmp : "none:none";
+ if (tmp) {
+ ret += ':';
+ sprintf(nbuf, "%d", ntohs(((struct sockaddr_in *) &m_HostAddr)->sin_port));
+ ret += nbuf;
+ }
+ ret += " -> ";
+ tmp = inet_ntoa(((struct sockaddr_in *) &m_PeerAddr)->sin_addr);
+ ret += tmp ? tmp : "none:none";
+ if (tmp) {
+ ret += ':';
+ sprintf(nbuf, "%d", ntohs(((struct sockaddr_in *) &m_PeerAddr)->sin_port));
+ ret += nbuf;
+ }
+ return ret;
}
bool ppsocket::
connect(const char * const Peer, int PeerPort, const char * const Host, int HostPort)
{
- //****************************************************
- //* If we aren't already bound set the host and bind *
- //****************************************************
-
- if (!bindSocket(Host, HostPort)) {
- if (m_LastError != 0) {
- return (false);
- }
- }
- //****************
- //* Set the peer *
- //****************
- if (!setPeer(Peer, PeerPort)) {
- return (false);
- }
- //***********
- //* Connect *
- //***********
- if (::connect(m_Socket, &m_PeerAddr, sizeof(m_PeerAddr)) != 0) {
- m_LastError = errno;
- return (false);
+ //****************************************************
+ //* If we aren't already bound set the host and bind *
+ //****************************************************
+
+ if (!bindSocket(Host, HostPort)) {
+ if (m_LastError != 0) {
+ return (false);
}
- if (myWatch)
- myWatch->addIO(m_Socket);
- return (true);
+ }
+ //****************
+ //* Set the peer *
+ //****************
+ if (!setPeer(Peer, PeerPort)) {
+ return (false);
+ }
+ //***********
+ //* Connect *
+ //***********
+ if (::connect(m_Socket, &m_PeerAddr, sizeof(m_PeerAddr)) != 0) {
+ m_LastError = errno;
+ return (false);
+ }
+ if (myWatch)
+ myWatch->addIO(m_Socket);
+ return (true);
}
bool ppsocket::
listen(const char * const Host, int Port)
{
- //****************************************************
- //* If we aren't already bound set the host and bind *
- //****************************************************
-
- if (!bindSocket(Host, Port)) {
- if (m_LastError != 0) {
- return (false);
- }
- }
- //**********************
- //* Listen on the port *
- //**********************
+ //****************************************************
+ //* If we aren't already bound set the host and bind *
+ //****************************************************
- if (myWatch)
- myWatch->addIO(m_Socket);
- if (::listen(m_Socket, 5) != 0) {
- m_LastError = errno;
- return (false);
+ if (!bindSocket(Host, Port)) {
+ if (m_LastError != 0) {
+ return (false);
}
- // Our accept member function relies on non-blocking accepts,
- // so set the flag here (rather than every time around the loop)
- fcntl(m_Socket, F_SETFL, O_NONBLOCK);
- return (true);
+ }
+ //**********************
+ //* Listen on the port *
+ //**********************
+
+ if (myWatch)
+ myWatch->addIO(m_Socket);
+ if (::listen(m_Socket, 5) != 0) {
+ m_LastError = errno;
+ return (false);
+ }
+ // Our accept member function relies on non-blocking accepts,
+ // so set the flag here (rather than every time around the loop)
+ fcntl(m_Socket, F_SETFL, O_NONBLOCK);
+ return (true);
}
ppsocket *ppsocket::
accept(string *Peer)
{
#ifdef sun
- int len;
+ int len;
#else
- socklen_t len;
+ socklen_t len;
#endif
- ppsocket *accepted;
- char *peer;
-
- //*****************************************************
- //* Allocate a new object to hold the accepted socket *
- //*****************************************************
- accepted = new ppsocket;
-
- if (!accepted) {
- m_LastError = errno;
- return NULL;
- }
- //***********************
- //* Accept a connection *
- //***********************
-
- len = sizeof(struct sockaddr);
- accepted->m_Socket = ::accept(m_Socket, &accepted->m_PeerAddr, &len);
-
- if (accepted->m_Socket == INVALID_SOCKET) {
- m_LastError = errno;
- delete accepted;
- return NULL;
- }
- //****************************************************
- //* Got a connection so fill in the other attributes *
- //****************************************************
-
- // Make sure the new socket hasn't inherited O_NONBLOCK
- // from the accept socket
- int flags = fcntl(accepted->m_Socket, F_GETFL, 0);
- flags &= ~O_NONBLOCK;
- fcntl(accepted->m_Socket, F_SETFL, flags);
-
- accepted->m_HostAddr = m_HostAddr;
- accepted->m_Bound = true;
-
- //****************************************************
- //* If required get the name of the connected client *
- //****************************************************
- if (Peer) {
- peer = inet_ntoa(((struct sockaddr_in *) &accepted->m_PeerAddr)->sin_addr);
- if (peer)
- *Peer = peer;
- }
- if (accepted && myWatch) {
- accepted->setWatch(myWatch);
- myWatch->addIO(accepted->m_Socket);
- }
- return accepted;
+ ppsocket *accepted;
+ char *peer;
+
+ //*****************************************************
+ //* Allocate a new object to hold the accepted socket *
+ //*****************************************************
+ accepted = new ppsocket;
+
+ if (!accepted) {
+ m_LastError = errno;
+ return NULL;
+ }
+ //***********************
+ //* Accept a connection *
+ //***********************
+
+ len = sizeof(struct sockaddr);
+ accepted->m_Socket = ::accept(m_Socket, &accepted->m_PeerAddr, &len);
+
+ if (accepted->m_Socket == INVALID_SOCKET) {
+ m_LastError = errno;
+ delete accepted;
+ return NULL;
+ }
+ //****************************************************
+ //* Got a connection so fill in the other attributes *
+ //****************************************************
+
+ // Make sure the new socket hasn't inherited O_NONBLOCK
+ // from the accept socket
+ int flags = fcntl(accepted->m_Socket, F_GETFL, 0);
+ flags &= ~O_NONBLOCK;
+ fcntl(accepted->m_Socket, F_SETFL, flags);
+
+ accepted->m_HostAddr = m_HostAddr;
+ accepted->m_Bound = true;
+
+ //****************************************************
+ //* If required get the name of the connected client *
+ //****************************************************
+ if (Peer) {
+ peer = inet_ntoa(((struct sockaddr_in *) &accepted->m_PeerAddr)->sin_addr);
+ if (peer)
+ *Peer = peer;
+ }
+ if (accepted && myWatch) {
+ accepted->setWatch(myWatch);
+ myWatch->addIO(accepted->m_Socket);
+ }
+ return accepted;
}
bool ppsocket::
dataToGet(int sec, int usec) const
{
- fd_set io;
- FD_ZERO(&io);
- FD_SET(m_Socket, &io);
- struct timeval t;
- t.tv_usec = usec;
- t.tv_sec = sec;
- return (select(m_Socket + 1, &io, NULL, NULL, &t) != 0) ? true : false;
+ fd_set io;
+ FD_ZERO(&io);
+ FD_SET(m_Socket, &io);
+ struct timeval t;
+ t.tv_usec = usec;
+ t.tv_sec = sec;
+ return (select(m_Socket + 1, &io, NULL, NULL, &t) != 0) ? true : false;
}
int ppsocket::
getBufferStore(bufferStore & a, bool wait)
{
- /* Returns a 0 for for no message,
- * 1 for message OK, and -1 for socket problem
- */
-
- u_int32_t l;
- long count = 0;
- unsigned char *buff;
- unsigned char *bp;
- if (!wait && !dataToGet(0, 0))
- return 0;
- a.init();
- if (recv(&l, sizeof(l), MSG_NOSIGNAL) != sizeof(l))
- return -1;
- l = ntohl(l);
- bp = buff = new unsigned char[l];
- while (l > 0) {
- int j = recv(bp, l, MSG_NOSIGNAL);
- if (j == SOCKET_ERROR || j == 0) {
- delete[]buff;
- return -1;
- }
- count += j;
- l -= j;
- bp += j;
- };
- a.init(buff, count);
- delete[]buff;
- return (a.getLen() == 0) ? 0 : 1;
+ /* Returns a 0 for for no message,
+ * 1 for message OK, and -1 for socket problem
+ */
+
+ u_int32_t l;
+ long count = 0;
+ unsigned char *buff;
+ unsigned char *bp;
+ if (!wait && !dataToGet(0, 0))
+ return 0;
+ a.init();
+ if (recv(&l, sizeof(l), MSG_NOSIGNAL) != sizeof(l)) {
+// cerr << "gBS: e=" << strerror(errno) << endl;
+ return -1;
+ }
+ l = ntohl(l);
+ bp = buff = new unsigned char[l];
+ while (l > 0) {
+ int j = recv(bp, l, MSG_NOSIGNAL);
+ if (j == SOCKET_ERROR || j == 0) {
+// cerr << "gBS: j=" << j << " e=" << strerror(errno) << endl;
+ delete[]buff;
+ return -1;
+ }
+ count += j;
+ l -= j;
+ bp += j;
+ };
+ a.init(buff, count);
+ delete[]buff;
+ return (a.getLen() == 0) ? 0 : 1;
}
bool ppsocket::
sendBufferStore(const bufferStore & a)
{
- long l = a.getLen();
- u_int32_t hl = htonl(l);
- long sent = 0;
- int retries = 0;
- int i;
-
- bufferStore b;
- b.addDWord(hl);
- b.addBuff(a);
-// i = send((char *)&hl, sizeof(hl), MSG_NOSIGNAL);
-// if (i != sizeof(hl))
-// return false;
- l += 4;
- while (l > 0) {
- i = send((const char *)b.getString(sent), l, MSG_NOSIGNAL);
- if (i == SOCKET_ERROR || i == 0)
- return (false);
- sent += i;
- l -= i;
- if (++retries > 5) {
- m_LastError = 0;
- return (false);
- }
+ long l = a.getLen();
+ u_int32_t hl = htonl(l);
+ long sent = 0;
+ int retries = 0;
+ int i;
+
+ bufferStore b;
+ b.addDWord(hl);
+ b.addBuff(a);
+ l += 4;
+ while (l > 0) {
+ i = send((const char *)b.getString(sent), l, MSG_NOSIGNAL);
+ if (i == SOCKET_ERROR || i == 0)
+ return (false);
+ sent += i;
+ l -= i;
+ if (++retries > 5) {
+ m_LastError = 0;
+ return (false);
}
- return true;
+ }
+ return true;
}
int ppsocket::
recv(void *buf, int len, int flags)
{
- int i = ::recv(m_Socket, buf, len, flags);
+ int i = ::recv(m_Socket, buf, len, flags);
- if (i < 0)
- m_LastError = errno;
+ if (i < 0)
+ m_LastError = errno;
- return (i);
+ return (i);
}
int ppsocket::
send(const void * const buf, int len, int flags)
{
- int i = ::send(m_Socket, buf, len, flags);
+ int i = ::send(m_Socket, buf, len, flags);
- if (i < 0)
- m_LastError = errno;
+ if (i < 0)
+ m_LastError = errno;
- return (i);
+ return (i);
}
bool ppsocket::
closeSocket(void)
{
- if (myWatch)
- myWatch->remIO(m_Socket);
- shutdown(m_Socket, SHUT_RDWR);
- if (::close(m_Socket) != 0) {
- m_LastError = errno;
- return false;
- }
- m_Socket = INVALID_SOCKET;
- return true;
+ if (myWatch)
+ myWatch->remIO(m_Socket);
+ shutdown(m_Socket, SHUT_RDWR);
+ if (::close(m_Socket) != 0) {
+ m_LastError = errno;
+ return false;
+ }
+ m_Socket = INVALID_SOCKET;
+ return true;
}
bool ppsocket::
bindSocket(const char * const Host, int Port)
{
- // If we are already bound return false but with no last error
- if (m_Bound) {
- m_LastError = 0;
- return false;
- }
+ // If we are already bound return false but with no last error
+ if (m_Bound) {
+ m_LastError = 0;
+ return false;
+ }
- // If the socket hasn't been created create it now
+ // If the socket hasn't been created create it now
- if (m_Socket == INVALID_SOCKET) {
- if (!createSocket())
- return false;
- }
+ if (m_Socket == INVALID_SOCKET) {
+ if (!createSocket())
+ return false;
+ }
- // Set SO_REUSEADDR
- int one = 1;
- if (setsockopt(m_Socket, SOL_SOCKET, SO_REUSEADDR,
- (const char *)&one, sizeof(int)) < 0)
- cerr << "Warning: Unable to set SO_REUSEADDR option\n";
+ // Set SO_REUSEADDR
+ int one = 1;
+ if (setsockopt(m_Socket, SOL_SOCKET, SO_REUSEADDR,
+ (const char *)&one, sizeof(int)) < 0)
+ cerr << "Warning: Unable to set SO_REUSEADDR option\n";
- // If a host name was supplied then use it
- if (!setHost(Host, Port))
- return false;
+ // If a host name was supplied then use it
+ if (!setHost(Host, Port))
+ return false;
- // Now bind the socket
- if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) != 0) {
- m_LastError = errno;
- return false;
- }
+ // Now bind the socket
+ if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) != 0) {
+ m_LastError = errno;
+ return false;
+ }
- m_Bound = true;
- return true;
+ m_Bound = true;
+ return true;
}
bool ppsocket::
bindInRange(const char * const Host, int Low, int High, int Retries)
{
- int port;
- int i;
+ int port;
+ int i;
- // If we are already bound return false but with no last error
- if (m_Bound) {
- m_LastError = 0;
- return (false);
- }
+ // If we are already bound return false but with no last error
+ if (m_Bound) {
+ m_LastError = 0;
+ return (false);
+ }
- // If the socket hasn't been created create it now
- if (m_Socket == INVALID_SOCKET) {
- if (!createSocket())
- return false;
+ // If the socket hasn't been created create it now
+ if (m_Socket == INVALID_SOCKET) {
+ if (!createSocket())
+ return false;
+ }
+
+ // If the number of retries is greater than the range then work
+ // through the range sequentially.
+ if (Retries > High - Low) {
+ for (port = Low; port <= High; port++) {
+ if (!setHost(Host, port))
+ return false;
+ if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) == 0)
+ break;
}
-
- // If the number of retries is greater than the range then work
- // through the range sequentially.
- if (Retries > High - Low) {
- for (port = Low; port <= High; port++) {
- if (!setHost(Host, port))
- return false;
- if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) == 0)
- break;
- }
- if (port > High) {
- m_LastError = errno;
- return false;
- }
- } else {
- for (i = 0; i < Retries; i++) {
- port = Low + (rand() % (High - Low));
- if (!setHost(Host, port))
- return false;
- if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) == 0)
- break;
- }
- if (i >= Retries) {
- m_LastError = errno;
- return false;
- }
+ if (port > High) {
+ m_LastError = errno;
+ return false;
}
- m_Bound = true;
- return true;
+ } else {
+ for (i = 0; i < Retries; i++) {
+ port = Low + (rand() % (High - Low));
+ if (!setHost(Host, port))
+ return false;
+ if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) == 0)
+ break;
+ }
+ if (i >= Retries) {
+ m_LastError = errno;
+ return false;
+ }
+ }
+ m_Bound = true;
+ return true;
}
bool ppsocket::
linger(bool LingerOn, int LingerTime)
{
- int i;
- struct linger l;
-
- // If the socket hasn't been created create it now
- if (m_Socket == INVALID_SOCKET) {
- if (!createSocket())
- return false;
- }
+ int i;
+ struct linger l;
- // Set the lingering
- if (LingerOn) {
- l.l_onoff = 1;
- l.l_linger = LingerTime;
- } else {
- l.l_onoff = 0;
- l.l_linger = 0;
- }
- i = setsockopt(m_Socket, SOL_SOCKET, SO_LINGER, (const char *) &l, sizeof(l));
- // Check for errors
- if (i != 0) {
- m_LastError = errno;
- return false;
- }
- return true;
+ // If the socket hasn't been created create it now
+ if (m_Socket == INVALID_SOCKET) {
+ if (!createSocket())
+ return false;
+ }
+
+ // Set the lingering
+ if (LingerOn) {
+ l.l_onoff = 1;
+ l.l_linger = LingerTime;
+ } else {
+ l.l_onoff = 0;
+ l.l_linger = 0;
+ }
+ i = setsockopt(m_Socket, SOL_SOCKET, SO_LINGER, (const char *) &l, sizeof(l));
+ // Check for errors
+ if (i != 0) {
+ m_LastError = errno;
+ return false;
+ }
+ return true;
}
bool ppsocket::
createSocket(void)
{
- // If the socket has already been created just return true
- if (m_Socket != INVALID_SOCKET)
- return true;
+ // If the socket has already been created just return true
+ if (m_Socket != INVALID_SOCKET)
+ return true;
- // Create the socket
- m_Socket = ::socket(PF_INET, SOCK_STREAM, 0);
- if (m_Socket == INVALID_SOCKET) {
- m_LastError = errno;
- return false;
- }
+ // Create the socket
+ m_Socket = ::socket(PF_INET, SOCK_STREAM, 0);
+ if (m_Socket == INVALID_SOCKET) {
+ m_LastError = errno;
+ return false;
+ }
- // By default set no lingering
- linger(false);
+ // By default set no lingering
+ linger(false);
- // Return indicating success
- return true;
+ // Return indicating success
+ return true;
}
bool ppsocket::
setPeer(const char * const Peer, int Port)
{
- struct hostent *he = NULL;
-
- // If a peer name was supplied then use it
- if (Peer) {
- if (!isdigit(Peer[0]))
- // RFC1035 specifies that hostnames must not start
- // with a digit. So we can speed up things here.
- he = gethostbyname(Peer);
- if (!he) {
- struct in_addr ipaddr;
-
- if (!inet_aton(Peer, &ipaddr)) {
- m_LastError = errno;
- return false;
- }
- he = gethostbyaddr((const char *)&ipaddr.s_addr, sizeof(ipaddr.s_addr), PF_INET);
- if (!he) {
- m_LastError = errno;
- return (false);
- }
- }
- memcpy(&((struct sockaddr_in *)&m_PeerAddr)->sin_addr, he->h_addr_list[0],
- sizeof(((struct sockaddr_in *)&m_PeerAddr)->sin_addr));
+ struct hostent *he = NULL;
+
+ // If a peer name was supplied then use it
+ if (Peer) {
+ if (!isdigit(Peer[0]))
+ // RFC1035 specifies that hostnames must not start
+ // with a digit. So we can speed up things here.
+ he = gethostbyname(Peer);
+ if (!he) {
+ struct in_addr ipaddr;
+
+ if (!inet_aton(Peer, &ipaddr)) {
+ m_LastError = errno;
+ return false;
+ }
+ he = gethostbyaddr((const char *)&ipaddr.s_addr, sizeof(ipaddr.s_addr), PF_INET);
+ if (!he) {
+ m_LastError = errno;
+ return (false);
+ }
}
- // If a port name was supplied use it
- if (Port > 0)
- ((struct sockaddr_in *)&m_PeerAddr)->sin_port = htons(Port);
- return true;
+ memcpy(&((struct sockaddr_in *)&m_PeerAddr)->sin_addr, he->h_addr_list[0],
+ sizeof(((struct sockaddr_in *)&m_PeerAddr)->sin_addr));
+ }
+ // If a port name was supplied use it
+ if (Port > 0)
+ ((struct sockaddr_in *)&m_PeerAddr)->sin_port = htons(Port);
+ return true;
}
bool ppsocket::
getPeer(string *Peer, int *Port)
{
- char *peer;
-
- if (Peer) {
- peer = inet_ntoa(((struct sockaddr_in *) &m_PeerAddr)->sin_addr);
- if (!peer) {
- m_LastError = errno;
- return (false);
- }
- *Peer = peer;
+ char *peer;
+
+ if (Peer) {
+ peer = inet_ntoa(((struct sockaddr_in *) &m_PeerAddr)->sin_addr);
+ if (!peer) {
+ m_LastError = errno;
+ return (false);
}
- if (Port)
- *Port = ntohs(((struct sockaddr_in *) &m_PeerAddr)->sin_port);
- return false;
+ *Peer = peer;
+ }
+ if (Port)
+ *Port = ntohs(((struct sockaddr_in *) &m_PeerAddr)->sin_port);
+ return false;
}
bool ppsocket::
setHost(const char * const Host, int Port)
{
- struct hostent *he;
-
- // If a host name was supplied then use it
- if (Host) {
- if (!isdigit(Host[0]))
- // RFC1035 specifies that hostnames must not start
- // with a digit. So we can speed up things here.
- he = gethostbyname(Host);
- he = gethostbyname(Host);
- if (!he) {
- struct in_addr ipaddr;
-
- if (!inet_aton(Host, &ipaddr)) {
- m_LastError = errno;
- return false;
- }
- he = gethostbyaddr((const char *)&ipaddr.s_addr, sizeof(ipaddr.s_addr), PF_INET);
- if (!he) {
- m_LastError = errno;
- return false;
- }
- }
- memcpy(&((struct sockaddr_in *)&m_HostAddr)->sin_addr, he->h_addr_list[0],
- sizeof(((struct sockaddr_in *)&m_HostAddr)->sin_addr));
+ struct hostent *he;
+
+ // If a host name was supplied then use it
+ if (Host) {
+ if (!isdigit(Host[0]))
+ // RFC1035 specifies that hostnames must not start
+ // with a digit. So we can speed up things here.
+ he = gethostbyname(Host);
+ he = gethostbyname(Host);
+ if (!he) {
+ struct in_addr ipaddr;
+
+ if (!inet_aton(Host, &ipaddr)) {
+ m_LastError = errno;
+ return false;
+ }
+ he = gethostbyaddr((const char *)&ipaddr.s_addr, sizeof(ipaddr.s_addr), PF_INET);
+ if (!he) {
+ m_LastError = errno;
+ return false;
+ }
}
-
- // If a port name was supplied use it
- if (Port > 0)
- ((struct sockaddr_in *)&m_HostAddr)->sin_port = htons(Port);
- return true;
+ memcpy(&((struct sockaddr_in *)&m_HostAddr)->sin_addr, he->h_addr_list[0],
+ sizeof(((struct sockaddr_in *)&m_HostAddr)->sin_addr));
+ }
+
+ // If a port name was supplied use it
+ if (Port > 0)
+ ((struct sockaddr_in *)&m_HostAddr)->sin_port = htons(Port);
+ return true;
}
bool ppsocket::
getHost(string *Host, int *Port)
{
- char *host;
-
- if (Host) {
- host = inet_ntoa(((struct sockaddr_in *)&m_HostAddr)->sin_addr);
- if (!host) {
- m_LastError = errno;
- return false;
- }
- *Host = host;
+ char *host;
+
+ if (Host) {
+ host = inet_ntoa(((struct sockaddr_in *)&m_HostAddr)->sin_addr);
+ if (!host) {
+ m_LastError = errno;
+ return false;
}
- if (Port)
- *Port = ntohs(((struct sockaddr_in *)&m_HostAddr)->sin_port);
- return true;
+ *Host = host;
+ }
+ if (Port)
+ *Port = ntohs(((struct sockaddr_in *)&m_HostAddr)->sin_port);
+ return true;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/ppsocket.h b/lib/ppsocket.h
index b8f7ebe..05593d3 100644
--- a/lib/ppsocket.h
+++ b/lib/ppsocket.h
@@ -1,3 +1,26 @@
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifndef _PPSOCKET_H_
#define _PPSOCKET_H_
@@ -17,189 +40,195 @@ class ppsocket
{
public:
- /**
- * Constructs a ppsocket
- */
- ppsocket();
-
- /**
- * Copy constructor
- */
- ppsocket(const ppsocket&);
-
- /**
- * Destructor
- */
- virtual ~ppsocket();
+ /**
+ * Constructs a ppsocket
+ */
+ ppsocket();
+
+ /**
+ * Copy constructor
+ */
+ ppsocket(const ppsocket&);
+
+ /**
+ * Destructor
+ */
+ virtual ~ppsocket();
- /**
- * Connects to a given host.
- *
- * @param Peer The Host to connect to (name or dotquad-string).
- * @param PeerPort The port to connect to.
- * @param Host The local address to bind to.
- * @param HostPort The local port to bind to.
- *
- * @returns true on success, false otherwise.
- */
- virtual bool connect(const char * const Peer, int PeerPort, const char * const Host = NULL, int HostPort = 0);
-
- /**
- * Reopens the connection after closing it.
- *
- * @returns true on success, false otherwise.
- */
- virtual bool reconnect();
-
- /**
- * Retrieve a string representation of the ppsocket.
- *
- * @returns a string in the form "<host>:<hostport> -> <peer>:<peerport>"
- * where elements not known, are replaced by "???" and none-existing
- * elements are represented by the word "none".
- */
- virtual string toString();
-
- /**
- * Starts listening.
- *
- * @param Host The local address to bind to.
- * @param Port The local port to listen on.
- *
- * @returns true on success, false otherwise.
- */
- virtual bool listen(const char * const Host, int Port);
-
- /**
- * Accept a connection.
- *
- * @param Peer If non-Null, the peer's name is returned here.
- *
- * @returns A pointer to a new instance for the accepted connection or NULL
- * if an error happened.
- */
- ppsocket *accept(string *Peer);
-
- /**
- * Check and optionally wait for incoming data.
- *
- * @param sec Timeout in seconds
- * @param usec Timeout in microseconds
- *
- * @returns true if data is available, false otherwise.
- */
- bool dataToGet(int sec, int usec) const;
-
- /**
- * Receive data into a @ref bufferStore .
- *
- * @param a The bufferStore to fill with received data.
- * @param wait If true, wait until something is received, else return
- * if no data is available.
- * @returns 1 if a bufferStore received, 0, if no bufferStore received, -1
- * on error.
- */
- int getBufferStore(bufferStore &a, bool wait = true);
-
- /**
- * Sends data from a @ref bufferStore .
- *
- * @param a The bufferStore to send.
- * @returns true on success, false otherwise.
- */
- bool sendBufferStore(const bufferStore &a);
-
- /**
- * Closes the connection.
- *
- * @returns true on success, false otherwise.
- */
- bool closeSocket(void);
-
- /**
- * Binds to a local address and port.
- *
- * @param Host The local address to bind to.
- * @param Port The local port to listen on.
- *
- * @returns true on success, false otherwise.
- */
- bool bindSocket(const char * const Host, int Port);
-
- /**
- * Tries repeated binds to a local address and port.
- * If @p Retries is <= @p High - @p Low, then
- * the port to bind is randomly chosen in the given range.
- * Otherwise, all ports starting from @p High up to @p Low
- * are tried in sequence.
- *
- * @param Host The local address to bind to.
- * @param Low The lowest local port to listen on.
- * @param High The highest local port to listen on.
- * @param Retries The number of retries until giving up.
- *
- * @returns true on success, false otherwise.
- */
- bool bindInRange(const char * const Host, int Low, int High, int Retries);
-
- /**
- * Sets the linger parameter of the socket.
- *
- * @param LingerOn true, if lingering should be on.
- * @param LingerTime If lingering is on, the linger-time.
- *
- * @returns true on success, false otherwise.
- */
- bool linger(bool LingerOn, int LingerTime = 0);
-
- /**
- * Retrieves peer information.
- *
- * @param Peer The peers name is returned here.
- * @param Port The peers port is returned here.
- *
- * @returns true on success, false otherwise.
- */
- bool getPeer(string *Peer, int *Port);
-
- /**
- * Retrieves local information.
- *
- * @param Host The local name is returned here.
- * @param Port The local port is returned here.
- *
- * @returns true on success, false otherwise.
- */
- bool getHost(string *Host, int *Port);
-
- /**
- * Registers an @ref IOWatch for this socket.
- * This IOWatch gets the socket added/removed
- * automatically.
- *
- * @param watch The IOWatch to register.
- */
- void setWatch(IOWatch *watch);
+ /**
+ * Connects to a given host.
+ *
+ * @param Peer The Host to connect to (name or dotquad-string).
+ * @param PeerPort The port to connect to.
+ * @param Host The local address to bind to.
+ * @param HostPort The local port to bind to.
+ *
+ * @returns true on success, false otherwise.
+ */
+ virtual bool connect(const char * const Peer, int PeerPort, const char * const Host = NULL, int HostPort = 0);
+
+ /**
+ * Reopens the connection after closing it.
+ *
+ * @returns true on success, false otherwise.
+ */
+ virtual bool reconnect();
+
+ /**
+ * Retrieve a string representation of the ppsocket.
+ *
+ * @returns a string in the form "<host>:<hostport> -> <peer>:<peerport>"
+ * where elements not known, are replaced by "???" and none-existing
+ * elements are represented by the word "none".
+ */
+ virtual string toString();
+
+ /**
+ * Starts listening.
+ *
+ * @param Host The local address to bind to.
+ * @param Port The local port to listen on.
+ *
+ * @returns true on success, false otherwise.
+ */
+ virtual bool listen(const char * const Host, int Port);
+
+ /**
+ * Accept a connection.
+ *
+ * @param Peer If non-Null, the peer's name is returned here.
+ *
+ * @returns A pointer to a new instance for the accepted connection or NULL
+ * if an error happened.
+ */
+ ppsocket *accept(string *Peer);
+
+ /**
+ * Check and optionally wait for incoming data.
+ *
+ * @param sec Timeout in seconds
+ * @param usec Timeout in microseconds
+ *
+ * @returns true if data is available, false otherwise.
+ */
+ bool dataToGet(int sec, int usec) const;
+
+ /**
+ * Receive data into a @ref bufferStore .
+ *
+ * @param a The bufferStore to fill with received data.
+ * @param wait If true, wait until something is received, else return
+ * if no data is available.
+ * @returns 1 if a bufferStore received, 0, if no bufferStore received, -1
+ * on error.
+ */
+ int getBufferStore(bufferStore &a, bool wait = true);
+
+ /**
+ * Sends data from a @ref bufferStore .
+ *
+ * @param a The bufferStore to send.
+ * @returns true on success, false otherwise.
+ */
+ bool sendBufferStore(const bufferStore &a);
+
+ /**
+ * Closes the connection.
+ *
+ * @returns true on success, false otherwise.
+ */
+ bool closeSocket(void);
+
+ /**
+ * Binds to a local address and port.
+ *
+ * @param Host The local address to bind to.
+ * @param Port The local port to listen on.
+ *
+ * @returns true on success, false otherwise.
+ */
+ bool bindSocket(const char * const Host, int Port);
+
+ /**
+ * Tries repeated binds to a local address and port.
+ * If @p Retries is <= @p High - @p Low, then
+ * the port to bind is randomly chosen in the given range.
+ * Otherwise, all ports starting from @p High up to @p Low
+ * are tried in sequence.
+ *
+ * @param Host The local address to bind to.
+ * @param Low The lowest local port to listen on.
+ * @param High The highest local port to listen on.
+ * @param Retries The number of retries until giving up.
+ *
+ * @returns true on success, false otherwise.
+ */
+ bool bindInRange(const char * const Host, int Low, int High, int Retries);
+
+ /**
+ * Sets the linger parameter of the socket.
+ *
+ * @param LingerOn true, if lingering should be on.
+ * @param LingerTime If lingering is on, the linger-time.
+ *
+ * @returns true on success, false otherwise.
+ */
+ bool linger(bool LingerOn, int LingerTime = 0);
+
+ /**
+ * Retrieves peer information.
+ *
+ * @param Peer The peers name is returned here.
+ * @param Port The peers port is returned here.
+ *
+ * @returns true on success, false otherwise.
+ */
+ bool getPeer(string *Peer, int *Port);
+
+ /**
+ * Retrieves local information.
+ *
+ * @param Host The local name is returned here.
+ * @param Port The local port is returned here.
+ *
+ * @returns true on success, false otherwise.
+ */
+ bool getHost(string *Host, int *Port);
+
+ /**
+ * Registers an @ref IOWatch for this socket.
+ * This IOWatch gets the socket added/removed
+ * automatically.
+ *
+ * @param watch The IOWatch to register.
+ */
+ void setWatch(IOWatch *watch);
- private:
- /**
- * Creates the socket.
- */
- virtual bool createSocket(void);
-
- int getLastError(void) { return(m_LastError); }
- bool setPeer(const char * const Peer, int Port);
- bool setHost(const char * const Host, int Port);
- int recv(void *buf, int len, int flags);
- int send(const void * const buf, int len, int flags);
+private:
+ /**
+ * Creates the socket.
+ */
+ virtual bool createSocket(void);
+
+ int getLastError(void) { return(m_LastError); }
+ bool setPeer(const char * const Peer, int Port);
+ bool setHost(const char * const Host, int Port);
+ int recv(void *buf, int len, int flags);
+ int send(const void * const buf, int len, int flags);
- struct sockaddr m_HostAddr;
- struct sockaddr m_PeerAddr;
- int m_Socket;
- int m_Port;
- bool m_Bound;
- int m_LastError;
- IOWatch *myWatch;
+ struct sockaddr m_HostAddr;
+ struct sockaddr m_PeerAddr;
+ int m_Socket;
+ int m_Port;
+ bool m_Bound;
+ int m_LastError;
+ IOWatch *myWatch;
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/psitime.cc b/lib/psitime.cc
index d79ca80..f239fe6 100644
--- a/lib/psitime.cc
+++ b/lib/psitime.cc
@@ -1,140 +1,161 @@
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 2000-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#include "psitime.h"
#include <stdlib.h>
PsiTime::PsiTime(void) {
- ptzValid = false;
- tryPsiZone();
- setUnixNow();
+ ptzValid = false;
+ tryPsiZone();
+ setUnixNow();
}
PsiTime::PsiTime(time_t time) {
- ptzValid = false;
- gettimeofday(NULL, &utz);
- setUnixTime(time);
+ ptzValid = false;
+ gettimeofday(NULL, &utz);
+ setUnixTime(time);
}
PsiTime::PsiTime(psi_timeval *_ptv, psi_timezone *_ptz) {
- if (_ptv != 0L)
- ptv = *_ptv;
- if (_ptz != 0L) {
- ptz = *_ptz;
- ptzValid = true;
- } else {
- ptzValid = false;
- tryPsiZone();
- }
- /* get our own timezone */
- gettimeofday(NULL, &utz);
- psi2unix();
+ if (_ptv != 0L)
+ ptv = *_ptv;
+ if (_ptz != 0L) {
+ ptz = *_ptz;
+ ptzValid = true;
+ } else {
+ ptzValid = false;
+ tryPsiZone();
+ }
+ /* get our own timezone */
+ gettimeofday(NULL, &utz);
+ psi2unix();
}
PsiTime::PsiTime(const unsigned long _ptvHi, const unsigned long _ptvLo) {
- ptv.tv_high = _ptvHi;
- ptv.tv_low = _ptvLo;
- ptzValid = false;
- tryPsiZone();
- /* get our own timezone */
- gettimeofday(NULL, &utz);
- psi2unix();
+ ptv.tv_high = _ptvHi;
+ ptv.tv_low = _ptvLo;
+ ptzValid = false;
+ tryPsiZone();
+ /* get our own timezone */
+ gettimeofday(NULL, &utz);
+ psi2unix();
}
PsiTime::PsiTime(struct timeval *_utv = 0L, struct timezone *_utz = 0L) {
- if (_utv != 0L)
- utv = *_utv;
- if (_utz != 0L)
- utz = *_utz;
- tryPsiZone();
- unix2psi();
+ if (_utv != 0L)
+ utv = *_utv;
+ if (_utz != 0L)
+ utz = *_utz;
+ tryPsiZone();
+ unix2psi();
}
PsiTime::PsiTime(const PsiTime &t) {
- utv = t.utv;
- utz = t.utz;
- ptv = t.ptv;
- ptz = t.ptz;
- ptzValid = t.ptzValid;
- tryPsiZone();
+ utv = t.utv;
+ utz = t.utz;
+ ptv = t.ptv;
+ ptz = t.ptz;
+ ptzValid = t.ptzValid;
+ tryPsiZone();
}
PsiTime::~PsiTime() {
- tryPsiZone();
+ tryPsiZone();
}
void PsiTime::setUnixTime(struct timeval *_utv) {
- if (_utv != 0L)
- utv = *_utv;
- unix2psi();
+ if (_utv != 0L)
+ utv = *_utv;
+ unix2psi();
}
void PsiTime::setUnixTime(time_t time) {
- utv.tv_sec = time;
- utv.tv_usec = 0;
- unix2psi();
+ utv.tv_sec = time;
+ utv.tv_usec = 0;
+ unix2psi();
}
void PsiTime::setUnixNow(void) {
- gettimeofday(&utv, &utz);
- unix2psi();
+ gettimeofday(&utv, &utz);
+ unix2psi();
}
void PsiTime::setPsiTime(psi_timeval *_ptv) {
- if (_ptv != 0L)
- ptv = *_ptv;
- psi2unix();
+ if (_ptv != 0L)
+ ptv = *_ptv;
+ psi2unix();
}
void PsiTime::setPsiTime(const unsigned long _ptvHi, const unsigned long _ptvLo) {
- ptv.tv_high = _ptvHi;
- ptv.tv_low = _ptvLo;
- psi2unix();
+ ptv.tv_high = _ptvHi;
+ ptv.tv_low = _ptvLo;
+ psi2unix();
}
void PsiTime::setPsiZone(psi_timezone *_ptz) {
- if (_ptz != 0L) {
- ptz = *_ptz;
- ptzValid = true;
- }
- psi2unix();
+ if (_ptz != 0L) {
+ ptz = *_ptz;
+ ptzValid = true;
+ }
+ psi2unix();
}
struct timeval &PsiTime::getTimeval(void) {
- return utv;
+ return utv;
}
time_t PsiTime::getTime(void) {
- return utv.tv_sec;
+ return utv.tv_sec;
}
psi_timeval &PsiTime::getPsiTimeval(void) {
- return ptv;
+ return ptv;
}
const unsigned long PsiTime::getPsiTimeLo(void) {
- return ptv.tv_low;
+ return ptv.tv_low;
}
const unsigned long PsiTime::getPsiTimeHi(void) {
- return ptv.tv_high;
+ return ptv.tv_high;
}
PsiTime &PsiTime::operator=(const PsiTime &t) {
- utv = t.utv;
- utz = t.utz;
- ptv = t.ptv;
- ptz = t.ptz;
- ptzValid = t.ptzValid;
- tryPsiZone();
- return *this;
+ utv = t.utv;
+ utz = t.utz;
+ ptv = t.ptv;
+ ptz = t.ptz;
+ ptzValid = t.ptzValid;
+ tryPsiZone();
+ return *this;
}
ostream &operator<<(ostream &s, const PsiTime &t) {
- const char *fmt = "%c";
- char buf[100];
- strftime(buf, sizeof(buf), fmt, localtime(&t.utv.tv_sec));
- s << buf;
- return s;
+ const char *fmt = "%c";
+ char buf[100];
+ strftime(buf, sizeof(buf), fmt, localtime(&t.utv.tv_sec));
+ s << buf;
+ return s;
}
/**
@@ -147,93 +168,99 @@ ostream &operator<<(ostream &s, const PsiTime &t) {
static unsigned long long
evalOffset(psi_timezone ptz, time_t time, bool valid) {
- unsigned long long offset = 0;
-
- if (valid) {
- offset = ptz.utc_offset;
- if (!(ptz.dst_zones & 0x40000000) || (ptz.dst_zones & ptz.home_zone))
- offset += 3600;
+ unsigned long long offset = 0;
+
+ if (valid) {
+ offset = ptz.utc_offset;
+ if (!(ptz.dst_zones & 0x40000000) || (ptz.dst_zones & ptz.home_zone))
+ offset += 3600;
+ } else {
+ /**
+ * Fallback. If no Psion zone given, use
+ * environment variable PSI_TZ
+ */
+ const char *offstr = getenv("PSI_TZ");
+ if (offstr != 0L) {
+ char *err = 0L;
+ offset = strtoul(offstr, &err, 0);
+ if (err != 0L && *err != '\0')
+ offset = 0;
} else {
- /**
- * Fallback. If no Psion zone given, use
- * environment variable PSI_TZ
- */
- const char *offstr = getenv("PSI_TZ");
- if (offstr != 0L) {
- char *err = 0L;
- offset = strtoul(offstr, &err, 0);
- if (err != 0L && *err != '\0')
- offset = 0;
- } else {
- /**
- * Fallback. If PSI_TZ is not set,
- * use the local timezone. This assumes,
- * that both Psion and local machine are
- * configured for the same timezone and
- * daylight saving.
- */
- struct tm *tm = localtime(&time);
- offset = timezone;
- if (tm->tm_isdst)
- offset += 3600;
- }
+ /**
+ * Fallback. If PSI_TZ is not set,
+ * use the local timezone. This assumes,
+ * that both Psion and local machine are
+ * configured for the same timezone and
+ * daylight saving.
+ */
+ struct tm *tm = localtime(&time);
+ offset = timezone;
+ if (tm->tm_isdst)
+ offset += 3600;
}
- offset *= 1000000;
- return offset;
+ }
+ offset *= 1000000;
+ return offset;
}
void PsiTime::psi2unix(void) {
- unsigned long long micro = ptv.tv_high;
- micro = (micro << 32) | ptv.tv_low;
+ unsigned long long micro = ptv.tv_high;
+ micro = (micro << 32) | ptv.tv_low;
- /* Substract Psion's idea of UTC offset */
- micro -= EPOCH_DIFF;
- micro -= evalOffset(ptz, micro / 1000000, ptzValid);
+ /* Substract Psion's idea of UTC offset */
+ micro -= EPOCH_DIFF;
+ micro -= evalOffset(ptz, micro / 1000000, ptzValid);
- utv.tv_sec = micro / 1000000;
- utv.tv_usec = micro % 1000000;
+ utv.tv_sec = micro / 1000000;
+ utv.tv_usec = micro % 1000000;
}
void PsiTime::unix2psi(void) {
- unsigned long long micro = utv.tv_sec * 1000000 + utv.tv_usec;
+ unsigned long long micro = utv.tv_sec * 1000000 + utv.tv_usec;
- /* Add Psion's idea of UTC offset */
- micro += evalOffset(ptz, utv.tv_sec, ptzValid);
- micro += EPOCH_DIFF;
+ /* Add Psion's idea of UTC offset */
+ micro += evalOffset(ptz, utv.tv_sec, ptzValid);
+ micro += EPOCH_DIFF;
- ptv.tv_low = micro & 0x0ffffffff;
- ptv.tv_high = (micro >> 32) & 0x0ffffffff;
+ ptv.tv_low = micro & 0x0ffffffff;
+ ptv.tv_high = (micro >> 32) & 0x0ffffffff;
}
void PsiTime::tryPsiZone() {
- if (ptzValid)
- return;
- if (PsiZone::getInstance().getZone(ptz))
- ptzValid = true;
+ if (ptzValid)
+ return;
+ if (PsiZone::getInstance().getZone(ptz))
+ ptzValid = true;
}
PsiZone *PsiZone::_instance = 0L;
PsiZone &PsiZone::
getInstance() {
- if (_instance == 0L)
- _instance = new PsiZone();
- return *_instance;
+ if (_instance == 0L)
+ _instance = new PsiZone();
+ return *_instance;
}
PsiZone::PsiZone() {
- _ptzValid = false;
+ _ptzValid = false;
}
void PsiZone::
setZone(psi_timezone &ptz) {
- _ptz = ptz;
- _ptzValid = true;
+ _ptz = ptz;
+ _ptzValid = true;
}
bool PsiZone::
getZone(psi_timezone &ptz) {
- if (_ptzValid)
- ptz = _ptz;
- return _ptzValid;
+ if (_ptzValid)
+ ptz = _ptz;
+ return _ptzValid;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/psitime.h b/lib/psitime.h
index 2b26379..a6c4f4f 100644
--- a/lib/psitime.h
+++ b/lib/psitime.h
@@ -1,10 +1,37 @@
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 2000-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifndef _PSITIME_H_
#define _PSITIME_H_
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <sys/time.h>
#include <unistd.h>
#include <ostream.h>
+#include <intl.h>
/**
* Holds a Psion time value.
@@ -13,63 +40,63 @@
* since 01.01.0001 in microseconds.
*/
typedef struct psi_timeval_t {
- /**
- * Prints a psi_timeval in human readable format.
- */
- friend ostream &operator<<(ostream &o, const psi_timeval_t &ptv) {
- ostream::fmtflags old = o.flags();
- unsigned long long micro = ptv.tv_high;
- micro = (micro << 32) | ptv.tv_low;
- micro /= 1000000;
- int s = micro % 60;
- micro /= 60;
- int m = micro % 60;
- micro /= 60;
- int h = micro % 24;
- micro /= 24;
- int d = micro % 365;
- micro /= 365;
- int y = micro;
- o << dec;
- if (y > 0)
- o << y << " year" << ((y > 1) ? "s " : " ");
- if (d > 0)
- o << d << " day" << ((d > 1) ? "s " : " ");
- if (h > 0)
- o << h << " hour" << ((h != 1) ? "s " : " ");
- if (m > 0)
- o << m << " minute" << ((m != 1) ? "s " : " ");
- o << s << " second" << ((s != 1) ? "s" : "");
- o.flags(old);
- return o;
- }
- /**
- * The lower 32 bits
- */
- unsigned long tv_low;
- /**
- * The upper 32 bits
- */
- unsigned long tv_high;
+ /**
+ * Prints a psi_timeval in human readable format.
+ */
+ friend ostream &operator<<(ostream &o, const psi_timeval_t &ptv) {
+ ostream::fmtflags old = o.flags();
+ unsigned long long micro = ptv.tv_high;
+ micro = (micro << 32) | ptv.tv_low;
+ micro /= 1000000;
+ int s = micro % 60;
+ micro /= 60;
+ int m = micro % 60;
+ micro /= 60;
+ int h = micro % 24;
+ micro /= 24;
+ int d = micro % 365;
+ micro /= 365;
+ int y = micro;
+ o << dec;
+ if (y > 0)
+ o << y << ((y > 1) ? _(" years ") : _(" year "));
+ if (d > 0)
+ o << d << ((d > 1) ? _(" days ") : _(" day "));
+ if (h > 0)
+ o << h << ((h != 1) ? _(" hours ") : _(" hour "));
+ if (m > 0)
+ o << m << ((m != 1) ? _(" minutes ") : _(" minute "));
+ o << s << ((s != 1) ? _(" seconds") : _(" second"));
+ o.flags(old);
+ return o;
+ }
+ /**
+ * The lower 32 bits
+ */
+ unsigned long tv_low;
+ /**
+ * The upper 32 bits
+ */
+ unsigned long tv_high;
} psi_timeval;
/**
* holds a Psion time zone description.
*/
typedef struct psi_timezone_t {
- friend ostream &operator<<(ostream &s, const psi_timezone_t &ptz) {
- ostream::fmtflags old = s.flags();
- int h = ptz.utc_offset / 3600;
- int m = ptz.utc_offset % 3600;
- s << "offs: " << dec << h << "h";
- if (m != 0)
- s << ", " << m << "m";
- s.flags(old);
- return s;
- }
- unsigned long utc_offset;
- unsigned long dst_zones;
- unsigned long home_zone;
+ friend ostream &operator<<(ostream &s, const psi_timezone_t &ptz) {
+ ostream::fmtflags old = s.flags();
+ int h = ptz.utc_offset / 3600;
+ int m = ptz.utc_offset % 3600;
+ s << "offs: " << dec << h << "h";
+ if (m != 0)
+ s << ", " << m << "m";
+ s.flags(old);
+ return s;
+ }
+ unsigned long utc_offset;
+ unsigned long dst_zones;
+ unsigned long home_zone;
} psi_timezone;
/**
@@ -98,169 +125,171 @@ typedef struct psi_timezone_t {
*/
class PsiTime {
public:
- /**
- * Contructs a new instance.
- *
- * @param _utv A Unix time value for initialization.
- * @param _utz A Unix timezone for initialization.
- */
- PsiTime(struct timeval *_utv, struct timezone *_utz = 0L);
-
- /**
- * Contructs a new instance.
- *
- * @param time A Unix time value for initialization.
- */
- PsiTime(time_t time);
-
- /**
- * Contructs a new instance.
- *
- * @param _ptv A Psion time value for initialization.
- * @param _ptz A Psion timezone for initialization.
- */
- PsiTime(psi_timeval *_ptv, psi_timezone *_ptz = 0L);
-
- /**
- * Contructs a new instance.
- *
- * @param _ptvHi The high 16 bits of a Psion time value for initialization.
- * @param _ptvLo The low 16 bits of a Psion time value for initialization.
- */
- PsiTime(const unsigned long _ptvHi, const unsigned long _ptvLo);
-
- /**
- * Constructs a new instance, initializing to now.
- */
- PsiTime(void);
-
- /**
- * A copy-constructor
- */
- PsiTime(const PsiTime &t);
-
- /**
- * Destroys the instance.
- */
- ~PsiTime();
-
- /**
- * Modifies the value of this instance.
- *
- * @param _ptv The new Psion time representation.
- */
- void setPsiTime(psi_timeval *_ptv);
-
- /**
- * Modifies the value of this instance.
- *
- * @param _ptvHi The high 32 bits of a Psion time.
- * @param _ptvLo The low 32 bits of a Psion time.
- */
- void setPsiTime(const unsigned long _ptvHi, const unsigned long _ptvLo);
-
- /**
- * Sets the Psion time zone of this instance.
- *
- * @param _ptz The new Psion time zone.
- */
- void setPsiZone(psi_timezone *_ptz);
-
- /**
- * Sets the value of this instance.
- *
- * @param _utv The new Unix time representation.
- */
- void setUnixTime(struct timeval *_utv);
-
- /**
- * Sets the value of this instance.
- *
- * @param _utv The new Unix time representation.
- */
- void setUnixTime(time_t time);
-
- /**
- * Sets the value of this instance to the
- * current time of the Unix machine.
- */
- void setUnixNow(void);
-
- /**
- * Retrieves the instance's current value
- * in Unix time format.
- *
- * @returns The instance's current time as Unix struct timeval.
- */
- struct timeval &getTimeval(void);
-
- /**
- * Retrieves the instance's current value
- * in Unix time format.
- *
- * @returns The instance's current time as Unix time_t.
- */
- time_t getTime(void);
-
- /**
- * Retrieves the instance's current value
- * in Psion time format.
- *
- * @returns The instance's current time a Psion struct psi_timeval_t.
- */
- psi_timeval &getPsiTimeval(void);
-
- /**
- * Retrieves the instance's current value
- * in Psion time format, high 32 bits.
- *
- * @returns The instance's current time as lower 32 bits of a Psion struct psi_timeval_t.
- */
- const unsigned long getPsiTimeLo(void);
-
- /**
- * Retrieves the instance's current value
- * in Psion time format, low 32 bits.
- *
- * @returns The instance's current time as upper 32 bits of a Psion struct psi_timeval_t.
- */
- const unsigned long getPsiTimeHi(void);
-
- /**
- * Prints the instance's value in human readable format.
- * This function uses the current locale setting for
- * formatting the time.
- *
- * @param s The stream to be written.
- * @param t The instance whose value should be displayed.
- *
- * @returns The stream.
- */
- friend ostream &operator<<(ostream &s, const PsiTime &t);
-
- /**
- * Assignment operator
- */
- PsiTime &operator=(const PsiTime &t);
-
- enum zone {
- PSI_TZ_NONE = 0,
- PSI_TZ_EUROPEAN = 1,
- PSI_TZ_NORTHERN = 2,
- PSI_TZ_SOUTHERN = 4,
- PSI_TZ_HOME = 0x40000000,
- };
+ /**
+ * Contructs a new instance.
+ *
+ * @param _utv A Unix time value for initialization.
+ * @param _utz A Unix timezone for initialization.
+ */
+ PsiTime(struct timeval *_utv, struct timezone *_utz = 0L);
+
+ /**
+ * Contructs a new instance.
+ *
+ * @param time A Unix time value for initialization.
+ */
+ PsiTime(time_t time);
+
+ /**
+ * Contructs a new instance.
+ *
+ * @param _ptv A Psion time value for initialization.
+ * @param _ptz A Psion timezone for initialization.
+ */
+ PsiTime(psi_timeval *_ptv, psi_timezone *_ptz = 0L);
+
+ /**
+ * Contructs a new instance.
+ *
+ * @param _ptvHi The high 16 bits of a Psion time value for initialization.
+ * @param _ptvLo The low 16 bits of a Psion time value for initialization.
+ */
+ PsiTime(const unsigned long _ptvHi, const unsigned long _ptvLo);
+
+ /**
+ * Constructs a new instance, initializing to now.
+ */
+ PsiTime(void);
+
+ /**
+ * A copy-constructor
+ */
+ PsiTime(const PsiTime &t);
+
+ /**
+ * Destroys the instance.
+ */
+ ~PsiTime();
+
+ /**
+ * Modifies the value of this instance.
+ *
+ * @param _ptv The new Psion time representation.
+ */
+ void setPsiTime(psi_timeval *_ptv);
+
+ /**
+ * Modifies the value of this instance.
+ *
+ * @param _ptvHi The high 32 bits of a Psion time.
+ * @param _ptvLo The low 32 bits of a Psion time.
+ */
+ void setPsiTime(const unsigned long _ptvHi, const unsigned long _ptvLo);
+
+ /**
+ * Sets the Psion time zone of this instance.
+ *
+ * @param _ptz The new Psion time zone.
+ */
+ void setPsiZone(psi_timezone *_ptz);
+
+ /**
+ * Sets the value of this instance.
+ *
+ * @param _utv The new Unix time representation.
+ */
+ void setUnixTime(struct timeval *_utv);
+
+ /**
+ * Sets the value of this instance.
+ *
+ * @param _utv The new Unix time representation.
+ */
+ void setUnixTime(time_t time);
+
+ /**
+ * Sets the value of this instance to the
+ * current time of the Unix machine.
+ */
+ void setUnixNow(void);
+
+ /**
+ * Retrieves the instance's current value
+ * in Unix time format.
+ *
+ * @returns The instance's current time as Unix struct timeval.
+ */
+ struct timeval &getTimeval(void);
+
+ /**
+ * Retrieves the instance's current value
+ * in Unix time format.
+ *
+ * @returns The instance's current time as Unix time_t.
+ */
+ time_t getTime(void);
+
+ /**
+ * Retrieves the instance's current value
+ * in Psion time format.
+ *
+ * @returns The instance's current time a Psion struct psi_timeval_t.
+ */
+ psi_timeval &getPsiTimeval(void);
+
+ /**
+ * Retrieves the instance's current value
+ * in Psion time format, high 32 bits.
+ *
+ * @returns The instance's current time as lower 32 bits of
+ * a Psion struct psi_timeval_t.
+ */
+ const unsigned long getPsiTimeLo(void);
+
+ /**
+ * Retrieves the instance's current value
+ * in Psion time format, low 32 bits.
+ *
+ * @returns The instance's current time as upper 32 bits of
+ * a Psion struct psi_timeval_t.
+ */
+ const unsigned long getPsiTimeHi(void);
+
+ /**
+ * Prints the instance's value in human readable format.
+ * This function uses the current locale setting for
+ * formatting the time.
+ *
+ * @param s The stream to be written.
+ * @param t The instance whose value should be displayed.
+ *
+ * @returns The stream.
+ */
+ friend ostream &operator<<(ostream &s, const PsiTime &t);
+
+ /**
+ * Assignment operator
+ */
+ PsiTime &operator=(const PsiTime &t);
+
+ enum zone {
+ PSI_TZ_NONE = 0,
+ PSI_TZ_EUROPEAN = 1,
+ PSI_TZ_NORTHERN = 2,
+ PSI_TZ_SOUTHERN = 4,
+ PSI_TZ_HOME = 0x40000000,
+ };
private:
- void psi2unix(void);
- void unix2psi(void);
- void tryPsiZone();
-
- psi_timeval ptv;
- psi_timezone ptz;
- struct timeval utv;
- struct timezone utz;
- bool ptzValid;
+ void psi2unix(void);
+ void unix2psi(void);
+ void tryPsiZone();
+
+ psi_timeval ptv;
+ psi_timezone ptz;
+ struct timeval utv;
+ struct timezone utz;
+ bool ptzValid;
};
/**
@@ -274,39 +303,45 @@ private:
* @author Fritz Elfert <felfert@to.com>
*/
class PsiZone {
- friend class rpcs32;
+ friend class rpcs32;
public:
- /**
- * Retrieve the singleton object.
- * If it does not exist, it is created.
- */
- static PsiZone &getInstance();
-
- /**
- * Retrieve the Psion's time zone.
- *
- * @param ptz The time zone is returned here.
- *
- * @returns false, if the time zone is not
- * known (yet).
- */
- bool getZone(psi_timezone &ptz);
+ /**
+ * Retrieve the singleton object.
+ * If it does not exist, it is created.
+ */
+ static PsiZone &getInstance();
+
+ /**
+ * Retrieve the Psion time zone.
+ *
+ * @param ptz The time zone is returned here.
+ *
+ * @returns false, if the time zone is not
+ * known (yet).
+ */
+ bool getZone(psi_timezone &ptz);
private:
- /**
- * This objects instance (singleton)
- */
- static PsiZone *_instance;
+ /**
+ * This objects instance (singleton)
+ */
+ static PsiZone *_instance;
- /**
- * Private constructor.
- */
- PsiZone();
+ /**
+ * Private constructor.
+ */
+ PsiZone();
- void setZone(psi_timezone &ptz);
+ void setZone(psi_timezone &ptz);
- bool _ptzValid;
- psi_timezone _ptz;
+ bool _ptzValid;
+ psi_timezone _ptz;
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rfsv.cc b/lib/rfsv.cc
index 30fd502..f9f2075 100644
--- a/lib/rfsv.cc
+++ b/lib/rfsv.cc
@@ -1,150 +1,175 @@
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999 Matt J. Gumbley <matt@gumbley.demon.co.uk>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#include "rfsv.h"
#include "ppsocket.h"
#include "bufferstore.h"
#include "Enum.h"
ENUM_DEFINITION(rfsv::errs, rfsv::E_PSI_GEN_NONE) {
- stringRep.add(rfsv::E_PSI_GEN_NONE, "no error");
- stringRep.add(rfsv::E_PSI_GEN_FAIL, "general");
- stringRep.add(rfsv::E_PSI_GEN_ARG, "bad argument");
- stringRep.add(rfsv::E_PSI_GEN_OS, "OS error");
- stringRep.add(rfsv::E_PSI_GEN_NSUP, "not supported");
- stringRep.add(rfsv::E_PSI_GEN_UNDER, "numeric underflow");
- stringRep.add(rfsv::E_PSI_GEN_OVER, "numeric overflow");
- stringRep.add(rfsv::E_PSI_GEN_RANGE, "numeric exception");
- stringRep.add(rfsv::E_PSI_GEN_INUSE, "in use");
- stringRep.add(rfsv::E_PSI_GEN_NOMEMORY, "out of memory");
- stringRep.add(rfsv::E_PSI_GEN_NOSEGMENTS, "out of segments");
- stringRep.add(rfsv::E_PSI_GEN_NOSEM, "out of semaphores");
- stringRep.add(rfsv::E_PSI_GEN_NOPROC, "out of processes");
- stringRep.add(rfsv::E_PSI_GEN_OPEN, "already open");
- stringRep.add(rfsv::E_PSI_GEN_NOTOPEN, "not open");
- stringRep.add(rfsv::E_PSI_GEN_IMAGE, "bad image");
- stringRep.add(rfsv::E_PSI_GEN_RECEIVER, "receiver error");
- stringRep.add(rfsv::E_PSI_GEN_DEVICE, "device error");
- stringRep.add(rfsv::E_PSI_GEN_FSYS, "no filesystem");
- stringRep.add(rfsv::E_PSI_GEN_START, "not ready");
- stringRep.add(rfsv::E_PSI_GEN_NOFONT, "no font");
- stringRep.add(rfsv::E_PSI_GEN_TOOWIDE, "too wide");
- stringRep.add(rfsv::E_PSI_GEN_TOOMANY, "too many");
- stringRep.add(rfsv::E_PSI_FILE_EXIST, "file already exists");
- stringRep.add(rfsv::E_PSI_FILE_NXIST, "no such file");
- stringRep.add(rfsv::E_PSI_FILE_WRITE, "write error");
- stringRep.add(rfsv::E_PSI_FILE_READ, "read error");
- stringRep.add(rfsv::E_PSI_FILE_EOF, "end of file");
- stringRep.add(rfsv::E_PSI_FILE_FULL, "disk/serial read buffer full");
- stringRep.add(rfsv::E_PSI_FILE_NAME, "invalid name");
- stringRep.add(rfsv::E_PSI_FILE_ACCESS, "access denied");
- stringRep.add(rfsv::E_PSI_FILE_LOCKED, "ressource locked");
- stringRep.add(rfsv::E_PSI_FILE_DEVICE, "no such device");
- stringRep.add(rfsv::E_PSI_FILE_DIR, "no such directory");
- stringRep.add(rfsv::E_PSI_FILE_RECORD, "no such record");
- stringRep.add(rfsv::E_PSI_FILE_RDONLY, "file is read-only");
- stringRep.add(rfsv::E_PSI_FILE_INV, "invalid I/O operation");
- stringRep.add(rfsv::E_PSI_FILE_PENDING, "I/O pending (not yet completed)");
- stringRep.add(rfsv::E_PSI_FILE_VOLUME, "invalid volume name");
- stringRep.add(rfsv::E_PSI_FILE_CANCEL, "cancelled");
- stringRep.add(rfsv::E_PSI_FILE_ALLOC, "no memory for control block");
- stringRep.add(rfsv::E_PSI_FILE_DISC, "unit disconnected");
- stringRep.add(rfsv::E_PSI_FILE_CONNECT, "already connected");
- stringRep.add(rfsv::E_PSI_FILE_RETRAN, "retransmission threshold exceeded");
- stringRep.add(rfsv::E_PSI_FILE_LINE, "physical link failure");
- stringRep.add(rfsv::E_PSI_FILE_INACT, "inactivity timer expired");
- stringRep.add(rfsv::E_PSI_FILE_PARITY, "serial parity error");
- stringRep.add(rfsv::E_PSI_FILE_FRAME, "serial framing error");
- stringRep.add(rfsv::E_PSI_FILE_OVERRUN, "serial overrun error");
- stringRep.add(rfsv::E_PSI_MDM_CONFAIL, "modem cannot connect to remote modem");
- stringRep.add(rfsv::E_PSI_MDM_BUSY, "remote modem busy");
- stringRep.add(rfsv::E_PSI_MDM_NOANS, "remote modem did not answer");
- stringRep.add(rfsv::E_PSI_MDM_BLACKLIST, "number blacklisted by the modem");
- stringRep.add(rfsv::E_PSI_FILE_NOTREADY, "drive not ready");
- stringRep.add(rfsv::E_PSI_FILE_UNKNOWN, "unknown media");
- stringRep.add(rfsv::E_PSI_FILE_DIRFULL, "directory full");
- stringRep.add(rfsv::E_PSI_FILE_PROTECT, "write-protected");
- stringRep.add(rfsv::E_PSI_FILE_CORRUPT, "media corrupt");
- stringRep.add(rfsv::E_PSI_FILE_ABORT, "aborted operation");
- stringRep.add(rfsv::E_PSI_FILE_ERASE, "failed to erase flash media");
- stringRep.add(rfsv::E_PSI_FILE_INVALID, "invalid file for DBF system");
- stringRep.add(rfsv::E_PSI_GEN_POWER, "power failure");
- stringRep.add(rfsv::E_PSI_FILE_TOOBIG, "too big");
- stringRep.add(rfsv::E_PSI_GEN_DESCR, "bad descriptor");
- stringRep.add(rfsv::E_PSI_GEN_LIB, "bad entry point");
- stringRep.add(rfsv::E_PSI_FILE_NDISC, "could not diconnect");
- stringRep.add(rfsv::E_PSI_FILE_DRIVER, "bad driver");
- stringRep.add(rfsv::E_PSI_FILE_COMPLETION, "operation not completed");
- stringRep.add(rfsv::E_PSI_GEN_BUSY, "server busy");
- stringRep.add(rfsv::E_PSI_GEN_TERMINATED, "terminated");
- stringRep.add(rfsv::E_PSI_GEN_DIED, "died");
- stringRep.add(rfsv::E_PSI_FILE_HANDLE, "bad handle");
- stringRep.add(rfsv::E_PSI_NOT_SIBO, "invalid operation for RFSV16");
- stringRep.add(rfsv::E_PSI_INTERNAL, "libplp internal error");
+ stringRep.add(rfsv::E_PSI_GEN_NONE, N_("no error"));
+ stringRep.add(rfsv::E_PSI_GEN_FAIL, N_("general"));
+ stringRep.add(rfsv::E_PSI_GEN_ARG, N_("bad argument"));
+ stringRep.add(rfsv::E_PSI_GEN_OS, N_("OS error"));
+ stringRep.add(rfsv::E_PSI_GEN_NSUP, N_("not supported"));
+ stringRep.add(rfsv::E_PSI_GEN_UNDER, N_("numeric underflow"));
+ stringRep.add(rfsv::E_PSI_GEN_OVER, N_("numeric overflow"));
+ stringRep.add(rfsv::E_PSI_GEN_RANGE, N_("numeric exception"));
+ stringRep.add(rfsv::E_PSI_GEN_INUSE, N_("in use"));
+ stringRep.add(rfsv::E_PSI_GEN_NOMEMORY, N_("out of memory"));
+ stringRep.add(rfsv::E_PSI_GEN_NOSEGMENTS, N_("out of segments"));
+ stringRep.add(rfsv::E_PSI_GEN_NOSEM, N_("out of semaphores"));
+ stringRep.add(rfsv::E_PSI_GEN_NOPROC, N_("out of processes"));
+ stringRep.add(rfsv::E_PSI_GEN_OPEN, N_("already open"));
+ stringRep.add(rfsv::E_PSI_GEN_NOTOPEN, N_("not open"));
+ stringRep.add(rfsv::E_PSI_GEN_IMAGE, N_("bad image"));
+ stringRep.add(rfsv::E_PSI_GEN_RECEIVER, N_("receiver error"));
+ stringRep.add(rfsv::E_PSI_GEN_DEVICE, N_("device error"));
+ stringRep.add(rfsv::E_PSI_GEN_FSYS, N_("no filesystem"));
+ stringRep.add(rfsv::E_PSI_GEN_START, N_("not ready"));
+ stringRep.add(rfsv::E_PSI_GEN_NOFONT, N_("no font"));
+ stringRep.add(rfsv::E_PSI_GEN_TOOWIDE, N_("too wide"));
+ stringRep.add(rfsv::E_PSI_GEN_TOOMANY, N_("too many"));
+ stringRep.add(rfsv::E_PSI_FILE_EXIST, N_("file already exists"));
+ stringRep.add(rfsv::E_PSI_FILE_NXIST, N_("no such file"));
+ stringRep.add(rfsv::E_PSI_FILE_WRITE, N_("write error"));
+ stringRep.add(rfsv::E_PSI_FILE_READ, N_("read error"));
+ stringRep.add(rfsv::E_PSI_FILE_EOF, N_("end of file"));
+ stringRep.add(rfsv::E_PSI_FILE_FULL, N_("disk/serial read buffer full"));
+ stringRep.add(rfsv::E_PSI_FILE_NAME, N_("invalid name"));
+ stringRep.add(rfsv::E_PSI_FILE_ACCESS, N_("access denied"));
+ stringRep.add(rfsv::E_PSI_FILE_LOCKED, N_("ressource locked"));
+ stringRep.add(rfsv::E_PSI_FILE_DEVICE, N_("no such device"));
+ stringRep.add(rfsv::E_PSI_FILE_DIR, N_("no such directory"));
+ stringRep.add(rfsv::E_PSI_FILE_RECORD, N_("no such record"));
+ stringRep.add(rfsv::E_PSI_FILE_RDONLY, N_("file is read-only"));
+ stringRep.add(rfsv::E_PSI_FILE_INV, N_("invalid I/O operation"));
+ stringRep.add(rfsv::E_PSI_FILE_PENDING, N_("I/O pending (not yet completed)"));
+ stringRep.add(rfsv::E_PSI_FILE_VOLUME, N_("invalid volume name"));
+ stringRep.add(rfsv::E_PSI_FILE_CANCEL, N_("cancelled"));
+ stringRep.add(rfsv::E_PSI_FILE_ALLOC, N_("no memory for control block"));
+ stringRep.add(rfsv::E_PSI_FILE_DISC, N_("unit disconnected"));
+ stringRep.add(rfsv::E_PSI_FILE_CONNECT, N_("already connected"));
+ stringRep.add(rfsv::E_PSI_FILE_RETRAN, N_("retransmission threshold exceeded"));
+ stringRep.add(rfsv::E_PSI_FILE_LINE, N_("physical link failure"));
+ stringRep.add(rfsv::E_PSI_FILE_INACT, N_("inactivity timer expired"));
+ stringRep.add(rfsv::E_PSI_FILE_PARITY, N_("serial parity error"));
+ stringRep.add(rfsv::E_PSI_FILE_FRAME, N_("serial framing error"));
+ stringRep.add(rfsv::E_PSI_FILE_OVERRUN, N_("serial overrun error"));
+ stringRep.add(rfsv::E_PSI_MDM_CONFAIL, N_("modem cannot connect to remote modem"));
+ stringRep.add(rfsv::E_PSI_MDM_BUSY, N_("remote modem busy"));
+ stringRep.add(rfsv::E_PSI_MDM_NOANS, N_("remote modem did not answer"));
+ stringRep.add(rfsv::E_PSI_MDM_BLACKLIST, N_("number blacklisted by the modem"));
+ stringRep.add(rfsv::E_PSI_FILE_NOTREADY, N_("drive not ready"));
+ stringRep.add(rfsv::E_PSI_FILE_UNKNOWN, N_("unknown media"));
+ stringRep.add(rfsv::E_PSI_FILE_DIRFULL, N_("directory full"));
+ stringRep.add(rfsv::E_PSI_FILE_PROTECT, N_("write-protected"));
+ stringRep.add(rfsv::E_PSI_FILE_CORRUPT, N_("media corrupt"));
+ stringRep.add(rfsv::E_PSI_FILE_ABORT, N_("aborted operation"));
+ stringRep.add(rfsv::E_PSI_FILE_ERASE, N_("failed to erase flash media"));
+ stringRep.add(rfsv::E_PSI_FILE_INVALID, N_("invalid file for DBF system"));
+ stringRep.add(rfsv::E_PSI_GEN_POWER, N_("power failure"));
+ stringRep.add(rfsv::E_PSI_FILE_TOOBIG, N_("too big"));
+ stringRep.add(rfsv::E_PSI_GEN_DESCR, N_("bad descriptor"));
+ stringRep.add(rfsv::E_PSI_GEN_LIB, N_("bad entry point"));
+ stringRep.add(rfsv::E_PSI_FILE_NDISC, N_("could not diconnect"));
+ stringRep.add(rfsv::E_PSI_FILE_DRIVER, N_("bad driver"));
+ stringRep.add(rfsv::E_PSI_FILE_COMPLETION, N_("operation not completed"));
+ stringRep.add(rfsv::E_PSI_GEN_BUSY, N_("server busy"));
+ stringRep.add(rfsv::E_PSI_GEN_TERMINATED, N_("terminated"));
+ stringRep.add(rfsv::E_PSI_GEN_DIED, N_("died"));
+ stringRep.add(rfsv::E_PSI_FILE_HANDLE, N_("bad handle"));
+ stringRep.add(rfsv::E_PSI_NOT_SIBO, N_("invalid operation for RFSV16"));
+ stringRep.add(rfsv::E_PSI_INTERNAL, N_("libplp internal error"));
}
const char *rfsv::getConnectName(void) {
- return "SYS$RFSV";
+ return "SYS$RFSV";
}
rfsv::~rfsv() {
- bufferStore a;
- a.addStringT("Close");
- if (status == E_PSI_GEN_NONE)
- skt->sendBufferStore(a);
- skt->closeSocket();
+ skt->closeSocket();
}
void rfsv::reconnect(void)
{
- skt->closeSocket();
- skt->reconnect();
- serNum = 0;
- reset();
+ //skt->closeSocket();
+ skt->reconnect();
+ serNum = 0;
+ reset();
}
void rfsv::reset(void) {
- bufferStore a;
- status = E_PSI_FILE_DISC;
- a.addStringT(getConnectName());
- if (skt->sendBufferStore(a)) {
- if (skt->getBufferStore(a) == 1) {
- if (!strcmp(a.getString(0), "Ok"))
- status = E_PSI_GEN_NONE;
- }
+ bufferStore a;
+ status = E_PSI_FILE_DISC;
+ a.addStringT(getConnectName());
+ if (skt->sendBufferStore(a)) {
+ if (skt->getBufferStore(a) == 1) {
+ if (!strcmp(a.getString(0), "Ok"))
+ status = E_PSI_GEN_NONE;
}
+ }
}
Enum<rfsv::errs> rfsv::getStatus(void) {
- return status;
+ return status;
}
string rfsv::
convertSlash(const string &name)
{
- string tmp = "";
- for (const char *p = name.c_str(); *p; p++)
- tmp += (*p == '/') ? '\\' : *p;
- return tmp;
+ string tmp = "";
+ for (const char *p = name.c_str(); *p; p++)
+ tmp += (*p == '/') ? '\\' : *p;
+ return tmp;
}
string rfsv::
attr2String(const u_int32_t attr)
{
- 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' : '-');
+ 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
- tmp += ((attr & PSI_A_NORMAL) ? 'n' : '-');
- tmp += ((attr & PSI_A_TEMP) ? 't' : '-');
- tmp += ((attr & PSI_A_COMPRESSED) ? 'c' : '-');
- // SIBO
- 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;
+ // EPOC
+ tmp += ((attr & PSI_A_NORMAL) ? 'n' : '-');
+ tmp += ((attr & PSI_A_TEMP) ? 't' : '-');
+ tmp += ((attr & PSI_A_COMPRESSED) ? 'c' : '-');
+ // SIBO
+ 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;
}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rfsv.h b/lib/rfsv.h
index 9125f01..dbed2c9 100644
--- a/lib/rfsv.h
+++ b/lib/rfsv.h
@@ -1,5 +1,28 @@
-#ifndef _rfsv_h_
-#define _rfsv_h_
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _RFSV_H_
+#define _RFSV_H_
#include <deque>
#include <string>
@@ -30,12 +53,12 @@ class rfsv32;
* @internal
*/
class rfsvDirhandle {
- friend rfsv16;
- friend rfsv32;
+ friend rfsv16;
+ friend rfsv32;
- private:
- u_int32_t h;
- bufferStore b;
+private:
+ u_int32_t h;
+ bufferStore b;
};
/**
@@ -52,534 +75,538 @@ class rfsvDirhandle {
* currently connected.
*/
class rfsv {
- public:
- /**
- * The kown modes for seek.
- */
- enum seek_mode {
- PSI_SEEK_SET = 1,
- PSI_SEEK_CUR = 2,
- PSI_SEEK_END = 3
- };
-
- /**
- * The known modes for file open.
- */
- enum open_flags {
- PSI_O_RDONLY = 0000,
- PSI_O_WRONLY = 0001,
- PSI_O_RDWR = 0002,
- };
-
- /**
- * The known modes for file creation.
- */
- enum open_mode {
- PSI_O_CREAT = 00100,
- PSI_O_EXCL = 00200,
- PSI_O_TRUNC = 01000,
- PSI_O_APPEND = 02000,
- };
-
- /**
- * The known error codes.
- */
- enum errs {
- E_PSI_GEN_NONE = 0,
- E_PSI_GEN_FAIL = -1,
- E_PSI_GEN_ARG = -2,
- E_PSI_GEN_OS = -3,
- E_PSI_GEN_NSUP = -4,
- E_PSI_GEN_UNDER = -5,
- E_PSI_GEN_OVER = -6,
- E_PSI_GEN_RANGE = -7,
- E_PSI_GEN_DIVIDE = -8,
- E_PSI_GEN_INUSE = -9,
- E_PSI_GEN_NOMEMORY = - 10,
- E_PSI_GEN_NOSEGMENTS = -11,
- E_PSI_GEN_NOSEM = -12,
- E_PSI_GEN_NOPROC = -13,
- E_PSI_GEN_OPEN = -14,
- E_PSI_GEN_NOTOPEN = -15,
- E_PSI_GEN_IMAGE = -16,
- E_PSI_GEN_RECEIVER = -17,
- E_PSI_GEN_DEVICE = -18,
- E_PSI_GEN_FSYS = -19,
- E_PSI_GEN_START = -20,
- E_PSI_GEN_NOFONT = -21,
- E_PSI_GEN_TOOWIDE = -22,
- E_PSI_GEN_TOOMANY = -23,
- E_PSI_FILE_EXIST = -32,
- E_PSI_FILE_NXIST = -33,
- E_PSI_FILE_WRITE = -34,
- E_PSI_FILE_READ = -35,
- E_PSI_FILE_EOF = -36,
- E_PSI_FILE_FULL = -37,
- E_PSI_FILE_NAME = -38,
- E_PSI_FILE_ACCESS = -39,
- E_PSI_FILE_LOCKED = -40,
- E_PSI_FILE_DEVICE = -41,
- E_PSI_FILE_DIR = -42,
- E_PSI_FILE_RECORD = -43,
- E_PSI_FILE_RDONLY = -44,
- E_PSI_FILE_INV = -45,
- E_PSI_FILE_PENDING = -46,
- E_PSI_FILE_VOLUME = -47,
- E_PSI_FILE_CANCEL = -48,
- E_PSI_FILE_ALLOC = -49,
- E_PSI_FILE_DISC = -50,
- E_PSI_FILE_CONNECT = -51,
- E_PSI_FILE_RETRAN = -52,
- E_PSI_FILE_LINE = -53,
- E_PSI_FILE_INACT = -54,
- E_PSI_FILE_PARITY = -55,
- E_PSI_FILE_FRAME = -56,
- E_PSI_FILE_OVERRUN = -57,
- E_PSI_MDM_CONFAIL = -58,
- E_PSI_MDM_BUSY = -59,
- E_PSI_MDM_NOANS = -60,
- E_PSI_MDM_BLACKLIST = -61,
- E_PSI_FILE_NOTREADY = -62,
- E_PSI_FILE_UNKNOWN = -63,
- E_PSI_FILE_DIRFULL = -64,
- E_PSI_FILE_PROTECT = -65,
- E_PSI_FILE_CORRUPT = -66,
- E_PSI_FILE_ABORT = -67,
- E_PSI_FILE_ERASE = -68,
- E_PSI_FILE_INVALID = -69,
- E_PSI_GEN_POWER = -100,
- E_PSI_FILE_TOOBIG = -101,
- E_PSI_GEN_DESCR = -102,
- E_PSI_GEN_LIB = -103,
- E_PSI_FILE_NDISC = -104,
- E_PSI_FILE_DRIVER = -105,
- E_PSI_FILE_COMPLETION = -106,
- E_PSI_GEN_BUSY = -107,
- E_PSI_GEN_TERMINATED = -108,
- E_PSI_GEN_DIED = -109,
- E_PSI_FILE_HANDLE = -110,
-
- // Special error code for "Operation not permitted in RFSV16"
- E_PSI_NOT_SIBO = -200,
- // Special error code for "internal library error"
- E_PSI_INTERNAL = -201
- };
-
- /**
- * The known file attributes
- */
- enum file_attribs {
- /** Attributes, valid on both <em>EPOC</em> and <em>SIBO</em>. */
- PSI_A_RDONLY = 0x0001,
- PSI_A_HIDDEN = 0x0002,
- PSI_A_SYSTEM = 0x0004,
- PSI_A_DIR = 0x0008,
- PSI_A_ARCHIVE = 0x0010,
- PSI_A_VOLUME = 0x0020,
-
- /** Attributes, valid on EPOC <em>only</em>. */
- PSI_A_NORMAL = 0x0040,
- PSI_A_TEMP = 0x0080,
- PSI_A_COMPRESSED = 0x0100,
-
- /** Attributes, valid on SIBO <em>only</em>. */
- PSI_A_READ = 0x0200,
- PSI_A_EXEC = 0x0400,
- PSI_A_STREAM = 0x0800,
- PSI_A_TEXT = 0x1000,
- };
-
- virtual ~rfsv();
- void reset();
- void reconnect();
-
- /**
- * Retrieves the current connection status.
- *
- * @returns The status of the connection.
- */
- Enum<errs> getStatus();
-
- /**
- * Opens a file.
- *
- * @param attr The open mode. Use @ref opMode to convert a combination of @ref open_flags
- * and @ref open_mode to the machine-specific representation.
- * @param name The name of the file to open.
- * @param handle The handle for usage with @ref fread ,
- * @ref fwrite , @ref fseek or @ref fclose is returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> fopen(const u_int32_t attr, const char * const name, u_int32_t &handle) = 0;
-
- /**
- * Creates a unique temporary file.
- * The file is opened for reading and writing.
- *
- * @param handle The handle for usage with @ref fread ,
- * @ref fwrite , @ref fseek or @ref fclose is returned here.
- * @param name The name of the temporary file is returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> mktemp(u_int32_t &handle, string &name) = 0;
-
- /**
- * Creates a named file.
- *
- * @param attr The open mode. Use @ref opMode to convert a combination of @ref open_flags
- * and @ref open_mode to the machine-specific representation.
- * @param name The name of the file to create.
- * @param handle The handle for usage with @ref fread ,
- * @ref fwrite , @ref fseek or @ref fclose is returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> fcreatefile(const u_int32_t attr, const char * const name, u_int32_t &handle) = 0;
-
- /**
- * Creates an named file, overwriting an existing file.
- *
- * @param attr The open mode. Use @ref opMode to convert a combination of @ref open_flags
- * and @ref open_mode to the machine-specific representation.
- * @param name The name of the file to create.
- * @param handle The handle for usage with @ref fread ,
- * @ref fwrite , @ref fseek or @ref fclose is returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> freplacefile(const u_int32_t attr, const char * const name, u_int32_t &handle) = 0;
-
- /**
- * Close a file on the Psion whih was previously opened/created by using
- * @ref fopen , @ref fcreatefile , @ref freplacefile or @ref mktemp .
- *
- * @param handle A valid file handle.
- */
- virtual Enum<errs> fclose(const u_int32_t handle) = 0;
-
- /**
- * Reads a directory on the Psion.
- * The returned STL deque of @ref PlpDirent contains all
- * requested directory entries.
- *
- * @param name The name of the directory
- * @param ret An STL deque of @ref PlpDirent entries.
- *
- * @returns A Psion error code (One of enum @ref rfsv::errs ).
- */
- virtual Enum<errs> dir(const char * const name, PlpDir &ret) = 0;
-
- /**
- * Retrieves the modification time of a file on the Psion.
- *
- * @param name Name of the file.
- * @param mtime Modification time is returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> fgetmtime(const char * const name, PsiTime &mtime) = 0;
-
- /**
- * Sets the modification time of a file on the Psion.
- *
- * @param name Name of the file whose modification time should be set.
- * @param mtime The desired modification time.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> fsetmtime(const char * const name, const PsiTime mtime) = 0;
-
- /**
- * Retrieves attributes of a file on the Psion.
- *
- * @param name Name of the file whose attributes ar to be retrieved.
- * @param attr The file's attributes are returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> fgetattr(const char * const name, u_int32_t &attr) = 0;
-
- /**
- * Retrieves attributes, size and modification time of a file on the Psion.
- *
- * @param name The name of the file.
- * @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, PlpDirent &e) =0;
-
- /**
- * @param name
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> fsetattr(const char * const name, const u_int32_t seta, const u_int32_t unseta) = 0;
-
- /**
- * Counts number of entries in a directory.
- *
- * @param name The directory whose entries are to be counted.
- * @param count The number of entries is returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> dircount(const char * const name, u_int32_t &count) = 0;
-
- /**
- * Retrieves available drives on the Psion.
- *
- * @param devbits On return, for every exiting drive, a bit is set in this
- * variable. The lowest bit represents drive A:.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> devlist(u_int32_t &devbits) = 0;
-
- /**
- * Retrieves details about a drive.
- *
- * @param dev An integer, representing the drive to get details from.
- * (0 represents A:, 1 is B: and so on ...)
- * @param drive A @ref PlpDrive object which is filled with the drive's
- * information upon return.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> devinfo(const u_int32_t dev, PlpDrive &drive) = 0;
-
- /**
- * Reads from a file on the Psion.
- *
- * @param handle Handle of the file to read from.
- * @param buffer The area where to store the data read.
- * @param len The number of bytes to read.
- * @param count The number of bytes actually read is returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> fread(const u_int32_t handle, unsigned char * const buffer, const u_int32_t len, u_int32_t &count) = 0;
-
- /**
- * Write to a file on the Psion.
- *
- * @param handle Handle of the file to read from.
- * @param buffer The area to be written.
- * @param len The number of bytes to write.
- * @param count The number of bytes actually written is returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> fwrite(const u_int32_t handle, const unsigned char * const buffer, const u_int32_t len, u_int32_t &count) = 0;
-
- /**
- * Copies a file from the Psion to the local machine.
- *
- * @param from Name of the file on the Psion to be copied.
- * @param to Name of the destination file on the local machine.
- * @param func Pointer to a function which gets called on every read.
- * This function can be used to show some progress etc. May be set
- * to NULL, where no callback is performed.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> copyFromPsion(const char *from, const char *to, void *, cpCallback_t func) = 0;
-
- /**
- * Copies a file from local machine to the Psion.
- *
- * @param from Name of the file on the local machine to be copied.
- * @param to Name of the destination file on the Psion.
- * @param func Pointer to a function which gets called on every read.
- * This function can be used to show some progress etc. May be set
- * to NULL, where no callback is performed.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> copyToPsion(const char * const from, const char * const to, void *, cpCallback_t func) = 0;
-
- /**
- * Copies a file from the Psion to the Psion.
- * On the EPOC variants, this runs much faster than reading
- * data from the Psion and then writing it back to the Psion, since
- * data transfer is handled locally on the Psion.
- *
- * @param from Name of the file to be copied.
- * @param to Name of the destination file.
- * @param func Pointer to a function which gets called on every read.
- * This function can be used to show some progress etc. May be set
- * to NULL, where no callback is performed.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> copyOnPsion(const char * const from, const char * const to, void *, cpCallback_t func) = 0;
-
- /**
- * Resizes an open file on the Psion.
- * If the new size is greater than the file's
- * current size, the contents of the added
- * data is undefined. If The new size is smaller,
- * the file is truncated.
- *
- * @param handle Handle of the file to be resized.
- * @param size New size for that file.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> fsetsize(const u_int32_t handle, const u_int32_t size) = 0;
-
- /**
- * Sets the current file position of a file on the Psion.
- *
- * @param handle The file handle.
- * @param offset Position to be seeked to.
- * @param mode The mode for seeking.
- * @param resultpos The final file position after seeking is returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> fseek(const u_int32_t handle, const int32_t offset, const u_int32_t mode, u_int32_t &resultpos) = 0;
-
- /**
- * Creates a directory on the Psion.
- *
- * @param name Name of the directory to be created.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> mkdir(const char * const name) = 0;
-
- /**
- * Removes a directory on the Psion.
- *
- * @param name Name of the directory to be removed.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> rmdir(const char * const name) = 0;
-
- /**
- * Renames a file on the Psion.
- *
- * @param oldname Name of the file to be renamed.
- * @param newname New Name for that file.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> rename(const char * const oldname, const char * const newname) = 0;
-
- /**
- * Removes a file on the Psion.
- *
- * @param name Name of the file to be removed.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> remove(const char * const name) = 0;
-
- /**
- * Open a directory for reading with readdir.
- *
- * @param attr A combination of PSI_A_.. flags, representing the desired types
- * of entries to be returned when calling @ref readdir .
- * @param name The name of the directory
- * @param handle A handle to be used with @ref readdir and @ref closedir .
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> opendir(const u_int32_t attr, const char * const name, rfsvDirhandle &handle) = 0;
-
- /**
- * Read directory entries.
- * This method reads entries of a directory, previously
- * opened with @ref opendir .
- *
- * @param handle A handle, obtained by calling @ref opendir .
- * @param entry The entry information is returned here.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> readdir(rfsvDirhandle &handle, PlpDirent &entry) = 0;
-
- /**
- * Close a directory, previously opened with @ref opendir.
- *
- * @param handle A handle, obtained by calling @ref opendir .
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> closedir(rfsvDirhandle &handle) = 0;
-
- /**
- * Set the name of a Psion Volume (Drive).
- *
- * @param drive The drive character of the Volume, whose name should be set.
- * @param name The new name for that drive.
- *
- * @returns A Psion error code (One of enum @ref #errs ).
- */
- virtual Enum<errs> setVolumeName(const char drive, const char * const name) = 0;
-
- /**
- * Converts a file attribute @ref rfsv::file_attribs to
- * human readable format, usable for showing them in directory
- * listings. The first 7 characters are common to all
- * machine types:
- * <pre>
- * Char Nr. Value
- * 0 'd' if a directory, '-' otherwise.
- * 1 'r' if file is readable, '-' otherwise.
- * 2 'w' if file is writeable, '-' otherwise.
- * 3 'h' if file is hidden, '-' otherwise.
- * 4 's' if file is a system file, '-' otherwise.
- * 5 'a' if file is modified (archive flag), '-' otherwise.
- * 6 'v' if file is a volume name, '-' otherwise.
- * </pre>
- * The rest (3 characters) are machine specific:
- * <pre>
- * Char Nr. EPOC Value SIBO Value
- * 7 'n' if normal, 'x' if executable, '-' otherwise.
- * 8 't' if temporary, 'b' if a stream, '-' otherwise.
- * 8 'c' if compressed, 't' if a textfile, '-' otherwise.
- * </pre>
- *
- * @param attr the generic file attribute.
- *
- * @returns Pointer to static textual representation of file attributes.
- *
- */
- string attr2String(const u_int32_t attr);
-
- /**
- * Converts an open-mode (A combination of the PSI_O_ constants.)
- * from generic representation to the machine-specific representation.
- *
- * @param mode The generic open mode.
- *
- * @returns The machine specific representation for use with
- * @ref fopen , @ref fcreatefile and @freplacefile.
- */
- virtual u_int32_t opMode(const u_int32_t mode) = 0;
-
- /**
- * Utility method, converts '/' to '\'.
- */
- static string convertSlash(const string &name);
+public:
+ /**
+ * The kown modes for seek.
+ */
+ enum seek_mode {
+ PSI_SEEK_SET = 1,
+ PSI_SEEK_CUR = 2,
+ PSI_SEEK_END = 3
+ };
+
+ /**
+ * The known modes for file open.
+ */
+ enum open_flags {
+ PSI_O_RDONLY = 0000,
+ PSI_O_WRONLY = 0001,
+ PSI_O_RDWR = 0002,
+ };
+
+ /**
+ * The known modes for file creation.
+ */
+ enum open_mode {
+ PSI_O_CREAT = 00100,
+ PSI_O_EXCL = 00200,
+ PSI_O_TRUNC = 01000,
+ PSI_O_APPEND = 02000,
+ };
+
+ /**
+ * The known error codes.
+ */
+ enum errs {
+ E_PSI_GEN_NONE = 0,
+ E_PSI_GEN_FAIL = -1,
+ E_PSI_GEN_ARG = -2,
+ E_PSI_GEN_OS = -3,
+ E_PSI_GEN_NSUP = -4,
+ E_PSI_GEN_UNDER = -5,
+ E_PSI_GEN_OVER = -6,
+ E_PSI_GEN_RANGE = -7,
+ E_PSI_GEN_DIVIDE = -8,
+ E_PSI_GEN_INUSE = -9,
+ E_PSI_GEN_NOMEMORY = - 10,
+ E_PSI_GEN_NOSEGMENTS = -11,
+ E_PSI_GEN_NOSEM = -12,
+ E_PSI_GEN_NOPROC = -13,
+ E_PSI_GEN_OPEN = -14,
+ E_PSI_GEN_NOTOPEN = -15,
+ E_PSI_GEN_IMAGE = -16,
+ E_PSI_GEN_RECEIVER = -17,
+ E_PSI_GEN_DEVICE = -18,
+ E_PSI_GEN_FSYS = -19,
+ E_PSI_GEN_START = -20,
+ E_PSI_GEN_NOFONT = -21,
+ E_PSI_GEN_TOOWIDE = -22,
+ E_PSI_GEN_TOOMANY = -23,
+ E_PSI_FILE_EXIST = -32,
+ E_PSI_FILE_NXIST = -33,
+ E_PSI_FILE_WRITE = -34,
+ E_PSI_FILE_READ = -35,
+ E_PSI_FILE_EOF = -36,
+ E_PSI_FILE_FULL = -37,
+ E_PSI_FILE_NAME = -38,
+ E_PSI_FILE_ACCESS = -39,
+ E_PSI_FILE_LOCKED = -40,
+ E_PSI_FILE_DEVICE = -41,
+ E_PSI_FILE_DIR = -42,
+ E_PSI_FILE_RECORD = -43,
+ E_PSI_FILE_RDONLY = -44,
+ E_PSI_FILE_INV = -45,
+ E_PSI_FILE_PENDING = -46,
+ E_PSI_FILE_VOLUME = -47,
+ E_PSI_FILE_CANCEL = -48,
+ E_PSI_FILE_ALLOC = -49,
+ E_PSI_FILE_DISC = -50,
+ E_PSI_FILE_CONNECT = -51,
+ E_PSI_FILE_RETRAN = -52,
+ E_PSI_FILE_LINE = -53,
+ E_PSI_FILE_INACT = -54,
+ E_PSI_FILE_PARITY = -55,
+ E_PSI_FILE_FRAME = -56,
+ E_PSI_FILE_OVERRUN = -57,
+ E_PSI_MDM_CONFAIL = -58,
+ E_PSI_MDM_BUSY = -59,
+ E_PSI_MDM_NOANS = -60,
+ E_PSI_MDM_BLACKLIST = -61,
+ E_PSI_FILE_NOTREADY = -62,
+ E_PSI_FILE_UNKNOWN = -63,
+ E_PSI_FILE_DIRFULL = -64,
+ E_PSI_FILE_PROTECT = -65,
+ E_PSI_FILE_CORRUPT = -66,
+ E_PSI_FILE_ABORT = -67,
+ E_PSI_FILE_ERASE = -68,
+ E_PSI_FILE_INVALID = -69,
+ E_PSI_GEN_POWER = -100,
+ E_PSI_FILE_TOOBIG = -101,
+ E_PSI_GEN_DESCR = -102,
+ E_PSI_GEN_LIB = -103,
+ E_PSI_FILE_NDISC = -104,
+ E_PSI_FILE_DRIVER = -105,
+ E_PSI_FILE_COMPLETION = -106,
+ E_PSI_GEN_BUSY = -107,
+ E_PSI_GEN_TERMINATED = -108,
+ E_PSI_GEN_DIED = -109,
+ E_PSI_FILE_HANDLE = -110,
+
+ // Special error code for "Operation not permitted in RFSV16"
+ E_PSI_NOT_SIBO = -200,
+ // Special error code for "internal library error"
+ E_PSI_INTERNAL = -201
+ };
+
+ /**
+ * The known file attributes
+ */
+ enum file_attribs {
+ /** Attributes, valid on both <em>EPOC</em> and <em>SIBO</em>. */
+ PSI_A_RDONLY = 0x0001,
+ PSI_A_HIDDEN = 0x0002,
+ PSI_A_SYSTEM = 0x0004,
+ PSI_A_DIR = 0x0008,
+ PSI_A_ARCHIVE = 0x0010,
+ PSI_A_VOLUME = 0x0020,
+
+ /** Attributes, valid on EPOC <em>only</em>. */
+ PSI_A_NORMAL = 0x0040,
+ PSI_A_TEMP = 0x0080,
+ PSI_A_COMPRESSED = 0x0100,
+
+ /** Attributes, valid on SIBO <em>only</em>. */
+ PSI_A_READ = 0x0200,
+ PSI_A_EXEC = 0x0400,
+ PSI_A_STREAM = 0x0800,
+ PSI_A_TEXT = 0x1000,
+ };
+
+ virtual ~rfsv();
+ void reset();
+ void reconnect();
+
+ /**
+ * Retrieves the current connection status.
+ *
+ * @returns The status of the connection.
+ */
+ Enum<errs> getStatus();
+
+ /**
+ * Opens a file.
+ *
+ * @param attr The open mode. Use @ref opMode to convert a combination of @ref open_flags
+ * and @ref open_mode to the machine-specific representation.
+ * @param name The name of the file to open.
+ * @param handle The handle for usage with @ref fread ,
+ * @ref fwrite , @ref fseek or @ref fclose is returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> fopen(const u_int32_t attr, const char * const name, u_int32_t &handle) = 0;
+
+ /**
+ * Creates a unique temporary file.
+ * The file is opened for reading and writing.
+ *
+ * @param handle The handle for usage with @ref fread ,
+ * @ref fwrite , @ref fseek or @ref fclose is returned here.
+ * @param name The name of the temporary file is returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> mktemp(u_int32_t &handle, string &name) = 0;
+
+ /**
+ * Creates a named file.
+ *
+ * @param attr The open mode. Use @ref opMode to convert a combination of @ref open_flags
+ * and @ref open_mode to the machine-specific representation.
+ * @param name The name of the file to create.
+ * @param handle The handle for usage with @ref fread ,
+ * @ref fwrite , @ref fseek or @ref fclose is returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> fcreatefile(const u_int32_t attr, const char * const name, u_int32_t &handle) = 0;
+
+ /**
+ * Creates an named file, overwriting an existing file.
+ *
+ * @param attr The open mode. Use @ref opMode to convert a combination of @ref open_flags
+ * and @ref open_mode to the machine-specific representation.
+ * @param name The name of the file to create.
+ * @param handle The handle for usage with @ref fread ,
+ * @ref fwrite , @ref fseek or @ref fclose is returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> freplacefile(const u_int32_t attr, const char * const name, u_int32_t &handle) = 0;
+
+ /**
+ * Close a file on the Psion whih was previously opened/created by using
+ * @ref fopen , @ref fcreatefile , @ref freplacefile or @ref mktemp .
+ *
+ * @param handle A valid file handle.
+ */
+ virtual Enum<errs> fclose(const u_int32_t handle) = 0;
+
+ /**
+ * Reads a directory on the Psion.
+ * The returned STL deque of @ref PlpDirent contains all
+ * requested directory entries.
+ *
+ * @param name The name of the directory
+ * @param ret An STL deque of @ref PlpDirent entries.
+ *
+ * @returns A Psion error code (One of enum @ref rfsv::errs ).
+ */
+ virtual Enum<errs> dir(const char * const name, PlpDir &ret) = 0;
+
+ /**
+ * Retrieves the modification time of a file on the Psion.
+ *
+ * @param name Name of the file.
+ * @param mtime Modification time is returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> fgetmtime(const char * const name, PsiTime &mtime) = 0;
+
+ /**
+ * Sets the modification time of a file on the Psion.
+ *
+ * @param name Name of the file whose modification time should be set.
+ * @param mtime The desired modification time.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> fsetmtime(const char * const name, const PsiTime mtime) = 0;
+
+ /**
+ * Retrieves attributes of a file on the Psion.
+ *
+ * @param name Name of the file whose attributes ar to be retrieved.
+ * @param attr The file's attributes are returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> fgetattr(const char * const name, u_int32_t &attr) = 0;
+
+ /**
+ * Retrieves attributes, size and modification time of a file on the Psion.
+ *
+ * @param name The name of the file.
+ * @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, PlpDirent &e) =0;
+
+ /**
+ * @param name
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> fsetattr(const char * const name, const u_int32_t seta, const u_int32_t unseta) = 0;
+
+ /**
+ * Counts number of entries in a directory.
+ *
+ * @param name The directory whose entries are to be counted.
+ * @param count The number of entries is returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> dircount(const char * const name, u_int32_t &count) = 0;
+
+ /**
+ * Retrieves available drives on the Psion.
+ * @p devbits On return, for every exiting drive, a bit is set in this
+ * variable. The lowest bit represents drive A:.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> devlist(u_int32_t &devbits) = 0;
+
+ /**
+ * Retrieves details about a drive.
+ *
+ * @param dev An integer, representing the drive to get details from.
+ * (0 represents A:, 1 is B: and so on ...)
+ * @param drive A @ref PlpDrive object which is filled with the drive's
+ * information upon return.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> devinfo(const u_int32_t dev, PlpDrive &drive) = 0;
+
+ /**
+ * Reads from a file on the Psion.
+ *
+ * @param handle Handle of the file to read from.
+ * @param buffer The area where to store the data read.
+ * @param len The number of bytes to read.
+ * @param count The number of bytes actually read is returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> fread(const u_int32_t handle, unsigned char * const buffer, const u_int32_t len, u_int32_t &count) = 0;
+
+ /**
+ * Write to a file on the Psion.
+ *
+ * @param handle Handle of the file to read from.
+ * @param buffer The area to be written.
+ * @param len The number of bytes to write.
+ * @param count The number of bytes actually written is returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> fwrite(const u_int32_t handle, const unsigned char * const buffer, const u_int32_t len, u_int32_t &count) = 0;
+
+ /**
+ * Copies a file from the Psion to the local machine.
+ *
+ * @param from Name of the file on the Psion to be copied.
+ * @param to Name of the destination file on the local machine.
+ * @param func Pointer to a function which gets called on every read.
+ * This function can be used to show some progress etc. May be set
+ * to NULL, where no callback is performed.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> copyFromPsion(const char *from, const char *to, void *, cpCallback_t func) = 0;
+
+ /**
+ * Copies a file from local machine to the Psion.
+ *
+ * @param from Name of the file on the local machine to be copied.
+ * @param to Name of the destination file on the Psion.
+ * @param func Pointer to a function which gets called on every read.
+ * This function can be used to show some progress etc. May be set
+ * to NULL, where no callback is performed.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> copyToPsion(const char * const from, const char * const to, void *, cpCallback_t func) = 0;
+
+ /**
+ * Copies a file from the Psion to the Psion.
+ * On the EPOC variants, this runs much faster than reading
+ * data from the Psion and then writing it back to the Psion, since
+ * data transfer is handled locally on the Psion.
+ *
+ * @param from Name of the file to be copied.
+ * @param to Name of the destination file.
+ * @param func Pointer to a function which gets called on every read.
+ * This function can be used to show some progress etc. May be set
+ * to NULL, where no callback is performed.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> copyOnPsion(const char * const from, const char * const to, void *, cpCallback_t func) = 0;
+
+ /**
+ * Resizes an open file on the Psion.
+ * If the new size is greater than the file's
+ * current size, the contents of the added
+ * data is undefined. If The new size is smaller,
+ * the file is truncated.
+ *
+ * @param handle Handle of the file to be resized.
+ * @param size New size for that file.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> fsetsize(const u_int32_t handle, const u_int32_t size) = 0;
+
+ /**
+ * Sets the current file position of a file on the Psion.
+ *
+ * @param handle The file handle.
+ * @param offset Position to be seeked to.
+ * @param mode The mode for seeking.
+ * @param resultpos The final file position after seeking is returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> fseek(const u_int32_t handle, const int32_t offset, const u_int32_t mode, u_int32_t &resultpos) = 0;
+
+ /**
+ * Creates a directory on the Psion.
+ *
+ * @param name Name of the directory to be created.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> mkdir(const char * const name) = 0;
+
+ /**
+ * Removes a directory on the Psion.
+ *
+ * @param name Name of the directory to be removed.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> rmdir(const char * const name) = 0;
+
+ /**
+ * Renames a file on the Psion.
+ *
+ * @param oldname Name of the file to be renamed.
+ * @param newname New Name for that file.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> rename(const char * const oldname, const char * const newname) = 0;
+
+ /**
+ * Removes a file on the Psion.
+ *
+ * @param name Name of the file to be removed.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> remove(const char * const name) = 0;
+
+ /**
+ * Open a directory for reading with readdir.
+ *
+ * @param attr A combination of PSI_A_.. flags, representing the desired types
+ * of entries to be returned when calling @ref readdir .
+ * @param name The name of the directory
+ * @param handle A handle to be used with @ref readdir and @ref closedir .
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> opendir(const u_int32_t attr, const char * const name, rfsvDirhandle &handle) = 0;
+
+ /**
+ * Read directory entries.
+ * This method reads entries of a directory, previously
+ * opened with @ref opendir .
+ *
+ * @param handle A handle, obtained by calling @ref opendir .
+ * @param entry The entry information is returned here.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> readdir(rfsvDirhandle &handle, PlpDirent &entry) = 0;
+
+ /**
+ * Close a directory, previously opened with @ref opendir.
+ *
+ * @param handle A handle, obtained by calling @ref opendir .
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> closedir(rfsvDirhandle &handle) = 0;
+
+ /**
+ * Set the name of a Psion Volume (Drive).
+ *
+ * @param drive The drive character of the Volume, whose name should be set.
+ * @param name The new name for that drive.
+ *
+ * @returns A Psion error code (One of enum @ref #errs ).
+ */
+ virtual Enum<errs> setVolumeName(const char drive, const char * const name) = 0;
+
+ /**
+ * Converts a file attribute @ref rfsv::file_attribs to
+ * human readable format, usable for showing them in directory
+ * listings. The first 7 characters are common to all
+ * machine types:
+ * <pre>
+ * Char Nr. Value
+ * 0 'd' if a directory, '-' otherwise.
+ * 1 'r' if file is readable, '-' otherwise.
+ * 2 'w' if file is writeable, '-' otherwise.
+ * 3 'h' if file is hidden, '-' otherwise.
+ * 4 's' if file is a system file, '-' otherwise.
+ * 5 'a' if file is modified (archive flag), '-' otherwise.
+ * 6 'v' if file is a volume name, '-' otherwise.
+ * </pre>
+ * The rest (3 characters) are machine specific:
+ * <pre>
+ * Char Nr. EPOC Value SIBO Value
+ * 7 'n' if normal, 'x' if executable, '-' otherwise.
+ * 8 't' if temporary, 'b' if a stream, '-' otherwise.
+ * 8 'c' if compressed, 't' if a textfile, '-' otherwise.
+ * </pre>
+ *
+ * @param attr the generic file attribute.
+ *
+ * @returns Pointer to static textual representation of file attributes.
+ *
+ */
+ string attr2String(const u_int32_t attr);
+
+ /**
+ * Converts an open-mode (A combination of the PSI_O_ constants.)
+ * from generic representation to the machine-specific representation.
+ *
+ * @param mode The generic open mode.
+ *
+ * @returns The machine specific representation for use with
+ * @ref fopen , @ref fcreatefile and @freplacefile.
+ */
+ virtual u_int32_t opMode(const u_int32_t mode) = 0;
+
+ /**
+ * Utility method, converts '/' to '\'.
+ */
+ static string convertSlash(const string &name);
protected:
- /**
- * Retrieves the PLP protocol name. Mainly internal use.
- *
- * @returns The connection name always "SYS$RFSV"
- */
- const char *getConnectName();
-
- ppsocket *skt;
- Enum<errs> status;
- int32_t serNum;
+ /**
+ * Retrieves the PLP protocol name. Mainly internal use.
+ *
+ * @returns The connection name always "SYS$RFSV"
+ */
+ const char *getConnectName();
+
+ ppsocket *skt;
+ Enum<errs> status;
+ int32_t serNum;
};
#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rfsv16.cc b/lib/rfsv16.cc
index f98816c..30c3673 100644
--- a/lib/rfsv16.cc
+++ b/lib/rfsv16.cc
@@ -1,28 +1,27 @@
-//
-// RFSV16 - An implementation of the PSION SIBO RFSV Client protocol
-//
-// Copyright (C) 1999 Philip Proudman
-// Modifications for plptools:
-// Copyright (C) 1999 Matt J. Gumbley <matt@gumbley.demon.co.uk>
-// Sources: rfsv32.cc by Fritz Elfert, and rfsv16.cc by Philip Proudman
-// Descriptions of the RFSV16 protocol by Michael Pieper, Olaf Flebbe & Me.
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999 Matt J. Gumbley <matt@gumbley.demon.co.uk>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -43,678 +42,678 @@
rfsv16::rfsv16(ppsocket *_skt)
{
- serNum = 0;
- status = rfsv::E_PSI_FILE_DISC;
- skt = _skt;
- reset();
+ serNum = 0;
+ status = rfsv::E_PSI_FILE_DISC;
+ skt = _skt;
+ reset();
}
Enum<rfsv::errs> rfsv16::
fopen(u_int32_t attr, const char *name, u_int32_t &handle)
-{
- bufferStore a;
- string realName = convertSlash(name);
-
- a.addWord(attr & 0xFFFF);
- a.addStringT(realName.c_str());
- if (!sendCommand(FOPEN, a))
- return E_PSI_FILE_DISC;
-
- Enum<rfsv::errs> res = getResponse(a);
- if (res == 0) {
- handle = (long)a.getWord(0);
- return E_PSI_GEN_NONE;
- }
- return res;
+{
+ bufferStore a;
+ string realName = convertSlash(name);
+
+ a.addWord(attr & 0xFFFF);
+ a.addStringT(realName.c_str());
+ if (!sendCommand(FOPEN, a))
+ return E_PSI_FILE_DISC;
+
+ Enum<rfsv::errs> res = getResponse(a);
+ if (res == 0) {
+ handle = (long)a.getWord(0);
+ return E_PSI_GEN_NONE;
+ }
+ return res;
}
// internal
Enum<rfsv::errs> rfsv16::
mktemp(u_int32_t &handle, string &tmpname)
{
- bufferStore a;
+ bufferStore a;
- a.addWord(P_FUNIQUE);
- a.addStringT("TMP");
- if (!sendCommand(OPENUNIQUE, a))
- return E_PSI_FILE_DISC;
-
- Enum<rfsv::errs> res = getResponse(a);
- if (res == E_PSI_GEN_NONE) {
- handle = a.getWord(0);
- tmpname = a.getString(2);
- return res;
- }
+ a.addWord(P_FUNIQUE);
+ a.addStringT("TMP");
+ if (!sendCommand(OPENUNIQUE, a))
+ return E_PSI_FILE_DISC;
+
+ Enum<rfsv::errs> res = getResponse(a);
+ if (res == E_PSI_GEN_NONE) {
+ handle = a.getWord(0);
+ tmpname = a.getString(2);
return res;
+ }
+ return res;
}
// internal and external
Enum<rfsv::errs> rfsv16::
fcreatefile(u_int32_t attr, const char *name, u_int32_t &handle)
{
- return fopen(attr | P_FCREATE, name, handle);
+ return fopen(attr | P_FCREATE, name, handle);
}
// this is internal - not used by plpnfsd, unlike fcreatefile
Enum<rfsv::errs> rfsv16::
freplacefile(u_int32_t attr, const char *name, u_int32_t &handle)
{
- return fopen(attr | P_FREPLACE, name, handle);
+ return fopen(attr | P_FREPLACE, name, handle);
}
Enum<rfsv::errs> rfsv16::
fopendir(const char * const name, u_int32_t &handle)
{
- return fopen(P_FDIR, name, handle);
+ return fopen(P_FDIR, name, handle);
}
Enum<rfsv::errs> rfsv16::
fclose(u_int32_t fileHandle)
{
- bufferStore a;
- a.addWord(fileHandle & 0xFFFF);
- if (!sendCommand(FCLOSE, a))
- return E_PSI_FILE_DISC;
- return getResponse(a);
+ bufferStore a;
+ a.addWord(fileHandle & 0xFFFF);
+ if (!sendCommand(FCLOSE, a))
+ return E_PSI_FILE_DISC;
+ return getResponse(a);
}
Enum<rfsv::errs> rfsv16::
opendir(const u_int32_t attr, const char *name, rfsvDirhandle &dH) {
- u_int32_t handle;
- Enum<rfsv::errs> res = fopendir(name, handle);
- dH.h = handle;
- dH.b.init();
- return res;
+ u_int32_t handle;
+ Enum<rfsv::errs> res = fopendir(name, handle);
+ dH.h = handle;
+ dH.b.init();
+ return res;
}
Enum<rfsv::errs> rfsv16::
closedir(rfsvDirhandle &dH) {
- return fclose(dH.h);
+ return fclose(dH.h);
}
Enum<rfsv::errs> rfsv16::
readdir(rfsvDirhandle &dH, PlpDirent &e) {
- Enum<rfsv::errs> res = E_PSI_GEN_NONE;
-
- if (dH.b.getLen() < 17) {
- dH.b.init();
- dH.b.addWord(dH.h & 0xFFFF);
- if (!sendCommand(FDIRREAD, dH.b))
- return E_PSI_FILE_DISC;
- res = getResponse(dH.b);
- dH.b.discardFirstBytes(2); // Don't know what these mean!
- }
- if ((res == E_PSI_GEN_NONE) && (dH.b.getLen() > 16)) {
- u_int16_t version = dH.b.getWord(0);
- if (version != 2) {
- cerr << "dir: not version 2" << endl;
- return E_PSI_GEN_FAIL;
- }
- e.attr = attr2std((u_int32_t)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());
+ Enum<rfsv::errs> res = E_PSI_GEN_NONE;
+ if (dH.b.getLen() < 17) {
+ dH.b.init();
+ dH.b.addWord(dH.h & 0xFFFF);
+ if (!sendCommand(FDIRREAD, dH.b))
+ return E_PSI_FILE_DISC;
+ res = getResponse(dH.b);
+ dH.b.discardFirstBytes(2); // Don't know what these mean!
+ }
+ if ((res == E_PSI_GEN_NONE) && (dH.b.getLen() > 16)) {
+ u_int16_t version = dH.b.getWord(0);
+ if (version != 2) {
+ cerr << "dir: not version 2" << endl;
+ return E_PSI_GEN_FAIL;
}
- return res;
+ e.attr = attr2std((u_int32_t)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());
+
+ }
+ return res;
}
Enum<rfsv::errs> rfsv16::
dir(const char *name, PlpDir &files)
{
- rfsvDirhandle h;
- files.clear();
- Enum<rfsv::errs> res = opendir(PSI_A_HIDDEN | PSI_A_SYSTEM | PSI_A_DIR, name, h);
- while (res == E_PSI_GEN_NONE) {
- PlpDirent e;
- res = readdir(h, e);
- if (res == E_PSI_GEN_NONE)
- files.push_back(e);
- }
- closedir(h);
- if (res == E_PSI_FILE_EOF)
- res = E_PSI_GEN_NONE;
- return res;
+ rfsvDirhandle h;
+ files.clear();
+ Enum<rfsv::errs> res = opendir(PSI_A_HIDDEN | PSI_A_SYSTEM | PSI_A_DIR, name, h);
+ while (res == E_PSI_GEN_NONE) {
+ PlpDirent e;
+ res = readdir(h, e);
+ if (res == E_PSI_GEN_NONE)
+ files.push_back(e);
+ }
+ closedir(h);
+ if (res == E_PSI_FILE_EOF)
+ res = E_PSI_GEN_NONE;
+ return res;
}
u_int32_t rfsv16::
opMode(u_int32_t mode)
{
- u_int32_t ret = 0;
+ u_int32_t ret = 0;
- ret |= ((mode & 03) == PSI_O_RDONLY) ? 0 : P_FUPDATE;
- ret |= (mode & PSI_O_TRUNC) ? P_FREPLACE : 0;
- ret |= (mode & PSI_O_CREAT) ? P_FCREATE : 0;
- ret |= (mode & PSI_O_APPEND) ? P_FAPPEND : 0;
- if ((mode & 03) == PSI_O_RDONLY)
- ret |= (mode & PSI_O_EXCL) ? 0 : P_FSHARE;
- return ret;
+ ret |= ((mode & 03) == PSI_O_RDONLY) ? 0 : P_FUPDATE;
+ ret |= (mode & PSI_O_TRUNC) ? P_FREPLACE : 0;
+ ret |= (mode & PSI_O_CREAT) ? P_FCREATE : 0;
+ ret |= (mode & PSI_O_APPEND) ? P_FAPPEND : 0;
+ if ((mode & 03) == PSI_O_RDONLY)
+ ret |= (mode & PSI_O_EXCL) ? 0 : P_FSHARE;
+ return ret;
}
Enum<rfsv::errs> rfsv16::
fgetmtime(const char * const name, PsiTime &mtime)
{
-cerr << "rfsv16::fgetmtime" << endl;
- // NB: fgetattr, fgeteattr is almost identical...
- bufferStore a;
- 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;
-
- Enum<rfsv::errs> res = getResponse(a);
- if (res != E_PSI_GEN_NONE) {
- cerr << "fgetmtime: Error " << res << " on file " << name << endl;
- return res;
- }
- else if (a.getLen() == 16) {
- mtime.setUnixTime(a.getDWord(8));
- return res;
- }
- cerr << "fgetmtime: Unknown response (" << name << ") " << a <<endl;
- return E_PSI_GEN_FAIL;
+ cerr << "rfsv16::fgetmtime" << endl;
+ // NB: fgetattr, fgeteattr is almost identical...
+ bufferStore a;
+ 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;
+
+ Enum<rfsv::errs> res = getResponse(a);
+ if (res != E_PSI_GEN_NONE) {
+ cerr << "fgetmtime: Error " << res << " on file " << name << endl;
+ return res;
+ }
+ else if (a.getLen() == 16) {
+ mtime.setUnixTime(a.getDWord(8));
+ return res;
+ }
+ cerr << "fgetmtime: Unknown response (" << name << ") " << a <<endl;
+ return E_PSI_GEN_FAIL;
}
Enum<rfsv::errs> rfsv16::
fsetmtime(const char *name, PsiTime mtime)
{
-cerr << "rfsv16::fsetmtime ***" << endl;
- // I don't think there's a protocol frame that allows us to set the
- // modification time. SFDATE allows setting of creation time...
- return E_PSI_NOT_SIBO;
+ cerr << "rfsv16::fsetmtime ***" << endl;
+ // I don't think there's a protocol frame that allows us to set the
+ // modification time. SFDATE allows setting of creation time...
+ return E_PSI_NOT_SIBO;
}
Enum<rfsv::errs> rfsv16::
fgetattr(const char * const name, u_int32_t &attr)
{
- // NB: fgetmtime, fgeteattr are almost identical...
- bufferStore a;
- 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;
-
- Enum<rfsv::errs> res = getResponse(a);
- if (res != 0) {
- cerr << "fgetattr: Error " << res << " on file " << name << endl;
- return res;
- }
- else if (a.getLen() == 16) {
- attr = attr2std((long)a.getWord(2));
- return res;
- }
- cerr << "fgetattr: Unknown response (" << name << ") " << a <<endl;
- return E_PSI_GEN_FAIL;
+ // NB: fgetmtime, fgeteattr are almost identical...
+ bufferStore a;
+ 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;
+
+ Enum<rfsv::errs> res = getResponse(a);
+ if (res != 0) {
+ cerr << "fgetattr: Error " << res << " on file " << name << endl;
+ return res;
+ }
+ else if (a.getLen() == 16) {
+ attr = attr2std((long)a.getWord(2));
+ return res;
+ }
+ cerr << "fgetattr: Unknown response (" << name << ") " << a <<endl;
+ return E_PSI_GEN_FAIL;
}
Enum<rfsv::errs> rfsv16::
fgeteattr(const char * const name, PlpDirent &e)
{
- bufferStore a;
- 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) {
- 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;
- return E_PSI_GEN_FAIL;
+ bufferStore a;
+ 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) {
+ 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;
+ return E_PSI_GEN_FAIL;
}
Enum<rfsv::errs> rfsv16::
fsetattr(const char *name, u_int32_t seta, u_int32_t unseta)
{
-cerr << "rfsv16::fsetattr" << endl;
- // seta are attributes to set; unseta are attributes to unset. Need to
- // turn this into attributes to change state and a bit mask.
- // 210000
- // 008421
- // a shr
- u_int32_t statusword = std2attr(seta) & (~ std2attr(unseta));
- statusword ^= 0x0000001; // r bit is inverted
- u_int32_t bitmask = std2attr(seta) | std2attr(unseta);
- // cerr << "seta is " << hex << setw(2) << setfill('0') << seta << endl;
- // cerr << "unseta is " << hex << setw(2) << setfill('0') << unseta << endl;
- // cerr << "statusword is " << hex << setw(2) << setfill('0') << statusword << endl;
- // cerr << "bitmask is " << hex << setw(2) << setfill('0') << bitmask << endl;
- bufferStore a;
- a.addWord(statusword & 0xFFFF);
- a.addWord(bitmask & 0xFFFF);
- a.addStringT(name);
- // and this needs sending in the length word.
- if (!sendCommand(SFSTAT, a))
- return E_PSI_FILE_DISC;
- return getResponse(a);
+ cerr << "rfsv16::fsetattr" << endl;
+ // seta are attributes to set; unseta are attributes to unset. Need to
+ // turn this into attributes to change state and a bit mask.
+ // 210000
+ // 008421
+ // a shr
+ u_int32_t statusword = std2attr(seta) & (~ std2attr(unseta));
+ statusword ^= 0x0000001; // r bit is inverted
+ u_int32_t bitmask = std2attr(seta) | std2attr(unseta);
+ // cerr << "seta is " << hex << setw(2) << setfill('0') << seta << endl;
+ // cerr << "unseta is " << hex << setw(2) << setfill('0') << unseta << endl;
+ // cerr << "statusword is " << hex << setw(2) << setfill('0') << statusword << endl;
+ // cerr << "bitmask is " << hex << setw(2) << setfill('0') << bitmask << endl;
+ bufferStore a;
+ a.addWord(statusword & 0xFFFF);
+ a.addWord(bitmask & 0xFFFF);
+ a.addStringT(name);
+ // and this needs sending in the length word.
+ if (!sendCommand(SFSTAT, a))
+ return E_PSI_FILE_DISC;
+ return getResponse(a);
}
Enum<rfsv::errs> rfsv16::
dircount(const char * const name, u_int32_t &count)
{
- u_int32_t fileHandle;
- Enum<rfsv::errs> res;
- count = 0;
+ u_int32_t fileHandle;
+ Enum<rfsv::errs> res;
+ count = 0;
+
+ res = fopen(P_FDIR, name, fileHandle);
+ if (res != E_PSI_GEN_NONE)
+ return res;
- res = fopen(P_FDIR, name, fileHandle);
+ while (1) {
+ bufferStore a;
+ a.addWord(fileHandle & 0xFFFF);
+ if (!sendCommand(FDIRREAD, a))
+ return E_PSI_FILE_DISC;
+ res = getResponse(a);
if (res != E_PSI_GEN_NONE)
- return res;
-
- while (1) {
- bufferStore a;
- a.addWord(fileHandle & 0xFFFF);
- if (!sendCommand(FDIRREAD, a))
- return E_PSI_FILE_DISC;
- res = getResponse(a);
- if (res != E_PSI_GEN_NONE)
- break;
- a.discardFirstBytes(2); // Don't know what these mean!
- while (a.getLen() > 16) {
- int version = a.getWord(0);
- if (version != 2) {
- cerr << "dir: not version 2" << endl;
- fclose(fileHandle);
- return E_PSI_GEN_FAIL;
- }
- // int status = a.getWord(2);
- // long size = a.getDWord(4);
- // long date = a.getDWord(8);
- const char *s = a.getString(16);
- a.discardFirstBytes(17+strlen(s));
- count++;
- }
+ break;
+ a.discardFirstBytes(2); // Don't know what these mean!
+ while (a.getLen() > 16) {
+ int version = a.getWord(0);
+ if (version != 2) {
+ cerr << "dir: not version 2" << endl;
+ fclose(fileHandle);
+ return E_PSI_GEN_FAIL;
+ }
+ // int status = a.getWord(2);
+ // long size = a.getDWord(4);
+ // long date = a.getDWord(8);
+ const char *s = a.getString(16);
+ a.discardFirstBytes(17+strlen(s));
+ count++;
}
- if (res == E_PSI_FILE_EOF)
- res = E_PSI_GEN_NONE;
- fclose(fileHandle);
- return res;
+ }
+ if (res == E_PSI_FILE_EOF)
+ res = E_PSI_GEN_NONE;
+ fclose(fileHandle);
+ return res;
}
Enum<rfsv::errs> rfsv16::
devlist(u_int32_t &devbits)
{
- Enum<rfsv::errs> res;
- u_int32_t fileHandle;
- devbits = 0;
+ Enum<rfsv::errs> res;
+ u_int32_t fileHandle;
+ devbits = 0;
+
+ // The following is taken from a trace between a Series 3c and PsiWin.
+ // Hope it works! We PARSE to find the correct node, then FOPEN
+ // (P_FDEVICE) this, FDEVICEREAD each entry, setting the appropriate
+ // drive-letter-bit in devbits, then FCLOSE.
+
+ bufferStore a;
+ a.init();
+ a.addByte(0x00); // no Name 1
+ a.addByte(0x00); // no Name 2
+ a.addByte(0x00); // no Name 3
+ if (!sendCommand(PARSE, a))
+ return E_PSI_FILE_DISC;
+ res = getResponse(a);
+ if (res != E_PSI_GEN_NONE)
+ return res;
- // The following is taken from a trace between a Series 3c and PsiWin.
- // Hope it works! We PARSE to find the correct node, then FOPEN
- // (P_FDEVICE) this, FDEVICEREAD each entry, setting the appropriate
- // drive-letter-bit in devbits, then FCLOSE.
+ // Find the drive to FOPEN
+ char name[4] = { 'x', ':', '\\', '\0' } ;
+ a.discardFirstBytes(6); // Result, fsys, dev, path, file, file, ending, flag
+ /* This leaves R E M : : M : \ */
+ name[0] = (char) a.getByte(5); // the M
+ res = fopen(P_FDEVICE, name, fileHandle);
+ if (res != E_PSI_GEN_NONE)
+ return status;
+ while (1) {
bufferStore a;
a.init();
- a.addByte(0x00); // no Name 1
- a.addByte(0x00); // no Name 2
- a.addByte(0x00); // no Name 3
- if (!sendCommand(PARSE, a))
- return E_PSI_FILE_DISC;
+ a.addWord(fileHandle & 0xFFFF);
+ if (!sendCommand(FDEVICEREAD, a))
+ return E_PSI_FILE_DISC;
res = getResponse(a);
- if (res != E_PSI_GEN_NONE)
- return res;
-
- // Find the drive to FOPEN
- char name[4] = { 'x', ':', '\\', '\0' } ;
- a.discardFirstBytes(6); // Result, fsys, dev, path, file, file, ending, flag
- /* This leaves R E M : : M : \ */
- name[0] = (char) a.getByte(5); // the M
- res = fopen(P_FDEVICE, name, fileHandle);
- if (res != E_PSI_GEN_NONE)
- return status;
-
- while (1) {
- bufferStore a;
- a.init();
- a.addWord(fileHandle & 0xFFFF);
- if (!sendCommand(FDEVICEREAD, a))
- return E_PSI_FILE_DISC;
- res = getResponse(a);
- if (res)
- break;
- u_int16_t version = a.getWord(0);
- if (version != 2) {
- cerr << "devlist: not version 2" << endl;
- fclose(fileHandle);
- return E_PSI_GEN_FAIL; // FIXME
- }
- char drive = a.getByte(64);
- if (drive >= 'A' && drive <= 'Z') {
- int shift = (drive - 'A');
- devbits |= (long) ( 1 << shift );
- }
- else {
- cerr << "devlist: non-alphabetic drive letter ("
- << drive << ")" << endl;
- }
+ if (res)
+ break;
+ u_int16_t version = a.getWord(0);
+ if (version != 2) {
+ cerr << "devlist: not version 2" << endl;
+ fclose(fileHandle);
+ return E_PSI_GEN_FAIL; // FIXME
}
- if (res == E_PSI_FILE_EOF)
- res = E_PSI_GEN_NONE;
- fclose(fileHandle);
- return res;
+ char drive = a.getByte(64);
+ if (drive >= 'A' && drive <= 'Z') {
+ int shift = (drive - 'A');
+ devbits |= (long) ( 1 << shift );
+ }
+ else {
+ cerr << "devlist: non-alphabetic drive letter ("
+ << drive << ")" << endl;
+ }
+ }
+ if (res == E_PSI_FILE_EOF)
+ res = E_PSI_GEN_NONE;
+ fclose(fileHandle);
+ return res;
}
static int sibo_dattr[] = {
- 1, // Unknown
- 2, // Floppy
- 3, // Disk
- 6, // Flash
- 5, // RAM
- 7, // ROM
- 7, // write-protected == ROM ?
+ 1, // Unknown
+ 2, // Floppy
+ 3, // Disk
+ 6, // Flash
+ 5, // RAM
+ 7, // ROM
+ 7, // write-protected == ROM ?
};
Enum<rfsv::errs> rfsv16::
devinfo(const u_int32_t devnum, PlpDrive &drive)
{
- bufferStore a;
- Enum<rfsv::errs> res;
- // long fileHandle;
-
- // Again, this is taken from an exchange between PsiWin and a 3c.
- // For each drive, we PARSE with its drive letter to get a response
- // (which we ignore), then do a STATUSDEVICE to get the info.
-
- a.init();
- a.addByte((char) (devnum + 'A')); // Name 1
- a.addByte(':');
- a.addByte(0x00);
- a.addByte(0x00); // No name 2
- a.addByte(0x00); // No name 3
- if (!sendCommand(PARSE, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE) {
- // cerr << "devinfo PARSE res is " << dec << (signed short int) res << endl;
- return res;
- }
-
- a.init();
- a.addByte((char) (devnum + 'A')); // Name 1
- a.addByte(':');
- a.addByte('\\');
- a.addByte(0x00);
- if (!sendCommand(STATUSDEVICE, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE) {
- // cerr << "devinfo STATUSDEVICE res is " << dec << (signed short int) res << endl;
- return res;
- }
+ bufferStore a;
+ Enum<rfsv::errs> res;
+ // long fileHandle;
+
+ // Again, this is taken from an exchange between PsiWin and a 3c.
+ // For each drive, we PARSE with its drive letter to get a response
+ // (which we ignore), then do a STATUSDEVICE to get the info.
+
+ a.init();
+ a.addByte((char) (devnum + 'A')); // Name 1
+ a.addByte(':');
+ a.addByte(0x00);
+ a.addByte(0x00); // No name 2
+ a.addByte(0x00); // No name 3
+ if (!sendCommand(PARSE, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE) {
+ // cerr << "devinfo PARSE res is " << dec << (signed short int) res << endl;
+ return res;
+ }
+
+ a.init();
+ a.addByte((char) (devnum + 'A')); // Name 1
+ a.addByte(':');
+ a.addByte('\\');
+ a.addByte(0x00);
+ if (!sendCommand(STATUSDEVICE, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE) {
+ // cerr << "devinfo STATUSDEVICE res is " << dec << (signed short int) res << endl;
+ return res;
+ }
- int attr = a.getWord(2);
- attr = sibo_dattr[a.getWord(2) & 0xff];
- drive.setMediaType(attr);
+ int attr = a.getWord(2);
+ attr = sibo_dattr[a.getWord(2) & 0xff];
+ drive.setMediaType(attr);
- attr = a.getWord(2);
- int changeable = a.getWord(4) ? 32 : 0;
- int internal = (attr & 0x2000) ? 16 : 0;
+ attr = a.getWord(2);
+ int changeable = a.getWord(4) ? 32 : 0;
+ int internal = (attr & 0x2000) ? 16 : 0;
- drive.setDriveAttribute(changeable | internal);
+ drive.setDriveAttribute(changeable | internal);
- int variable = (attr & 0x4000) ? 1 : 0;
- int dualdens = (attr & 0x1000) ? 2 : 0;
- int formattable = (attr & 0x0800) ? 4 : 0;
- int protect = ((attr & 0xff) == 6) ? 8 : 0;
+ int variable = (attr & 0x4000) ? 1 : 0;
+ int dualdens = (attr & 0x1000) ? 2 : 0;
+ int formattable = (attr & 0x0800) ? 4 : 0;
+ int protect = ((attr & 0xff) == 6) ? 8 : 0;
- drive.setMediaAttribute(variable|dualdens|formattable|protect);
+ drive.setMediaAttribute(variable|dualdens|formattable|protect);
- drive.setUID(0);
- drive.setSize(a.getDWord(6), 0);
- drive.setSpace(a.getDWord(10), 0);
+ drive.setUID(0);
+ drive.setSize(a.getDWord(6), 0);
+ drive.setSpace(a.getDWord(10), 0);
- drive.setName('A' + devnum, a.getString(14));
+ drive.setName('A' + devnum, a.getString(14));
- return res;
+ return res;
}
bool rfsv16::
sendCommand(enum commands cc, bufferStore & data)
{
- if (status == E_PSI_FILE_DISC) {
- reconnect();
- if (status == E_PSI_FILE_DISC)
- return false;
- }
-
- bool result;
- bufferStore a;
- a.addWord(cc);
- a.addWord(data.getLen());
- a.addBuff(data);
+ if (status == E_PSI_FILE_DISC) {
+ reconnect();
+ if (status == E_PSI_FILE_DISC)
+ return false;
+ }
+
+ bool result;
+ bufferStore a;
+ a.addWord(cc);
+ a.addWord(data.getLen());
+ a.addBuff(data);
+ result = skt->sendBufferStore(a);
+ if (!result) {
+ reconnect();
result = skt->sendBufferStore(a);
- if (!result) {
- reconnect();
- result = skt->sendBufferStore(a);
if (!result)
- status = E_PSI_FILE_DISC;
- }
- return result;
+ status = E_PSI_FILE_DISC;
+ }
+ return result;
}
Enum<rfsv::errs> rfsv16::
getResponse(bufferStore & data)
{
- // getWord(2) is the size field
- // which is the body of the response not counting the command (002a) and
- // the size word.
- if (skt->getBufferStore(data) != 1) {
- cerr << "rfsv16::getResponse: duff response. "
- "getBufferStore failed." << endl;
- } else if (data.getWord(0) == 0x2a &&
- data.getWord(2) == data.getLen()-4) {
- Enum<errs> ret = (enum errs)data.getWord(4);
- data.discardFirstBytes(6);
- return ret;
- } else {
+ // getWord(2) is the size field
+ // which is the body of the response not counting the command (002a) and
+ // the size word.
+ if (skt->getBufferStore(data) != 1) {
+ cerr << "rfsv16::getResponse: duff response. "
+ "getBufferStore failed." << endl;
+ } else if (data.getWord(0) == 0x2a &&
+ data.getWord(2) == data.getLen()-4) {
+ Enum<errs> ret = (enum errs)data.getWord(4);
+ data.discardFirstBytes(6);
+ return ret;
+ } else {
cerr << "rfsv16::getResponse: duff response. Size field:" <<
- data.getWord(2) << " Frame size:" <<
- data.getLen()-4 << " Result field:" <<
- data.getWord(4) << endl;
- }
- status = E_PSI_FILE_DISC;
- return status;
+ data.getWord(2) << " Frame size:" <<
+ data.getLen()-4 << " Result field:" <<
+ data.getWord(4) << endl;
+ }
+ status = E_PSI_FILE_DISC;
+ return status;
}
Enum<rfsv::errs> rfsv16::
fread(const u_int32_t handle, unsigned char * const buf, const u_int32_t len, u_int32_t &count)
{
- Enum<rfsv::errs> res;
- unsigned char *p = buf;
-
- count = 0;
- while (count < len) {
- bufferStore a;
-
- // Read in blocks of 291 bytes; the maximum payload for
- // an RFSV frame. ( As seen in traces ) - this isn't optimal:
- // RFSV can handle fragmentation of frames, where only the
- // first FREAD RESPONSE frame has a RESPONSE (00 2A), SIZE
- // and RESULT field. Every subsequent frame
- // just has data, 297 bytes (or less) of it.
- //
- a.addWord(handle);
- a.addWord((len - count) > RFSV16_MAXDATALEN
- ? RFSV16_MAXDATALEN
- : (len - count));
- if (!sendCommand(FREAD, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE) {
- if (res == E_PSI_FILE_EOF)
- return E_PSI_GEN_NONE;
- return res;
- }
- long l = a.getLen();
- memcpy(buf, a.getString(), l);
- count += l;
- p += l;
+ Enum<rfsv::errs> res;
+ unsigned char *p = buf;
+
+ count = 0;
+ while (count < len) {
+ bufferStore a;
+
+ // Read in blocks of 291 bytes; the maximum payload for
+ // an RFSV frame. ( As seen in traces ) - this isn't optimal:
+ // RFSV can handle fragmentation of frames, where only the
+ // first FREAD RESPONSE frame has a RESPONSE (00 2A), SIZE
+ // and RESULT field. Every subsequent frame
+ // just has data, 297 bytes (or less) of it.
+ //
+ a.addWord(handle);
+ a.addWord((len - count) > RFSV16_MAXDATALEN
+ ? RFSV16_MAXDATALEN
+ : (len - count));
+ if (!sendCommand(FREAD, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE) {
+ if (res == E_PSI_FILE_EOF)
+ return E_PSI_GEN_NONE;
+ return res;
}
- return res;
+ long l = a.getLen();
+ memcpy(buf, a.getString(), l);
+ count += l;
+ p += l;
+ }
+ return res;
}
Enum<rfsv::errs> rfsv16::
fwrite(const u_int32_t handle, const unsigned char * const buf, const u_int32_t len, u_int32_t &count)
{
- Enum<rfsv::errs> res;
- const unsigned char *p = buf;
-
- count = 0;
- while (count < len) {
- bufferStore a;
- int nbytes;
-
- // Write in blocks of 291 bytes; the maximum payload for
- // an RFSV frame. ( As seen in traces ) - this isn't optimal:
- // RFSV can handle fragmentation of frames, where only the
- // first FREAD RESPONSE frame has a RESPONSE (00 2A), SIZE
- // and RESULT field. Every subsequent frame
- // just has data, 297 bytes (or less) of it.
- nbytes = (len - count) > RFSV16_MAXDATALEN
- ? RFSV16_MAXDATALEN
- : (len - count);
- a.addWord(handle);
- a.addBytes(p, nbytes);
- if (!sendCommand(FWRITE, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
-
- count += nbytes;
- p += nbytes;
- }
- return res;
+ Enum<rfsv::errs> res;
+ const unsigned char *p = buf;
+
+ count = 0;
+ while (count < len) {
+ bufferStore a;
+ int nbytes;
+
+ // Write in blocks of 291 bytes; the maximum payload for
+ // an RFSV frame. ( As seen in traces ) - this isn't optimal:
+ // RFSV can handle fragmentation of frames, where only the
+ // first FREAD RESPONSE frame has a RESPONSE (00 2A), SIZE
+ // and RESULT field. Every subsequent frame
+ // just has data, 297 bytes (or less) of it.
+ nbytes = (len - count) > RFSV16_MAXDATALEN
+ ? RFSV16_MAXDATALEN
+ : (len - count);
+ a.addWord(handle);
+ a.addBytes(p, nbytes);
+ if (!sendCommand(FWRITE, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE)
+ return res;
+
+ count += nbytes;
+ p += nbytes;
+ }
+ return res;
}
Enum<rfsv::errs> rfsv16::
copyFromPsion(const char *from, const char *to, void *ptr, cpCallback_t cb)
{
- Enum<rfsv::errs> res;
- u_int32_t handle;
- u_int32_t len;
- u_int32_t total = 0;
+ Enum<rfsv::errs> res;
+ u_int32_t handle;
+ u_int32_t len;
+ u_int32_t total = 0;
- if ((res = fopen(P_FSHARE | P_FSTREAM, from, handle)) != E_PSI_GEN_NONE)
- return res;
- ofstream op(to);
- if (!op) {
- fclose(handle);
- return E_PSI_GEN_FAIL;
+ if ((res = fopen(P_FSHARE | P_FSTREAM, from, handle)) != E_PSI_GEN_NONE)
+ return res;
+ ofstream op(to);
+ if (!op) {
+ fclose(handle);
+ return E_PSI_GEN_FAIL;
+ }
+ do {
+ unsigned char buf[RFSV_SENDLEN];
+ if ((res = fread(handle, buf, sizeof(buf), len)) == E_PSI_GEN_NONE) {
+ if (len > 0)
+ op.write(buf, len);
+ total += len;
+ if (cb && !cb(ptr, total))
+ res = E_PSI_FILE_CANCEL;
}
- do {
- unsigned char buf[RFSV_SENDLEN];
- if ((res = fread(handle, buf, sizeof(buf), len)) == E_PSI_GEN_NONE) {
- if (len > 0)
- op.write(buf, len);
- total += len;
- if (cb && !cb(ptr, total))
- res = E_PSI_FILE_CANCEL;
- }
- } while (len > 0 && (res == E_PSI_GEN_NONE));
+ } while (len > 0 && (res == E_PSI_GEN_NONE));
- fclose(handle);
- op.close();
- if (res == E_PSI_FILE_EOF)
- res = E_PSI_GEN_NONE;
- return res;
+ fclose(handle);
+ op.close();
+ if (res == E_PSI_FILE_EOF)
+ res = E_PSI_GEN_NONE;
+ return res;
}
Enum<rfsv::errs> rfsv16::
copyToPsion(const char *from, const char *to, void *ptr, cpCallback_t cb)
{
- u_int32_t handle;
- u_int32_t len = 0;
- u_int32_t total = 0;
- Enum<rfsv::errs> res;
-
- ifstream ip(from);
- if (!ip)
- return E_PSI_FILE_NXIST;
- res = fcreatefile(P_FSTREAM | P_FUPDATE, to, handle);
- if (res != E_PSI_GEN_NONE) {
- res = freplacefile(P_FSTREAM | P_FUPDATE, to, handle);
- if (res != E_PSI_GEN_NONE)
- return res;
- }
- unsigned char *buff = new unsigned char[RFSV_SENDLEN];
- while (res == E_PSI_GEN_NONE && ip && !ip.eof()) {
- ip.read(buff, RFSV_SENDLEN);
- if ((res = fwrite(handle, buff, ip.gcount(), len)) == E_PSI_GEN_NONE) {
- total += len;
- if (cb && !cb(ptr, total))
- res = E_PSI_FILE_CANCEL;
- }
+ u_int32_t handle;
+ u_int32_t len = 0;
+ u_int32_t total = 0;
+ Enum<rfsv::errs> res;
+
+ ifstream ip(from);
+ if (!ip)
+ return E_PSI_FILE_NXIST;
+ res = fcreatefile(P_FSTREAM | P_FUPDATE, to, handle);
+ if (res != E_PSI_GEN_NONE) {
+ res = freplacefile(P_FSTREAM | P_FUPDATE, to, handle);
+ if (res != E_PSI_GEN_NONE)
+ return res;
+ }
+ unsigned char *buff = new unsigned char[RFSV_SENDLEN];
+ while (res == E_PSI_GEN_NONE && ip && !ip.eof()) {
+ ip.read(buff, RFSV_SENDLEN);
+ if ((res = fwrite(handle, buff, ip.gcount(), len)) == E_PSI_GEN_NONE) {
+ total += len;
+ if (cb && !cb(ptr, total))
+ res = E_PSI_FILE_CANCEL;
}
- delete[]buff;
- fclose(handle);
- ip.close();
- return res;
+ }
+ delete[]buff;
+ fclose(handle);
+ ip.close();
+ return res;
}
Enum<rfsv::errs> rfsv16::
copyOnPsion(const char *from, const char *to, void *ptr, cpCallback_t cb)
{
- u_int32_t handle_from;
- u_int32_t handle_to;
- u_int32_t len;
- u_int32_t wlen;
- u_int32_t total = 0;
- Enum<rfsv::errs> res;
-
- if ((res = fopen(P_FSHARE | P_FSTREAM, from, handle_from)) != E_PSI_GEN_NONE)
- return res;
- res = fcreatefile(P_FSTREAM | P_FUPDATE, to, handle_to);
- if (res != E_PSI_GEN_NONE) {
- res = freplacefile(P_FSTREAM | P_FUPDATE, to, handle_to);
- if (res != E_PSI_GEN_NONE)
- return res;
- }
- do {
- unsigned char buf[RFSV_SENDLEN];
- if ((res = fread(handle_from, buf, sizeof(buf), len)) == E_PSI_GEN_NONE) {
- if (len > 0) {
- if ((res = fwrite(handle_to, buf, len, wlen)) == E_PSI_GEN_NONE) {
- total += wlen;
- if (cb && !cb(ptr, total))
- res = E_PSI_FILE_CANCEL;
- }
- }
- }
- } while (len > 0 && wlen > 0 && (res == E_PSI_GEN_NONE));
- fclose(handle_from);
- fclose(handle_to);
- if (res == E_PSI_FILE_EOF)
- res = E_PSI_GEN_NONE;
+ u_int32_t handle_from;
+ u_int32_t handle_to;
+ u_int32_t len;
+ u_int32_t wlen;
+ u_int32_t total = 0;
+ Enum<rfsv::errs> res;
+
+ if ((res = fopen(P_FSHARE | P_FSTREAM, from, handle_from)) != E_PSI_GEN_NONE)
return res;
+ res = fcreatefile(P_FSTREAM | P_FUPDATE, to, handle_to);
+ if (res != E_PSI_GEN_NONE) {
+ res = freplacefile(P_FSTREAM | P_FUPDATE, to, handle_to);
+ if (res != E_PSI_GEN_NONE)
+ return res;
+ }
+ do {
+ unsigned char buf[RFSV_SENDLEN];
+ if ((res = fread(handle_from, buf, sizeof(buf), len)) == E_PSI_GEN_NONE) {
+ if (len > 0) {
+ if ((res = fwrite(handle_to, buf, len, wlen)) == E_PSI_GEN_NONE) {
+ total += wlen;
+ if (cb && !cb(ptr, total))
+ res = E_PSI_FILE_CANCEL;
+ }
+ }
+ }
+ } while (len > 0 && wlen > 0 && (res == E_PSI_GEN_NONE));
+ fclose(handle_from);
+ fclose(handle_to);
+ if (res == E_PSI_FILE_EOF)
+ res = E_PSI_GEN_NONE;
+ return res;
}
Enum<rfsv::errs> rfsv16::
fsetsize(u_int32_t handle, u_int32_t size)
{
- bufferStore a;
- a.addWord(handle & 0xffff);
- a.addDWord(size);
- if (!sendCommand(FSETEOF, a))
- return E_PSI_FILE_DISC;
- return getResponse(a);
+ bufferStore a;
+ a.addWord(handle & 0xffff);
+ a.addDWord(size);
+ if (!sendCommand(FSETEOF, a))
+ return E_PSI_FILE_DISC;
+ return getResponse(a);
}
/*
@@ -725,14 +724,14 @@ fsetsize(u_int32_t handle, u_int32_t size)
Enum<rfsv::errs> rfsv16::
fseek(const u_int32_t handle, const int32_t pos, const u_int32_t mode, u_int32_t &resultpos)
{
- bufferStore a;
- Enum<rfsv::errs> res;
- u_int32_t savpos = 0;
- u_int32_t realpos;
- u_int32_t calcpos = 0;
+ bufferStore a;
+ Enum<rfsv::errs> res;
+ u_int32_t savpos = 0;
+ u_int32_t realpos;
+ u_int32_t calcpos = 0;
/*
- seek-parameter for psion:
+ seek-parameter for psion:
dword position
dword handle
dword mode
@@ -742,150 +741,150 @@ fseek(const u_int32_t handle, const int32_t pos, const u_int32_t mode, u_int32_t
??no more?? 4 = sense recpos
??no more?? 5 = set recpos
??no more?? 6 = text-rewind
- */
+*/
- if ((mode < PSI_SEEK_SET) || (mode > PSI_SEEK_END))
- return E_PSI_GEN_ARG;
-
- if ((mode == PSI_SEEK_CUR) && (pos >= 0)) {
- /* get and save current position */
- a.init();
- a.addWord(handle);
- a.addDWord(0);
- a.addWord(PSI_SEEK_CUR);
- if (!sendCommand(FSEEK, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
- savpos = a.getDWord(0);
- if (pos == 0) {
- resultpos = savpos;
- return res;
- }
+ if ((mode < PSI_SEEK_SET) || (mode > PSI_SEEK_END))
+ return E_PSI_GEN_ARG;
+
+ if ((mode == PSI_SEEK_CUR) && (pos >= 0)) {
+ /* get and save current position */
+ a.init();
+ a.addWord(handle);
+ a.addDWord(0);
+ a.addWord(PSI_SEEK_CUR);
+ if (!sendCommand(FSEEK, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE)
+ return res;
+ savpos = a.getDWord(0);
+ if (pos == 0) {
+ resultpos = savpos;
+ return res;
}
- if ((mode == PSI_SEEK_END) && (pos >= 0)) {
- /* get and save end position */
- a.init();
- a.addWord(handle);
- a.addDWord(0);
- a.addWord(PSI_SEEK_END);
- if (!sendCommand(FSEEK, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
- savpos = a.getDWord(0);
- if (pos == 0) {
- resultpos = savpos;
- return res;
- }
+ }
+ if ((mode == PSI_SEEK_END) && (pos >= 0)) {
+ /* get and save end position */
+ a.init();
+ a.addWord(handle);
+ a.addDWord(0);
+ a.addWord(PSI_SEEK_END);
+ if (!sendCommand(FSEEK, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE)
+ return res;
+ savpos = a.getDWord(0);
+ if (pos == 0) {
+ resultpos = savpos;
+ return res;
}
- /* Now the real seek */
+ }
+ /* Now the real seek */
+ a.addWord(handle);
+ a.addDWord(pos);
+ a.addWord(mode);
+ if (!sendCommand(FSEEK, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != 0)
+ return res;
+ realpos = a.getDWord(0);
+ switch (mode) {
+ case PSI_SEEK_SET:
+ calcpos = pos;
+ break;
+ case PSI_SEEK_CUR:
+ calcpos = savpos + pos;
+ break;
+ case PSI_SEEK_END:
+ resultpos = realpos;
+ return res;
+ break;
+ }
+ if (calcpos > realpos) {
+ /* Beyond end of file */
+ res = fsetsize(handle, calcpos);
+ if (res != E_PSI_GEN_NONE)
+ return res;
+ a.init();
a.addWord(handle);
- a.addDWord(pos);
- a.addWord(mode);
+ a.addDWord(calcpos);
+ a.addWord(PSI_SEEK_SET);
if (!sendCommand(FSEEK, a))
- return E_PSI_FILE_DISC;
+ return E_PSI_FILE_DISC;
if ((res = getResponse(a)) != 0)
- return res;
+ return res;
realpos = a.getDWord(0);
- switch (mode) {
- case PSI_SEEK_SET:
- calcpos = pos;
- break;
- case PSI_SEEK_CUR:
- calcpos = savpos + pos;
- break;
- case PSI_SEEK_END:
- resultpos = realpos;
- return res;
- break;
- }
- if (calcpos > realpos) {
- /* Beyond end of file */
- res = fsetsize(handle, calcpos);
- if (res != E_PSI_GEN_NONE)
- return res;
- a.init();
- a.addWord(handle);
- a.addDWord(calcpos);
- a.addWord(PSI_SEEK_SET);
- if (!sendCommand(FSEEK, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != 0)
- return res;
- realpos = a.getDWord(0);
- }
- resultpos = realpos;
- return res;
+ }
+ resultpos = realpos;
+ return res;
}
Enum<rfsv::errs> rfsv16::
mkdir(const char* dirName)
{
- string realName = convertSlash(dirName);
- bufferStore a;
- a.addStringT(realName.c_str());
- sendCommand(MKDIR, a);
- Enum<rfsv::errs> res = getResponse(a);
- if (res == E_PSI_GEN_NONE) {
- // Correct response
- return res;
- }
- cerr << "Unknown response from mkdir "<< res <<endl;
- return E_PSI_GEN_FAIL;
+ string realName = convertSlash(dirName);
+ bufferStore a;
+ a.addStringT(realName.c_str());
+ sendCommand(MKDIR, a);
+ Enum<rfsv::errs> res = getResponse(a);
+ if (res == E_PSI_GEN_NONE) {
+ // Correct response
+ return res;
+ }
+ cerr << "Unknown response from mkdir "<< res <<endl;
+ return E_PSI_GEN_FAIL;
}
Enum<rfsv::errs> rfsv16::
rmdir(const char *dirName)
{
- // There doesn't seem to be an RMDIR command, but DELETE works. We
- // should probably check to see if the file is a directory first!
- return remove(dirName);
+ // There doesn't seem to be an RMDIR command, but DELETE works. We
+ // should probably check to see if the file is a directory first!
+ return remove(dirName);
}
Enum<rfsv::errs> rfsv16::
rename(const char *oldName, const char *newName)
{
-cerr << "rfsv16::rename ***" << endl;
-
- string realOldName = convertSlash(oldName);
- string realNewName = convertSlash(newName);
- bufferStore a;
- a.addStringT(realOldName.c_str());
- a.addStringT(realNewName.c_str());
- sendCommand(RENAME, a);
- Enum<rfsv::errs> res = getResponse(a);
- if (res == E_PSI_GEN_NONE) {
- // Correct response
- return res;
- }
- cerr << "Unknown response from rename "<< res <<endl;
- return E_PSI_GEN_FAIL;
+ cerr << "rfsv16::rename ***" << endl;
+
+ string realOldName = convertSlash(oldName);
+ string realNewName = convertSlash(newName);
+ bufferStore a;
+ a.addStringT(realOldName.c_str());
+ a.addStringT(realNewName.c_str());
+ sendCommand(RENAME, a);
+ Enum<rfsv::errs> res = getResponse(a);
+ if (res == E_PSI_GEN_NONE) {
+ // Correct response
+ return res;
+ }
+ cerr << "Unknown response from rename "<< res <<endl;
+ return E_PSI_GEN_FAIL;
}
Enum<rfsv::errs> rfsv16::
remove(const char* psionName)
{
- Enum<rfsv::errs> res;
- string realName = convertSlash(psionName);
- bufferStore a;
- a.addStringT(realName.c_str());
- // and this needs sending in the length word.
- sendCommand(DELETE, a);
- res = getResponse(a);
- if (res == E_PSI_GEN_NONE) {
- // Correct response
- return res;
- }
- cerr << "Unknown response from delete "<< res <<endl;
- return E_PSI_GEN_FAIL;
+ Enum<rfsv::errs> res;
+ string realName = convertSlash(psionName);
+ bufferStore a;
+ a.addStringT(realName.c_str());
+ // and this needs sending in the length word.
+ sendCommand(DELETE, a);
+ res = getResponse(a);
+ if (res == E_PSI_GEN_NONE) {
+ // Correct response
+ return res;
+ }
+ cerr << "Unknown response from delete "<< res <<endl;
+ return E_PSI_GEN_FAIL;
}
Enum<rfsv::errs> rfsv16::
setVolumeName(const char drive , const char * const name)
{
-// Not yet ...
- return E_PSI_GEN_FAIL;
+// Not yet ...
+ return E_PSI_GEN_FAIL;
}
/*
@@ -894,36 +893,36 @@ setVolumeName(const char drive , const char * const name)
u_int32_t rfsv16::
attr2std(u_int32_t attr)
{
- u_int32_t res = 0;
-
- // Common attributes
- if (!(attr & P_FAWRITE))
- res |= PSI_A_RDONLY;
- if (attr & P_FAHIDDEN)
- res |= PSI_A_HIDDEN;
- if (attr & P_FASYSTEM)
- res |= PSI_A_SYSTEM;
- if (attr & P_FADIR)
- res |= PSI_A_DIR;
- if (attr & P_FAMOD)
- res |= PSI_A_ARCHIVE;
- if (attr & P_FAVOLUME)
- res |= PSI_A_VOLUME;
-
- // SIBO-specific
- if (attr & P_FAREAD)
- res |= PSI_A_READ;
- if (attr & P_FAEXEC)
- res |= PSI_A_EXEC;
- if (attr & P_FASTREAM)
- res |= PSI_A_STREAM;
- if (attr & P_FATEXT)
- res |= PSI_A_TEXT;
-
- // Do what we can for EPOC
- res |= PSI_A_NORMAL;
-
- return res;
+ u_int32_t res = 0;
+
+ // Common attributes
+ if (!(attr & P_FAWRITE))
+ res |= PSI_A_RDONLY;
+ if (attr & P_FAHIDDEN)
+ res |= PSI_A_HIDDEN;
+ if (attr & P_FASYSTEM)
+ res |= PSI_A_SYSTEM;
+ if (attr & P_FADIR)
+ res |= PSI_A_DIR;
+ if (attr & P_FAMOD)
+ res |= PSI_A_ARCHIVE;
+ if (attr & P_FAVOLUME)
+ res |= PSI_A_VOLUME;
+
+ // SIBO-specific
+ if (attr & P_FAREAD)
+ res |= PSI_A_READ;
+ if (attr & P_FAEXEC)
+ res |= PSI_A_EXEC;
+ if (attr & P_FASTREAM)
+ res |= PSI_A_STREAM;
+ if (attr & P_FATEXT)
+ res |= PSI_A_TEXT;
+
+ // Do what we can for EPOC
+ res |= PSI_A_NORMAL;
+
+ return res;
}
/*
@@ -932,31 +931,37 @@ attr2std(u_int32_t attr)
u_int32_t rfsv16::
std2attr(const u_int32_t attr)
{
- u_int32_t res = 0;
-
- // Common attributes
- if (!(attr & PSI_A_RDONLY))
- res |= P_FAWRITE;
- if (attr & PSI_A_HIDDEN)
- res |= P_FAHIDDEN;
- if (attr & PSI_A_SYSTEM)
- res |= P_FASYSTEM;
- if (attr & PSI_A_DIR)
- res |= P_FADIR;
- if (attr & PSI_A_ARCHIVE)
- res |= P_FAMOD;
- if (attr & PSI_A_VOLUME)
- res |= P_FAVOLUME;
-
- // SIBO-specific
- if (attr & PSI_A_READ)
- res |= P_FAREAD;
- if (attr & PSI_A_EXEC)
- res |= P_FAEXEC;
- if (attr & PSI_A_STREAM)
- res |= P_FASTREAM;
- if (attr & PSI_A_TEXT)
- res |= P_FATEXT;
-
- return res;
+ u_int32_t res = 0;
+
+ // Common attributes
+ if (!(attr & PSI_A_RDONLY))
+ res |= P_FAWRITE;
+ if (attr & PSI_A_HIDDEN)
+ res |= P_FAHIDDEN;
+ if (attr & PSI_A_SYSTEM)
+ res |= P_FASYSTEM;
+ if (attr & PSI_A_DIR)
+ res |= P_FADIR;
+ if (attr & PSI_A_ARCHIVE)
+ res |= P_FAMOD;
+ if (attr & PSI_A_VOLUME)
+ res |= P_FAVOLUME;
+
+ // SIBO-specific
+ if (attr & PSI_A_READ)
+ res |= P_FAREAD;
+ if (attr & PSI_A_EXEC)
+ res |= P_FAEXEC;
+ if (attr & PSI_A_STREAM)
+ res |= P_FASTREAM;
+ if (attr & PSI_A_TEXT)
+ res |= P_FATEXT;
+
+ return res;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rfsv16.h b/lib/rfsv16.h
index 42661f8..2cd4393 100644
--- a/lib/rfsv16.h
+++ b/lib/rfsv16.h
@@ -1,5 +1,28 @@
-#ifndef _rfsv16_h_
-#define _rfsv16_h_
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _RFSV16_H_
+#define _RFSV16_H_
#include "rfsv.h"
@@ -13,113 +36,123 @@ class rfsvfactory;
* @ref rfsv . For a complete documentation, see @ref rfsv .
*/
class rfsv16 : public rfsv {
- friend rfsvfactory;
+
+ /**
+ * rfsvfactory may call our constructor.
+ */
+ friend rfsvfactory;
public:
- Enum<rfsv::errs> fopen(const u_int32_t, const char * const, u_int32_t &);
- Enum<rfsv::errs> mktemp(u_int32_t &, string &);
- Enum<rfsv::errs> fcreatefile(const u_int32_t, const char * const, u_int32_t &);
- Enum<rfsv::errs> freplacefile(const u_int32_t, const char * const, u_int32_t &);
- Enum<rfsv::errs> fclose(const u_int32_t);
- Enum<rfsv::errs> dir(const char * const, PlpDir &);
- Enum<rfsv::errs> fgetmtime(const char * const, PsiTime &);
- Enum<rfsv::errs> fsetmtime(const char * const, const PsiTime);
- Enum<rfsv::errs> fgetattr(const char * const, u_int32_t &);
- Enum<rfsv::errs> fgeteattr(const char * const, PlpDirent &);
- Enum<rfsv::errs> fsetattr(const char * const, const u_int32_t seta, const u_int32_t unseta);
- Enum<rfsv::errs> dircount(const char * const, u_int32_t &);
- Enum<rfsv::errs> devlist(u_int32_t &);
- Enum<rfsv::errs> devinfo(const u_int32_t, PlpDrive &);
- Enum<rfsv::errs> fread(const u_int32_t, unsigned char * const, const u_int32_t, u_int32_t &);
- Enum<rfsv::errs> fwrite(const u_int32_t, const unsigned char * const, const u_int32_t, u_int32_t &);
- Enum<rfsv::errs> copyFromPsion(const char * const, const char * const, void *, cpCallback_t);
- Enum<rfsv::errs> copyToPsion(const char * const, const char * const, void *, cpCallback_t);
- Enum<rfsv::errs> copyOnPsion(const char *, const char *, void *, cpCallback_t);
- Enum<rfsv::errs> fsetsize(const u_int32_t, const u_int32_t);
- Enum<rfsv::errs> fseek(const u_int32_t, const int32_t, const u_int32_t, u_int32_t &);
- Enum<rfsv::errs> mkdir(const char * const);
- Enum<rfsv::errs> rmdir(const char * const);
- Enum<rfsv::errs> rename(const char * const, const char * const);
- Enum<rfsv::errs> remove(const char * const);
- Enum<rfsv::errs> opendir(const u_int32_t, const char * const, rfsvDirhandle &);
- Enum<rfsv::errs> readdir(rfsvDirhandle &, PlpDirent &);
- Enum<rfsv::errs> closedir(rfsvDirhandle &);
- Enum<rfsv::errs> setVolumeName(const char, const char * const);
+ Enum<rfsv::errs> fopen(const u_int32_t, const char * const, u_int32_t &);
+ Enum<rfsv::errs> mktemp(u_int32_t &, string &);
+ Enum<rfsv::errs> fcreatefile(const u_int32_t, const char * const, u_int32_t &);
+ Enum<rfsv::errs> freplacefile(const u_int32_t, const char * const, u_int32_t &);
+ Enum<rfsv::errs> fclose(const u_int32_t);
+ Enum<rfsv::errs> dir(const char * const, PlpDir &);
+ Enum<rfsv::errs> fgetmtime(const char * const, PsiTime &);
+ Enum<rfsv::errs> fsetmtime(const char * const, const PsiTime);
+ Enum<rfsv::errs> fgetattr(const char * const, u_int32_t &);
+ Enum<rfsv::errs> fgeteattr(const char * const, PlpDirent &);
+ Enum<rfsv::errs> fsetattr(const char * const, const u_int32_t seta, const u_int32_t unseta);
+ Enum<rfsv::errs> dircount(const char * const, u_int32_t &);
+ Enum<rfsv::errs> devlist(u_int32_t &);
+ Enum<rfsv::errs> devinfo(const u_int32_t, PlpDrive &);
+ Enum<rfsv::errs> fread(const u_int32_t, unsigned char * const, const u_int32_t, u_int32_t &);
+ Enum<rfsv::errs> fwrite(const u_int32_t, const unsigned char * const, const u_int32_t, u_int32_t &);
+ Enum<rfsv::errs> copyFromPsion(const char * const, const char * const, void *, cpCallback_t);
+ Enum<rfsv::errs> copyToPsion(const char * const, const char * const, void *, cpCallback_t);
+ Enum<rfsv::errs> copyOnPsion(const char *, const char *, void *, cpCallback_t);
+ Enum<rfsv::errs> fsetsize(const u_int32_t, const u_int32_t);
+ Enum<rfsv::errs> fseek(const u_int32_t, const int32_t, const u_int32_t, u_int32_t &);
+ Enum<rfsv::errs> mkdir(const char * const);
+ Enum<rfsv::errs> rmdir(const char * const);
+ Enum<rfsv::errs> rename(const char * const, const char * const);
+ Enum<rfsv::errs> remove(const char * const);
+ Enum<rfsv::errs> opendir(const u_int32_t, const char * const, rfsvDirhandle &);
+ Enum<rfsv::errs> readdir(rfsvDirhandle &, PlpDirent &);
+ Enum<rfsv::errs> closedir(rfsvDirhandle &);
+ Enum<rfsv::errs> setVolumeName(const char, const char * const);
- u_int32_t opMode(const u_int32_t);
+ u_int32_t opMode(const u_int32_t);
private:
- enum commands {
- FOPEN = 0, // File Open
- FCLOSE = 2, // File Close
- FREAD = 4, // File Read
- FDIRREAD = 6, // Read Directory entries
- FDEVICEREAD = 8, // Device Information
- FWRITE = 10, // File Write
- FSEEK = 12, // File Seek
- FFLUSH = 14, // Flush
- FSETEOF = 16,
- RENAME = 18,
- DELETE = 20,
- FINFO = 22,
- SFSTAT = 24,
- PARSE = 26,
- MKDIR = 28,
- OPENUNIQUE = 30,
- STATUSDEVICE = 32,
- PATHTEST = 34,
- STATUSSYSTEM = 36,
- CHANGEDIR = 38,
- SFDATE = 40,
- RESPONSE = 42
- };
+ enum commands {
+ FOPEN = 0, // File Open
+ FCLOSE = 2, // File Close
+ FREAD = 4, // File Read
+ FDIRREAD = 6, // Read Directory entries
+ FDEVICEREAD = 8, // Device Information
+ FWRITE = 10, // File Write
+ FSEEK = 12, // File Seek
+ FFLUSH = 14, // Flush
+ FSETEOF = 16,
+ RENAME = 18,
+ DELETE = 20,
+ FINFO = 22,
+ SFSTAT = 24,
+ PARSE = 26,
+ MKDIR = 28,
+ OPENUNIQUE = 30,
+ STATUSDEVICE = 32,
+ PATHTEST = 34,
+ STATUSSYSTEM = 36,
+ CHANGEDIR = 38,
+ SFDATE = 40,
+ RESPONSE = 42
+ };
- enum fopen_attrib {
- P_FOPEN = 0x0000, /* Open file */
- P_FCREATE = 0x0001, /* Create file */
- P_FREPLACE = 0x0002, /* Replace file */
- P_FAPPEND = 0x0003, /* Append records */
- P_FUNIQUE = 0x0004, /* Unique file open */
- P_FSTREAM = 0x0000, /* Stream access to a binary file */
- P_FSTREAM_TEXT = 0x0010, /* Stream access to a text file */
- P_FTEXT = 0x0020, /* Record access to a text file */
- P_FDIR = 0x0030, /* Record access to a directory file */
- P_FFORMAT = 0x0040, /* Format a device */
- P_FDEVICE = 0x0050, /* Record access to device name list */
- P_FNODE = 0x0060, /* Record access to node name list */
- P_FUPDATE = 0x0100, /* Read and write access */
- P_FRANDOM = 0x0200, /* Random access */
- P_FSHARE = 0x0400 /* File can be shared */
- };
+ enum fopen_attrib {
+ P_FOPEN = 0x0000, /* Open file */
+ P_FCREATE = 0x0001, /* Create file */
+ P_FREPLACE = 0x0002, /* Replace file */
+ P_FAPPEND = 0x0003, /* Append records */
+ P_FUNIQUE = 0x0004, /* Unique file open */
+ P_FSTREAM = 0x0000, /* Stream access to a binary file */
+ P_FSTREAM_TEXT = 0x0010, /* Stream access to a text file */
+ P_FTEXT = 0x0020, /* Record access to a text file */
+ P_FDIR = 0x0030, /* Record access to a directory file */
+ P_FFORMAT = 0x0040, /* Format a device */
+ P_FDEVICE = 0x0050, /* Record access to device name list */
+ P_FNODE = 0x0060, /* Record access to node name list */
+ P_FUPDATE = 0x0100, /* Read and write access */
+ P_FRANDOM = 0x0200, /* Random access */
+ P_FSHARE = 0x0400 /* File can be shared */
+ };
- enum status_enum {
- P_FAWRITE = 0x0001, /* can the file be written to? */
- P_FAHIDDEN = 0x0002, /* set if file is hidden */
- P_FASYSTEM = 0x0004, /* set if file is a system file */
- P_FAVOLUME = 0x0008, /* set if the name is a volume name */
- P_FADIR = 0x0010, /* set if file is a directory file */
- P_FAMOD = 0x0020, /* has the file been modified? */
- P_FAREAD = 0x0100, /* can the file be read? */
- P_FAEXEC = 0x0200, /* is the file executable? */
- P_FASTREAM = 0x0400, /* is the file a byte stream file? */
- P_FATEXT = 0x0800, /* is it a text file? */
- P_FAMASK = 0x0f3f /* All of the above */
- };
+ enum status_enum {
+ P_FAWRITE = 0x0001, /* can the file be written to? */
+ P_FAHIDDEN = 0x0002, /* set if file is hidden */
+ P_FASYSTEM = 0x0004, /* set if file is a system file */
+ P_FAVOLUME = 0x0008, /* set if the name is a volume name */
+ P_FADIR = 0x0010, /* set if file is a directory file */
+ P_FAMOD = 0x0020, /* has the file been modified? */
+ P_FAREAD = 0x0100, /* can the file be read? */
+ P_FAEXEC = 0x0200, /* is the file executable? */
+ P_FASTREAM = 0x0400, /* is the file a byte stream file? */
+ P_FATEXT = 0x0800, /* is it a text file? */
+ P_FAMASK = 0x0f3f /* All of the above */
+ };
- /**
- * Private constructor. Shall be called by
- * rfsvfactory only.
- */
- rfsv16(ppsocket *);
+ /**
+ * Private constructor. Shall be called by
+ * rfsvfactory only.
+ */
+ rfsv16(ppsocket *);
- // Miscellaneous
- Enum<rfsv::errs> fopendir(const char * const, u_int32_t &);
- u_int32_t attr2std(const u_int32_t);
- u_int32_t std2attr(const u_int32_t);
+ // Miscellaneous
+ Enum<rfsv::errs> fopendir(const char * const, u_int32_t &);
+ u_int32_t attr2std(const u_int32_t);
+ u_int32_t std2attr(const u_int32_t);
- // Communication
- bool sendCommand(enum commands, bufferStore &);
- Enum<rfsv::errs> getResponse(bufferStore &);
+ // Communication
+ bool sendCommand(enum commands, bufferStore &);
+ Enum<rfsv::errs> getResponse(bufferStore &);
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rfsv32.cc b/lib/rfsv32.cc
index 0e6fd47..2dc5fbb 100644
--- a/lib/rfsv32.cc
+++ b/lib/rfsv32.cc
@@ -1,24 +1,26 @@
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -38,561 +40,561 @@
rfsv32::rfsv32(ppsocket * _skt)
{
- skt = _skt;
- serNum = 0;
- status = rfsv::E_PSI_FILE_DISC;
- reset();
+ skt = _skt;
+ serNum = 0;
+ status = rfsv::E_PSI_FILE_DISC;
+ reset();
}
Enum<rfsv::errs> rfsv32::
fopen(u_int32_t attr, const char *name, u_int32_t &handle)
{
- bufferStore a;
- string n = convertSlash(name);
- a.addDWord(attr);
- 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);
- if (res == E_PSI_GEN_NONE && a.getLen() == 4) {
- handle = a.getDWord(0);
- return E_PSI_GEN_NONE;
- }
- return res;
+ bufferStore a;
+ string n = convertSlash(name);
+ a.addDWord(attr);
+ 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);
+ if (res == E_PSI_GEN_NONE && a.getLen() == 4) {
+ handle = a.getDWord(0);
+ return E_PSI_GEN_NONE;
+ }
+ return res;
}
Enum<rfsv::errs> rfsv32::
mktemp(u_int32_t &handle, string &tmpname)
{
- bufferStore a;
- if (!sendCommand(TEMP_FILE, a))
- return E_PSI_FILE_DISC;
- Enum<rfsv::errs> res = getResponse(a);
- if (res == E_PSI_GEN_NONE) {
- handle = a.getDWord(0);
- tmpname = a.getString(6);
- }
- return res;
+ bufferStore a;
+ if (!sendCommand(TEMP_FILE, a))
+ return E_PSI_FILE_DISC;
+ Enum<rfsv::errs> res = getResponse(a);
+ if (res == E_PSI_GEN_NONE) {
+ handle = a.getDWord(0);
+ tmpname = a.getString(6);
+ }
+ return res;
}
Enum<rfsv::errs> rfsv32::
fcreatefile(u_int32_t attr, const char *name, u_int32_t &handle)
{
- bufferStore a;
- string n = convertSlash(name);
- a.addDWord(attr);
- 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);
- if (res == E_PSI_GEN_NONE && a.getLen() == 4)
- handle = a.getDWord(0);
- return res;
+ bufferStore a;
+ string n = convertSlash(name);
+ a.addDWord(attr);
+ 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);
+ if (res == E_PSI_GEN_NONE && a.getLen() == 4)
+ handle = a.getDWord(0);
+ return res;
}
Enum<rfsv::errs> rfsv32::
freplacefile(const u_int32_t attr, const char * const name, u_int32_t &handle)
{
- bufferStore a;
- string n = convertSlash(name);
- a.addDWord(attr);
- 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);
- if (res == E_PSI_GEN_NONE && a.getLen() == 4)
- handle = a.getDWord(0);
- return res;
+ bufferStore a;
+ string n = convertSlash(name);
+ a.addDWord(attr);
+ 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);
+ if (res == E_PSI_GEN_NONE && a.getLen() == 4)
+ handle = a.getDWord(0);
+ return res;
}
Enum<rfsv::errs> rfsv32::
fopendir(const u_int32_t attr, const char * const name, u_int32_t &handle)
{
- bufferStore a;
- string n = convertSlash(name);
- a.addDWord(attr | EPOC_ATTR_GETUID);
- 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);
- if (!res && a.getLen() == 4)
- handle = a.getDWord(0);
- return res;
+ bufferStore a;
+ string n = convertSlash(name);
+ a.addDWord(attr | EPOC_ATTR_GETUID);
+ 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);
+ if (!res && a.getLen() == 4)
+ handle = a.getDWord(0);
+ return res;
}
Enum<rfsv::errs> rfsv32::
fclose(u_int32_t handle)
{
- bufferStore a;
- a.addDWord(handle);
- if (!sendCommand(CLOSE_HANDLE, a))
- return E_PSI_FILE_DISC;
- return getResponse(a);
+ bufferStore a;
+ a.addDWord(handle);
+ if (!sendCommand(CLOSE_HANDLE, a))
+ return E_PSI_FILE_DISC;
+ return getResponse(a);
}
Enum<rfsv::errs> rfsv32::
opendir(const u_int32_t attr, const char *name, rfsvDirhandle &dH) {
- u_int32_t handle;
- Enum<rfsv::errs> res = fopendir(std2attr(attr), name, handle);
- dH.h = handle;
- dH.b.init();
- return res;
+ u_int32_t handle;
+ Enum<rfsv::errs> res = fopendir(std2attr(attr), name, handle);
+ dH.h = handle;
+ dH.b.init();
+ return res;
}
Enum<rfsv::errs> rfsv32::
closedir(rfsvDirhandle &dH) {
- return fclose(dH.h);
+ return fclose(dH.h);
}
Enum<rfsv::errs> rfsv32::
readdir(rfsvDirhandle &dH, PlpDirent &e) {
- Enum<rfsv::errs> res = E_PSI_GEN_NONE;
-
- if (dH.b.getLen() < 17) {
- dH.b.init();
- dH.b.addDWord(dH.h);
- if (!sendCommand(READ_DIR, dH.b))
- return E_PSI_FILE_DISC;
- res = getResponse(dH.b);
- }
- if ((res == E_PSI_GEN_NONE) && (dH.b.getLen() > 16)) {
- 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 = 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));
-
- int d = 36;
- for (int i = 0; i < longLen; i++, d++)
- e.name += dH.b.getByte(d);
- while (d % 4)
- d++;
- d += shortLen;
- while (d % 4)
- d++;
- dH.b.discardFirstBytes(d);
- }
- return res;
+ Enum<rfsv::errs> res = E_PSI_GEN_NONE;
+
+ if (dH.b.getLen() < 17) {
+ dH.b.init();
+ dH.b.addDWord(dH.h);
+ if (!sendCommand(READ_DIR, dH.b))
+ return E_PSI_FILE_DISC;
+ res = getResponse(dH.b);
+ }
+ if ((res == E_PSI_GEN_NONE) && (dH.b.getLen() > 16)) {
+ 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 = 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));
+
+ int d = 36;
+ for (int i = 0; i < longLen; i++, d++)
+ e.name += dH.b.getByte(d);
+ while (d % 4)
+ d++;
+ d += shortLen;
+ while (d % 4)
+ d++;
+ dH.b.discardFirstBytes(d);
+ }
+ return res;
}
Enum<rfsv::errs> rfsv32::
dir(const char *name, PlpDir &files)
{
- rfsvDirhandle h;
- files.clear();
- Enum<rfsv::errs> res = opendir(PSI_A_HIDDEN | PSI_A_SYSTEM | PSI_A_DIR, name, h);
- while (res == E_PSI_GEN_NONE) {
- PlpDirent e;
- res = readdir(h, e);
- if (res == E_PSI_GEN_NONE)
- files.push_back(e);
- }
- closedir(h);
- if (res == E_PSI_FILE_EOF)
- res = E_PSI_GEN_NONE;
- return res;
+ rfsvDirhandle h;
+ files.clear();
+ Enum<rfsv::errs> res = opendir(PSI_A_HIDDEN | PSI_A_SYSTEM | PSI_A_DIR, name, h);
+ while (res == E_PSI_GEN_NONE) {
+ PlpDirent e;
+ res = readdir(h, e);
+ if (res == E_PSI_GEN_NONE)
+ files.push_back(e);
+ }
+ closedir(h);
+ if (res == E_PSI_FILE_EOF)
+ res = E_PSI_GEN_NONE;
+ return res;
}
u_int32_t rfsv32::
opMode(const u_int32_t mode)
{
- u_int32_t ret = 0;
+ u_int32_t ret = 0;
- ret |= (((mode & 03) == PSI_O_RDONLY) ? 0 : EPOC_OMODE_READ_WRITE);
- if (!ret)
- ret |= (mode & PSI_O_EXCL) ? 0 : EPOC_OMODE_SHARE_READERS;
- return ret;
+ ret |= (((mode & 03) == PSI_O_RDONLY) ? 0 : EPOC_OMODE_READ_WRITE);
+ if (!ret)
+ ret |= (mode & PSI_O_EXCL) ? 0 : EPOC_OMODE_SHARE_READERS;
+ return ret;
}
Enum<rfsv::errs> rfsv32::
fgetmtime(const char * const name, PsiTime &mtime)
{
- bufferStore a;
- 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.setPsiTime(a.getDWord(4), a.getDWord(0));
+ bufferStore a;
+ 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.setPsiTime(a.getDWord(4), a.getDWord(0));
+ return res;
}
Enum<rfsv::errs> rfsv32::
fsetmtime(const char * const name, PsiTime mtime)
{
- bufferStore a;
- string n = convertSlash(name);
- a.addDWord(mtime.getPsiTimeLo());
- a.addDWord(mtime.getPsiTimeHi());
- a.addWord(n.size());
- a.addString(n.c_str());
- if (!sendCommand(SET_MODIFIED, a))
- return E_PSI_FILE_DISC;
- return getResponse(a);
+ bufferStore a;
+ string n = convertSlash(name);
+ a.addDWord(mtime.getPsiTimeLo());
+ a.addDWord(mtime.getPsiTimeHi());
+ a.addWord(n.size());
+ a.addString(n.c_str());
+ if (!sendCommand(SET_MODIFIED, a))
+ return E_PSI_FILE_DISC;
+ return getResponse(a);
}
Enum<rfsv::errs> rfsv32::
fgetattr(const char * const name, u_int32_t &attr)
{
- bufferStore a;
- 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);
- if (res != E_PSI_GEN_NONE)
- return res;
- attr = attr2std(a.getDWord(0));
+ bufferStore a;
+ 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);
+ if (res != E_PSI_GEN_NONE)
return res;
+ attr = attr2std(a.getDWord(0));
+ return res;
}
Enum<rfsv::errs> rfsv32::
fgeteattr(const char * const name, PlpDirent &e)
{
- bufferStore a;
- 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);
- // long longLen = a.getDWord(32);
+ bufferStore a;
+ 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);
+ // long longLen = a.getDWord(32);
- 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));
+ 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;
+ return res;
}
Enum<rfsv::errs> rfsv32::
fsetattr(const char * const name, const u_int32_t seta, const u_int32_t unseta)
{
- bufferStore a;
- string n = convertSlash(name);
- a.addDWord(std2attr(seta));
- a.addDWord(std2attr(unseta));
- a.addWord(n.size());
- a.addString(n.c_str());
- if (!sendCommand(SET_ATT, a))
- return E_PSI_FILE_DISC;
- return getResponse(a);
+ bufferStore a;
+ string n = convertSlash(name);
+ a.addDWord(std2attr(seta));
+ a.addDWord(std2attr(unseta));
+ a.addWord(n.size());
+ a.addString(n.c_str());
+ if (!sendCommand(SET_ATT, a))
+ return E_PSI_FILE_DISC;
+ return getResponse(a);
}
Enum<rfsv::errs> rfsv32::
dircount(const char * const name, u_int32_t &count)
{
- u_int32_t handle;
- Enum<rfsv::errs> res = fopendir(EPOC_ATTR_HIDDEN | EPOC_ATTR_SYSTEM | EPOC_ATTR_DIRECTORY, name, handle);
- count = 0;
- if (res != E_PSI_GEN_NONE)
- return res;
+ u_int32_t handle;
+ Enum<rfsv::errs> res = fopendir(EPOC_ATTR_HIDDEN | EPOC_ATTR_SYSTEM | EPOC_ATTR_DIRECTORY, name, handle);
+ count = 0;
+ if (res != E_PSI_GEN_NONE)
+ return res;
- while (1) {
- bufferStore a;
- a.addDWord(handle);
- if (!sendCommand(READ_DIR, a))
- return E_PSI_FILE_DISC;
- res = getResponse(a);
- if (res != E_PSI_GEN_NONE)
- break;
- while (a.getLen() > 16) {
- int d = 36 + a.getDWord(32);
- while (d % 4)
- d++;
- d += a.getDWord(0);
- while (d % 4)
- d++;
- a.discardFirstBytes(d);
- count++;
- }
+ while (1) {
+ bufferStore a;
+ a.addDWord(handle);
+ if (!sendCommand(READ_DIR, a))
+ return E_PSI_FILE_DISC;
+ res = getResponse(a);
+ if (res != E_PSI_GEN_NONE)
+ break;
+ while (a.getLen() > 16) {
+ int d = 36 + a.getDWord(32);
+ while (d % 4)
+ d++;
+ d += a.getDWord(0);
+ while (d % 4)
+ d++;
+ a.discardFirstBytes(d);
+ count++;
}
- fclose(handle);
- if (res == E_PSI_FILE_EOF)
- res = E_PSI_GEN_NONE;
- return res;
+ }
+ fclose(handle);
+ if (res == E_PSI_FILE_EOF)
+ res = E_PSI_GEN_NONE;
+ return res;
}
Enum<rfsv::errs> rfsv32::
devlist(u_int32_t &devbits)
{
- bufferStore a;
- Enum<rfsv::errs> res;
-
- if (!sendCommand(GET_DRIVE_LIST, a))
- return E_PSI_FILE_DISC;
- res = getResponse(a);
- devbits = 0;
- if ((res == E_PSI_GEN_NONE) && (a.getLen() == 26)) {
- for (int i = 25; i >= 0; i--) {
- devbits <<= 1;
- if (a.getByte(i) != 0)
- devbits |= 1;
- }
+ bufferStore a;
+ Enum<rfsv::errs> res;
+
+ if (!sendCommand(GET_DRIVE_LIST, a))
+ return E_PSI_FILE_DISC;
+ res = getResponse(a);
+ devbits = 0;
+ if ((res == E_PSI_GEN_NONE) && (a.getLen() == 26)) {
+ for (int i = 25; i >= 0; i--) {
+ devbits <<= 1;
+ if (a.getByte(i) != 0)
+ devbits |= 1;
}
- return res;
+ }
+ return res;
}
Enum<rfsv::errs> rfsv32::
devinfo(const u_int32_t dev, PlpDrive &drive)
{
- bufferStore a;
- Enum<rfsv::errs> res;
-
- a.addDWord(dev);
- if (!sendCommand(DRIVE_INFO, a))
- return E_PSI_FILE_DISC;
- res = getResponse(a);
- if (res == E_PSI_GEN_NONE) {
- drive.setMediaType(a.getDWord(0));
- drive.setDriveAttribute(a.getDWord(8));
- drive.setMediaAttribute(a.getDWord(12));
- drive.setUID(a.getDWord(16));
- drive.setSize(a.getDWord(20), a.getDWord(24));
- drive.setSpace(a.getDWord(28), a.getDWord(32));
- a.addByte(0);
- drive.setName('A' + dev, a.getString(40));
- }
- return res;
+ bufferStore a;
+ Enum<rfsv::errs> res;
+
+ a.addDWord(dev);
+ if (!sendCommand(DRIVE_INFO, a))
+ return E_PSI_FILE_DISC;
+ res = getResponse(a);
+ if (res == E_PSI_GEN_NONE) {
+ drive.setMediaType(a.getDWord(0));
+ drive.setDriveAttribute(a.getDWord(8));
+ drive.setMediaAttribute(a.getDWord(12));
+ drive.setUID(a.getDWord(16));
+ drive.setSize(a.getDWord(20), a.getDWord(24));
+ drive.setSpace(a.getDWord(28), a.getDWord(32));
+ a.addByte(0);
+ drive.setName('A' + dev, a.getString(40));
+ }
+ return res;
}
bool rfsv32::
sendCommand(enum commands cc, bufferStore & data)
{
- if (status == E_PSI_FILE_DISC) {
- reconnect();
- if (status == E_PSI_FILE_DISC)
- return false;
- }
- bool result;
- bufferStore a;
- a.addWord(cc);
- a.addWord(serNum);
- if (serNum < 0xffff)
- serNum++;
- else
- serNum = 0;
- a.addBuff(data);
+ if (status == E_PSI_FILE_DISC) {
+ reconnect();
+ if (status == E_PSI_FILE_DISC)
+ return false;
+ }
+ bool result;
+ bufferStore a;
+ a.addWord(cc);
+ a.addWord(serNum);
+ if (serNum < 0xffff)
+ serNum++;
+ else
+ serNum = 0;
+ a.addBuff(data);
+ result = skt->sendBufferStore(a);
+ if (!result) {
+ reconnect();
result = skt->sendBufferStore(a);
- if (!result) {
- reconnect();
- result = skt->sendBufferStore(a);
if (!result)
- status = E_PSI_FILE_DISC;
- }
- return result;
+ status = E_PSI_FILE_DISC;
+ }
+ return result;
}
Enum<rfsv::errs> rfsv32::
getResponse(bufferStore & data)
{
- if (skt->getBufferStore(data) == 1 &&
- data.getWord(0) == 0x11) {
- int32_t ret = data.getDWord(4);
- data.discardFirstBytes(8);
- return err2psierr(ret);
- } else
- status = E_PSI_FILE_DISC;
- return status;
+ if (skt->getBufferStore(data) == 1 &&
+ data.getWord(0) == 0x11) {
+ int32_t ret = data.getDWord(4);
+ data.discardFirstBytes(8);
+ return err2psierr(ret);
+ } else
+ status = E_PSI_FILE_DISC;
+ return status;
}
Enum<rfsv::errs> rfsv32::
fread(const u_int32_t handle, unsigned char * const buf, const u_int32_t len, u_int32_t &count)
{
- Enum<rfsv::errs> res;
- count = 0;
- long l;
- unsigned char *p = buf;
-
- do {
- bufferStore a;
- a.addDWord(handle);
- a.addDWord(((len - count) > RFSV_SENDLEN)?RFSV_SENDLEN:(len - count));
- if (!sendCommand(READ_FILE, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
- if ((l = a.getLen()) > 0) {
- memcpy(p, a.getString(), l);
- count += l;
- p += res;
- }
- } while ((count < len) && (l > 0));
- return res;
+ Enum<rfsv::errs> res;
+ count = 0;
+ long l;
+ unsigned char *p = buf;
+
+ do {
+ bufferStore a;
+ a.addDWord(handle);
+ a.addDWord(((len - count) > RFSV_SENDLEN)?RFSV_SENDLEN:(len - count));
+ if (!sendCommand(READ_FILE, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE)
+ return res;
+ if ((l = a.getLen()) > 0) {
+ memcpy(p, a.getString(), l);
+ count += l;
+ p += res;
+ }
+ } while ((count < len) && (l > 0));
+ return res;
}
Enum<rfsv::errs> rfsv32::
fwrite(const u_int32_t handle, const unsigned char * const buf, const u_int32_t len, u_int32_t &count)
{
- Enum<rfsv::errs> res;
- const unsigned char *p = buf;
- long l;
-
- count = 0;
- do {
- l = ((len - count) > RFSV_SENDLEN)?RFSV_SENDLEN:(len - count);
- if (l > 0) {
- bufferStore a;
- bufferStore tmp(p, l);
- a.addDWord(handle);
- a.addBuff(tmp);
- if (!sendCommand(WRITE_FILE, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
- count += l;
- p += l;
- }
- } while ((count < len) && (l > 0));
- return res;
+ Enum<rfsv::errs> res;
+ const unsigned char *p = buf;
+ long l;
+
+ count = 0;
+ do {
+ l = ((len - count) > RFSV_SENDLEN)?RFSV_SENDLEN:(len - count);
+ if (l > 0) {
+ bufferStore a;
+ bufferStore tmp(p, l);
+ a.addDWord(handle);
+ a.addBuff(tmp);
+ if (!sendCommand(WRITE_FILE, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE)
+ return res;
+ count += l;
+ p += l;
+ }
+ } while ((count < len) && (l > 0));
+ return res;
}
Enum<rfsv::errs> rfsv32::
copyFromPsion(const char *from, const char *to, void *ptr, cpCallback_t cb)
{
- Enum<rfsv::errs> res;
- u_int32_t handle;
- u_int32_t len;
- u_int32_t total = 0;
+ Enum<rfsv::errs> res;
+ u_int32_t handle;
+ u_int32_t len;
+ u_int32_t total = 0;
- if ((res = fopen(EPOC_OMODE_SHARE_READERS | EPOC_OMODE_BINARY, from, handle)) != E_PSI_GEN_NONE)
- return res;
- ofstream op(to);
- if (!op) {
- fclose(handle);
- return E_PSI_GEN_FAIL;
- }
- unsigned char *buff = new unsigned char[RFSV_SENDLEN];
- do {
- if ((res = fread(handle, buff, RFSV_SENDLEN, len)) == E_PSI_GEN_NONE) {
- op.write(buff, len);
- total += len;
- if (cb && !cb(ptr, total))
- res = E_PSI_FILE_CANCEL;
- }
- } while ((len > 0) && (res == E_PSI_GEN_NONE));
- delete[]buff;
- fclose(handle);
- op.close();
+ if ((res = fopen(EPOC_OMODE_SHARE_READERS | EPOC_OMODE_BINARY, from, handle)) != E_PSI_GEN_NONE)
return res;
+ ofstream op(to);
+ if (!op) {
+ fclose(handle);
+ return E_PSI_GEN_FAIL;
+ }
+ unsigned char *buff = new unsigned char[RFSV_SENDLEN];
+ do {
+ if ((res = fread(handle, buff, RFSV_SENDLEN, len)) == E_PSI_GEN_NONE) {
+ op.write(buff, len);
+ total += len;
+ if (cb && !cb(ptr, total))
+ res = E_PSI_FILE_CANCEL;
+ }
+ } while ((len > 0) && (res == E_PSI_GEN_NONE));
+ delete[]buff;
+ fclose(handle);
+ op.close();
+ return res;
}
Enum<rfsv::errs> rfsv32::
copyToPsion(const char *from, const char *to, void *ptr, cpCallback_t cb)
{
- u_int32_t handle;
- Enum<rfsv::errs> res;
+ u_int32_t handle;
+ Enum<rfsv::errs> res;
- ifstream ip(from);
- if (!ip)
- return E_PSI_FILE_NXIST;
- res = fcreatefile(EPOC_OMODE_BINARY | EPOC_OMODE_SHARE_EXCLUSIVE | EPOC_OMODE_READ_WRITE, to, handle);
- if (res != E_PSI_GEN_NONE) {
- res = freplacefile(EPOC_OMODE_BINARY | EPOC_OMODE_SHARE_EXCLUSIVE | EPOC_OMODE_READ_WRITE, to, handle);
- if (res != E_PSI_GEN_NONE)
- return res;
- }
- unsigned char *buff = new unsigned char[RFSV_SENDLEN];
- u_int32_t total = 0;
- while (ip && !ip.eof() && (res == E_PSI_GEN_NONE)) {
- u_int32_t len;
- ip.read(buff, RFSV_SENDLEN);
- if ((res = fwrite(handle, buff, ip.gcount(), len)) == E_PSI_GEN_NONE) {
- total += len;
- if (cb && !cb(ptr, total))
- res = E_PSI_FILE_CANCEL;
- }
+ ifstream ip(from);
+ if (!ip)
+ return E_PSI_FILE_NXIST;
+ res = fcreatefile(EPOC_OMODE_BINARY | EPOC_OMODE_SHARE_EXCLUSIVE | EPOC_OMODE_READ_WRITE, to, handle);
+ if (res != E_PSI_GEN_NONE) {
+ res = freplacefile(EPOC_OMODE_BINARY | EPOC_OMODE_SHARE_EXCLUSIVE | EPOC_OMODE_READ_WRITE, to, handle);
+ if (res != E_PSI_GEN_NONE)
+ return res;
+ }
+ unsigned char *buff = new unsigned char[RFSV_SENDLEN];
+ u_int32_t total = 0;
+ while (ip && !ip.eof() && (res == E_PSI_GEN_NONE)) {
+ u_int32_t len;
+ ip.read(buff, RFSV_SENDLEN);
+ if ((res = fwrite(handle, buff, ip.gcount(), len)) == E_PSI_GEN_NONE) {
+ total += len;
+ if (cb && !cb(ptr, total))
+ res = E_PSI_FILE_CANCEL;
}
- fclose(handle);
- ip.close();
- delete[]buff;
- return res;
+ }
+ fclose(handle);
+ ip.close();
+ delete[]buff;
+ return res;
}
Enum<rfsv::errs> rfsv32::
copyOnPsion(const char *from, const char *to, void *ptr, cpCallback_t cb)
{
- u_int32_t handle_from;
- u_int32_t handle_to;
- PlpDirent from_e;
- Enum<rfsv::errs> res;
+ u_int32_t handle_from;
+ u_int32_t handle_to;
+ PlpDirent from_e;
+ Enum<rfsv::errs> res;
- 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)
- return res;
- res = fcreatefile(EPOC_OMODE_BINARY | EPOC_OMODE_SHARE_EXCLUSIVE | EPOC_OMODE_READ_WRITE, to, handle_to);
+ 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)
+ return res;
+ res = fcreatefile(EPOC_OMODE_BINARY | EPOC_OMODE_SHARE_EXCLUSIVE | EPOC_OMODE_READ_WRITE, to, handle_to);
+ if (res != E_PSI_GEN_NONE) {
+ res = freplacefile(EPOC_OMODE_BINARY | EPOC_OMODE_SHARE_EXCLUSIVE | EPOC_OMODE_READ_WRITE, to, handle_to);
if (res != E_PSI_GEN_NONE) {
- res = freplacefile(EPOC_OMODE_BINARY | EPOC_OMODE_SHARE_EXCLUSIVE | EPOC_OMODE_READ_WRITE, to, handle_to);
- if (res != E_PSI_GEN_NONE) {
- fclose(handle_from);
- return res;
- }
+ fclose(handle_from);
+ return res;
}
-
- u_int32_t total = 0;
- while (res == E_PSI_GEN_NONE) {
- bufferStore b;
- b.addDWord(RFSV_SENDLEN * 10);
- b.addDWord(handle_to);
- b.addDWord(handle_from);
- if (!sendCommand(READ_WRITE_FILE, b))
- return E_PSI_FILE_DISC;
- res = getResponse(b);
- if (res != E_PSI_GEN_NONE)
- break;
- if (b.getLen() != 4) {
- res = E_PSI_GEN_FAIL;
- break;
- }
- u_int32_t len = b.getDWord(0);
- total += len;
- if (cb && !cb(ptr, total))
- res = E_PSI_FILE_CANCEL;
- if (len != (RFSV_SENDLEN * 10))
- break;
- }
- fclose(handle_from);
- fclose(handle_to);
+ }
+
+ u_int32_t total = 0;
+ while (res == E_PSI_GEN_NONE) {
+ bufferStore b;
+ b.addDWord(RFSV_SENDLEN * 10);
+ b.addDWord(handle_to);
+ b.addDWord(handle_from);
+ if (!sendCommand(READ_WRITE_FILE, b))
+ return E_PSI_FILE_DISC;
+ res = getResponse(b);
if (res != E_PSI_GEN_NONE)
- remove(to);
- return res;
+ break;
+ if (b.getLen() != 4) {
+ res = E_PSI_GEN_FAIL;
+ break;
+ }
+ u_int32_t len = b.getDWord(0);
+ total += len;
+ if (cb && !cb(ptr, total))
+ res = E_PSI_FILE_CANCEL;
+ if (len != (RFSV_SENDLEN * 10))
+ break;
+ }
+ fclose(handle_from);
+ fclose(handle_to);
+ if (res != E_PSI_GEN_NONE)
+ remove(to);
+ return res;
}
Enum<rfsv::errs> rfsv32::
fsetsize(u_int32_t handle, u_int32_t size)
{
- bufferStore a;
- a.addDWord(handle);
- a.addDWord(size);
- if (!sendCommand(SET_SIZE, a))
- return E_PSI_FILE_DISC;
- return getResponse(a);
+ bufferStore a;
+ a.addDWord(handle);
+ a.addDWord(size);
+ if (!sendCommand(SET_SIZE, a))
+ return E_PSI_FILE_DISC;
+ return getResponse(a);
}
/*
@@ -603,15 +605,15 @@ fsetsize(u_int32_t handle, u_int32_t size)
Enum<rfsv::errs> rfsv32::
fseek(const u_int32_t handle, const int32_t pos, const u_int32_t mode, u_int32_t &resultpos)
{
- bufferStore a;
- Enum<rfsv::errs> res;
- u_int32_t savpos = 0;
- u_int32_t calcpos = 0;
- int32_t mypos = pos;
- u_int32_t realpos;
+ bufferStore a;
+ Enum<rfsv::errs> res;
+ u_int32_t savpos = 0;
+ u_int32_t calcpos = 0;
+ int32_t mypos = pos;
+ u_int32_t realpos;
/*
- seek-parameter for psion:
+ seek-parameter for psion:
dword position
dword handle
dword mode
@@ -621,218 +623,218 @@ fseek(const u_int32_t handle, const int32_t pos, const u_int32_t mode, u_int32_t
??no more?? 4 = sense recpos
??no more?? 5 = set recpos
??no more?? 6 = text-rewind
- */
+*/
- if ((mode < PSI_SEEK_SET) || (mode > PSI_SEEK_END))
- return E_PSI_GEN_ARG;
-
- if ((mode == PSI_SEEK_CUR) && (mypos >= 0)) {
- /* get and save current position */
- a.addDWord(0);
- a.addDWord(handle);
- a.addDWord(PSI_SEEK_CUR);
- if (!sendCommand(SEEK_FILE, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
- savpos = a.getDWord(0);
- if (mypos == 0) {
- resultpos = savpos;
- return res;
- }
- a.init();
- }
- if ((mode == PSI_SEEK_END) && (mypos >= 0)) {
- /* get and save end position */
- a.addDWord(0);
- a.addDWord(handle);
- a.addDWord(PSI_SEEK_END);
- if (!sendCommand(SEEK_FILE, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
- savpos = a.getDWord(0);
- if (mypos == 0) {
- resultpos = savpos;
- return res;
- }
- /* Expand file */
- a.init();
- a.addDWord(handle);
- a.addDWord(savpos + mypos);
- if (!sendCommand(SET_SIZE, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
- mypos = 0;
- a.init();
- }
- /* Now the real seek */
- a.addDWord(mypos);
+ if ((mode < PSI_SEEK_SET) || (mode > PSI_SEEK_END))
+ return E_PSI_GEN_ARG;
+
+ if ((mode == PSI_SEEK_CUR) && (mypos >= 0)) {
+ /* get and save current position */
+ a.addDWord(0);
a.addDWord(handle);
- a.addDWord(mode);
+ a.addDWord(PSI_SEEK_CUR);
if (!sendCommand(SEEK_FILE, a))
- return E_PSI_FILE_DISC;
+ return E_PSI_FILE_DISC;
if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
- realpos = a.getDWord(0);
- switch (mode) {
- case PSI_SEEK_SET:
- calcpos = mypos;
- break;
- case PSI_SEEK_CUR:
- calcpos = savpos + mypos;
- break;
- case PSI_SEEK_END:
- resultpos = realpos;
- return res;
- break;
+ return res;
+ savpos = a.getDWord(0);
+ if (mypos == 0) {
+ resultpos = savpos;
+ return res;
}
- if (calcpos > realpos) {
- /* Beyond end of file */
- a.init();
- a.addDWord(handle);
- a.addDWord(calcpos);
- if (!sendCommand(SET_SIZE, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
- a.addDWord(calcpos);
- a.addDWord(handle);
- a.addDWord(PSI_SEEK_SET);
- if (!sendCommand(SEEK_FILE, a))
- return E_PSI_FILE_DISC;
- if ((res = getResponse(a)) != E_PSI_GEN_NONE)
- return res;
- realpos = a.getDWord(0);
+ a.init();
+ }
+ if ((mode == PSI_SEEK_END) && (mypos >= 0)) {
+ /* get and save end position */
+ a.addDWord(0);
+ a.addDWord(handle);
+ a.addDWord(PSI_SEEK_END);
+ if (!sendCommand(SEEK_FILE, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE)
+ return res;
+ savpos = a.getDWord(0);
+ if (mypos == 0) {
+ resultpos = savpos;
+ return res;
}
- resultpos = realpos;
+ /* Expand file */
+ a.init();
+ a.addDWord(handle);
+ a.addDWord(savpos + mypos);
+ if (!sendCommand(SET_SIZE, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE)
+ return res;
+ mypos = 0;
+ a.init();
+ }
+ /* Now the real seek */
+ a.addDWord(mypos);
+ a.addDWord(handle);
+ a.addDWord(mode);
+ if (!sendCommand(SEEK_FILE, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE)
return res;
+ realpos = a.getDWord(0);
+ switch (mode) {
+ case PSI_SEEK_SET:
+ calcpos = mypos;
+ break;
+ case PSI_SEEK_CUR:
+ calcpos = savpos + mypos;
+ break;
+ case PSI_SEEK_END:
+ resultpos = realpos;
+ return res;
+ break;
+ }
+ if (calcpos > realpos) {
+ /* Beyond end of file */
+ a.init();
+ a.addDWord(handle);
+ a.addDWord(calcpos);
+ if (!sendCommand(SET_SIZE, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE)
+ return res;
+ a.addDWord(calcpos);
+ a.addDWord(handle);
+ a.addDWord(PSI_SEEK_SET);
+ if (!sendCommand(SEEK_FILE, a))
+ return E_PSI_FILE_DISC;
+ if ((res = getResponse(a)) != E_PSI_GEN_NONE)
+ return res;
+ realpos = a.getDWord(0);
+ }
+ resultpos = realpos;
+ return res;
}
Enum<rfsv::errs> rfsv32::
mkdir(const char *name)
{
- bufferStore a;
- 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);
+ bufferStore a;
+ 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);
}
Enum<rfsv::errs> rfsv32::
rmdir(const char *name)
{
- bufferStore a;
- 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);
+ bufferStore a;
+ 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);
}
Enum<rfsv::errs> rfsv32::
rename(const char *oldname, const char *newname)
{
- bufferStore a;
- 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);
+ bufferStore a;
+ 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);
}
Enum<rfsv::errs> rfsv32::
remove(const char *name)
{
- bufferStore a;
- 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);
+ bufferStore a;
+ 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);
}
Enum<rfsv::errs> rfsv32::
setVolumeName(const char drive , const char * const name)
{
- bufferStore a;
- a.addDWord(drive - 'A');
- a.addWord(strlen(name));
- a.addStringT(name);
- if (!sendCommand(SET_VOLUME_LABEL, a))
- return E_PSI_FILE_DISC;
- return getResponse(a);
+ bufferStore a;
+ a.addDWord(drive - 'A');
+ a.addWord(strlen(name));
+ a.addStringT(name);
+ if (!sendCommand(SET_VOLUME_LABEL, a))
+ return E_PSI_FILE_DISC;
+ return getResponse(a);
}
static enum rfsv::errs e2psi[] = {
- rfsv::E_PSI_FILE_DIRFULL, // -43
- rfsv::E_PSI_GEN_POWER, // -42
- rfsv::E_PSI_GEN_DIVIDE, // -41
- rfsv::E_PSI_FILE_TOOBIG, // -40
- rfsv::E_PSI_FILE_ABORT, // -39
- rfsv::E_PSI_GEN_DESCR, // -38
- rfsv::E_PSI_GEN_LIB, // -37
- rfsv::E_PSI_FILE_NDISC, // -36
- rfsv::E_PSI_FILE_DISC, // -35
- rfsv::E_PSI_FILE_CONNECT, // -34
- rfsv::E_PSI_FILE_RETRAN, // -33
- rfsv::E_PSI_FILE_PARITY, // -32
- rfsv::E_PSI_FILE_OVERRUN, // -31
- rfsv::E_PSI_FILE_FRAME, // -30
- rfsv::E_PSI_FILE_LINE, // -29
- rfsv::E_PSI_FILE_NAME, // -28
- rfsv::E_PSI_FILE_DRIVER, // -27
- rfsv::E_PSI_FILE_FULL, // -26
- rfsv::E_PSI_FILE_EOF, // -25
- rfsv::E_PSI_GEN_FSYS, // -24
- rfsv::E_PSI_FILE_WRITE, // -23
- rfsv::E_PSI_FILE_LOCKED, // -22
- rfsv::E_PSI_FILE_ACCESS, // -21
- rfsv::E_PSI_FILE_CORRUPT, // -20
- rfsv::E_PSI_FILE_UNKNOWN, // -19
- rfsv::E_PSI_FILE_NOTREADY, // -18
- rfsv::E_PSI_FILE_COMPLETION, // -17
- rfsv::E_PSI_GEN_BUSY, // -16
- rfsv::E_PSI_GEN_TERMINATED, // -15
- rfsv::E_PSI_GEN_INUSE, // -14
- rfsv::E_PSI_GEN_DIED, // -13
- rfsv::E_PSI_FILE_DIR, // -12
- rfsv::E_PSI_FILE_EXIST, // -11
- rfsv::E_PSI_GEN_UNDER, // -10
- rfsv::E_PSI_GEN_OVER, // -9
- rfsv::E_PSI_FILE_HANDLE, // -8
- rfsv::E_PSI_GEN_RANGE, // -7
- rfsv::E_PSI_GEN_ARG, // -6
- rfsv::E_PSI_GEN_NSUP, // -5
- rfsv::E_PSI_GEN_NOMEMORY, // -4
- rfsv::E_PSI_FILE_CANCEL, // -3
- rfsv::E_PSI_GEN_FAIL, // -2
- rfsv::E_PSI_FILE_NXIST, // -1
- rfsv::E_PSI_GEN_NONE // 0
+ rfsv::E_PSI_FILE_DIRFULL, // -43
+ rfsv::E_PSI_GEN_POWER, // -42
+ rfsv::E_PSI_GEN_DIVIDE, // -41
+ rfsv::E_PSI_FILE_TOOBIG, // -40
+ rfsv::E_PSI_FILE_ABORT, // -39
+ rfsv::E_PSI_GEN_DESCR, // -38
+ rfsv::E_PSI_GEN_LIB, // -37
+ rfsv::E_PSI_FILE_NDISC, // -36
+ rfsv::E_PSI_FILE_DISC, // -35
+ rfsv::E_PSI_FILE_CONNECT, // -34
+ rfsv::E_PSI_FILE_RETRAN, // -33
+ rfsv::E_PSI_FILE_PARITY, // -32
+ rfsv::E_PSI_FILE_OVERRUN, // -31
+ rfsv::E_PSI_FILE_FRAME, // -30
+ rfsv::E_PSI_FILE_LINE, // -29
+ rfsv::E_PSI_FILE_NAME, // -28
+ rfsv::E_PSI_FILE_DRIVER, // -27
+ rfsv::E_PSI_FILE_FULL, // -26
+ rfsv::E_PSI_FILE_EOF, // -25
+ rfsv::E_PSI_GEN_FSYS, // -24
+ rfsv::E_PSI_FILE_WRITE, // -23
+ rfsv::E_PSI_FILE_LOCKED, // -22
+ rfsv::E_PSI_FILE_ACCESS, // -21
+ rfsv::E_PSI_FILE_CORRUPT, // -20
+ rfsv::E_PSI_FILE_UNKNOWN, // -19
+ rfsv::E_PSI_FILE_NOTREADY, // -18
+ rfsv::E_PSI_FILE_COMPLETION, // -17
+ rfsv::E_PSI_GEN_BUSY, // -16
+ rfsv::E_PSI_GEN_TERMINATED, // -15
+ rfsv::E_PSI_GEN_INUSE, // -14
+ rfsv::E_PSI_GEN_DIED, // -13
+ rfsv::E_PSI_FILE_DIR, // -12
+ rfsv::E_PSI_FILE_EXIST, // -11
+ rfsv::E_PSI_GEN_UNDER, // -10
+ rfsv::E_PSI_GEN_OVER, // -9
+ rfsv::E_PSI_FILE_HANDLE, // -8
+ rfsv::E_PSI_GEN_RANGE, // -7
+ rfsv::E_PSI_GEN_ARG, // -6
+ rfsv::E_PSI_GEN_NSUP, // -5
+ rfsv::E_PSI_GEN_NOMEMORY, // -4
+ rfsv::E_PSI_FILE_CANCEL, // -3
+ rfsv::E_PSI_GEN_FAIL, // -2
+ rfsv::E_PSI_FILE_NXIST, // -1
+ rfsv::E_PSI_GEN_NONE // 0
};
Enum<rfsv::errs> rfsv32::
err2psierr(int32_t status)
{
- if ((status > E_EPOC_NONE) || (status < E_EPOC_DIR_FULL)) {
- cerr << "FATAL: inavlid error-code" << endl;
- cerr << "status: " << status << " " << hex << status << endl;
- return E_PSI_INTERNAL;
- }
- return e2psi[status - E_EPOC_DIR_FULL];
+ if ((status > E_EPOC_NONE) || (status < E_EPOC_DIR_FULL)) {
+ cerr << "FATAL: inavlid error-code" << endl;
+ cerr << "status: " << status << " " << hex << status << endl;
+ return E_PSI_INTERNAL;
+ }
+ return e2psi[status - E_EPOC_DIR_FULL];
}
@@ -842,34 +844,34 @@ err2psierr(int32_t status)
u_int32_t rfsv32::
attr2std(const u_int32_t attr)
{
- long res = 0;
-
- // Common attributes
- if (attr & EPOC_ATTR_RONLY)
- res |= PSI_A_RDONLY;
- if (attr & EPOC_ATTR_HIDDEN)
- res |= PSI_A_HIDDEN;
- if (attr & EPOC_ATTR_SYSTEM)
- res |= PSI_A_SYSTEM;
- if (attr & EPOC_ATTR_DIRECTORY)
- res |= PSI_A_DIR;
- if (attr & EPOC_ATTR_ARCHIVE)
- res |= PSI_A_ARCHIVE;
- if (attr & EPOC_ATTR_VOLUME)
- res |= PSI_A_VOLUME;
-
- // EPOC-specific
- if (attr & EPOC_ATTR_NORMAL)
- res |= PSI_A_NORMAL;
- if (attr & EPOC_ATTR_TEMPORARY)
- res |= PSI_A_TEMP;
- if (attr & EPOC_ATTR_COMPRESSED)
- res |= PSI_A_COMPRESSED;
-
- // Do what we can for SIBO
- res |= PSI_A_READ;
+ long res = 0;
- return res;
+ // Common attributes
+ if (attr & EPOC_ATTR_RONLY)
+ res |= PSI_A_RDONLY;
+ if (attr & EPOC_ATTR_HIDDEN)
+ res |= PSI_A_HIDDEN;
+ if (attr & EPOC_ATTR_SYSTEM)
+ res |= PSI_A_SYSTEM;
+ if (attr & EPOC_ATTR_DIRECTORY)
+ res |= PSI_A_DIR;
+ if (attr & EPOC_ATTR_ARCHIVE)
+ res |= PSI_A_ARCHIVE;
+ if (attr & EPOC_ATTR_VOLUME)
+ res |= PSI_A_VOLUME;
+
+ // EPOC-specific
+ if (attr & EPOC_ATTR_NORMAL)
+ res |= PSI_A_NORMAL;
+ if (attr & EPOC_ATTR_TEMPORARY)
+ res |= PSI_A_TEMP;
+ if (attr & EPOC_ATTR_COMPRESSED)
+ res |= PSI_A_COMPRESSED;
+
+ // Do what we can for SIBO
+ res |= PSI_A_READ;
+
+ return res;
}
/*
@@ -878,28 +880,34 @@ attr2std(const u_int32_t attr)
u_int32_t rfsv32::
std2attr(const u_int32_t attr)
{
- long res = 0;
- // Common attributes
- if (attr & PSI_A_RDONLY)
- res |= EPOC_ATTR_RONLY;
- if (attr & PSI_A_HIDDEN)
- res |= EPOC_ATTR_HIDDEN;
- if (attr & PSI_A_SYSTEM)
- res |= EPOC_ATTR_SYSTEM;
- if (attr & PSI_A_DIR)
- res |= EPOC_ATTR_DIRECTORY;
- if (attr & PSI_A_ARCHIVE)
- res |= EPOC_ATTR_ARCHIVE;
- if (attr & PSI_A_VOLUME)
- res |= EPOC_ATTR_VOLUME;
-
- // EPOC-specific
- if (attr & PSI_A_NORMAL)
- res |= EPOC_ATTR_NORMAL;
- if (attr & PSI_A_TEMP)
- res |= EPOC_ATTR_TEMPORARY;
- if (attr & PSI_A_COMPRESSED)
- res |= EPOC_ATTR_COMPRESSED;
-
- return res;
+ long res = 0;
+ // Common attributes
+ if (attr & PSI_A_RDONLY)
+ res |= EPOC_ATTR_RONLY;
+ if (attr & PSI_A_HIDDEN)
+ res |= EPOC_ATTR_HIDDEN;
+ if (attr & PSI_A_SYSTEM)
+ res |= EPOC_ATTR_SYSTEM;
+ if (attr & PSI_A_DIR)
+ res |= EPOC_ATTR_DIRECTORY;
+ if (attr & PSI_A_ARCHIVE)
+ res |= EPOC_ATTR_ARCHIVE;
+ if (attr & PSI_A_VOLUME)
+ res |= EPOC_ATTR_VOLUME;
+
+ // EPOC-specific
+ if (attr & PSI_A_NORMAL)
+ res |= EPOC_ATTR_NORMAL;
+ if (attr & PSI_A_TEMP)
+ res |= EPOC_ATTR_TEMPORARY;
+ if (attr & PSI_A_COMPRESSED)
+ res |= EPOC_ATTR_COMPRESSED;
+
+ return res;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rfsv32.h b/lib/rfsv32.h
index 4afb95a..9baefaa 100644
--- a/lib/rfsv32.h
+++ b/lib/rfsv32.h
@@ -1,5 +1,29 @@
-#ifndef _rfsv32_h_
-#define _rfsv32_h_
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _RFSV32_H_
+#define _RFSV32_H_
#include "rfsv.h"
#include "plpdirent.h"
@@ -14,165 +38,175 @@ class rfsvfactory;
* @ref rfsv . For a complete documentation, see @ref rfsv .
*/
class rfsv32 : public rfsv {
- friend rfsvfactory;
+
+ /**
+ * rfsvfactory may call our constructor.
+ */
+ friend rfsvfactory;
public:
- Enum<rfsv::errs> dir(const char * const, PlpDir &);
- Enum<rfsv::errs> dircount(const char * const, u_int32_t &);
- Enum<rfsv::errs> copyFromPsion(const char * const, const char * const, void *, cpCallback_t);
- Enum<rfsv::errs> copyToPsion(const char * const, const char * const, void *, cpCallback_t);
- Enum<rfsv::errs> copyOnPsion(const char * const, const char * const, void *, cpCallback_t);
- Enum<rfsv::errs> mkdir(const char * const);
- Enum<rfsv::errs> rmdir(const char * const);
- Enum<rfsv::errs> remove(const char * const);
- Enum<rfsv::errs> rename(const char * const, const char * const);
- Enum<rfsv::errs> mktemp(u_int32_t &, string &);
- Enum<rfsv::errs> fgeteattr(const char * const, PlpDirent &);
- Enum<rfsv::errs> fgetattr(const char * const, u_int32_t &);
- Enum<rfsv::errs> fsetattr(const char * const, const u_int32_t, const u_int32_t);
- Enum<rfsv::errs> fgetmtime(const char * const, PsiTime &);
- Enum<rfsv::errs> fsetmtime(const char * const, PsiTime const);
- Enum<rfsv::errs> fopen(const u_int32_t, const char * const, u_int32_t &);
- Enum<rfsv::errs> fcreatefile(const u_int32_t, const char * const, u_int32_t &);
- Enum<rfsv::errs> freplacefile(const u_int32_t, const char * const, u_int32_t &);
- Enum<rfsv::errs> fseek(const u_int32_t, const int32_t, const u_int32_t, u_int32_t &);
- Enum<rfsv::errs> fread(const u_int32_t, unsigned char * const, const u_int32_t, u_int32_t &);
- Enum<rfsv::errs> fwrite(const u_int32_t, const unsigned char * const, const u_int32_t, u_int32_t &);
- Enum<rfsv::errs> fsetsize(u_int32_t, u_int32_t);
- Enum<rfsv::errs> fclose(const u_int32_t);
-
- Enum<rfsv::errs> devlist(u_int32_t &);
- Enum<rfsv::errs> devinfo(const u_int32_t, PlpDrive&);
- Enum<rfsv::errs> opendir(const u_int32_t, const char * const, rfsvDirhandle &);
- Enum<rfsv::errs> readdir(rfsvDirhandle &, PlpDirent &);
- Enum<rfsv::errs> closedir(rfsvDirhandle &);
- Enum<rfsv::errs> setVolumeName(const char, const char * const);
- u_int32_t opMode(const u_int32_t);
+ Enum<rfsv::errs> dir(const char * const, PlpDir &);
+ Enum<rfsv::errs> dircount(const char * const, u_int32_t &);
+ Enum<rfsv::errs> copyFromPsion(const char * const, const char * const, void *, cpCallback_t);
+ Enum<rfsv::errs> copyToPsion(const char * const, const char * const, void *, cpCallback_t);
+ Enum<rfsv::errs> copyOnPsion(const char * const, const char * const, void *, cpCallback_t);
+ Enum<rfsv::errs> mkdir(const char * const);
+ Enum<rfsv::errs> rmdir(const char * const);
+ Enum<rfsv::errs> remove(const char * const);
+ Enum<rfsv::errs> rename(const char * const, const char * const);
+ Enum<rfsv::errs> mktemp(u_int32_t &, string &);
+ Enum<rfsv::errs> fgeteattr(const char * const, PlpDirent &);
+ Enum<rfsv::errs> fgetattr(const char * const, u_int32_t &);
+ Enum<rfsv::errs> fsetattr(const char * const, const u_int32_t, const u_int32_t);
+ Enum<rfsv::errs> fgetmtime(const char * const, PsiTime &);
+ Enum<rfsv::errs> fsetmtime(const char * const, PsiTime const);
+ Enum<rfsv::errs> fopen(const u_int32_t, const char * const, u_int32_t &);
+ Enum<rfsv::errs> fcreatefile(const u_int32_t, const char * const, u_int32_t &);
+ Enum<rfsv::errs> freplacefile(const u_int32_t, const char * const, u_int32_t &);
+ Enum<rfsv::errs> fseek(const u_int32_t, const int32_t, const u_int32_t, u_int32_t &);
+ Enum<rfsv::errs> fread(const u_int32_t, unsigned char * const, const u_int32_t, u_int32_t &);
+ Enum<rfsv::errs> fwrite(const u_int32_t, const unsigned char * const, const u_int32_t, u_int32_t &);
+ Enum<rfsv::errs> fsetsize(u_int32_t, u_int32_t);
+ Enum<rfsv::errs> fclose(const u_int32_t);
+
+ Enum<rfsv::errs> devlist(u_int32_t &);
+ Enum<rfsv::errs> devinfo(const u_int32_t, PlpDrive&);
+ Enum<rfsv::errs> opendir(const u_int32_t, const char * const, rfsvDirhandle &);
+ Enum<rfsv::errs> readdir(rfsvDirhandle &, PlpDirent &);
+ Enum<rfsv::errs> closedir(rfsvDirhandle &);
+ Enum<rfsv::errs> setVolumeName(const char, const char * const);
+ u_int32_t opMode(const u_int32_t);
private:
- enum file_attrib {
- EPOC_ATTR_RONLY = 0x0001,
- EPOC_ATTR_HIDDEN = 0x0002,
- EPOC_ATTR_SYSTEM = 0x0004,
- EPOC_ATTR_DIRECTORY = 0x0010,
- EPOC_ATTR_ARCHIVE = 0x0020,
- EPOC_ATTR_VOLUME = 0x0040,
- EPOC_ATTR_NORMAL = 0x0080,
- EPOC_ATTR_TEMPORARY = 0x0100,
- EPOC_ATTR_COMPRESSED = 0x0800,
- EPOC_ATTR_MASK = 0x09f7, /* All of the above */
- EPOC_ATTR_GETUID = 0x10000000 /* Deliver UIDs on dir listing */
- };
-
- enum open_mode {
- EPOC_OMODE_SHARE_EXCLUSIVE = 0x0000,
- EPOC_OMODE_SHARE_READERS = 0x0001,
- EPOC_OMODE_SHARE_ANY = 0x0002,
- EPOC_OMODE_BINARY = 0x0000,
- EPOC_OMODE_TEXT = 0x0020,
- EPOC_OMODE_READ_WRITE = 0x0200
- };
-
- enum epoc_errs {
- E_EPOC_NONE = 0,
- E_EPOC_NOT_FOUND = -1,
- E_EPOC_GENERAL = -2,
- E_EPOC_CANCEL = -3,
- E_EPOC_NO_MEMORY = -4,
- E_EPOC_NOT_SUPPORTED = -5,
- E_EPOC_ARGUMENT = -6,
- E_EPOC_TOTAL_LOSS_OF_PRECISION = -7,
- E_EPOC_BAD_HANDLE = -8,
- E_EPOC_OVERFLOW = -9,
- E_EPOC_UNDERFLOW = -10,
- E_EPOC_ALREADY_EXISTS = -11,
- E_EPOC_PATH_NOT_FOUND = -12,
- E_EPOC_DIED = -13,
- E_EPOC_IN_USE = -14,
- E_EPOC_SERVER_TERMINATED = -15,
- E_EPOC_SERVER_BUSY = -16,
- E_EPOC_COMPLETION = -17,
- E_EPOC_NOT_READY = -18,
- E_EPOC_UNKNOWN = -19,
- E_EPOC_CORRUPT = -20,
- E_EPOC_ACCESS_DENIED = -21,
- E_EPOC_LOCKED = -22,
- E_EPOC_WRITE = -23,
- E_EPOC_DISMOUNTED = -24,
- E_EPOC_EoF = -25,
- E_EPOC_DISK_FULL = -26,
- E_EPOC_BAD_DRIVER = -27,
- E_EPOC_BAD_NAME = -28,
- E_EPOC_COMMS_LINE_FAIL = -29,
- E_EPOC_COMMS_FRAME = -30,
- E_EPOC_COMMS_OVERRUN = -31,
- E_EPOC_COMMS_PARITY = -32,
- E_EPOC_TIMEOUT = -33,
- E_EPOC_COULD_NOT_CONNECT = -34,
- E_EPOC_COULD_NOT_DISCONNECT = -35,
- E_EPOC_DISCONNECTED = -36,
- E_EPOC_BAD_LIBRARY_ENTRY_POINT = -37,
- E_EPOC_BAD_DESCRIPTOR = -38,
- E_EPOC_ABORT = -39,
- E_EPOC_TOO_BIG = -40,
- E_EPOC_DIVIDE_BY_ZERO = -41,
- E_EPOC_BAD_POWER = -42,
- E_EPOC_DIR_FULL = -43
- };
-
- enum commands {
- CLOSE_HANDLE = 0x01,
- OPEN_DIR = 0x10,
- READ_DIR = 0x12,
- GET_DRIVE_LIST = 0x13,
- DRIVE_INFO = 0x14,
- SET_VOLUME_LABEL = 0x15,
- OPEN_FILE = 0x16,
- TEMP_FILE = 0x17,
- READ_FILE = 0x18,
- WRITE_FILE = 0x19,
- SEEK_FILE = 0x1a,
- DELETE = 0x1b,
- REMOTE_ENTRY = 0x1c,
- FLUSH = 0x1d,
- SET_SIZE = 0x1e,
- RENAME = 0x1f,
- MK_DIR_ALL = 0x20,
- RM_DIR = 0x21,
- SET_ATT = 0x22,
- ATT = 0x23,
- SET_MODIFIED = 0x24,
- MODIFIED = 0x25,
- SET_SESSION_PATH = 0x26,
- SESSION_PATH = 0x27,
- READ_WRITE_FILE = 0x28,
- CREATE_FILE = 0x29,
- REPLACE_FILE = 0x2a,
- PATH_TEST = 0x2b,
- LOCK = 0x2d,
- UNLOCK = 0x2e,
- OPEN_DIR_UID = 0x2f,
- DRIVE_NAME = 0x30,
- SET_DRIVE_NAME = 0x31,
- REPLACE = 0x32
- };
-
- /**
- * Private constructor. Shall be called by
- * rfsvfactory only.
- */
- rfsv32(ppsocket *);
-
- Enum<rfsv::errs> err2psierr(int32_t);
- Enum<rfsv::errs> fopendir(const u_int32_t, const char *, u_int32_t &);
- u_int32_t attr2std(const u_int32_t);
- u_int32_t std2attr(const u_int32_t);
-
-
- // Communication
- bool sendCommand(enum commands, bufferStore &);
- Enum<rfsv::errs> getResponse(bufferStore &);
+ enum file_attrib {
+ EPOC_ATTR_RONLY = 0x0001,
+ EPOC_ATTR_HIDDEN = 0x0002,
+ EPOC_ATTR_SYSTEM = 0x0004,
+ EPOC_ATTR_DIRECTORY = 0x0010,
+ EPOC_ATTR_ARCHIVE = 0x0020,
+ EPOC_ATTR_VOLUME = 0x0040,
+ EPOC_ATTR_NORMAL = 0x0080,
+ EPOC_ATTR_TEMPORARY = 0x0100,
+ EPOC_ATTR_COMPRESSED = 0x0800,
+ EPOC_ATTR_MASK = 0x09f7, /* All of the above */
+ EPOC_ATTR_GETUID = 0x10000000 /* Deliver UIDs on dir listing */
+ };
+
+ enum open_mode {
+ EPOC_OMODE_SHARE_EXCLUSIVE = 0x0000,
+ EPOC_OMODE_SHARE_READERS = 0x0001,
+ EPOC_OMODE_SHARE_ANY = 0x0002,
+ EPOC_OMODE_BINARY = 0x0000,
+ EPOC_OMODE_TEXT = 0x0020,
+ EPOC_OMODE_READ_WRITE = 0x0200
+ };
+
+ enum epoc_errs {
+ E_EPOC_NONE = 0,
+ E_EPOC_NOT_FOUND = -1,
+ E_EPOC_GENERAL = -2,
+ E_EPOC_CANCEL = -3,
+ E_EPOC_NO_MEMORY = -4,
+ E_EPOC_NOT_SUPPORTED = -5,
+ E_EPOC_ARGUMENT = -6,
+ E_EPOC_TOTAL_LOSS_OF_PRECISION = -7,
+ E_EPOC_BAD_HANDLE = -8,
+ E_EPOC_OVERFLOW = -9,
+ E_EPOC_UNDERFLOW = -10,
+ E_EPOC_ALREADY_EXISTS = -11,
+ E_EPOC_PATH_NOT_FOUND = -12,
+ E_EPOC_DIED = -13,
+ E_EPOC_IN_USE = -14,
+ E_EPOC_SERVER_TERMINATED = -15,
+ E_EPOC_SERVER_BUSY = -16,
+ E_EPOC_COMPLETION = -17,
+ E_EPOC_NOT_READY = -18,
+ E_EPOC_UNKNOWN = -19,
+ E_EPOC_CORRUPT = -20,
+ E_EPOC_ACCESS_DENIED = -21,
+ E_EPOC_LOCKED = -22,
+ E_EPOC_WRITE = -23,
+ E_EPOC_DISMOUNTED = -24,
+ E_EPOC_EoF = -25,
+ E_EPOC_DISK_FULL = -26,
+ E_EPOC_BAD_DRIVER = -27,
+ E_EPOC_BAD_NAME = -28,
+ E_EPOC_COMMS_LINE_FAIL = -29,
+ E_EPOC_COMMS_FRAME = -30,
+ E_EPOC_COMMS_OVERRUN = -31,
+ E_EPOC_COMMS_PARITY = -32,
+ E_EPOC_TIMEOUT = -33,
+ E_EPOC_COULD_NOT_CONNECT = -34,
+ E_EPOC_COULD_NOT_DISCONNECT = -35,
+ E_EPOC_DISCONNECTED = -36,
+ E_EPOC_BAD_LIBRARY_ENTRY_POINT = -37,
+ E_EPOC_BAD_DESCRIPTOR = -38,
+ E_EPOC_ABORT = -39,
+ E_EPOC_TOO_BIG = -40,
+ E_EPOC_DIVIDE_BY_ZERO = -41,
+ E_EPOC_BAD_POWER = -42,
+ E_EPOC_DIR_FULL = -43
+ };
+
+ enum commands {
+ CLOSE_HANDLE = 0x01,
+ OPEN_DIR = 0x10,
+ READ_DIR = 0x12,
+ GET_DRIVE_LIST = 0x13,
+ DRIVE_INFO = 0x14,
+ SET_VOLUME_LABEL = 0x15,
+ OPEN_FILE = 0x16,
+ TEMP_FILE = 0x17,
+ READ_FILE = 0x18,
+ WRITE_FILE = 0x19,
+ SEEK_FILE = 0x1a,
+ DELETE = 0x1b,
+ REMOTE_ENTRY = 0x1c,
+ FLUSH = 0x1d,
+ SET_SIZE = 0x1e,
+ RENAME = 0x1f,
+ MK_DIR_ALL = 0x20,
+ RM_DIR = 0x21,
+ SET_ATT = 0x22,
+ ATT = 0x23,
+ SET_MODIFIED = 0x24,
+ MODIFIED = 0x25,
+ SET_SESSION_PATH = 0x26,
+ SESSION_PATH = 0x27,
+ READ_WRITE_FILE = 0x28,
+ CREATE_FILE = 0x29,
+ REPLACE_FILE = 0x2a,
+ PATH_TEST = 0x2b,
+ LOCK = 0x2d,
+ UNLOCK = 0x2e,
+ OPEN_DIR_UID = 0x2f,
+ DRIVE_NAME = 0x30,
+ SET_DRIVE_NAME = 0x31,
+ REPLACE = 0x32
+ };
+
+ /**
+ * Private constructor. Shall be called by
+ * rfsvfactory only.
+ */
+ rfsv32(ppsocket *);
+
+ Enum<rfsv::errs> err2psierr(int32_t);
+ Enum<rfsv::errs> fopendir(const u_int32_t, const char *, u_int32_t &);
+ u_int32_t attr2std(const u_int32_t);
+ u_int32_t std2attr(const u_int32_t);
+
+
+ // Communication
+ bool sendCommand(enum commands, bufferStore &);
+ Enum<rfsv::errs> getResponse(bufferStore &);
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rfsvfactory.cc b/lib/rfsvfactory.cc
index 3699903..3a142da 100644
--- a/lib/rfsvfactory.cc
+++ b/lib/rfsvfactory.cc
@@ -1,23 +1,25 @@
-//
-// RFSVFACTORY - factory object that creates an appropriate RFSV object
-// based on whatever the NCP daemon discovered in the INFO exchange.
-//
-// Copyright (C) 1999 Matt J. Gumbley <matt@gumbley.demon.co.uk>
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Matt J. Gumbley <matt@gumbley.demon.co.uk>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -38,62 +40,68 @@
#include "Enum.h"
ENUM_DEFINITION(rfsvfactory::errs, rfsvfactory::FACERR_NONE) {
- stringRep.add(rfsvfactory::FACERR_NONE, "no error");
- stringRep.add(rfsvfactory::FACERR_COULD_NOT_SEND, "could not send version request");
- stringRep.add(rfsvfactory::FACERR_AGAIN, "try again");
- stringRep.add(rfsvfactory::FACERR_NOPSION, "no psion connected");
- stringRep.add(rfsvfactory::FACERR_PROTVERSION, "wrong protocol version");
- stringRep.add(rfsvfactory::FACERR_NORESPONSE, "no response from ncpd");
+ stringRep.add(rfsvfactory::FACERR_NONE, N_("no error"));
+ stringRep.add(rfsvfactory::FACERR_COULD_NOT_SEND, N_("could not send version request"));
+ stringRep.add(rfsvfactory::FACERR_AGAIN, N_("try again"));
+ stringRep.add(rfsvfactory::FACERR_NOPSION, N_("no psion connected"));
+ stringRep.add(rfsvfactory::FACERR_PROTVERSION, N_("wrong protocol version"));
+ stringRep.add(rfsvfactory::FACERR_NORESPONSE, N_("no response from ncpd"));
}
rfsvfactory::rfsvfactory(ppsocket *_skt) : serNum(0)
{
- err = FACERR_NONE;
- skt = _skt;
+ err = FACERR_NONE;
+ skt = _skt;
}
rfsv * rfsvfactory::create(bool reconnect)
{
- // skt is connected to the ncp daemon, which will have (hopefully) seen
- // an INFO exchange, where the protocol version of the remote Psion was
- // sent, and noted. We have to ask the ncp daemon which protocol it saw,
- // so we can instantiate the correct RFSV protocol handler for the
- // caller. We announce ourselves to the NCP daemon, and the relevant
- // RFSV module will also announce itself.
+ // skt is connected to the ncp daemon, which will have (hopefully) seen
+ // an INFO exchange, where the protocol version of the remote Psion was
+ // sent, and noted. We have to ask the ncp daemon which protocol it saw,
+ // so we can instantiate the correct RFSV protocol handler for the
+ // caller. We announce ourselves to the NCP daemon, and the relevant
+ // RFSV module will also announce itself.
- bufferStore a;
+ bufferStore a;
- err = FACERR_NONE;
- a.addStringT("NCP$INFO");
- if (!skt->sendBufferStore(a)) {
- if (!reconnect)
- err = FACERR_COULD_NOT_SEND;
- else {
- skt->closeSocket();
- serNum = 0;
- skt->reconnect();
- err = FACERR_AGAIN;
- }
- return NULL;
+ err = FACERR_NONE;
+ a.addStringT("NCP$INFO");
+ if (!skt->sendBufferStore(a)) {
+ if (!reconnect)
+ err = FACERR_COULD_NOT_SEND;
+ else {
+ skt->closeSocket();
+ serNum = 0;
+ skt->reconnect();
+ err = FACERR_AGAIN;
}
- if (skt->getBufferStore(a) == 1) {
- if (a.getLen() > 8 && !strncmp(a.getString(), "Series 3", 8)) {
- return new rfsv16(skt);
- }
- else if (a.getLen() > 8 && !strncmp(a.getString(), "Series 5", 8)) {
- return new rfsv32(skt);
- }
- if ((a.getLen() > 8) && !strncmp(a.getString(), "No Psion", 8)) {
- skt->closeSocket();
- serNum = 0;
- skt->reconnect();
- err = FACERR_NOPSION;
- return NULL;
- }
- // Invalid protocol version
- err = FACERR_PROTVERSION;
- } else
- err = FACERR_NORESPONSE;
-
return NULL;
+ }
+ if (skt->getBufferStore(a) == 1) {
+ if (a.getLen() > 8 && !strncmp(a.getString(), "Series 3", 8)) {
+ return new rfsv16(skt);
+ }
+ else if (a.getLen() > 8 && !strncmp(a.getString(), "Series 5", 8)) {
+ return new rfsv32(skt);
+ }
+ if ((a.getLen() > 8) && !strncmp(a.getString(), "No Psion", 8)) {
+ skt->closeSocket();
+ serNum = 0;
+ skt->reconnect();
+ err = FACERR_NOPSION;
+ return NULL;
+ }
+ // Invalid protocol version
+ err = FACERR_PROTVERSION;
+ } else
+ err = FACERR_NORESPONSE;
+
+ return NULL;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rfsvfactory.h b/lib/rfsvfactory.h
index 8af4575..04117fd 100644
--- a/lib/rfsvfactory.h
+++ b/lib/rfsvfactory.h
@@ -1,5 +1,29 @@
-#ifndef _rfsvfactory_h_
-#define _rfsvfactory_h_
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999 Matt J. Gumbley <matt@gumbley.demon.co.uk>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _RFSVFACTORY_H_
+#define _RFSVFACTORY_H_
#include "rfsv.h"
@@ -10,56 +34,62 @@ class ppsocket;
* @ref rfsv protocol variant depending on the connected Psion.
*/
class rfsvfactory {
-
- public:
- /**
- * The known errors which can happen during @ref create .
- */
- enum errs {
- FACERR_NONE = 0,
- FACERR_COULD_NOT_SEND = 1,
- FACERR_AGAIN = 2,
- FACERR_NOPSION = 3,
- FACERR_PROTVERSION = 4,
- FACERR_NORESPONSE = 5,
- };
- /**
- * Constructs a rfsvfactory.
- *
- * @param skt The socket to be used for connecting
- * to the ncpd daemon.
- */
- rfsvfactory(ppsocket * skt);
+public:
+ /**
+ * The known errors which can happen during @ref create .
+ */
+ enum errs {
+ FACERR_NONE = 0,
+ FACERR_COULD_NOT_SEND = 1,
+ FACERR_AGAIN = 2,
+ FACERR_NOPSION = 3,
+ FACERR_PROTVERSION = 4,
+ FACERR_NORESPONSE = 5,
+ };
+
+ /**
+ * Constructs a rfsvfactory.
+ *
+ * @param skt The socket to be used for connecting
+ * to the ncpd daemon.
+ */
+ rfsvfactory(ppsocket * skt);
- /**
- * Creates a new @ref rfsv instance.
- *
- * @param reconnect Set to true, if automatic reconnect
- * should be performed on failure.
- *
- * @returns A pointer to a newly created rfsv instance or
- * NULL on failure.
- */
- virtual rfsv * create(bool);
+ /**
+ * Creates a new @ref rfsv instance.
+ *
+ * @param reconnect Set to true, if automatic reconnect
+ * should be performed on failure.
+ *
+ * @returns A pointer to a newly created rfsv instance or
+ * NULL on failure.
+ */
+ virtual rfsv * create(bool);
- /**
- * Retrieve an error code.
- *
- * @returns The error code, in case @ref create has
- * failed, 0 otherwise.
- */
- virtual Enum<errs> getError() { return err; }
+ /**
+ * Retrieve an error code.
+ *
+ * @returns The error code, in case @ref create has
+ * failed, 0 otherwise.
+ */
+ virtual Enum<errs> getError() { return err; }
- private:
- /**
- * The socket to be used for connecting to the
- * ncpd daemon.
- */
- ppsocket *skt;
- int serNum;
- Enum<errs> err;
+private:
+ /**
+ * The socket to be used for connecting to the
+ * ncpd daemon.
+ */
+ ppsocket *skt;
+ int serNum;
+ Enum<errs> err;
};
#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
+
diff --git a/lib/rpcs.cc b/lib/rpcs.cc
index 837f235..2e1288d 100644
--- a/lib/rpcs.cc
+++ b/lib/rpcs.cc
@@ -1,19 +1,25 @@
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -32,56 +38,61 @@
#include "Enum.h"
ENUM_DEFINITION(rpcs::machs, rpcs::PSI_MACH_UNKNOWN) {
- stringRep.add(rpcs::PSI_MACH_UNKNOWN, "Unknown device");
- stringRep.add(rpcs::PSI_MACH_PC, "PC");
- stringRep.add(rpcs::PSI_MACH_MC, "MC");
- stringRep.add(rpcs::PSI_MACH_HC, "HC");
- stringRep.add(rpcs::PSI_MACH_S3, "Series 3");
- stringRep.add(rpcs::PSI_MACH_S3A, "Series 3a, 3c or 3mx");
- stringRep.add(rpcs::PSI_MACH_WORKABOUT, "Workabout");
- stringRep.add(rpcs::PSI_MACH_SIENNA, "Sienna");
- stringRep.add(rpcs::PSI_MACH_S3C, "Series 3c");
- stringRep.add(rpcs::PSI_MACH_S5, "Series 5");
- stringRep.add(rpcs::PSI_MACH_WINC, "WinC");
+ stringRep.add(rpcs::PSI_MACH_UNKNOWN, N_("Unknown device"));
+ stringRep.add(rpcs::PSI_MACH_PC, N_("PC"));
+ stringRep.add(rpcs::PSI_MACH_MC, N_("MC"));
+ stringRep.add(rpcs::PSI_MACH_HC, N_("HC"));
+ stringRep.add(rpcs::PSI_MACH_S3, N_("Series 3"));
+ stringRep.add(rpcs::PSI_MACH_S3A, N_("Series 3a, 3c or 3mx"));
+ stringRep.add(rpcs::PSI_MACH_WORKABOUT, N_("Workabout"));
+ stringRep.add(rpcs::PSI_MACH_SIENNA, N_("Sienna"));
+ stringRep.add(rpcs::PSI_MACH_S3C, N_("Series 3c"));
+ stringRep.add(rpcs::PSI_MACH_S5, N_("Series 5"));
+ stringRep.add(rpcs::PSI_MACH_WINC, N_("WinC"));
}
ENUM_DEFINITION(rpcs::batterystates, rpcs::PSI_BATT_DEAD) {
- stringRep.add(rpcs::PSI_BATT_DEAD, "Empty");
- stringRep.add(rpcs::PSI_BATT_VERYLOW, "Very Low");
- stringRep.add(rpcs::PSI_BATT_LOW, "Low");
- stringRep.add(rpcs::PSI_BATT_GOOD, "Good");
+ stringRep.add(rpcs::PSI_BATT_DEAD, N_("Empty"));
+ stringRep.add(rpcs::PSI_BATT_VERYLOW, N_("Very Low"));
+ stringRep.add(rpcs::PSI_BATT_LOW, N_("Low"));
+ stringRep.add(rpcs::PSI_BATT_GOOD, N_("Good"));
}
ENUM_DEFINITION(rpcs::languages, rpcs::PSI_LANG_TEST) {
- stringRep.add(rpcs::PSI_LANG_TEST, "Test");
- stringRep.add(rpcs::PSI_LANG_en_GB, "English");
- stringRep.add(rpcs::PSI_LANG_de_DE, "German");
- stringRep.add(rpcs::PSI_LANG_fr_FR, "French");
- stringRep.add(rpcs::PSI_LANG_es_ES, "Spanish");
- stringRep.add(rpcs::PSI_LANG_it_IT, "Italian");
- stringRep.add(rpcs::PSI_LANG_sv_SE, "Swedish");
- stringRep.add(rpcs::PSI_LANG_da_DK, "Danish");
- stringRep.add(rpcs::PSI_LANG_no_NO, "Norwegian");
- stringRep.add(rpcs::PSI_LANG_fi_FI, "Finnish");
- stringRep.add(rpcs::PSI_LANG_en_US, "American");
- stringRep.add(rpcs::PSI_LANG_fr_CH, "Swiss French");
- stringRep.add(rpcs::PSI_LANG_de_CH, "Swiss German");
- stringRep.add(rpcs::PSI_LANG_pt_PT, "Portugese");
- stringRep.add(rpcs::PSI_LANG_tr_TR, "Turkish");
- stringRep.add(rpcs::PSI_LANG_is_IS, "Icelandic");
- stringRep.add(rpcs::PSI_LANG_ru_RU, "Russian");
- stringRep.add(rpcs::PSI_LANG_hu_HU, "Hungarian");
- stringRep.add(rpcs::PSI_LANG_nl_NL, "Dutch");
- stringRep.add(rpcs::PSI_LANG_nl_BE, "Belgian Flemish");
- stringRep.add(rpcs::PSI_LANG_en_AU, "Australian");
- stringRep.add(rpcs::PSI_LANG_fr_BE, "Belgish French");
- stringRep.add(rpcs::PSI_LANG_de_AT, "Austrian");
- stringRep.add(rpcs::PSI_LANG_en_NZ, "New Zealand"); // FIXME: not shure about ISO code
- stringRep.add(rpcs::PSI_LANG_fr_CA, "International French"); // FIXME: not shure about ISO code
- stringRep.add(rpcs::PSI_LANG_cs_CZ, "Czech");
- stringRep.add(rpcs::PSI_LANG_sk_SK, "Slovak");
- stringRep.add(rpcs::PSI_LANG_pl_PL, "Polish");
- stringRep.add(rpcs::PSI_LANG_sl_SI, "Slovenian");
+ stringRep.add(rpcs::PSI_LANG_TEST, N_("Test"));
+ stringRep.add(rpcs::PSI_LANG_en_GB, N_("English"));
+ stringRep.add(rpcs::PSI_LANG_de_DE, N_("German"));
+ stringRep.add(rpcs::PSI_LANG_fr_FR, N_("French"));
+ stringRep.add(rpcs::PSI_LANG_es_ES, N_("Spanish"));
+ stringRep.add(rpcs::PSI_LANG_it_IT, N_("Italian"));
+ stringRep.add(rpcs::PSI_LANG_sv_SE, N_("Swedish"));
+ stringRep.add(rpcs::PSI_LANG_da_DK, N_("Danish"));
+ stringRep.add(rpcs::PSI_LANG_no_NO, N_("Norwegian"));
+ stringRep.add(rpcs::PSI_LANG_fi_FI, N_("Finnish"));
+ stringRep.add(rpcs::PSI_LANG_en_US, N_("American"));
+ stringRep.add(rpcs::PSI_LANG_fr_CH, N_("Swiss French"));
+ stringRep.add(rpcs::PSI_LANG_de_CH, N_("Swiss German"));
+ stringRep.add(rpcs::PSI_LANG_pt_PT, N_("Portugese"));
+ stringRep.add(rpcs::PSI_LANG_tr_TR, N_("Turkish"));
+ stringRep.add(rpcs::PSI_LANG_is_IS, N_("Icelandic"));
+ stringRep.add(rpcs::PSI_LANG_ru_RU, N_("Russian"));
+ stringRep.add(rpcs::PSI_LANG_hu_HU, N_("Hungarian"));
+ stringRep.add(rpcs::PSI_LANG_nl_NL, N_("Dutch"));
+ stringRep.add(rpcs::PSI_LANG_nl_BE, N_("Belgian Flemish"));
+ stringRep.add(rpcs::PSI_LANG_en_AU, N_("Australian"));
+ stringRep.add(rpcs::PSI_LANG_fr_BE, N_("Belgish French"));
+ stringRep.add(rpcs::PSI_LANG_de_AT, N_("Austrian"));
+ stringRep.add(rpcs::PSI_LANG_en_NZ, N_("New Zealand")); // FIXME: not shure about ISO code
+ stringRep.add(rpcs::PSI_LANG_fr_CA, N_("International French")); // FIXME: not shure about ISO code
+ stringRep.add(rpcs::PSI_LANG_cs_CZ, N_("Czech"));
+ stringRep.add(rpcs::PSI_LANG_sk_SK, N_("Slovak"));
+ stringRep.add(rpcs::PSI_LANG_pl_PL, N_("Polish"));
+ stringRep.add(rpcs::PSI_LANG_sl_SI, N_("Slovenian"));
+}
+
+rpcs::~rpcs()
+{
+ skt->closeSocket();
}
//
@@ -90,35 +101,35 @@ ENUM_DEFINITION(rpcs::languages, rpcs::PSI_LANG_TEST) {
void rpcs::
reconnect(void)
{
- skt->closeSocket();
- skt->reconnect();
- reset();
+ //skt->closeSocket();
+ skt->reconnect();
+ reset();
}
void rpcs::
reset(void)
{
- bufferStore a;
- status = rfsv::E_PSI_FILE_DISC;
- a.addStringT(getConnectName());
- if (skt->sendBufferStore(a)) {
- if (skt->getBufferStore(a) == 1) {
- if (!strcmp(a.getString(0), "Ok"))
- status = rfsv::E_PSI_GEN_NONE;
- }
+ bufferStore a;
+ status = rfsv::E_PSI_FILE_DISC;
+ a.addStringT(getConnectName());
+ if (skt->sendBufferStore(a)) {
+ if (skt->getBufferStore(a) == 1) {
+ if (!strcmp(a.getString(0), "Ok"))
+ status = rfsv::E_PSI_GEN_NONE;
}
+ }
}
Enum<rfsv::errs> rpcs::
getStatus(void)
{
- return status;
+ return status;
}
const char *rpcs::
getConnectName(void)
{
- return "SYS$RPCS";
+ return "SYS$RPCS";
}
//
@@ -127,45 +138,45 @@ getConnectName(void)
bool rpcs::
sendCommand(enum commands cc, bufferStore & data)
{
- if (status == rfsv::E_PSI_FILE_DISC) {
- reconnect();
- if (status == rfsv::E_PSI_FILE_DISC)
- return false;
- }
- bool result;
- bufferStore a;
- a.addByte(cc);
- a.addBuff(data);
+ if (status == rfsv::E_PSI_FILE_DISC) {
+ reconnect();
+ if (status == rfsv::E_PSI_FILE_DISC)
+ return false;
+ }
+ bool result;
+ bufferStore a;
+ a.addByte(cc);
+ a.addBuff(data);
+ result = skt->sendBufferStore(a);
+ if (!result) {
+ reconnect();
result = skt->sendBufferStore(a);
- if (!result) {
- reconnect();
- result = skt->sendBufferStore(a);
- if (!result)
- status = rfsv::E_PSI_FILE_DISC;
- }
- return result;
+ if (!result)
+ status = rfsv::E_PSI_FILE_DISC;
+ }
+ return result;
}
Enum<rfsv::errs> rpcs::
getResponse(bufferStore & data, bool statusIsFirstByte)
{
- Enum<rfsv::errs> ret;
- if (skt->getBufferStore(data) == 1) {
- if (statusIsFirstByte) {
- ret = (enum rfsv::errs)((char)data.getByte(0));
- data.discardFirstBytes(1);
- } else {
- int l = data.getLen();
- if (l > 0) {
- ret = (enum rfsv::errs)((char)data.getByte(data.getLen() - 1));
- data.init((const unsigned char *)data.getString(), l - 1);
- } else
- ret = rfsv::E_PSI_GEN_FAIL;
- }
- return ret;
- } else
- status = rfsv::E_PSI_FILE_DISC;
- return status;
+ Enum<rfsv::errs> ret;
+ if (skt->getBufferStore(data) == 1) {
+ if (statusIsFirstByte) {
+ ret = (enum rfsv::errs)((char)data.getByte(0));
+ data.discardFirstBytes(1);
+ } else {
+ int l = data.getLen();
+ if (l > 0) {
+ ret = (enum rfsv::errs)((char)data.getByte(data.getLen() - 1));
+ data.init((const unsigned char *)data.getString(), l - 1);
+ } else
+ ret = rfsv::E_PSI_GEN_FAIL;
+ }
+ return ret;
+ } else
+ status = rfsv::E_PSI_FILE_DISC;
+ return status;
}
//
@@ -174,184 +185,190 @@ getResponse(bufferStore & data, bool statusIsFirstByte)
Enum<rfsv::errs> rpcs::
getNCPversion(int &major, int &minor)
{
- Enum<rfsv::errs> res;
- bufferStore a;
-
- if (!sendCommand(QUERY_NCP, a))
- return rfsv::E_PSI_FILE_DISC;
- if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
- return res;
- if (a.getLen() != 2)
- return rfsv::E_PSI_GEN_FAIL;
- major = a.getByte(0);
- minor = a.getByte(1);
+ Enum<rfsv::errs> res;
+ bufferStore a;
+
+ if (!sendCommand(QUERY_NCP, a))
+ return rfsv::E_PSI_FILE_DISC;
+ if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
return res;
+ if (a.getLen() != 2)
+ return rfsv::E_PSI_GEN_FAIL;
+ major = a.getByte(0);
+ minor = a.getByte(1);
+ return res;
}
Enum<rfsv::errs> rpcs::
execProgram(const char *program, const char *args)
{
- bufferStore a;
-
- a.addStringT(program);
- int l = strlen(program);
- for (int i = 127; i > l; i--)
- a.addByte(0);
-
- /**
- * This is a hack for the jotter app on mx5 pro. (and probably others)
- * Jotter seems to read it's arguments one char past normal apps.
- * Without this hack, The Drive-Character gets lost. Other apps don't
- * seem to be hurt by the additional blank.
- */
- a.addByte(strlen(args) + 1);
- a.addByte(' ');
-
- a.addStringT(args);
- if (!sendCommand(EXEC_PROG, a))
- return rfsv::E_PSI_FILE_DISC;
- return getResponse(a, true);
+ bufferStore a;
+
+ a.addStringT(program);
+ int l = strlen(program);
+ for (int i = 127; i > l; i--)
+ a.addByte(0);
+
+ /**
+ * This is a hack for the jotter app on mx5 pro. (and probably others)
+ * Jotter seems to read it's arguments one char past normal apps.
+ * Without this hack, The Drive-Character gets lost. Other apps don't
+ * seem to be hurt by the additional blank.
+ */
+ a.addByte(strlen(args) + 1);
+ a.addByte(' ');
+
+ a.addStringT(args);
+ if (!sendCommand(EXEC_PROG, a))
+ return rfsv::E_PSI_FILE_DISC;
+ return getResponse(a, true);
}
Enum<rfsv::errs> rpcs::
stopProgram(const char *program)
{
- bufferStore a;
+ bufferStore a;
- a.addStringT(program);
- if (!sendCommand(STOP_PROG, a))
- return rfsv::E_PSI_FILE_DISC;
- return getResponse(a, true);
+ a.addStringT(program);
+ if (!sendCommand(STOP_PROG, a))
+ return rfsv::E_PSI_FILE_DISC;
+ return getResponse(a, true);
}
Enum<rfsv::errs> rpcs::
queryProgram(const char *program)
{
- bufferStore a;
+ bufferStore a;
- a.addStringT(program);
- if (!sendCommand(QUERY_PROG, a))
- return rfsv::E_PSI_FILE_DISC;
- return getResponse(a, true);
+ a.addStringT(program);
+ if (!sendCommand(QUERY_PROG, a))
+ return rfsv::E_PSI_FILE_DISC;
+ return getResponse(a, true);
}
Enum<rfsv::errs> rpcs::
formatOpen(const char *drive, int &handle, int &count)
{
- Enum<rfsv::errs> res;
- bufferStore a;
-
- a.addStringT(drive);
- if (!sendCommand(FORMAT_OPEN, a))
- return rfsv::E_PSI_FILE_DISC;
- if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
- return res;
- if (a.getLen() != 4)
- return rfsv::E_PSI_GEN_FAIL;
- handle = a.getWord(0);
- count = a.getWord(2);
+ Enum<rfsv::errs> res;
+ bufferStore a;
+
+ a.addStringT(drive);
+ if (!sendCommand(FORMAT_OPEN, a))
+ return rfsv::E_PSI_FILE_DISC;
+ if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
return res;
+ if (a.getLen() != 4)
+ return rfsv::E_PSI_GEN_FAIL;
+ handle = a.getWord(0);
+ count = a.getWord(2);
+ return res;
}
Enum<rfsv::errs> rpcs::
formatRead(int handle)
{
- bufferStore a;
+ bufferStore a;
- a.addWord(handle);
- if (!sendCommand(FORMAT_READ, a))
- return rfsv::E_PSI_FILE_DISC;
- return getResponse(a, true);
+ a.addWord(handle);
+ if (!sendCommand(FORMAT_READ, a))
+ return rfsv::E_PSI_FILE_DISC;
+ return getResponse(a, true);
}
Enum<rfsv::errs> rpcs::
getUniqueID(const char *device, long &id)
{
- Enum<rfsv::errs> res;
- bufferStore a;
-
- a.addStringT(device);
- if (!sendCommand(GET_UNIQUEID, a))
- return rfsv::E_PSI_FILE_DISC;
- if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
- return res;
- if (a.getLen() != 4)
- return rfsv::E_PSI_GEN_FAIL;
- id = a.getDWord(0);
+ Enum<rfsv::errs> res;
+ bufferStore a;
+
+ a.addStringT(device);
+ if (!sendCommand(GET_UNIQUEID, a))
+ return rfsv::E_PSI_FILE_DISC;
+ if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
return res;
+ if (a.getLen() != 4)
+ return rfsv::E_PSI_GEN_FAIL;
+ id = a.getDWord(0);
+ return res;
}
Enum<rfsv::errs> rpcs::
getOwnerInfo(bufferArray &owner)
{
- Enum<rfsv::errs> res;
- bufferStore a;
+ Enum<rfsv::errs> res;
+ bufferStore a;
- if (!sendCommand(GET_OWNERINFO, a))
- return rfsv::E_PSI_FILE_DISC;
- if ((res = (enum rfsv::errs)getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
- return res;
- a.addByte(0);
- int l = a.getLen();
- char *s = (char *)a.getString(0);
- for (int i = 0; i < l; i++)
- if (s[i] == 6)
- s[i] = 0;
- owner.clear();
- while (l > 0) {
- if (*s != '\0') {
- bufferStore b;
- b.addStringT(s);
- owner += b;
- l -= (strlen(s) + 1);
- s += (strlen(s) + 1);
- } else {
- l--;
- s++;
- }
- }
+ if (!sendCommand(GET_OWNERINFO, a))
+ return rfsv::E_PSI_FILE_DISC;
+ if ((res = (enum rfsv::errs)getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
return res;
+ a.addByte(0);
+ int l = a.getLen();
+ char *s = (char *)a.getString(0);
+ for (int i = 0; i < l; i++)
+ if (s[i] == 6)
+ s[i] = 0;
+ owner.clear();
+ while (l > 0) {
+ if (*s != '\0') {
+ bufferStore b;
+ b.addStringT(s);
+ owner += b;
+ l -= (strlen(s) + 1);
+ s += (strlen(s) + 1);
+ } else {
+ l--;
+ s++;
+ }
+ }
+ return res;
}
Enum<rfsv::errs> rpcs::
getMachineType(Enum<machs> &type)
{
- Enum<rfsv::errs> res;
- bufferStore a;
-
- if (!sendCommand(GET_MACHINETYPE, a))
- return rfsv::E_PSI_FILE_DISC;
- if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
- return res;
- if (a.getLen() != 2)
- return rfsv::E_PSI_GEN_FAIL;
- type = (enum machs)a.getWord(0);
+ Enum<rfsv::errs> res;
+ bufferStore a;
+
+ if (!sendCommand(GET_MACHINETYPE, a))
+ return rfsv::E_PSI_FILE_DISC;
+ if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
return res;
+ if (a.getLen() != 2)
+ return rfsv::E_PSI_GEN_FAIL;
+ type = (enum machs)a.getWord(0);
+ return res;
}
Enum<rfsv::errs> rpcs::
fuser(const char *name, char *buf, int maxlen)
{
- Enum<rfsv::errs> res;
- bufferStore a;
- char *p;
-
- a.addStringT(name);
- if (!sendCommand(FUSER, a))
- return rfsv::E_PSI_FILE_DISC;
- if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
- return res;
- strncpy(buf, a.getString(0), maxlen - 1);
- while ((p = strchr(buf, 6)))
- *p = '\0';
+ Enum<rfsv::errs> res;
+ bufferStore a;
+ char *p;
+
+ a.addStringT(name);
+ if (!sendCommand(FUSER, a))
+ return rfsv::E_PSI_FILE_DISC;
+ if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
return res;
+ strncpy(buf, a.getString(0), maxlen - 1);
+ while ((p = strchr(buf, 6)))
+ *p = '\0';
+ return res;
}
Enum<rfsv::errs> rpcs::
quitServer(void)
{
- bufferStore a;
- if (!sendCommand(QUIT_SERVER, a))
- return rfsv::E_PSI_FILE_DISC;
- return getResponse(a, true);
+ bufferStore a;
+ if (!sendCommand(QUIT_SERVER, a))
+ return rfsv::E_PSI_FILE_DISC;
+ return getResponse(a, true);
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rpcs.h b/lib/rpcs.h
index bc7eb3c..68eb3d5 100644
--- a/lib/rpcs.h
+++ b/lib/rpcs.h
@@ -1,5 +1,27 @@
-#ifndef _rpcs_h_
-#define _rpcs_h_
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _RPCS_H_
+#define _RPCS_H_
#include "psitime.h"
#include "rfsv.h"
@@ -25,343 +47,349 @@ class bufferArray;
* @author Fritz Elfert <felfert@to.com>
*/
class rpcs {
- public:
- /**
- * The known machine types.
- */
- enum machs {
- PSI_MACH_UNKNOWN = 0,
- PSI_MACH_PC = 1,
- PSI_MACH_MC = 2,
- PSI_MACH_HC = 3,
- PSI_MACH_S3 = 4,
- PSI_MACH_S3A = 5,
- PSI_MACH_WORKABOUT = 6,
- PSI_MACH_SIENNA = 7,
- PSI_MACH_S3C = 8,
- PSI_MACH_S5 = 32,
- PSI_MACH_WINC = 33,
- // TODO: Code for 5mx
- };
-
- /**
- * The known interface languages.
- */
- enum languages {
- PSI_LANG_TEST = 0,
- PSI_LANG_en_GB = 1,
- PSI_LANG_fr_FR = 2,
- PSI_LANG_de_DE = 3,
- PSI_LANG_es_ES = 4,
- PSI_LANG_it_IT = 5,
- PSI_LANG_sv_SE = 6,
- PSI_LANG_da_DK = 7,
- PSI_LANG_no_NO = 8,
- PSI_LANG_fi_FI = 9,
- PSI_LANG_en_US = 10,
- PSI_LANG_fr_CH = 11,
- PSI_LANG_de_CH = 12,
- PSI_LANG_pt_PT = 13,
- PSI_LANG_tr_TR = 14,
- PSI_LANG_is_IS = 15,
- PSI_LANG_ru_RU = 16,
- PSI_LANG_hu_HU = 17,
- PSI_LANG_nl_NL = 18,
- PSI_LANG_nl_BE = 19,
- PSI_LANG_en_AU = 20,
- PSI_LANG_fr_BE = 21,
- PSI_LANG_de_AT = 22,
- PSI_LANG_en_NZ = 23,
- PSI_LANG_fr_CA = 24,
- PSI_LANG_cs_CZ = 25,
- PSI_LANG_sk_SK = 26,
- PSI_LANG_pl_PL = 27,
- PSI_LANG_sl_SI = 28,
- };
-
- /**
- * The known battery states.
- */
- enum batterystates {
- PSI_BATT_DEAD = 0,
- PSI_BATT_VERYLOW = 1,
- PSI_BATT_LOW = 2,
- PSI_BATT_GOOD = 3,
- };
-
- /**
- * This struct holds the data returned
- * by @ref rpcs::getMachineInfo.
- */
- typedef struct machineInfo_t {
- Enum<machs> machineType;
- char machineName[17];
- unsigned long long machineUID;
- unsigned long countryCode;
- Enum<languages> uiLanguage;
-
- unsigned short romMajor;
- unsigned short romMinor;
- unsigned short romBuild;
- unsigned long romSize;
- bool romProgrammable;
-
- unsigned long ramSize;
- unsigned long ramFree;
- unsigned long ramMaxFree;
- unsigned long ramDiskSize;
-
- unsigned long registrySize;
- unsigned long displayWidth;
- unsigned long displayHeight;
-
- psi_timeval time;
- psi_timezone tz;
-
- psi_timeval mainBatteryInsertionTime;
- Enum<batterystates> mainBatteryStatus;
- psi_timeval mainBatteryUsedTime;
- unsigned long mainBatteryCurrent;
- unsigned long mainBatteryUsedPower;
- unsigned long mainBatteryVoltage;
- unsigned long mainBatteryMaxVoltage;
-
- Enum<batterystates> backupBatteryStatus;
- unsigned long backupBatteryVoltage;
- unsigned long backupBatteryMaxVoltage;
- psi_timeval backupBatteryUsedTime;
-
- bool externalPower;
- } machineInfo;
-
- /**
- * Provides a virtual destructor.
- */
- virtual ~rpcs() {};
-
- /**
- * Initializes a connection to the remote
- * machine.
- */
- void reset();
-
- /**
- * Attempts to re-establish a remote
- * connection by first closing the socket,
- * then connecting again to the ncpd daemon
- * and finally calling @ref reset.
- */
- void reconnect();
-
- /**
- * Retrieves the current status of the
- * connection.
- *
- * @returns The connection status.
- */
- Enum<rfsv::errs> getStatus();
-
- /**
- * Retrieves the version of the NCP protocol
- * on the remote side.
- *
- * This function is working with both SIBO and EPOC
- * devices.
- *
- * @param major The major part of the NCP version.
- * Valid only if returned with no error.
- * @param minor The minor part of the NCP version.
- * Valid only if returned with no error.
- *
- * @returns A psion error code. 0 = Ok.
- */
- Enum<rfsv::errs> getNCPversion(int &major, int &minor);
-
- /**
- * Starts execution of a program on the remote machine.
- *
- * This function is working with both SIBO and EPOC
- * devices.
- *
- * @param program The full path of the executable
- * on the remote machine
- * @param args The arguments for this program, separated
- * by space.
- *
- * @returns A psion error code. 0 = Ok.
- */
- Enum<rfsv::errs> execProgram(const char *program, const char *args);
-
- /**
- * Requests termination of a program running on the
- * remote machine.
- *
- * This function is working with both SIBO and EPOC
- * devices.
- *
- * @param program
- *
- * @returns A psion error code. 0 = Ok.
- */
- Enum<rfsv::errs> stopProgram(const char *);
-
- Enum<rfsv::errs> queryProgram(const char *);
- Enum<rfsv::errs> formatOpen(const char *, int &, int &);
- Enum<rfsv::errs> formatRead(int);
- Enum<rfsv::errs> getUniqueID(const char *, long &);
-
- /**
- * Retrieve owner information of the remote machine.
- *
- * This function is working with both SIBO and EPOC
- * devices.
- *
- * @param owner A bufferArray, containing the lines
- * of the owner info upon return.
- *
- * @returns A psion error code. 0 = Ok.
- */
- Enum<rfsv::errs> getOwnerInfo(bufferArray &);
-
- /**
- * Retrieves the type of machine on the remote side
- * as defined in @ref #machs.
- *
- * This function is working with both SIBO and EPOC
- * devices
- *
- * @param type The code describing the type of machine
- * on the remote side is stored here on return.
- *
- * @returns A psion error code. 0 = Ok.
- */
- Enum<rfsv::errs> getMachineType(Enum<machs> &type);
-
- /**
- * Retrieves the name of a process, having a
- * given file opened on the remote side.
- *
- * This function is working with both SIBO and EPOC
- * devices
- *
- * @param name The full path of a file to be checked
- * for beeing used by a program.
- * @param buf A buffer which gets filled with the
- * program's name.
- * @param maxlen The maximum capacity of the buffer.
- */
- Enum<rfsv::errs> fuser(const char *name, char *buf, int maxlen);
-
- /**
- * Requests the remote server to terminate.
- *
- * This function is working with both SIBO and EPOC
- * devices. There is usually no need to call this
- * function, because the remote server is automatically
- * stopped on disconnect.
- *
- * @returns A psion error code. 0 = Ok.
- */
- Enum<rfsv::errs> quitServer(void);
-
- // API different on SIBO and EPOC
- virtual Enum<rfsv::errs> queryDrive(const char, bufferArray &) = 0;
- /**
- * Retrieves the command line of a running process.
- *
- * This function works with EPOC only. Using it with SIBO
- * machines, returns always an error code E_PSI_NOT_SIBO.
- *
- * @param process Name of process. Format: processname.$pid
- * @param ret The program name and arguments are returned here.
- *
- * @return Psion error code. 0 = Ok.
- */
- virtual Enum<rfsv::errs> getCmdLine(const char *process, bufferStore &ret) = 0;
- /**
- * Retrieve general Information about the connected
- * machine.
- *
- * This function works with EPOC only. Using it with SIBO
- * machines, returns always an error code E_PSI_NOT_SIBO.
- *
- * @param machineInfo The struct holding all information on return.
- * @return Psion error code. 0 = Ok.
- */
- virtual Enum<rfsv::errs> getMachineInfo(machineInfo &) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> closeHandle(int) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> regOpenIter(void) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> regReadIter(void) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> regWrite(void) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> regRead(void) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> regDelete(void) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> setTime(void) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> configOpen(void) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> configRead(void) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> configWrite(void) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> queryOpen(void) { return rfsv::E_PSI_NOT_SIBO;}
- virtual Enum<rfsv::errs> queryRead(void) { return rfsv::E_PSI_NOT_SIBO;}
-
- protected:
- /**
- * The socket, used for communication
- * with ncpd.
- */
- ppsocket *skt;
-
- /**
- * The current status of the connection.
- */
- Enum<rfsv::errs> status;
-
- /**
- * The possible commands.
- */
- enum commands {
- QUERY_NCP = 0x00,
- EXEC_PROG = 0x01,
- QUERY_DRIVE = 0x02,
- STOP_PROG = 0x03,
- QUERY_PROG = 0x04,
- FORMAT_OPEN = 0x05,
- FORMAT_READ = 0x06,
- GET_UNIQUEID = 0x07,
- GET_OWNERINFO = 0x08,
- GET_MACHINETYPE = 0x09,
- GET_CMDLINE = 0x0a,
- FUSER = 0x0b,
- GET_MACHINE_INFO = 0x64,
- REG_OPEN_ITER = 0x66,
- REG_READ_ITER = 0x67,
- REG_WRITE = 0x68,
- REG_READ = 0x69,
- REG_DELETE = 0x6a,
- SET_TIME = 0x6b,
- CONFIG_OPEN = 0x6c,
- CONFIG_READ = 0x6d,
- CONFIG_WRITE = 0x6e,
- QUERY_OPEN = 0x6f,
- QUERY_READ = 0x70,
- QUIT_SERVER = 0xff
- };
-
- /**
- * Sends a command to the remote side.
- *
- * If communication fails, a reconnect is triggered
- * and a second attempt to transmit the request
- * is attempted. If that second attempt fails,
- * the function returns an error an sets rpcs::status
- * to E_PSI_FILE_DISC.
- *
- * @param cc The command to execute on the remote side.
- * @param data Additional data for this command.
- *
- * @returns true on success, false on failure.
- */
- bool sendCommand(enum commands cc, bufferStore &data);
- Enum<rfsv::errs> getResponse(bufferStore &data, bool statusIsFirstByte);
- const char *getConnectName();
+public:
+ /**
+ * The known machine types.
+ */
+ enum machs {
+ PSI_MACH_UNKNOWN = 0,
+ PSI_MACH_PC = 1,
+ PSI_MACH_MC = 2,
+ PSI_MACH_HC = 3,
+ PSI_MACH_S3 = 4,
+ PSI_MACH_S3A = 5,
+ PSI_MACH_WORKABOUT = 6,
+ PSI_MACH_SIENNA = 7,
+ PSI_MACH_S3C = 8,
+ PSI_MACH_S5 = 32,
+ PSI_MACH_WINC = 33,
+ // TODO: Code for 5mx
+ };
+
+ /**
+ * The known interface languages.
+ */
+ enum languages {
+ PSI_LANG_TEST = 0,
+ PSI_LANG_en_GB = 1,
+ PSI_LANG_fr_FR = 2,
+ PSI_LANG_de_DE = 3,
+ PSI_LANG_es_ES = 4,
+ PSI_LANG_it_IT = 5,
+ PSI_LANG_sv_SE = 6,
+ PSI_LANG_da_DK = 7,
+ PSI_LANG_no_NO = 8,
+ PSI_LANG_fi_FI = 9,
+ PSI_LANG_en_US = 10,
+ PSI_LANG_fr_CH = 11,
+ PSI_LANG_de_CH = 12,
+ PSI_LANG_pt_PT = 13,
+ PSI_LANG_tr_TR = 14,
+ PSI_LANG_is_IS = 15,
+ PSI_LANG_ru_RU = 16,
+ PSI_LANG_hu_HU = 17,
+ PSI_LANG_nl_NL = 18,
+ PSI_LANG_nl_BE = 19,
+ PSI_LANG_en_AU = 20,
+ PSI_LANG_fr_BE = 21,
+ PSI_LANG_de_AT = 22,
+ PSI_LANG_en_NZ = 23,
+ PSI_LANG_fr_CA = 24,
+ PSI_LANG_cs_CZ = 25,
+ PSI_LANG_sk_SK = 26,
+ PSI_LANG_pl_PL = 27,
+ PSI_LANG_sl_SI = 28,
+ };
+
+ /**
+ * The known battery states.
+ */
+ enum batterystates {
+ PSI_BATT_DEAD = 0,
+ PSI_BATT_VERYLOW = 1,
+ PSI_BATT_LOW = 2,
+ PSI_BATT_GOOD = 3,
+ };
+
+ /**
+ * This struct holds the data returned
+ * by @ref rpcs::getMachineInfo.
+ */
+ typedef struct machineInfo_t {
+ Enum<machs> machineType;
+ char machineName[17];
+ unsigned long long machineUID;
+ unsigned long countryCode;
+ Enum<languages> uiLanguage;
+
+ unsigned short romMajor;
+ unsigned short romMinor;
+ unsigned short romBuild;
+ unsigned long romSize;
+ bool romProgrammable;
+
+ unsigned long ramSize;
+ unsigned long ramFree;
+ unsigned long ramMaxFree;
+ unsigned long ramDiskSize;
+
+ unsigned long registrySize;
+ unsigned long displayWidth;
+ unsigned long displayHeight;
+
+ psi_timeval time;
+ psi_timezone tz;
+
+ psi_timeval mainBatteryInsertionTime;
+ Enum<batterystates> mainBatteryStatus;
+ psi_timeval mainBatteryUsedTime;
+ unsigned long mainBatteryCurrent;
+ unsigned long mainBatteryUsedPower;
+ unsigned long mainBatteryVoltage;
+ unsigned long mainBatteryMaxVoltage;
+
+ Enum<batterystates> backupBatteryStatus;
+ unsigned long backupBatteryVoltage;
+ unsigned long backupBatteryMaxVoltage;
+ psi_timeval backupBatteryUsedTime;
+
+ bool externalPower;
+ } machineInfo;
+
+ /**
+ * Virtual destructor.
+ */
+ virtual ~rpcs();
+
+ /**
+ * Initializes a connection to the remote
+ * machine.
+ */
+ void reset();
+
+ /**
+ * Attempts to re-establish a remote
+ * connection by first closing the socket,
+ * then connecting again to the ncpd daemon
+ * and finally calling @ref reset.
+ */
+ void reconnect();
+
+ /**
+ * Retrieves the current status of the
+ * connection.
+ *
+ * @returns The connection status.
+ */
+ Enum<rfsv::errs> getStatus();
+
+ /**
+ * Retrieves the version of the NCP protocol
+ * on the remote side.
+ *
+ * This function is working with both SIBO and EPOC
+ * devices.
+ *
+ * @param major The major part of the NCP version.
+ * Valid only if returned with no error.
+ * @param minor The minor part of the NCP version.
+ * Valid only if returned with no error.
+ *
+ * @returns A psion error code. 0 = Ok.
+ */
+ Enum<rfsv::errs> getNCPversion(int &major, int &minor);
+
+ /**
+ * Starts execution of a program on the remote machine.
+ *
+ * This function is working with both SIBO and EPOC
+ * devices.
+ *
+ * @param program The full path of the executable
+ * on the remote machine
+ * @param args The arguments for this program, separated
+ * by space.
+ *
+ * @returns A psion error code. 0 = Ok.
+ */
+ Enum<rfsv::errs> execProgram(const char *program, const char *args);
+
+ /**
+ * Requests termination of a program running on the
+ * remote machine.
+ *
+ * This function is working with both SIBO and EPOC
+ * devices.
+ *
+ * @param program
+ *
+ * @returns A psion error code. 0 = Ok.
+ */
+ Enum<rfsv::errs> stopProgram(const char *);
+
+ Enum<rfsv::errs> queryProgram(const char *);
+ Enum<rfsv::errs> formatOpen(const char *, int &, int &);
+ Enum<rfsv::errs> formatRead(int);
+ Enum<rfsv::errs> getUniqueID(const char *, long &);
+
+ /**
+ * Retrieve owner information of the remote machine.
+ *
+ * This function is working with both SIBO and EPOC
+ * devices.
+ *
+ * @param owner A bufferArray, containing the lines
+ * of the owner info upon return.
+ *
+ * @returns A psion error code. 0 = Ok.
+ */
+ Enum<rfsv::errs> getOwnerInfo(bufferArray &);
+
+ /**
+ * Retrieves the type of machine on the remote side
+ * as defined in @ref #machs.
+ *
+ * This function is working with both SIBO and EPOC
+ * devices
+ *
+ * @param type The code describing the type of machine
+ * on the remote side is stored here on return.
+ *
+ * @returns A psion error code. 0 = Ok.
+ */
+ Enum<rfsv::errs> getMachineType(Enum<machs> &type);
+
+ /**
+ * Retrieves the name of a process, having a
+ * given file opened on the remote side.
+ *
+ * This function is working with both SIBO and EPOC
+ * devices
+ *
+ * @param name The full path of a file to be checked
+ * for beeing used by a program.
+ * @param buf A buffer which gets filled with the
+ * program's name.
+ * @param maxlen The maximum capacity of the buffer.
+ */
+ Enum<rfsv::errs> fuser(const char *name, char *buf, int maxlen);
+
+ /**
+ * Requests the remote server to terminate.
+ *
+ * This function is working with both SIBO and EPOC
+ * devices. There is usually no need to call this
+ * function, because the remote server is automatically
+ * stopped on disconnect.
+ *
+ * @returns A psion error code. 0 = Ok.
+ */
+ Enum<rfsv::errs> quitServer(void);
+
+ // API different on SIBO and EPOC
+ virtual Enum<rfsv::errs> queryDrive(const char, bufferArray &) = 0;
+ /**
+ * Retrieves the command line of a running process.
+ *
+ * This function works with EPOC only. Using it with SIBO
+ * machines, returns always an error code E_PSI_NOT_SIBO.
+ *
+ * @param process Name of process. Format: processname.$pid
+ * @param ret The program name and arguments are returned here.
+ *
+ * @return Psion error code. 0 = Ok.
+ */
+ virtual Enum<rfsv::errs> getCmdLine(const char *process, bufferStore &ret) = 0;
+ /**
+ * Retrieve general Information about the connected
+ * machine.
+ *
+ * This function works with EPOC only. Using it with SIBO
+ * machines, returns always an error code E_PSI_NOT_SIBO.
+ *
+ * @param machineInfo The struct holding all information on return.
+ * @return Psion error code. 0 = Ok.
+ */
+ virtual Enum<rfsv::errs> getMachineInfo(machineInfo &) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> closeHandle(int) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> regOpenIter(void) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> regReadIter(void) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> regWrite(void) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> regRead(void) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> regDelete(void) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> setTime(void) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> configOpen(void) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> configRead(void) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> configWrite(void) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> queryOpen(void) { return rfsv::E_PSI_NOT_SIBO;}
+ virtual Enum<rfsv::errs> queryRead(void) { return rfsv::E_PSI_NOT_SIBO;}
+
+protected:
+ /**
+ * The socket, used for communication
+ * with ncpd.
+ */
+ ppsocket *skt;
+
+ /**
+ * The current status of the connection.
+ */
+ Enum<rfsv::errs> status;
+
+ /**
+ * The possible commands.
+ */
+ enum commands {
+ QUERY_NCP = 0x00,
+ EXEC_PROG = 0x01,
+ QUERY_DRIVE = 0x02,
+ STOP_PROG = 0x03,
+ QUERY_PROG = 0x04,
+ FORMAT_OPEN = 0x05,
+ FORMAT_READ = 0x06,
+ GET_UNIQUEID = 0x07,
+ GET_OWNERINFO = 0x08,
+ GET_MACHINETYPE = 0x09,
+ GET_CMDLINE = 0x0a,
+ FUSER = 0x0b,
+ GET_MACHINE_INFO = 0x64,
+ REG_OPEN_ITER = 0x66,
+ REG_READ_ITER = 0x67,
+ REG_WRITE = 0x68,
+ REG_READ = 0x69,
+ REG_DELETE = 0x6a,
+ SET_TIME = 0x6b,
+ CONFIG_OPEN = 0x6c,
+ CONFIG_READ = 0x6d,
+ CONFIG_WRITE = 0x6e,
+ QUERY_OPEN = 0x6f,
+ QUERY_READ = 0x70,
+ QUIT_SERVER = 0xff
+ };
+
+ /**
+ * Sends a command to the remote side.
+ *
+ * If communication fails, a reconnect is triggered
+ * and a second attempt to transmit the request
+ * is attempted. If that second attempt fails,
+ * the function returns an error an sets rpcs::status
+ * to E_PSI_FILE_DISC.
+ *
+ * @param cc The command to execute on the remote side.
+ * @param data Additional data for this command.
+ *
+ * @returns true on success, false on failure.
+ */
+ bool sendCommand(enum commands cc, bufferStore &data);
+ Enum<rfsv::errs> getResponse(bufferStore &data, bool statusIsFirstByte);
+ const char *getConnectName();
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rpcs16.cc b/lib/rpcs16.cc
index 0a3121b..a65c937 100644
--- a/lib/rpcs16.cc
+++ b/lib/rpcs16.cc
@@ -1,19 +1,26 @@
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Matt J. Gumbley <matt@gumbley.demon.co.uk>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -31,33 +38,30 @@
rpcs16::rpcs16(ppsocket * _skt)
{
- skt = _skt;
- reset();
-}
-
-rpcs16::~rpcs16()
-{
- bufferStore a;
- a.addStringT("Close");
- if (status == rfsv::E_PSI_GEN_NONE)
- skt->sendBufferStore(a);
- skt->closeSocket();
+ skt = _skt;
+ reset();
}
Enum<rfsv::errs> rpcs16::
queryDrive(char drive, bufferArray &ret)
{
- bufferStore a;
- a.addByte(drive);
- if (!sendCommand(rpcs::QUERY_DRIVE, a))
- return rfsv::E_PSI_FILE_DISC;
- Enum<rfsv::errs> res = getResponse(a, true);
-cout << dec << "qd: " << res << " " << a.getLen() << " a="<< a << endl;
- return res;
+ bufferStore a;
+ a.addByte(drive);
+ if (!sendCommand(rpcs::QUERY_DRIVE, a))
+ return rfsv::E_PSI_FILE_DISC;
+ Enum<rfsv::errs> res = getResponse(a, true);
+ cout << dec << "qd: " << res << " " << a.getLen() << " a="<< a << endl;
+ return res;
}
Enum<rfsv::errs> rpcs16::
getCmdLine(const char *process, bufferStore &ret)
{
- return rfsv::E_PSI_GEN_NONE;
+ return rfsv::E_PSI_GEN_NONE;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rpcs16.h b/lib/rpcs16.h
index cc4d601..24fcc6e 100644
--- a/lib/rpcs16.h
+++ b/lib/rpcs16.h
@@ -1,5 +1,28 @@
-#ifndef _rpcs16_h_
-#define _rpcs16_h_
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _RPCS16_H_
+#define _RPCS16_H_
#include "rpcs.h"
@@ -15,15 +38,20 @@ class rpcsfactory;
* @ref rpcs . For a complete documentation, see @ref rpcs .
*/
class rpcs16 : public rpcs {
- friend rpcsfactory;
+ friend rpcsfactory;
public:
- ~rpcs16();
-
- Enum<rfsv::errs> queryDrive(const char, bufferArray &);
- Enum<rfsv::errs> getCmdLine(const char *, bufferStore &);
+ Enum<rfsv::errs> queryDrive(const char, bufferArray &);
+ Enum<rfsv::errs> getCmdLine(const char *, bufferStore &);
+
private:
- rpcs16(ppsocket *);
+ rpcs16(ppsocket *);
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rpcs32.cc b/lib/rpcs32.cc
index 772dea6..38d7933 100644
--- a/lib/rpcs32.cc
+++ b/lib/rpcs32.cc
@@ -1,19 +1,25 @@
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -33,140 +39,131 @@
rpcs32::rpcs32(ppsocket * _skt)
{
- skt = _skt;
- reset();
-}
-
-rpcs32::~rpcs32()
-{
- bufferStore a;
- a.addStringT("Close");
- if (status == rfsv::E_PSI_GEN_NONE)
- skt->sendBufferStore(a);
- skt->closeSocket();
+ skt = _skt;
+ reset();
}
Enum<rfsv::errs> rpcs32::
queryDrive(char drive, bufferArray &ret)
{
- bufferStore a;
- Enum<rfsv::errs> res;
-
- a.addByte(drive);
- if (!sendCommand(rpcs::QUERY_DRIVE, a))
- return rfsv::E_PSI_FILE_DISC;
- if ((res = getResponse(a, false)) != rfsv::E_PSI_GEN_NONE)
- return res;
- int l = a.getLen();
- ret.clear();
- while (l > 0) {
- bufferStore b, c;
- const char *s;
- char *p;
- int pid;
- int sl;
-
- s = a.getString(0);
- sl = strlen(s) + 1;
- l -= sl;
- a.discardFirstBytes(sl);
- if ((p = strstr(s, ".$"))) {
- *p = '\0'; p += 2;
- sscanf(p, "%d", &pid);
- } else
- pid = 0;
- b.addWord(pid);
- b.addStringT(s);
- s = a.getString(0);
- sl = strlen(s) + 1;
- l -= sl;
- a.discardFirstBytes(sl);
- c.addStringT(s);
- ret.push(c);
- ret.push(b);
- }
+ bufferStore a;
+ Enum<rfsv::errs> res;
+
+ a.addByte(drive);
+ if (!sendCommand(rpcs::QUERY_DRIVE, a))
+ return rfsv::E_PSI_FILE_DISC;
+ if ((res = getResponse(a, false)) != rfsv::E_PSI_GEN_NONE)
return res;
+ int l = a.getLen();
+ ret.clear();
+ while (l > 0) {
+ bufferStore b, c;
+ const char *s;
+ char *p;
+ int pid;
+ int sl;
+
+ s = a.getString(0);
+ sl = strlen(s) + 1;
+ l -= sl;
+ a.discardFirstBytes(sl);
+ if ((p = strstr(s, ".$"))) {
+ *p = '\0'; p += 2;
+ sscanf(p, "%d", &pid);
+ } else
+ pid = 0;
+ b.addWord(pid);
+ b.addStringT(s);
+ s = a.getString(0);
+ sl = strlen(s) + 1;
+ l -= sl;
+ a.discardFirstBytes(sl);
+ c.addStringT(s);
+ ret.push(c);
+ ret.push(b);
+ }
+ return res;
}
Enum<rfsv::errs> rpcs32::
getCmdLine(const char *process, bufferStore &ret)
{
- bufferStore a;
- Enum<rfsv::errs> res;
-
- a.addStringT(process);
- if (!sendCommand(rpcs::GET_CMDLINE, a))
- return rfsv::E_PSI_FILE_DISC;
- res = getResponse(a, true);
- ret = a;
- return res;
+ bufferStore a;
+ Enum<rfsv::errs> res;
+
+ a.addStringT(process);
+ if (!sendCommand(rpcs::GET_CMDLINE, a))
+ return rfsv::E_PSI_FILE_DISC;
+ res = getResponse(a, true);
+ ret = a;
+ return res;
}
Enum<rfsv::errs> rpcs32::
getMachineInfo(machineInfo &mi)
{
- bufferStore a;
- Enum<rfsv::errs> res;
-
- if (!sendCommand(rpcs::GET_MACHINE_INFO, a))
- return rfsv::E_PSI_FILE_DISC;
- if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
- return res;
- if (a.getLen() != 256)
- return rfsv::E_PSI_GEN_FAIL;
- mi.machineType = (enum rpcs::machs)a.getDWord(0);
- strncpy(mi.machineName, a.getString(16), 16);
- mi.machineName[16] = '\0';
- mi.machineUID = a.getDWord(44);
- mi.machineUID <<= 32;
- mi.machineUID |= a.getDWord(40);
- mi.countryCode = a.getDWord(56);
- mi.uiLanguage = (enum rpcs::languages)a.getDWord(164);
-
- mi.romMajor = a.getByte(4);
- mi.romMinor = a.getByte(5);
- mi.romBuild = a.getWord(6);
- mi.romSize = a.getDWord(140);
-
- mi.ramSize = a.getDWord(136);
- mi.ramMaxFree = a.getDWord(144);
- mi.ramFree = a.getDWord(148);
- mi.ramDiskSize = a.getDWord(152);
-
- mi.registrySize = a.getDWord(156);
- mi.romProgrammable = (a.getDWord(160) != 0);
-
- mi.displayWidth = a.getDWord(32);
- mi.displayHeight = a.getDWord(36);
-
- mi.time.tv_low = a.getDWord(48);
- mi.time.tv_high = a.getDWord(52);
-
- mi.tz.utc_offset = a.getDWord(60);
- mi.tz.dst_zones = a.getDWord(64);
- mi.tz.home_zone = a.getDWord(68);
-
- PsiZone::getInstance().setZone(mi.tz);
-
- mi.mainBatteryInsertionTime.tv_low = a.getDWord(72);
- mi.mainBatteryInsertionTime.tv_high = a.getDWord(76);
- mi.mainBatteryStatus = (enum rpcs::batterystates)a.getDWord(80);
- mi.mainBatteryUsedTime.tv_low = a.getDWord(84);
- mi.mainBatteryUsedTime.tv_high = a.getDWord(88);
- mi.mainBatteryCurrent = a.getDWord(92);
- mi.mainBatteryUsedPower = a.getDWord(96);
- mi.mainBatteryVoltage = a.getDWord(100);
- mi.mainBatteryMaxVoltage = a.getDWord(104);
-
- mi.backupBatteryStatus = (enum rpcs::batterystates)a.getDWord(108);
- mi.backupBatteryVoltage = a.getDWord(112);
- mi.backupBatteryMaxVoltage = a.getDWord(116);
- mi.backupBatteryUsedTime.tv_low = a.getDWord(124);
- mi.backupBatteryUsedTime.tv_high = a.getDWord(128);
-
- mi.externalPower = (a.getDWord(120) != 0);
+ bufferStore a;
+ Enum<rfsv::errs> res;
+ if (!sendCommand(rpcs::GET_MACHINE_INFO, a))
+ return rfsv::E_PSI_FILE_DISC;
+ if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
return res;
+ if (a.getLen() != 256)
+ return rfsv::E_PSI_GEN_FAIL;
+ mi.machineType = (enum rpcs::machs)a.getDWord(0);
+ strncpy(mi.machineName, a.getString(16), 16);
+ mi.machineName[16] = '\0';
+ mi.machineUID = a.getDWord(44);
+ mi.machineUID <<= 32;
+ mi.machineUID |= a.getDWord(40);
+ mi.countryCode = a.getDWord(56);
+ mi.uiLanguage = (enum rpcs::languages)a.getDWord(164);
+
+ mi.romMajor = a.getByte(4);
+ mi.romMinor = a.getByte(5);
+ mi.romBuild = a.getWord(6);
+ mi.romSize = a.getDWord(140);
+
+ mi.ramSize = a.getDWord(136);
+ mi.ramMaxFree = a.getDWord(144);
+ mi.ramFree = a.getDWord(148);
+ mi.ramDiskSize = a.getDWord(152);
+
+ mi.registrySize = a.getDWord(156);
+ mi.romProgrammable = (a.getDWord(160) != 0);
+
+ mi.displayWidth = a.getDWord(32);
+ mi.displayHeight = a.getDWord(36);
+
+ mi.time.tv_low = a.getDWord(48);
+ mi.time.tv_high = a.getDWord(52);
+
+ mi.tz.utc_offset = a.getDWord(60);
+ mi.tz.dst_zones = a.getDWord(64);
+ mi.tz.home_zone = a.getDWord(68);
+
+ PsiZone::getInstance().setZone(mi.tz);
+
+ mi.mainBatteryInsertionTime.tv_low = a.getDWord(72);
+ mi.mainBatteryInsertionTime.tv_high = a.getDWord(76);
+ mi.mainBatteryStatus = (enum rpcs::batterystates)a.getDWord(80);
+ mi.mainBatteryUsedTime.tv_low = a.getDWord(84);
+ mi.mainBatteryUsedTime.tv_high = a.getDWord(88);
+ mi.mainBatteryCurrent = a.getDWord(92);
+ mi.mainBatteryUsedPower = a.getDWord(96);
+ mi.mainBatteryVoltage = a.getDWord(100);
+ mi.mainBatteryMaxVoltage = a.getDWord(104);
+
+ mi.backupBatteryStatus = (enum rpcs::batterystates)a.getDWord(108);
+ mi.backupBatteryVoltage = a.getDWord(112);
+ mi.backupBatteryMaxVoltage = a.getDWord(116);
+ mi.backupBatteryUsedTime.tv_low = a.getDWord(124);
+ mi.backupBatteryUsedTime.tv_high = a.getDWord(128);
+
+ mi.externalPower = (a.getDWord(120) != 0);
+
+ return res;
}
static unsigned long hhh;
@@ -174,55 +171,61 @@ static unsigned long hhh;
Enum<rfsv::errs> rpcs32::
regOpenIter(void)
{
- bufferStore a;
- Enum<rfsv::errs> res;
-
- a.addStringT("HKLM\\");
- if (!sendCommand(rpcs::REG_OPEN_ITER, a))
- return rfsv::E_PSI_FILE_DISC;
- res = getResponse(a, true);
- cout << "ro: r=" << res << " a=" << a << endl;
- if (a.getLen() > 0)
- hhh = a.getDWord(0);
- return rfsv::E_PSI_GEN_NONE;
+ bufferStore a;
+ Enum<rfsv::errs> res;
+
+ a.addStringT("HKLM\\");
+ if (!sendCommand(rpcs::REG_OPEN_ITER, a))
+ return rfsv::E_PSI_FILE_DISC;
+ res = getResponse(a, true);
+ cout << "ro: r=" << res << " a=" << a << endl;
+ if (a.getLen() > 0)
+ hhh = a.getDWord(0);
+ return rfsv::E_PSI_GEN_NONE;
}
Enum<rfsv::errs> rpcs32::
configOpen(void)
{
- bufferStore a;
- Enum<rfsv::errs> res;
-
- if (!sendCommand(rpcs::CONFIG_OPEN, a))
- return rfsv::E_PSI_FILE_DISC;
- res = getResponse(a, true);
- cout << "co: r=" << res << " a=" << a << endl;
- if (a.getLen() > 0)
- hhh = a.getDWord(0);
- return rfsv::E_PSI_GEN_NONE;
+ bufferStore a;
+ Enum<rfsv::errs> res;
+
+ if (!sendCommand(rpcs::CONFIG_OPEN, a))
+ return rfsv::E_PSI_FILE_DISC;
+ res = getResponse(a, true);
+ cout << "co: r=" << res << " a=" << a << endl;
+ if (a.getLen() > 0)
+ hhh = a.getDWord(0);
+ return rfsv::E_PSI_GEN_NONE;
}
Enum<rfsv::errs> rpcs32::
configRead(void)
{
- bufferStore a;
- Enum<rfsv::errs> res;
- int l;
- FILE *f;
-
- f = fopen("blah", "w");
- do {
- a.init();
- a.addDWord(hhh);
- if (!sendCommand(rpcs::CONFIG_READ, a))
- return rfsv::E_PSI_FILE_DISC;
- if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
- return res;
- l = a.getLen();
- cout << "cr: " << l << endl;
- fwrite(a.getString(0), 1, l, f);
- } while (l > 0);
- fclose(f);
+ bufferStore a;
+ Enum<rfsv::errs> res;
+ int l;
+ FILE *f;
+
+ f = fopen("blah", "w");
+ do {
+ a.init();
+ a.addDWord(hhh);
+ if (!sendCommand(rpcs::CONFIG_READ, a))
+ return rfsv::E_PSI_FILE_DISC;
+ if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
+ return res;
+ l = a.getLen();
+ cout << "cr: " << l << endl;
+ fwrite(a.getString(0), 1, l, f);
+ } while (l > 0);
+ fclose(f);
//cout << "cr: r=" << res << " a=" << a << endl;
- return rfsv::E_PSI_GEN_NONE;
+ return rfsv::E_PSI_GEN_NONE;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rpcs32.h b/lib/rpcs32.h
index 5230247..5b56a4c 100644
--- a/lib/rpcs32.h
+++ b/lib/rpcs32.h
@@ -1,5 +1,28 @@
-#ifndef _rpcs32_h_
-#define _rpcs32_h_
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _RPCS32_H_
+#define _RPCS32_H_
#include "rpcs.h"
@@ -14,35 +37,39 @@ class rpcsfactory;
* @ref rpcs . For a complete documentation, see @ref rpcs .
*/
class rpcs32 : public rpcs {
- friend rpcsfactory;
+ friend rpcsfactory;
public:
- ~rpcs32();
-
- Enum<rfsv::errs> queryDrive(const char, bufferArray &);
- Enum<rfsv::errs> getCmdLine(const char *, bufferStore &);
- Enum<rfsv::errs> getMachineInfo(machineInfo &);
- Enum<rfsv::errs> configOpen(void);
- Enum<rfsv::errs> configRead(void);
+ Enum<rfsv::errs> queryDrive(const char, bufferArray &);
+ Enum<rfsv::errs> getCmdLine(const char *, bufferStore &);
+ Enum<rfsv::errs> getMachineInfo(machineInfo &);
+ Enum<rfsv::errs> configOpen(void);
+ Enum<rfsv::errs> configRead(void);
#if 0
- Enum<rfsv::errs> closeHandle(int);
+ Enum<rfsv::errs> closeHandle(int);
#endif
- Enum<rfsv::errs> regOpenIter(void);
+ Enum<rfsv::errs> regOpenIter(void);
#if 0
- Enum<rfsv::errs> regReadIter(void);
- Enum<rfsv::errs> regWrite(void);
- Enum<rfsv::errs> regRead(void);
- Enum<rfsv::errs> regDelete(void);
- Enum<rfsv::errs> setTime(void);
- Enum<rfsv::errs> configOpen(void);
- Enum<rfsv::errs> configRead(void);
- Enum<rfsv::errs> configWrite(void);
- Enum<rfsv::errs> queryOpen(void);
- Enum<rfsv::errs> queryRead(void);
- Enum<rfsv::errs> quitServer(void);
+ Enum<rfsv::errs> regReadIter(void);
+ Enum<rfsv::errs> regWrite(void);
+ Enum<rfsv::errs> regRead(void);
+ Enum<rfsv::errs> regDelete(void);
+ Enum<rfsv::errs> setTime(void);
+ Enum<rfsv::errs> configOpen(void);
+ Enum<rfsv::errs> configRead(void);
+ Enum<rfsv::errs> configWrite(void);
+ Enum<rfsv::errs> queryOpen(void);
+ Enum<rfsv::errs> queryRead(void);
+ Enum<rfsv::errs> quitServer(void);
#endif
private:
- rpcs32(ppsocket *);
+ rpcs32(ppsocket *);
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rpcsfactory.cc b/lib/rpcsfactory.cc
index bd3b77d..0861c2c 100644
--- a/lib/rpcsfactory.cc
+++ b/lib/rpcsfactory.cc
@@ -1,24 +1,25 @@
-//
-// RPCSFACTORY - factory object that creates an appropriate RPCS object
-// based on whatever the NCP daemon discovered in the INFO exchange.
-// Derived from rfsvfactory by Matt J. Gumbley <matt@gumbley.demon.co.uk>
-//
-// Copyright (C) 2000 Fritz Elfert <felfert@to.com>
-//
-// 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.
-//
-// This program 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 General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 2000-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -39,62 +40,67 @@
#include "Enum.h"
ENUM_DEFINITION(rpcsfactory::errs, rpcsfactory::FACERR_NONE) {
- stringRep.add(rpcsfactory::FACERR_NONE, "no error");
- stringRep.add(rpcsfactory::FACERR_COULD_NOT_SEND, "could not send version request");
- stringRep.add(rpcsfactory::FACERR_AGAIN, "try again");
- stringRep.add(rpcsfactory::FACERR_NOPSION, "no psion connected");
- stringRep.add(rpcsfactory::FACERR_PROTVERSION, "wrong protocol version");
- stringRep.add(rpcsfactory::FACERR_NORESPONSE, "no response from ncpd");
+ stringRep.add(rpcsfactory::FACERR_NONE, N_("no error"));
+ stringRep.add(rpcsfactory::FACERR_COULD_NOT_SEND, N_("could not send version request"));
+ stringRep.add(rpcsfactory::FACERR_AGAIN, N_("try again"));
+ stringRep.add(rpcsfactory::FACERR_NOPSION, N_("no psion connected"));
+ stringRep.add(rpcsfactory::FACERR_PROTVERSION, N_("wrong protocol version"));
+ stringRep.add(rpcsfactory::FACERR_NORESPONSE, N_("no response from ncpd"));
}
rpcsfactory::rpcsfactory(ppsocket *_skt)
{
- err = FACERR_NONE;
- skt = _skt;
+ err = FACERR_NONE;
+ skt = _skt;
}
rpcs * rpcsfactory::create(bool reconnect)
{
- // skt is connected to the ncp daemon, which will have (hopefully) seen
- // an INFO exchange, where the protocol version of the remote Psion was
- // sent, and noted. We have to ask the ncp daemon which protocol it saw,
- // so we can instantiate the correct rpcs protocol handler for the
- // caller. We announce ourselves to the NCP daemon, and the relevant
- // rpcs module will also announce itself.
+ // skt is connected to the ncp daemon, which will have (hopefully) seen
+ // an INFO exchange, where the protocol version of the remote Psion was
+ // sent, and noted. We have to ask the ncp daemon which protocol it saw,
+ // so we can instantiate the correct rpcs protocol handler for the
+ // caller. We announce ourselves to the NCP daemon, and the relevant
+ // rpcs module will also announce itself.
- bufferStore a;
+ bufferStore a;
- err = FACERR_NONE;
- a.addStringT("NCP$INFO");
- if (!skt->sendBufferStore(a)) {
- if (!reconnect)
- err = FACERR_COULD_NOT_SEND;
- else {
- skt->closeSocket();
- skt->reconnect();
- err = FACERR_AGAIN;
- }
- return NULL;
+ err = FACERR_NONE;
+ a.addStringT("NCP$INFO");
+ if (!skt->sendBufferStore(a)) {
+ if (!reconnect)
+ err = FACERR_COULD_NOT_SEND;
+ else {
+ skt->closeSocket();
+ skt->reconnect();
+ err = FACERR_AGAIN;
}
- if (skt->getBufferStore(a) == 1) {
- if (a.getLen() > 8 && !strncmp(a.getString(), "Series 3", 8)) {
- return new rpcs16(skt);
- }
- else if (a.getLen() > 8 && !strncmp(a.getString(), "Series 5", 8)) {
- return new rpcs32(skt);
- }
- if ((a.getLen() > 8) && !strncmp(a.getString(), "No Psion", 8)) {
- skt->closeSocket();
- skt->reconnect();
- err = FACERR_NOPSION;
- return NULL;
- }
- // Invalid protocol version
- err = FACERR_PROTVERSION;
- } else
- err = FACERR_NORESPONSE;
-
- // No message returned.
return NULL;
+ }
+ if (skt->getBufferStore(a) == 1) {
+ if (a.getLen() > 8 && !strncmp(a.getString(), "Series 3", 8)) {
+ return new rpcs16(skt);
+ }
+ else if (a.getLen() > 8 && !strncmp(a.getString(), "Series 5", 8)) {
+ return new rpcs32(skt);
+ }
+ if ((a.getLen() > 8) && !strncmp(a.getString(), "No Psion", 8)) {
+ skt->closeSocket();
+ skt->reconnect();
+ err = FACERR_NOPSION;
+ return NULL;
+ }
+ // Invalid protocol version
+ err = FACERR_PROTVERSION;
+ } else
+ err = FACERR_NORESPONSE;
+
+ // No message returned.
+ return NULL;
}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/lib/rpcsfactory.h b/lib/rpcsfactory.h
index cc36f0d..c08800a 100644
--- a/lib/rpcsfactory.h
+++ b/lib/rpcsfactory.h
@@ -1,5 +1,28 @@
-#ifndef _rpcsfactory_h_
-#define _rpcsfactory_h_
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * 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.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _RPCSFACTORY_H_
+#define _RPCSFACTORY_H_
#include "rpcs.h"
@@ -12,53 +35,58 @@ class ppsocket;
class rpcsfactory {
public:
- /**
- * The known errors which can happen during @ref create .
- */
- enum errs {
- FACERR_NONE = 0,
- FACERR_COULD_NOT_SEND = 1,
- FACERR_AGAIN = 2,
- FACERR_NOPSION = 3,
- FACERR_PROTVERSION = 4,
- FACERR_NORESPONSE = 5,
- };
+ /**
+ * The known errors which can happen during @ref create .
+ */
+ enum errs {
+ FACERR_NONE = 0,
+ FACERR_COULD_NOT_SEND = 1,
+ FACERR_AGAIN = 2,
+ FACERR_NOPSION = 3,
+ FACERR_PROTVERSION = 4,
+ FACERR_NORESPONSE = 5,
+ };
- /**
- * Constructs a rpcsfactory.
- *
- * @param skt The socket to be used for connecting
- * to the ncpd daemon.
- */
- rpcsfactory(ppsocket * skt);
+ /**
+ * Constructs a rpcsfactory.
+ *
+ * @param skt The socket to be used for connecting
+ * to the ncpd daemon.
+ */
+ rpcsfactory(ppsocket * skt);
- /**
- * Creates a new rpcs instance.
- *
- * @param reconnect Set to true, if automatic reconnect
- * should be performed on failure.
- *
- * @returns A pointer to a newly created rpcs instance or
- * NULL on failure.
- */
- virtual rpcs * create(bool reconnect);
+ /**
+ * Creates a new rpcs instance.
+ *
+ * @param reconnect Set to true, if automatic reconnect
+ * should be performed on failure.
+ *
+ * @returns A pointer to a newly created rpcs instance or
+ * NULL on failure.
+ */
+ virtual rpcs * create(bool reconnect);
- /**
- * Retrieve an error code.
- *
- * @returns The error code, in case @ref create has
- * failed, 0 otherwise.
- */
- virtual Enum<errs> getError() { return err; }
+ /**
+ * Retrieve an error code.
+ *
+ * @returns The error code, in case @ref create has
+ * failed, 0 otherwise.
+ */
+ virtual Enum<errs> getError() { return err; }
private:
- /**
- * The socket to be used for connecting to the
- * ncpd daemon.
- */
- ppsocket *skt;
- Enum<errs> err;
+ /**
+ * The socket to be used for connecting to the
+ * ncpd daemon.
+ */
+ ppsocket *skt;
+ Enum<errs> err;
};
#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */