From a7e4250b20fa5012942c4fe05ee0c7f701c5799f Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Sun, 4 Feb 2001 04:23:06 +0000 Subject: Cleaned up ppsocket. More 64bit-related stuff. --- Makefile.cvs | 2 + kde2/Makefile.am | 3 + kde2/kioslave/kio_plp.cpp | 30 +-- lib/bufferstore.cc | 4 +- lib/bufferstore.h | 6 +- lib/ppsocket.cc | 467 +++++++++++++++------------------------------- lib/ppsocket.h | 252 ++++++++++++++++++------- lib/rfsv.cc | 2 +- lib/rfsv.h | 44 ++--- lib/rfsv16.cc | 163 ++++++---------- lib/rfsv16.h | 38 ++-- lib/rfsv32.cc | 88 ++++----- lib/rfsv32.h | 44 ++--- ncpd/linkchan.cc | 2 +- ncpd/main.cc | 7 +- ncpd/ncp.cc | 2 +- ncpd/packet.cc | 6 +- plpbackup/plpbackup.cc | 11 +- plpftp/ftp.cc | 25 +-- plpnfsd/main.cc | 35 ++-- plpnfsd/mp_pfs_ops.c | 2 +- 21 files changed, 568 insertions(+), 665 deletions(-) diff --git a/Makefile.cvs b/Makefile.cvs index 990b106..753682a 100644 --- a/Makefile.cvs +++ b/Makefile.cvs @@ -10,6 +10,7 @@ devel: $(LIBTOOLFILES) $(AUTOMAKEFILES) aclocal -I conf/m4/plptools -I conf/m4/kde autoheader automake + make -C kde2 -f Makefile.am am_edit autoconf touch include/stamp-h.in @@ -17,6 +18,7 @@ dist: $(LIBTOOLFILES) $(AUTOMAKEFILES) aclocal -I conf/m4/plptools conf/m4/kde autoheader automake --include-deps + make -C kde2 -f Makefile.am am_edit autoconf touch include/stamp-h.in ./configure diff --git a/kde2/Makefile.am b/kde2/Makefile.am index 4c8fb84..fe79aad 100644 --- a/kde2/Makefile.am +++ b/kde2/Makefile.am @@ -10,3 +10,6 @@ TMPDEST= # maintainer-clean-local: rm -f Makefile.in + +am_edit: + perl ../conf/am_edit diff --git a/kde2/kioslave/kio_plp.cpp b/kde2/kioslave/kio_plp.cpp index 72b1060..e0464bd 100644 --- a/kde2/kioslave/kio_plp.cpp +++ b/kde2/kioslave/kio_plp.cpp @@ -247,21 +247,21 @@ openConnection() { } } - long devbits; + u_int32_t devbits; Enum res; if ((res = plpRfsv->devlist(devbits)) == rfsv::E_PSI_GEN_NONE) { for (int i = 0; i < 26; i++) { - char vname[256]; - long vtotal, vfree, vattr, vuniqueid; + string vname; + u_int32_t vtotal, vfree, vattr, vuniqueid; if ((devbits & 1) != 0) { if (plpRfsv->devinfo(i, vfree, vtotal, vattr, vuniqueid, vname) == rfsv::E_PSI_GEN_NONE) { QString name; - if (strlen(vname)) - name = QString(vname); + if (!vname.empty()) + name = QString(vname.c_str()); else name.sprintf("%c", 'A' + i); drives.append(name); @@ -688,10 +688,10 @@ get( const KURL& url ) { convertName(name); Enum res; - long handle; - long len; - long size; - long total = 0; + u_int32_t handle; + u_int32_t len; + u_int32_t size; + u_int32_t total = 0; if (emitTotalSize(name)) return; @@ -738,7 +738,7 @@ put( const KURL& url, int _mode, bool _overwrite, bool /*_resume*/ ) { convertName(name); Enum res; - long handle; + u_int32_t handle; int result; res = plpRfsv->fcreatefile(plpRfsv->opMode(rfsv::PSI_O_RDWR), name, handle); @@ -756,8 +756,8 @@ put( const KURL& url, int _mode, bool _overwrite, bool /*_resume*/ ) { if (result > 0) do { - long written; - int count = (len > RFSV_SENDLEN) ? RFSV_SENDLEN : len; + u_int32_t written; + u_int32_t count = (len > RFSV_SENDLEN) ? RFSV_SENDLEN : len; res = plpRfsv->fwrite(handle, data, count, written); if (checkForError(res)) { plpRfsv->fclose(handle); @@ -820,7 +820,7 @@ rename(const KURL &src, const KURL &dest, bool _overwrite) { convertName(from); convertName(to); if (!_overwrite) { - long attr; + u_int32_t attr; if ((res = plpRfsv->fgetattr(to, attr)) == rfsv::E_PSI_GEN_NONE) { error(ERR_FILE_ALREADY_EXIST, to); @@ -836,7 +836,7 @@ rename(const KURL &src, const KURL &dest, bool _overwrite) { extern "C" { static int -progresswrapper(void *ptr, long total) { +progresswrapper(void *ptr, u_int32_t total) { ((PLPProtocol *)ptr)->calcprogress(total); return 1; @@ -877,7 +877,7 @@ copy( const KURL &src, const KURL &dest, int _mode, bool _overwrite ) { convertName(to); Enum res; if (!_overwrite) { - long attr; + u_int32_t attr; if ((res = plpRfsv->fgetattr(to, attr)) == rfsv::E_PSI_GEN_NONE) { error(ERR_FILE_ALREADY_EXIST, to); return; diff --git a/lib/bufferstore.cc b/lib/bufferstore.cc index f2686dc..35bea26 100644 --- a/lib/bufferstore.cc +++ b/lib/bufferstore.cc @@ -84,11 +84,11 @@ unsigned char bufferStore::getByte(long pos) const { return buff[pos+start]; } -unsigned int bufferStore::getWord(long pos) const { +u_int16_t bufferStore::getWord(long pos) const { return buff[pos+start] + (buff[pos+start+1] << 8); } -unsigned int bufferStore::getDWord(long pos) const { +u_int32_t bufferStore::getDWord(long pos) const { return buff[pos+start] + (buff[pos+start+1] << 8) + (buff[pos+start+2] << 16) + diff --git a/lib/bufferstore.h b/lib/bufferstore.h index 65f6607..d9c2e54 100644 --- a/lib/bufferstore.h +++ b/lib/bufferstore.h @@ -1,6 +1,8 @@ #ifndef _bufferstore_h #define _bufferstore_h +#include + class ostream; /** @@ -68,7 +70,7 @@ public: * * @returns The value of the word at index pos */ - unsigned int getWord(long pos = 0) const; + u_int16_t getWord(long pos = 0) const; /** * Retrieves the dword at index pos. @@ -77,7 +79,7 @@ public: * * @returns The value of the dword at index pos */ - unsigned int getDWord(long pos = 0) const; + u_int32_t getDWord(long pos = 0) const; /** * Retrieves the characters at index pos. diff --git a/lib/ppsocket.cc b/lib/ppsocket.cc index 86ff4f4..e43b9e6 100644 --- a/lib/ppsocket.cc +++ b/lib/ppsocket.cc @@ -24,12 +24,13 @@ #endif #include -#include #include #include #include #include #include +#include +#include #include #include #include @@ -38,29 +39,16 @@ #include "bufferstore.h" #include "ppsocket.h" -//********************************************************************** -// For unix we need a few definitions -//********************************************************************** +#define INVALID_SOCKET -1 +#define SOCKET_ERROR -1 -#ifndef MAKEWORD -#define MAKEWORD(a, b) ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8)) -#endif -#ifndef SHORT -#define SHORT int -#endif - -//This constructor is useful when converting a socket -//to a derived class of socket 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_Timeout = another.m_Timeout; m_LastError = another.m_LastError; - - m_Timeout = INFINITE; } @@ -71,20 +59,18 @@ ppsocket::ppsocket() 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; m_Bound = false; m_LastError = 0; - m_Timeout = INFINITE; } ppsocket::~ppsocket() { if (m_Socket != INVALID_SOCKET) { shutdown(m_Socket, 3); - close(m_Socket); + ::close(m_Socket); } } @@ -93,40 +79,52 @@ reconnect() { if (m_Socket != INVALID_SOCKET) { shutdown(m_Socket, 3); - close(m_Socket); + ::close(m_Socket); } m_Socket = INVALID_SOCKET; if (!createSocket()) return (false); m_LastError = 0; - m_Bound = 0; + m_Bound = false; if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) != 0) { - m_LastError = lastErrorCode(); + m_LastError = errno; return (false); } if (::connect(m_Socket, &m_PeerAddr, sizeof(m_PeerAddr)) != 0) { - m_LastError = lastErrorCode(); + m_LastError = errno; return (false); } return (true); } -void ppsocket:: -printPeer() +string ppsocket:: +toString() { - char *pPeer = 0; + string ret = ""; + char nbuf[10]; + char *tmp = 0L; int port; - pPeer = inet_ntoa(((struct sockaddr_in *) &m_PeerAddr)->sin_addr); - if (pPeer) { - port = ntohs(((struct sockaddr_in *) &m_PeerAddr)->sin_port); - cout << "Peer : " << pPeer << " Port : " << port << endl; - } else - cerr << "Error getting Peer details\n"; + 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(char *Peer, int PeerPort, char *Host, int HostPort) +connect(const char * const Peer, int PeerPort, const char * const Host, int HostPort) { //**************************************************** //* If we aren't already bound set the host and bind * @@ -147,14 +145,14 @@ connect(char *Peer, int PeerPort, char *Host, int HostPort) //* Connect * //*********** if (::connect(m_Socket, &m_PeerAddr, sizeof(m_PeerAddr)) != 0) { - m_LastError = lastErrorCode(); + m_LastError = errno; return (false); } return (true); } bool ppsocket:: -listen(char *Host, int Port) +listen(const char * const Host, int Port) { //**************************************************** //* If we aren't already bound set the host and bind * @@ -170,7 +168,7 @@ listen(char *Host, int Port) //********************** if (::listen(m_Socket, 5) != 0) { - m_LastError = lastErrorCode(); + m_LastError = errno; return (false); } // Our accept member function relies on non-blocking accepts, @@ -180,7 +178,7 @@ listen(char *Host, int Port) } ppsocket *ppsocket:: -accept(char *Peer, int MaxLen) +accept(string *Peer) { #ifdef sun int len; @@ -193,24 +191,23 @@ accept(char *Peer, int MaxLen) //***************************************************** //* Allocate a new object to hold the accepted socket * //***************************************************** - accepted = new ppsocket; if (!accepted) { - m_LastError = lastErrorCode(); - return (NULL); + m_LastError = errno; + return NULL; } //*********************** //* Accept a connection * //*********************** len = sizeof(struct sockaddr); - accepted->m_Socket =::accept(m_Socket, &accepted->m_PeerAddr, &len); + accepted->m_Socket = ::accept(m_Socket, &accepted->m_PeerAddr, &len); if (accepted->m_Socket == INVALID_SOCKET) { - m_LastError = lastErrorCode(); + m_LastError = errno; delete accepted; - return (NULL); + return NULL; } //**************************************************** //* Got a connection so fill in the other attributes * @@ -230,33 +227,12 @@ accept(char *Peer, int MaxLen) //**************************************************** //* If required get the name of the connected client * //**************************************************** - if (Peer) { peer = inet_ntoa(((struct sockaddr_in *) &accepted->m_PeerAddr)->sin_addr); - if (peer) { - strncpy(Peer, peer, MaxLen); - Peer[MaxLen] = '\0'; - } - } else { - strcpy(Peer, ""); + if (peer) + *Peer = peer; } - return (accepted); -} - -int ppsocket:: -printf(const char *Format,...) -{ - int i; - va_list ap; - char s[512]; - - va_start(ap, Format); - vsprintf(s, Format, ap); - va_end(ap); - - i = writeTimeout(s, strlen(s), 0); - - return (i); + return accepted; } bool ppsocket:: @@ -278,7 +254,7 @@ getBufferStore(bufferStore & a, bool wait) * 1 for message OK, and -1 for socket problem */ - long l; + u_int32_t l; long count = 0; unsigned char *buff; unsigned char *bp; @@ -286,12 +262,12 @@ getBufferStore(bufferStore & a, bool wait) return 0; a.init(); - if (readTimeout(&l, sizeof(l), 0) != sizeof(l)) + if (recv(&l, sizeof(l), 0) != sizeof(l)) return -1; l = ntohl(l); bp = buff = new unsigned char[l]; while (l > 0) { - int j = readTimeout(bp, l, 0); + int j = recv(bp, l, 0); if (j == SOCKET_ERROR || j == 0) { delete[]buff; return -1; @@ -309,16 +285,16 @@ bool ppsocket:: sendBufferStore(const bufferStore & a) { long l = a.getLen(); - long hl = htonl(l); + u_int32_t hl = htonl(l); long sent = 0; int retries = 0; int i; - i = writeTimeout((char *) &hl, sizeof(hl), 0); + i = send((char *) &hl, sizeof(hl), 0); if (i != sizeof(hl)) return false; while (l > 0) { - i = writeTimeout((const char *)a.getString(sent), l, 0); + i = send((const char *)a.getString(sent), l, 0); if (i == SOCKET_ERROR || i == 0) return (false); sent += i; @@ -332,157 +308,23 @@ sendBufferStore(const bufferStore & a) } int ppsocket:: -readEx(unsigned char *Data, int cTerm, int MaxLen) -{ - int i, j; - - for (i = 0; i < MaxLen; i++) { - j = readTimeout(Data + i, 1, 0); - - if (j == SOCKET_ERROR || j == 0) { - Data[i] = '\0'; - return (i > 0 ? i : 0); - } - if (Data[i] == cTerm) - break; - } - - return (i + 1); -} - -bool ppsocket:: -puts(const char *Data) -{ - int tosend, sent, retries, i; - - tosend = strlen(Data); - sent = retries = 0; - - while (tosend > 0) { - i = writeTimeout(Data + sent, tosend, 0); - - if (i == SOCKET_ERROR || i == 0) - return (sent > 0 ? true : false); - - sent += i; - tosend -= i; - - if (++retries > 5) { - m_LastError = 0; - return (false); - } - } - - return (true); -} - -char ppsocket:: -sgetc(void) -{ - int i; - char c; - - i = readTimeout(&c, 1, 0); - if (i == SOCKET_ERROR || i == 0) { - return (0); - } - return (c); -} - -bool ppsocket:: -sputc(char c) -{ - int i; - - cout << hex << (int) c << endl; - i = writeTimeout(&c, 1, 0); - if (i == SOCKET_ERROR || i == 0) - return (false); - return (true); -} - -int ppsocket:: -read(void *Data, size_t Size, size_t NumObj) +recv(void *buf, int len, int flags) { - int i = readTimeout(Data, Size * NumObj, 0); - - return (i); -} - -int ppsocket:: -write(const void *Data, size_t Size, size_t NumObj) -{ - int i = writeTimeout((char *) Data, Size * NumObj, 0); - - return (i); -} - -int ppsocket:: -recv(char *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 = lastErrorCode(); + m_LastError = errno; return (i); } int ppsocket:: -send(const char *buf, int len, int flags) +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 = lastErrorCode(); - - return (i); -} - -int ppsocket:: -readTimeout(void *buf, int len, int flags) -{ - int i; - - //********************************************************* - //* If there is no timeout use the Berkeley recv function * - //********************************************************* - - if (m_Timeout == INFINITE) { - i = ::recv(m_Socket, buf, len, flags); - - if (i == SOCKET_ERROR) { - m_LastError = lastErrorCode(); - } - } - //******************************************** - //* If there is a timeout use overlapped i/o * - //******************************************** - - else { - i = SOCKET_ERROR; - } - - - return (i); -} - -int ppsocket:: -writeTimeout(const char *buf, int len, int flags) -{ - int i; - // If there is no timeout use the Berkeley send function - - if (m_Timeout == INFINITE) { - i =::send(m_Socket, buf, len, flags); - - if (i == SOCKET_ERROR) { - m_LastError = lastErrorCode(); - } - } else { - // If there is a timeout use overlapped i/o - i = SOCKET_ERROR; - } + m_LastError = errno; return (i); } @@ -491,97 +333,97 @@ bool ppsocket:: closeSocket(void) { shutdown(m_Socket, 3); - if (close(m_Socket) != 0) { - m_LastError = lastErrorCode(); - return (false); + if (::close(m_Socket) != 0) { + m_LastError = errno; + return false; } m_Socket = INVALID_SOCKET; - - return (true); + return true; } bool ppsocket:: -bindSocket(char *Host, int Port) +bindSocket(const char * const Host, int Port) { // If we are already bound return false but with no last error - - m_LastError = 0; - if (m_Bound) { - return (false); + 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 (!createSocket()) + return false; } + // Set SO_REUSEADDR int one = 1; - if (setsockopt( m_Socket, SOL_SOCKET, SO_REUSEADDR, - (const char *) &one, sizeof(int)) < 0 ) + 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 (!setHost(Host, Port)) + return false; + // Now bind the socket if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) != 0) { - m_LastError = lastErrorCode(); - return (false); + m_LastError = errno; + return false; } - m_Bound = true; - return (true); + m_Bound = true; + return true; } bool ppsocket:: -bindInRange(char *Host, int Low, int High, int Retries) +bindInRange(const char * const Host, int Low, int High, int Retries) { - int port, i; + int port; + int i; // If we are already bound return false but with no last error - m_LastError = 0; 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 (!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; + return false; + if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) == 0) + break; } if (port > High) { - m_LastError = lastErrorCode(); - return (false); + m_LastError = errno; + return false; } } else { for (i = 0; i < Retries; i++) { port = Low + (rand() % (High - Low)); if (!setHost(Host, port)) - return (false); + return false; if (::bind(m_Socket, &m_HostAddr, sizeof(m_HostAddr)) == 0) break; } if (i >= Retries) { - m_LastError = lastErrorCode(); - return (false); + m_LastError = errno; + return false; } } m_Bound = true; - return (true); + return true; } bool ppsocket:: @@ -592,10 +434,10 @@ linger(bool LingerOn, int LingerTime) // If the socket hasn't been created create it now if (m_Socket == INVALID_SOCKET) { - if (!createSocket()) { - return (false); - } + if (!createSocket()) + return false; } + // Set the lingering if (LingerOn) { l.l_onoff = 1; @@ -607,11 +449,10 @@ linger(bool LingerOn, int LingerTime) i = setsockopt(m_Socket, SOL_SOCKET, SO_LINGER, (const char *) &l, sizeof(l)); // Check for errors if (i != 0) { - m_LastError = lastErrorCode(); - return (false); + m_LastError = errno; + return false; } - // Return indicating success - return (true); + return true; } bool ppsocket:: @@ -619,122 +460,122 @@ createSocket(void) { // If the socket has already been created just return true if (m_Socket != INVALID_SOCKET) - return (true); + return true; + // Create the socket - m_Socket =::socket(PF_INET, SOCK_STREAM, 0); + m_Socket = ::socket(PF_INET, SOCK_STREAM, 0); if (m_Socket == INVALID_SOCKET) { - m_LastError = lastErrorCode(); - return (false); + m_LastError = errno; + return false; } + // By default set no lingering - linger(false, 0); + linger(false); + // Return indicating success - return (true); + return true; } bool ppsocket:: -setPeer(char *Peer, int Port) +setPeer(const char * const Peer, int Port) { - struct hostent *he; + struct hostent *he = NULL; // If a peer name was supplied then use it if (Peer) { - he = gethostbyname(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) { - unsigned long ipaddress = inet_addr(Peer); - if (ipaddress == INADDR_NONE) { - m_LastError = lastErrorCode(); - return (false); + struct in_addr ipaddr; + + if (!inet_aton(Peer, &ipaddr)) { + m_LastError = errno; + return false; } - he = gethostbyaddr((const char *) &ipaddress, 4, PF_INET); + he = gethostbyaddr(&ipaddr.s_addr, sizeof(ipaddr.s_addr), PF_INET); if (!he) { - m_LastError = lastErrorCode(); + m_LastError = errno; return (false); } } - memcpy((void *) &((struct sockaddr_in *) &m_PeerAddr)->sin_addr, (void *) he->h_addr_list[0], 4); + 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((SHORT) Port); - return (true); + ((struct sockaddr_in *)&m_PeerAddr)->sin_port = htons(Port); + return true; } bool ppsocket:: -getPeer(char *Peer, int MaxLen, int *Port) +getPeer(string *Peer, int *Port) { char *peer; if (Peer) { peer = inet_ntoa(((struct sockaddr_in *) &m_PeerAddr)->sin_addr); if (!peer) { - m_LastError = lastErrorCode(); + m_LastError = errno; return (false); } - strncpy(Peer, peer, MaxLen); - Peer[MaxLen] = '\0'; + *Peer = peer; } if (Port) *Port = ntohs(((struct sockaddr_in *) &m_PeerAddr)->sin_port); - return (false); + return false; } bool ppsocket:: -setHost(char *Host, int Port) +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) { - unsigned long ipaddress = inet_addr(Host); - if (ipaddress == INADDR_NONE) { - m_LastError = lastErrorCode(); - return (false); + struct in_addr ipaddr; + + if (!inet_aton(Host, &ipaddr)) { + m_LastError = errno; + return false; } - he = gethostbyaddr((const char *) &ipaddress, 4, PF_INET); + he = gethostbyaddr(&ipaddr.s_addr, sizeof(ipaddr.s_addr), PF_INET); if (!he) { - m_LastError = lastErrorCode(); - return (false); + m_LastError = errno; + return false; } } - memcpy((void *) &((struct sockaddr_in *) &m_HostAddr)->sin_addr, (void *) he->h_addr_list[0], 4); + 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 a port name was supplied use it if (Port > 0) - ((struct sockaddr_in *) &m_HostAddr)->sin_port = htons((SHORT) Port); - return (true); + ((struct sockaddr_in *)&m_HostAddr)->sin_port = htons(Port); + return true; } bool ppsocket:: -getHost(char *Host, int MaxLen, int *Port) +getHost(string *Host, int *Port) { char *host; if (Host) { - host = inet_ntoa(((struct sockaddr_in *) &m_HostAddr)->sin_addr); + host = inet_ntoa(((struct sockaddr_in *)&m_HostAddr)->sin_addr); if (!host) { - m_LastError = lastErrorCode(); - return (false); + m_LastError = errno; + return false; } - strncpy(Host, host, MaxLen); - Host[MaxLen] = '\0'; + *Host = host; } if (Port) - *Port = ntohs(((struct sockaddr_in *) &m_HostAddr)->sin_port); - return (false); -} - -DWORD ppsocket:: -lastErrorCode() -{ - return errno; -} - -void ppsocket:: -setSocketInvalid() -{ - m_Socket = INVALID_SOCKET; + *Port = ntohs(((struct sockaddr_in *)&m_HostAddr)->sin_port); + return true; } diff --git a/lib/ppsocket.h b/lib/ppsocket.h index 696ca78..57cc788 100644 --- a/lib/ppsocket.h +++ b/lib/ppsocket.h @@ -1,88 +1,198 @@ #ifndef _PPSOCKET_H_ #define _PPSOCKET_H_ +#include #include #include #include #include -#define DWORD unsigned int -#define SOCKET int - -#ifndef INADDR_NONE -#define INADDR_NONE (in_addr_t)-1 -#endif -#define INVALID_SOCKET -1 -#define SOCKET_ERROR -1 -#define INFINITE 0 - -extern int errno; - class bufferStore; +/** + * A class for dealing with sockets. + */ class ppsocket { public: - ppsocket(); - virtual ~ppsocket(); - - virtual bool connect(char* Peer, int PeerPort, char* Host = NULL, int HostPort = 0); - virtual bool reconnect(); - virtual void printPeer(); - virtual bool listen(char* Host, int Port); - ppsocket* accept(char* Peer, int MaxLen); - bool dataToGet() const; - int getBufferStore(bufferStore &a, bool wait = true); - bool sendBufferStore(const bufferStore &a); - int printf(const char* Format, ...); - int readEx(unsigned char *Data, int cTerm, int MaxLen); - bool puts(const char* Data); - char sgetc(void); - bool sputc(char c); - int read(void* Data, size_t Size, size_t NumObj); - virtual int write(const void* Data, size_t Size, size_t NumObj); - int recv(char* buf, int len, int flags); - int send(const char* buf, int len, int flags); - int readTimeout(void * buf, int len, int flags); - int writeTimeout(const char *buf, int len, int flags); - inline void timeout(DWORD t) { m_Timeout = t; } - inline DWORD timeout(void) { return(m_Timeout); } - bool closeSocket(void); - bool bindSocket(char* Host, int Port); - bool bindInRange(char* Host, int Low, int High, int Retries); - bool linger(bool LingerOn, int LingerTime = 0); - virtual bool createSocket(void); - bool setPeer(char *Peer, int Port); - bool getPeer(char *Peer, int MaxLen, int* Port); - bool setHost(char *Host, int Port); - bool getHost(char *Host, int MaxLen, int* Port); - DWORD getLastError(void) { return(m_LastError); } - inline SOCKET socket(void) const { return(m_Socket); } - DWORD lastErrorCode(); - - //set the current socket to invalid - //useful when deleting if the socket has been - //copied to another and should not be closed - //when this instance is destructed - void setSocketInvalid(); - -protected: - ppsocket(const ppsocket&); - struct sockaddr* getPeerAddrStruct() { return &m_PeerAddr; } - struct sockaddr* getHostAddrStruct() { return &m_HostAddr; } - void setHostAddrStruct(struct sockaddr* pHostStruct) { m_HostAddr = *pHostStruct; } - void setSocket(SOCKET& sock) { m_Socket = sock; } - void setBound() { m_Bound = true;} - void updateLastError() {m_LastError = lastErrorCode(); } - -private: - SOCKET m_Socket; - struct sockaddr m_HostAddr, m_PeerAddr; - int m_Port; - bool m_Bound; - DWORD m_Timeout; - DWORD m_LastError; + /** + * 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 ": -> :" + * 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 for incoming data. + * + * @returns true if data is available, false otherwise. + */ + bool dataToGet() 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); + + /** + * Retrieves the socket number. + * + * @returns the socket number. + */ + inline int socket(void) const { return(m_Socket); } + + 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; }; #endif diff --git a/lib/rfsv.cc b/lib/rfsv.cc index 68635d5..30fd502 100644 --- a/lib/rfsv.cc +++ b/lib/rfsv.cc @@ -126,7 +126,7 @@ convertSlash(const string &name) } string rfsv:: -attr2String(const long attr) +attr2String(const u_int32_t attr) { string tmp = ""; tmp += ((attr & PSI_A_DIR) ? 'd' : '-'); diff --git a/lib/rfsv.h b/lib/rfsv.h index 03ed36f..0cfe7b2 100644 --- a/lib/rfsv.h +++ b/lib/rfsv.h @@ -11,17 +11,17 @@ typedef deque PlpDir; class ppsocket; -const long RFSV_SENDLEN = 2000; +const int RFSV_SENDLEN = 2000; /** * Defines the callback procedure for * progress indication of copy operations. */ -typedef int (*cpCallback_t)(void *, long); +typedef int (*cpCallback_t)(void *, u_int32_t); class rfsvDirhandle { public: - unsigned long h; + u_int32_t h; bufferStore b; }; @@ -198,7 +198,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum fopen(const long attr, const char * const name, long &handle) = 0; + virtual Enum fopen(const u_int32_t attr, const char * const name, u_int32_t &handle) = 0; /** * Creates a unique temporary file. @@ -210,7 +210,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum mktemp(long &handle, char * const name) = 0; + virtual Enum mktemp(u_int32_t &handle, string &name) = 0; /** * Creates a named file. @@ -223,7 +223,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum fcreatefile(const long attr, const char * const name, long &handle) = 0; + virtual Enum fcreatefile(const u_int32_t attr, const char * const name, u_int32_t &handle) = 0; /** * Creates an named file, overwriting an existing file. @@ -236,7 +236,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum freplacefile(const long attr, const char * const name, long &handle) = 0; + virtual Enum 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 @@ -244,7 +244,7 @@ class rfsv { * * @param handle A valid file handle. */ - virtual Enum fclose(const long handle) = 0; + virtual Enum fclose(const u_int32_t handle) = 0; /** * Reads a directory on the Psion. @@ -286,7 +286,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum fgetattr(const char * const name, long &attr) = 0; + virtual Enum fgetattr(const char * const name, u_int32_t &attr) = 0; /** * Retrieves attributes, size and modification time of a file on the Psion. @@ -303,7 +303,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum fsetattr(const char * const name, const long seta, const long unseta) = 0; + virtual Enum fsetattr(const char * const name, const u_int32_t seta, const u_int32_t unseta) = 0; /** * Counts number of entries in a directory. @@ -313,7 +313,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum dircount(const char * const name, long &count) = 0; + virtual Enum dircount(const char * const name, u_int32_t &count) = 0; /** * Retrieves available drives on the Psion. @@ -323,7 +323,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum devlist(long &devbits) = 0; + virtual Enum devlist(u_int32_t &devbits) = 0; /** * Retrieves details about a drive. @@ -334,11 +334,11 @@ class rfsv { * @param total On return, the total capacity in bytes is returned here. * @param attr On return, the attributes of the drive are returned here. * @param uniqueid On return, the unique Id of the drive is returned here. - * @param name On return, the volume name is copied to this pointer's destination. + * @param name On return, the volume name returned here. * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum devinfo(const int dev, long &free, long &total, long &attr, long &uniqueid, char * const name) = 0; + virtual Enum devinfo(const u_int32_t dev, u_int32_t &free, u_int32_t &total, u_int32_t &attr, u_int32_t &uniqueid, string &name) = 0; /** * Reads from a file on the Psion. @@ -350,7 +350,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum fread(const long handle, unsigned char * const buffer, const long len, long &count) = 0; + virtual Enum 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. @@ -362,7 +362,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum fwrite(const long handle, const unsigned char * const buffer, const long len, long &count) = 0; + virtual Enum 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. @@ -418,7 +418,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum fsetsize(const long handle, const long size) = 0; + virtual Enum fsetsize(const u_int32_t handle, const u_int32_t size) = 0; /** * Sets the current file position of a file on the Psion. @@ -430,7 +430,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum fseek(const long handle, const long offset, const long mode, long &resultpos) = 0; + virtual Enum 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. @@ -479,7 +479,7 @@ class rfsv { * * @returns A Psion error code (One of enum @ref #errs ). */ - virtual Enum opendir(const long attr, const char * const name, rfsvDirhandle &handle) = 0; + virtual Enum opendir(const u_int32_t attr, const char * const name, rfsvDirhandle &handle) = 0; /** * Read directory entries. @@ -540,7 +540,7 @@ class rfsv { * @returns Pointer to static textual representation of file attributes. * */ - string attr2String(const long attr); + string attr2String(const u_int32_t attr); /** * Converts an open-mode (A combination of the PSI_O_ constants.) @@ -551,7 +551,7 @@ class rfsv { * @returns The machine specific representation for use with * @ref fopen , @ref fcreatefile and @freplacefile. */ - virtual long opMode(const long mode) = 0; + virtual u_int32_t opMode(const u_int32_t mode) = 0; /** * Utility method, converts '/' to '\'. @@ -568,7 +568,7 @@ protected: ppsocket *skt; Enum status; - int serNum; + int32_t serNum; }; #endif diff --git a/lib/rfsv16.cc b/lib/rfsv16.cc index c4798eb..2b474cb 100644 --- a/lib/rfsv16.cc +++ b/lib/rfsv16.cc @@ -50,7 +50,7 @@ rfsv16::rfsv16(ppsocket *_skt) } Enum rfsv16:: -fopen(long attr, const char *name, long &handle) +fopen(u_int32_t attr, const char *name, u_int32_t &handle) { bufferStore a; string realName = convertSlash(name); @@ -70,24 +70,19 @@ fopen(long attr, const char *name, long &handle) // internal Enum rfsv16:: -mktemp(long &handle, char * const tmpname) +mktemp(u_int32_t &handle, string &tmpname) { bufferStore a; - // FIXME: anything that calls fopen should NOT do the name - // conversion - it's just done here. - a.addWord(P_FUNIQUE); - a.addString("TMP"); - a.addByte(0x00); // Needs to be manually Null-Terminated. + a.addStringT("TMP"); if (!sendCommand(OPENUNIQUE, a)) return E_PSI_FILE_DISC; Enum res = getResponse(a); if (res == E_PSI_GEN_NONE) { handle = a.getWord(0); - if (tmpname) - strcpy(tmpname, a.getString(2)); + tmpname = a.getString(2); return res; } return res; @@ -95,26 +90,26 @@ mktemp(long &handle, char * const tmpname) // internal and external Enum rfsv16:: -fcreatefile(long attr, const char *name, long &handle) +fcreatefile(u_int32_t attr, const char *name, u_int32_t &handle) { return fopen(attr | P_FCREATE, name, handle); } // this is internal - not used by plpnfsd, unlike fcreatefile Enum rfsv16:: -freplacefile(long attr, const char *name, long &handle) +freplacefile(u_int32_t attr, const char *name, u_int32_t &handle) { return fopen(attr | P_FREPLACE, name, handle); } Enum rfsv16:: -fopendir(const char * const name, long &handle) +fopendir(const char * const name, u_int32_t &handle) { return fopen(P_FDIR, name, handle); } Enum rfsv16:: -fclose(long fileHandle) +fclose(u_int32_t fileHandle) { bufferStore a; a.addWord(fileHandle & 0xFFFF); @@ -124,8 +119,8 @@ fclose(long fileHandle) } Enum rfsv16:: -opendir(const long attr, const char *name, rfsvDirhandle &dH) { - long handle; +opendir(const u_int32_t attr, const char *name, rfsvDirhandle &dH) { + u_int32_t handle; Enum res = fopendir(name, handle); dH.h = handle; dH.b.init(); @@ -150,12 +145,12 @@ readdir(rfsvDirhandle &dH, PlpDirent &e) { dH.b.discardFirstBytes(2); // Don't know what these mean! } if ((res == E_PSI_GEN_NONE) && (dH.b.getLen() > 16)) { - int version = dH.b.getWord(0); + 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((long)dH.b.getWord(2)); + 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); @@ -186,57 +181,10 @@ dir(const char *name, PlpDir &files) return res; } -#if 0 -Enum rfsv16:: -dir(const char * const dirName, bufferArray &files) +u_int32_t rfsv16:: +opMode(u_int32_t mode) { - long fileHandle; - Enum res = fopendir(dirName, fileHandle); - - 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; - } - long attr = attr2std((long)a.getWord(2)); - long size = a.getDWord(4); - long date = a.getDWord(8); - const char *s = a.getString(16); - a.discardFirstBytes(17+strlen(s)); - - bufferStore temp; - temp.addDWord(date); - temp.addDWord(size); - temp.addDWord(attr); - temp.addStringT(s); - files += temp; - } - } - if (res == E_PSI_FILE_EOF) - res = E_PSI_GEN_NONE; - fclose(fileHandle); - return res; -} -#endif - -long rfsv16:: -opMode(long mode) -{ - long ret = 0; + u_int32_t ret = 0; ret |= ((mode & 03) == PSI_O_RDONLY) ? 0 : P_FUPDATE; ret |= (mode & PSI_O_TRUNC) ? P_FREPLACE : 0; @@ -282,7 +230,7 @@ cerr << "rfsv16::fsetmtime ***" << endl; } Enum rfsv16:: -fgetattr(const char * const name, long &attr) +fgetattr(const char * const name, u_int32_t &attr) { // NB: fgetmtime, fgeteattr are almost identical... bufferStore a; @@ -336,7 +284,7 @@ fgeteattr(const char * const name, PlpDirent &e) } Enum rfsv16:: -fsetattr(const char *name, long seta, long unseta) +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 @@ -344,9 +292,9 @@ cerr << "rfsv16::fsetattr" << endl; // 210000 // 008421 // a shr - long statusword = std2attr(seta) & (~ std2attr(unseta)); + u_int32_t statusword = std2attr(seta) & (~ std2attr(unseta)); statusword ^= 0x0000001; // r bit is inverted - long bitmask = std2attr(seta) | std2attr(unseta); + 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; @@ -354,8 +302,7 @@ cerr << "rfsv16::fsetattr" << endl; bufferStore a; a.addWord(statusword & 0xFFFF); a.addWord(bitmask & 0xFFFF); - a.addString(name); - a.addByte(0x00); // needs to be null-terminated, + a.addStringT(name); // and this needs sending in the length word. if (!sendCommand(SFSTAT, a)) return E_PSI_FILE_DISC; @@ -363,9 +310,9 @@ cerr << "rfsv16::fsetattr" << endl; } Enum rfsv16:: -dircount(const char * const name, long &count) +dircount(const char * const name, u_int32_t &count) { - long fileHandle; + u_int32_t fileHandle; Enum res; count = 0; @@ -404,10 +351,10 @@ dircount(const char * const name, long &count) } Enum rfsv16:: -devlist(long &devbits) +devlist(u_int32_t &devbits) { Enum res; - long fileHandle; + u_int32_t fileHandle; devbits = 0; // The following is taken from a trace between a Series 3c and PsiWin. @@ -444,7 +391,7 @@ devlist(long &devbits) res = getResponse(a); if (res) break; - int version = a.getWord(0); + u_int16_t version = a.getWord(0); if (version != 2) { cerr << "devlist: not version 2" << endl; fclose(fileHandle); @@ -467,7 +414,7 @@ devlist(long &devbits) } Enum rfsv16:: -devinfo(const int devnum, long &free, long &size, long &attr, long &uniqueid, char * const name) +devinfo(const u_int32_t devnum, u_int32_t &free, u_int32_t &size, u_int32_t &attr, u_int32_t &uniqueid, string &name) { bufferStore a; Enum res; @@ -489,7 +436,7 @@ devinfo(const int devnum, long &free, long &size, long &attr, long &uniqueid, ch // cerr << "devinfo PARSE res is " << dec << (signed short int) res << endl; return res; } - + a.init(); a.addByte((char) (devnum + 'A')); // Name 1 a.addByte(':'); @@ -509,10 +456,8 @@ devinfo(const int devnum, long &free, long &size, long &attr, long &uniqueid, ch // int battery = a.getWord(30); // const char *devicename = a.getString(62); uniqueid = 0; - if (name) { - name[0] = (char) (devnum + 'A'); - name[1] = '\0'; - } + name = ""; + name += (char)(devnum + 'A'); return res; } @@ -566,7 +511,7 @@ getResponse(bufferStore & data) } Enum rfsv16:: -fread(const long handle, unsigned char * const buf, const long len, long &count) +fread(const u_int32_t handle, unsigned char * const buf, const u_int32_t len, u_int32_t &count) { Enum res; unsigned char *p = buf; @@ -602,7 +547,7 @@ fread(const long handle, unsigned char * const buf, const long len, long &count) } Enum rfsv16:: -fwrite(const long handle, const unsigned char * const buf, const long len, long &count) +fwrite(const u_int32_t handle, const unsigned char * const buf, const u_int32_t len, u_int32_t &count) { Enum res; const unsigned char *p = buf; @@ -637,10 +582,10 @@ fwrite(const long handle, const unsigned char * const buf, const long len, long Enum rfsv16:: copyFromPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) { - long handle; Enum res; - long len; - long total = 0; + 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; @@ -670,9 +615,9 @@ copyFromPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) Enum rfsv16:: copyToPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) { - long handle; - long len = 0; - long total = 0; + u_int32_t handle; + u_int32_t len = 0; + u_int32_t total = 0; Enum res; ifstream ip(from); @@ -702,11 +647,11 @@ copyToPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) Enum rfsv16:: copyOnPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) { - long handle_from; - long handle_to; - long len; - long wlen; - long total = 0; + u_int32_t handle_from; + u_int32_t handle_to; + u_int32_t len; + u_int32_t wlen; + u_int32_t total = 0; Enum res; if ((res = fopen(P_FSHARE | P_FSTREAM, from, handle_from)) != E_PSI_GEN_NONE) @@ -737,10 +682,10 @@ copyOnPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) } Enum rfsv16:: -fsetsize(long handle, long size) +fsetsize(u_int32_t handle, u_int32_t size) { bufferStore a; - a.addWord(handle); + a.addWord(handle & 0xffff); a.addDWord(size); if (!sendCommand(FSETEOF, a)) return E_PSI_FILE_DISC; @@ -753,13 +698,13 @@ fsetsize(long handle, long size) * contains garbage instead of zeroes. */ Enum rfsv16:: -fseek(const long handle, const long pos, const long mode, long &resultpos) +fseek(const u_int32_t handle, const int32_t pos, const u_int32_t mode, u_int32_t &resultpos) { bufferStore a; Enum res; - long savpos = 0; - long realpos; - long calcpos = 0; + u_int32_t savpos = 0; + u_int32_t realpos; + u_int32_t calcpos = 0; /* seek-parameter for psion: @@ -921,10 +866,10 @@ setVolumeName(const char drive , const char * const name) /* * Translate SIBO attributes to standard attributes. */ -long rfsv16:: -attr2std(long attr) +u_int32_t rfsv16:: +attr2std(u_int32_t attr) { - long res = 0; + u_int32_t res = 0; // Common attributes if (!(attr & P_FAWRITE)) @@ -959,10 +904,10 @@ attr2std(long attr) /* * Translate standard attributes to SIBO attributes. */ -long rfsv16:: -std2attr(const long attr) +u_int32_t rfsv16:: +std2attr(const u_int32_t attr) { - long res = 0; + u_int32_t res = 0; // Common attributes if (!(attr & PSI_A_RDONLY)) diff --git a/lib/rfsv16.h b/lib/rfsv16.h index 0b3bdab..00de31e 100644 --- a/lib/rfsv16.h +++ b/lib/rfsv16.h @@ -7,37 +7,37 @@ class rfsv16 : public rfsv { public: rfsv16(ppsocket *); - Enum fopen(const long, const char * const, long &); - Enum mktemp(long &, char * const); - Enum fcreatefile(const long, const char * const, long &); - Enum freplacefile(const long, const char * const, long &); - Enum fclose(const long); + Enum fopen(const u_int32_t, const char * const, u_int32_t &); + Enum mktemp(u_int32_t &, string &); + Enum fcreatefile(const u_int32_t, const char * const, u_int32_t &); + Enum freplacefile(const u_int32_t, const char * const, u_int32_t &); + Enum fclose(const u_int32_t); Enum dir(const char * const, PlpDir &); Enum fgetmtime(const char * const, PsiTime &); Enum fsetmtime(const char * const, const PsiTime); - Enum fgetattr(const char * const, long &); + Enum fgetattr(const char * const, u_int32_t &); Enum fgeteattr(const char * const, PlpDirent &); - Enum fsetattr(const char * const, const long seta, const long unseta); - Enum dircount(const char * const, long &); - Enum devlist(long &); - Enum devinfo(const int, long &, long &, long &, long &, char * const); - Enum fread(const long, unsigned char * const, const long, long &); - Enum fwrite(const long, const unsigned char * const, const long, long &); + Enum fsetattr(const char * const, const u_int32_t seta, const u_int32_t unseta); + Enum dircount(const char * const, u_int32_t &); + Enum devlist(u_int32_t &); + Enum devinfo(const u_int32_t, u_int32_t &, u_int32_t &, u_int32_t &, u_int32_t &, string &); + Enum fread(const u_int32_t, unsigned char * const, const u_int32_t, u_int32_t &); + Enum fwrite(const u_int32_t, const unsigned char * const, const u_int32_t, u_int32_t &); Enum copyFromPsion(const char * const, const char * const, void *, cpCallback_t); Enum copyToPsion(const char * const, const char * const, void *, cpCallback_t); Enum copyOnPsion(const char *, const char *, void *, cpCallback_t); - Enum fsetsize(const long, const long); - Enum fseek(const long, const long, const long, long &); + Enum fsetsize(const u_int32_t, const u_int32_t); + Enum fseek(const u_int32_t, const int32_t, const u_int32_t, u_int32_t &); Enum mkdir(const char * const); Enum rmdir(const char * const); Enum rename(const char * const, const char * const); Enum remove(const char * const); - Enum opendir(const long, const char * const, rfsvDirhandle &); + Enum opendir(const u_int32_t, const char * const, rfsvDirhandle &); Enum readdir(rfsvDirhandle &, PlpDirent &); Enum closedir(rfsvDirhandle &); Enum setVolumeName(const char, const char * const); - long opMode(const long); + u_int32_t opMode(const u_int32_t); private: enum commands { @@ -99,9 +99,9 @@ private: // Miscellaneous - Enum fopendir(const char * const, long &); - long attr2std(const long); - long std2attr(const long); + Enum 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 &); diff --git a/lib/rfsv32.cc b/lib/rfsv32.cc index 0eb9911..74a1959 100644 --- a/lib/rfsv32.cc +++ b/lib/rfsv32.cc @@ -45,7 +45,7 @@ rfsv32::rfsv32(ppsocket * _skt) } Enum rfsv32:: -fopen(long attr, const char *name, long &handle) +fopen(u_int32_t attr, const char *name, u_int32_t &handle) { bufferStore a; string n = convertSlash(name); @@ -63,7 +63,7 @@ fopen(long attr, const char *name, long &handle) } Enum rfsv32:: -mktemp(long &handle, char * const tmpname) +mktemp(u_int32_t &handle, string &tmpname) { bufferStore a; if (!sendCommand(TEMP_FILE, a)) @@ -71,13 +71,13 @@ mktemp(long &handle, char * const tmpname) Enum res = getResponse(a); if (res == E_PSI_GEN_NONE) { handle = a.getDWord(0); - strcpy(tmpname, a.getString(6)); + tmpname = a.getString(6); } return res; } Enum rfsv32:: -fcreatefile(long attr, const char *name, long &handle) +fcreatefile(u_int32_t attr, const char *name, u_int32_t &handle) { bufferStore a; string n = convertSlash(name); @@ -93,7 +93,7 @@ fcreatefile(long attr, const char *name, long &handle) } Enum rfsv32:: -freplacefile(const long attr, const char * const name, long &handle) +freplacefile(const u_int32_t attr, const char * const name, u_int32_t &handle) { bufferStore a; string n = convertSlash(name); @@ -109,7 +109,7 @@ freplacefile(const long attr, const char * const name, long &handle) } Enum rfsv32:: -fopendir(const long attr, const char * const name, long &handle) +fopendir(const u_int32_t attr, const char * const name, u_int32_t &handle) { bufferStore a; string n = convertSlash(name); @@ -125,7 +125,7 @@ fopendir(const long attr, const char * const name, long &handle) } Enum rfsv32:: -fclose(long handle) +fclose(u_int32_t handle) { bufferStore a; a.addDWord(handle); @@ -135,8 +135,8 @@ fclose(long handle) } Enum rfsv32:: -opendir(const long attr, const char *name, rfsvDirhandle &dH) { - long handle; +opendir(const u_int32_t attr, const char *name, rfsvDirhandle &dH) { + u_int32_t handle; Enum res = fopendir(std2attr(attr), name, handle); dH.h = handle; dH.b.init(); @@ -201,10 +201,10 @@ dir(const char *name, PlpDir &files) return res; } -long rfsv32:: -opMode(const long mode) +u_int32_t rfsv32:: +opMode(const u_int32_t mode) { - long ret = 0; + u_int32_t ret = 0; ret |= (((mode & 03) == PSI_O_RDONLY) ? 0 : EPOC_OMODE_READ_WRITE); if (!ret) @@ -243,7 +243,7 @@ fsetmtime(const char * const name, PsiTime mtime) } Enum rfsv32:: -fgetattr(const char * const name, long &attr) +fgetattr(const char * const name, u_int32_t &attr) { bufferStore a; string n = convertSlash(name); @@ -290,7 +290,7 @@ fgeteattr(const char * const name, PlpDirent &e) } Enum rfsv32:: -fsetattr(const char * const name, const long seta, const long unseta) +fsetattr(const char * const name, const u_int32_t seta, const u_int32_t unseta) { bufferStore a; string n = convertSlash(name); @@ -304,9 +304,9 @@ fsetattr(const char * const name, const long seta, const long unseta) } Enum rfsv32:: -dircount(const char * const name, long &count) +dircount(const char * const name, u_int32_t &count) { - long handle; + u_int32_t handle; Enum res = fopendir(EPOC_ATTR_HIDDEN | EPOC_ATTR_SYSTEM | EPOC_ATTR_DIRECTORY, name, handle); count = 0; if (res != E_PSI_GEN_NONE) @@ -338,7 +338,7 @@ dircount(const char * const name, long &count) } Enum rfsv32:: -devlist(long &devbits) +devlist(u_int32_t &devbits) { bufferStore a; Enum res; @@ -358,7 +358,7 @@ devlist(long &devbits) } Enum rfsv32:: -devinfo(const int dev, long &free, long &total, long &attr, long &uniqueid, char * const name) +devinfo(const u_int32_t dev, u_int32_t &free, u_int32_t &total, u_int32_t &attr, u_int32_t &uniqueid, string &name) { bufferStore a; Enum res; @@ -374,8 +374,7 @@ devinfo(const int dev, long &free, long &total, long &attr, long &uniqueid, char free = a.getDWord(28); // vnamelen = a.getDWord(36); a.addByte(0); - if (name) - strcpy(name, a.getString(40)); + name = a.getString(40); } return res; } @@ -412,7 +411,7 @@ getResponse(bufferStore & data) { if (skt->getBufferStore(data) == 1 && data.getWord(0) == 0x11) { - long ret = data.getDWord(4); + int32_t ret = data.getDWord(4); data.discardFirstBytes(8); return err2psierr(ret); } else @@ -421,7 +420,7 @@ getResponse(bufferStore & data) } Enum rfsv32:: -fread(const long handle, unsigned char * const buf, const long len, long &count) +fread(const u_int32_t handle, unsigned char * const buf, const u_int32_t len, u_int32_t &count) { Enum res; count = 0; @@ -446,7 +445,7 @@ fread(const long handle, unsigned char * const buf, const long len, long &count) } Enum rfsv32:: -fwrite(const long handle, const unsigned char * const buf, const long len, long &count) +fwrite(const u_int32_t handle, const unsigned char * const buf, const u_int32_t len, u_int32_t &count) { Enum res; const unsigned char *p = buf; @@ -474,10 +473,10 @@ fwrite(const long handle, const unsigned char * const buf, const long len, long Enum rfsv32:: copyFromPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) { - long handle; Enum res; - long len; - long total = 0; + 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; @@ -504,7 +503,7 @@ copyFromPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) Enum rfsv32:: copyToPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) { - long handle; + u_int32_t handle; Enum res; ifstream ip(from); @@ -517,9 +516,9 @@ copyToPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) return res; } unsigned char *buff = new unsigned char[RFSV_SENDLEN]; - long total = 0; + u_int32_t total = 0; while (ip && !ip.eof() && (res == E_PSI_GEN_NONE)) { - long len; + u_int32_t len; ip.read(buff, RFSV_SENDLEN); if ((res = fwrite(handle, buff, ip.gcount(), len)) == E_PSI_GEN_NONE) { total += len; @@ -536,8 +535,8 @@ copyToPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) Enum rfsv32:: copyOnPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) { - long handle_from; - long handle_to; + u_int32_t handle_from; + u_int32_t handle_to; PlpDirent from_e; Enum res; @@ -555,7 +554,7 @@ copyOnPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) } } - long total = 0; + u_int32_t total = 0; while (res == E_PSI_GEN_NONE) { bufferStore b; b.addDWord(RFSV_SENDLEN * 10); @@ -570,7 +569,7 @@ copyOnPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) res = E_PSI_GEN_FAIL; break; } - unsigned long len = b.getDWord(0); + u_int32_t len = b.getDWord(0); total += len; if (cb && !cb(ptr, total)) res = E_PSI_FILE_CANCEL; @@ -585,7 +584,7 @@ copyOnPsion(const char *from, const char *to, void *ptr, cpCallback_t cb) } Enum rfsv32:: -fsetsize(long handle, long size) +fsetsize(u_int32_t handle, u_int32_t size) { bufferStore a; a.addDWord(handle); @@ -601,14 +600,14 @@ fsetsize(long handle, long size) * contains garbage instead of zeroes. */ Enum rfsv32:: -fseek(const long handle, const long pos, const long mode, long &resultpos) +fseek(const u_int32_t handle, const int32_t pos, const u_int32_t mode, u_int32_t &resultpos) { bufferStore a; Enum res; - long savpos = 0; - long calcpos = 0; - long mypos = pos; - long realpos; + u_int32_t savpos = 0; + u_int32_t calcpos = 0; + int32_t mypos = pos; + u_int32_t realpos; /* seek-parameter for psion: @@ -825,10 +824,11 @@ static enum rfsv::errs e2psi[] = { }; Enum rfsv32:: -err2psierr(long status) +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]; @@ -838,8 +838,8 @@ err2psierr(long status) /* * Translate EPOC attributes to standard attributes. */ -long rfsv32:: -attr2std(const long attr) +u_int32_t rfsv32:: +attr2std(const u_int32_t attr) { long res = 0; @@ -874,8 +874,8 @@ attr2std(const long attr) /* * Translate standard attributes to EPOC attributes. */ -long rfsv32:: -std2attr(const long attr) +u_int32_t rfsv32:: +std2attr(const u_int32_t attr) { long res = 0; // Common attributes diff --git a/lib/rfsv32.h b/lib/rfsv32.h index 4a738da..0e9cf64 100644 --- a/lib/rfsv32.h +++ b/lib/rfsv32.h @@ -10,7 +10,7 @@ public: rfsv32(ppsocket *); Enum dir(const char * const, PlpDir &); - Enum dircount(const char * const, long &); + Enum dircount(const char * const, u_int32_t &); Enum copyFromPsion(const char * const, const char * const, void *, cpCallback_t); Enum copyToPsion(const char * const, const char * const, void *, cpCallback_t); Enum copyOnPsion(const char * const, const char * const, void *, cpCallback_t); @@ -18,28 +18,28 @@ public: Enum rmdir(const char * const); Enum remove(const char * const); Enum rename(const char * const, const char * const); - Enum mktemp(long &, char * const); + Enum mktemp(u_int32_t &, string &); Enum fgeteattr(const char * const, PlpDirent &); - Enum fgetattr(const char * const, long &); - Enum fsetattr(const char * const, const long, const long); + Enum fgetattr(const char * const, u_int32_t &); + Enum fsetattr(const char * const, const u_int32_t, const u_int32_t); Enum fgetmtime(const char * const, PsiTime &); Enum fsetmtime(const char * const, PsiTime const); - Enum fopen(const long, const char * const, long &); - Enum fcreatefile(const long, const char * const, long &); - Enum freplacefile(const long, const char * const, long &); - Enum fseek(const long, const long, const long, long &); - Enum fread(const long, unsigned char * const, const long, long &); - Enum fwrite(const long, const unsigned char * const, const long, long &); - Enum fsetsize(long, long); - Enum fclose(const long); + Enum fopen(const u_int32_t, const char * const, u_int32_t &); + Enum fcreatefile(const u_int32_t, const char * const, u_int32_t &); + Enum freplacefile(const u_int32_t, const char * const, u_int32_t &); + Enum fseek(const u_int32_t, const int32_t, const u_int32_t, u_int32_t &); + Enum fread(const u_int32_t, unsigned char * const, const u_int32_t, u_int32_t &); + Enum fwrite(const u_int32_t, const unsigned char * const, const u_int32_t, u_int32_t &); + Enum fsetsize(u_int32_t, u_int32_t); + Enum fclose(const u_int32_t); - Enum devlist(long &); - Enum devinfo(const int, long &, long &, long &, long &, char * const); - Enum opendir(const long, const char * const, rfsvDirhandle &); + Enum devlist(u_int32_t &); + Enum devinfo(const u_int32_t, u_int32_t &, u_int32_t &, u_int32_t &, u_int32_t &, string &); + Enum opendir(const u_int32_t, const char * const, rfsvDirhandle &); Enum readdir(rfsvDirhandle &, PlpDirent &); Enum closedir(rfsvDirhandle &); Enum setVolumeName(const char, const char * const); - long opMode(const long); + u_int32_t opMode(const u_int32_t); private: @@ -150,19 +150,15 @@ private: REPLACE = 0x32 }; - Enum err2psierr(long); - Enum fopendir(const long, const char *, long &); - long attr2std(const long); - long std2attr(const long); + Enum err2psierr(int32_t); + Enum 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 getResponse(bufferStore &); - - // time-conversion - // unsigned long micro2time(unsigned long, unsigned long); - // void time2micro(unsigned long, unsigned long &, unsigned long &); }; #endif diff --git a/ncpd/linkchan.cc b/ncpd/linkchan.cc index f8e586f..21ec39f 100644 --- a/ncpd/linkchan.cc +++ b/ncpd/linkchan.cc @@ -23,7 +23,7 @@ // e-mail philip.proudman@btinternet.com #include -#include +#include #include "linkchan.h" #include "bufferstore.h" diff --git a/ncpd/main.cc b/ncpd/main.cc index 2392d09..76d0bb2 100644 --- a/ncpd/main.cc +++ b/ncpd/main.cc @@ -27,10 +27,11 @@ #endif #include -#include +#include #include #include #include +#include #include "ncp.h" #include "bufferstore.h" @@ -64,8 +65,8 @@ int_handler(int) void checkForNewSocketConnection(ppsocket & skt, int &numScp, socketChan ** scp, ncp * a, IOWatch & iow) { - char peer[201]; - ppsocket *next = skt.accept(peer, 200); + string peer; + ppsocket *next = skt.accept(&peer); if (next != NULL) { // New connect if (verbose) diff --git a/ncpd/ncp.cc b/ncpd/ncp.cc index 8af83d8..b3cf009 100644 --- a/ncpd/ncp.cc +++ b/ncpd/ncp.cc @@ -27,7 +27,7 @@ #endif #include -#include +#include #include #include "ncp.h" diff --git a/ncpd/packet.cc b/ncpd/packet.cc index ebefc0a..6d97ccc 100644 --- a/ncpd/packet.cc +++ b/ncpd/packet.cc @@ -32,9 +32,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/plpbackup/plpbackup.cc b/plpbackup/plpbackup.cc index 8735ea3..48e3202 100644 --- a/plpbackup/plpbackup.cc +++ b/plpbackup/plpbackup.cc @@ -156,7 +156,7 @@ runrestore(rfsv *a, rpcs *r) { // the ususal \System\Apps\\.app // on all drives. if (strchr(cmd, '\\') == NULL) { - long devbits; + u_int32_t devbits; char tmp[512]; if ((res = a->devlist(devbits)) == rfsv::E_PSI_GEN_NONE) { int i; @@ -215,7 +215,7 @@ collectFiles(rfsv *a, char *dir) { } static int -reportProgress(void *, long size) +reportProgress(void *, u_int32_t size) { unsigned long percent; char pstr[10]; @@ -416,12 +416,13 @@ main(int argc, char **argv) } } else { char drive[3]; - long devbits; - long vtotal, vfree, vattr, vuniqueid; + u_int32_t devbits; + u_int32_t vtotal, vfree, vattr, vuniqueid; if (a->devlist(devbits) == rfsv::E_PSI_GEN_NONE) { for (i = 0; i < 26; i++) { - if ((devbits & 1) && a->devinfo(i, vfree, vtotal, vattr, vuniqueid, NULL) == rfsv::E_PSI_GEN_NONE) { + string n; + if ((devbits & 1) && a->devinfo(i, vfree, vtotal, vattr, vuniqueid, n) == rfsv::E_PSI_GEN_NONE) { if (vattr != 7) { sprintf(drive, "%c:\0", 'A' + i); if (verbose > 0) diff --git a/plpftp/ftp.cc b/plpftp/ftp.cc index 222dd4e..aad6187 100644 --- a/plpftp/ftp.cc +++ b/plpftp/ftp.cc @@ -171,13 +171,13 @@ Wildmat(const char *s, char *p) } static int -checkAbortNoHash(void *, long) +checkAbortNoHash(void *, u_int32_t) { return continueRunning; } static int -checkAbortHash(void *, long) +checkAbortHash(void *, u_int32_t) { if (continueRunning) { printf("#"); fflush(stdout); @@ -241,15 +241,16 @@ session(rfsv & a, rpcs & r, int xargc, char **xargv) } if (!strcmp(DDRIVE, "AUTO")) { - long devbits; - long vtotal, vfree, vattr, vuniqueid; + u_int32_t devbits; + u_int32_t vtotal, vfree, vattr, vuniqueid; int i; strcpy(defDrive, "::"); if (a.devlist(devbits) == rfsv::E_PSI_GEN_NONE) { for (i = 0; i < 26; i++) { - if ((devbits & 1) && a.devinfo(i, vfree, vtotal, vattr, vuniqueid, NULL) == rfsv::E_PSI_GEN_NONE) { + string n; + if ((devbits & 1) && a.devinfo(i, vfree, vtotal, vattr, vuniqueid, n) == rfsv::E_PSI_GEN_NONE) { defDrive[0] = 'A' + i; break; } @@ -338,7 +339,7 @@ session(rfsv & a, rpcs & r, int xargc, char **xargv) continue; } if (!strcmp(argv[0], "gattr") && (argc == 2)) { - long attr; + u_int32_t attr; strcpy(f1, psionDir); strcat(f1, argv[1]); if ((res = a.fgetattr(f1, attr)) != rfsv::E_PSI_GEN_NONE) @@ -404,7 +405,7 @@ session(rfsv & a, rpcs & r, int xargc, char **xargv) continue; } if (!strcmp(argv[0], "dircnt")) { - long cnt; + u_int32_t cnt; if ((res = a.dircount(psionDir, cnt)) != rfsv::E_PSI_GEN_NONE) cerr << "Error: " << res << endl; else @@ -412,12 +413,12 @@ session(rfsv & a, rpcs & r, int xargc, char **xargv) continue; } if (!strcmp(argv[0], "devs")) { - long devbits; + u_int32_t devbits; if ((res = a.devlist(devbits)) == rfsv::E_PSI_GEN_NONE) { cout << "Drive Type Volname Total Free UniqueID" << endl; for (int i = 0; i < 26; i++) { - char vname[256]; - long vtotal, vfree, vattr, vuniqueid; + string vname; + u_int32_t vtotal, vfree, vattr, vuniqueid; if ((devbits & 1) != 0) { if (a.devinfo(i, vfree, vtotal, vattr, vuniqueid, vname) == rfsv::E_PSI_GEN_NONE) @@ -463,7 +464,7 @@ session(rfsv & a, rpcs & r, int xargc, char **xargv) strcpy(psionDir, defDrive); strcat(psionDir, DBASEDIR); } else { - long tmp; + u_int32_t tmp; if (!strcmp(argv[1], "..")) { strcpy(f1, psionDir); char *p = f1 + strlen(f1); @@ -852,7 +853,7 @@ session(rfsv & a, rpcs & r, int xargc, char **xargv) // registered in the Psion's path properly. Now try the ususal // \System\Apps\\.app on all drives. if (strchr(cmd, '\\') == NULL) { - long devbits; + u_int32_t devbits; char tmp[512]; if ((res = a.devlist(devbits)) == rfsv::E_PSI_GEN_NONE) { int i; diff --git a/plpnfsd/main.cc b/plpnfsd/main.cc index d1e0337..81e7176 100644 --- a/plpnfsd/main.cc +++ b/plpnfsd/main.cc @@ -28,9 +28,9 @@ extern "C" { static rfsv *a; static rfsvfactory *rf; static char *a_filename = 0; -static long a_handle; -static long a_offset; -static long a_openmode; +static u_int32_t a_handle; +static u_int32_t a_offset; +static u_int32_t a_openmode; static rpcs *r; static rpcsfactory *rp; @@ -232,7 +232,7 @@ long rfsv_dir(const char *file, dentry **e) { return ret; } -long rfsv_dircount(const char *file, long *count) { +long rfsv_dircount(const char *file, u_int32_t *count) { if (!a) return -1; return a->dircount(file, *count); @@ -280,7 +280,7 @@ long rfsv_fclose(long handle) { } long rfsv_fcreate(long attr, const char *file, long *handle) { - long ph; + u_int32_t ph; long ret; if (!a) @@ -310,8 +310,8 @@ static long rfsv_opencached(const char *name, long mode) { } long rfsv_read(char *buf, long offset, long len, char *name) { - long ret = 0; - long r_offset; + u_int32_t ret = 0; + u_int32_t r_offset; if (!a) return -1; @@ -334,8 +334,8 @@ long rfsv_read(char *buf, long offset, long len, char *name) { } long rfsv_write(char *buf, long offset, long len, char *name) { - long ret = 0; - long r_offset; + u_int32_t ret = 0; + u_int32_t r_offset; if (!a) return -1; @@ -368,7 +368,7 @@ long rfsv_setmtime(const char *name, long time) { } long rfsv_setsize(const char *name, long size) { - long ph; + u_int32_t ph; long ret; if (!a) @@ -405,12 +405,13 @@ long rfsv_getattr(const char *name, long *attr, long *size, long *time) { } long rfsv_statdev(char letter) { - long vfree, vtotal, vattr, vuniqueid; - int devnum = letter - 'A'; + u_int32_t vfree, vtotal, vattr, vuniqueid; + u_int32_t devnum = letter - 'A'; + string n; if (!a) return -1; - return (a->devinfo(devnum, vfree, vtotal, vattr, vuniqueid, NULL) != rfsv::E_PSI_GEN_NONE); + return (a->devinfo(devnum, vfree, vtotal, vattr, vuniqueid, n) != rfsv::E_PSI_GEN_NONE); } long rfsv_rename(const char *oldname, const char *newname) { @@ -421,7 +422,7 @@ long rfsv_rename(const char *oldname, const char *newname) { long rfsv_drivelist(int *cnt, device **dlist) { *dlist = NULL; - long devbits; + u_int32_t devbits; long ret; int i; @@ -430,15 +431,15 @@ long rfsv_drivelist(int *cnt, device **dlist) { ret = a->devlist(devbits); if (ret == 0) for (i = 0; i<26; i++) { - char name[256]; - long vtotal, vfree, vattr, vuniqueid; + string name; + u_int32_t vtotal, vfree, vattr, vuniqueid; if ((devbits & 1) && ((a->devinfo(i, vfree, vtotal, vattr, vuniqueid, name) == rfsv::E_PSI_GEN_NONE))) { device *next = *dlist; *dlist = (device *)malloc(sizeof(device)); (*dlist)->next = next; - (*dlist)->name = strdup(name); + (*dlist)->name = strdup(name.c_str()); (*dlist)->total = vtotal; (*dlist)->free = vfree; (*dlist)->letter = 'A' + i; diff --git a/plpnfsd/mp_pfs_ops.c b/plpnfsd/mp_pfs_ops.c index 9418c5d..8141a14 100644 --- a/plpnfsd/mp_pfs_ops.c +++ b/plpnfsd/mp_pfs_ops.c @@ -430,7 +430,7 @@ create_it(createargs *ca, int isdir) char *name = dirinode->name; fattr *fp; p_inode *inode; - long phandle; + u_int32_t phandle; int rfsv_ret; debuglog("create: in %s %s (%#o, %d)\n", -- cgit v1.2.3