From 7f56dbb8441f56470edb5d9d20ceecf26055ab2c Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 14 Aug 2022 17:05:02 +0000 Subject: [PATCH] Type change: USHORT -> u2 --- src/defines.h | 1 - src/inputlirc.cc | 2 +- src/inputudp.cc | 2 +- src/serialize.cc | 46 +++++++++++++++++++++++----------------------- src/serialize.h | 44 ++++++++++++++++++++++---------------------- src/tcp.cc | 2 +- src/tcp.h | 2 +- src/udp4.cc | 4 ++-- src/udp4.h | 6 +++--- src/udp6.cc | 4 ++-- src/udp6.h | 6 +++--- src/vconnect.cc | 2 +- src/vdpc.cc | 6 +++--- src/vdpc.h | 6 +++--- src/vdr.cc | 2 +- src/vdr.h | 4 ++-- 16 files changed, 69 insertions(+), 70 deletions(-) diff --git a/src/defines.h b/src/defines.h index 210c57a..a835c96 100644 --- a/src/defines.h +++ b/src/defines.h @@ -21,7 +21,6 @@ #define DEFINES_H typedef unsigned char UCHAR; -typedef unsigned short USHORT; #include diff --git a/src/inputlirc.cc b/src/inputlirc.cc index ec13e70..0c9e3c3 100644 --- a/src/inputlirc.cc +++ b/src/inputlirc.cc @@ -124,7 +124,7 @@ bool InputLIRC::start() else if (checkA) // If no checkC, must be checkA { LogNT::getInstance()->info(TAG, "Starting with IP: {} {}", lircIP, lircPort); - tr = tcp.connect(lircIP, static_cast(lircPort)); + tr = tcp.connect(lircIP, static_cast(lircPort)); } if (!tr) diff --git a/src/inputudp.cc b/src/inputudp.cc index 0ab47b0..11eff5b 100644 --- a/src/inputudp.cc +++ b/src/inputudp.cc @@ -41,7 +41,7 @@ bool InputUDP::init() log->debug(TAG, "Starting InputUDP command server on port {}", port); - if (!udp6.init(static_cast(port))) + if (!udp6.init(static_cast(port))) { log->debug(TAG, "UDP6 init error"); initted = false; diff --git a/src/serialize.cc b/src/serialize.cc index 4e6cc5b..a303bc3 100644 --- a/src/serialize.cc +++ b/src/serialize.cc @@ -107,10 +107,10 @@ int SerializeBuffer::encodeLong(u4 data) { current+=sizeof(u4); return 0; } -int SerializeBuffer::encodeShort(USHORT data) { - if (checkSpace( (int)sizeof(USHORT))!=0) return -1; - *((USHORT *)(current))=htons(data); - current+=sizeof(USHORT); +int SerializeBuffer::encodeShort(u2 data) { + if (checkSpace( (int)sizeof(u2))!=0) return -1; + *((u2 *)(current))=htons(data); + current+=sizeof(u2); return 0; } int SerializeBuffer::encodeByte(UCHAR data) { @@ -152,10 +152,10 @@ int SerializeBuffer::decodeLong(u4 &data) { current+=sizeof(u4); return 0; } -int SerializeBuffer::decodeShort(USHORT &data) { - if (checkSpace( (int)sizeof(USHORT))!=0) return -1; - data=ntohs(*((USHORT *)(current))); - current+=sizeof(USHORT); +int SerializeBuffer::decodeShort(u2 &data) { + if (checkSpace( (int)sizeof(u2))!=0) return -1; + data=ntohs(*((u2 *)(current))); + current+=sizeof(u2); return 0; } int SerializeBuffer::decodeByte(UCHAR &data) { @@ -203,7 +203,7 @@ int Serializable::getSerializedStringLen(const char * str) { return rt; } -USHORT Serializable::getVersion() { +u2 Serializable::getVersion() { return version; } @@ -233,7 +233,7 @@ int Serializable::serialize(SerializeBuffer *b) { } int Serializable::deserialize(SerializeBuffer *b) { - USHORT vers=0; + u2 vers=0; if (b->decodeShort(vers) != 0) return -1; u4 len=0; if (b->decodeLong(len) != 0) return -1; @@ -253,7 +253,7 @@ SerializableList::SerializableList() { } SerializableList::~SerializableList(){} -int SerializableList::addParam(Serializable *p,USHORT v) { +int SerializableList::addParam(Serializable *p,u2 v) { if (v < version || p == NULL) return -1; Pentry entry; entry.ptype=TSER; @@ -263,17 +263,17 @@ int SerializableList::addParam(Serializable *p,USHORT v) { version=v; return 0; } -int SerializableList::addParam(USHORT *p,USHORT v) { +int SerializableList::addParam(u2 *p,u2 v) { if (v < version || p == NULL) return -1; Pentry entry; - entry.ptype=TUSHORT; + entry.ptype=Tu2; entry.ptr.pshort=p; entry.version=v; list.push_back(entry); version=v; return 0; } -int SerializableList::addParam(u4 *p,USHORT v) { +int SerializableList::addParam(u4 *p,u2 v) { if (v < version || p == NULL) return -1; Pentry entry; entry.ptype=TULONG; @@ -283,7 +283,7 @@ int SerializableList::addParam(u4 *p,USHORT v) { version=v; return 0; } -int SerializableList::addParam(u8 *p,USHORT v) { +int SerializableList::addParam(u8 *p,u2 v) { if (v < version || p == NULL) return -1; Pentry entry; entry.ptype=TULLONG; @@ -293,7 +293,7 @@ int SerializableList::addParam(u8 *p,USHORT v) { version=v; return 0; } -int SerializableList::addParam(char **p,USHORT v) { +int SerializableList::addParam(char **p,u2 v) { if (v < version || p == NULL) return -1; Pentry entry; entry.ptype=TCHAR; @@ -307,7 +307,7 @@ int SerializableList::addParam(char **p,USHORT v) { bool SerializableList::Pentry::isEqual(void *p,SerializableList::Ptypes t) { void *cmp=NULL; switch(t) { - case TUSHORT: + case Tu2: cmp=(void *)ptr.pshort; break; case TULONG: @@ -339,8 +339,8 @@ bool SerializableList::isDeserialized(Serializable *p){ if (!e) return false; return e->isDeserialized; } -bool SerializableList::isDeserialized(USHORT *p){ - SerializableList::Pentry *e=findEntry(p,TUSHORT); +bool SerializableList::isDeserialized(u2 *p){ + SerializableList::Pentry *e=findEntry(p,Tu2); if (!e) return false; return e->isDeserialized; } @@ -366,8 +366,8 @@ int SerializableList::getSerializedLenImpl(){ int rt=0; for (vector::iterator it=list.begin();it::iterator it=list.begin();itencodeShort(*(*it).ptr.pshort) != 0) return -1; break; case TULONG: @@ -421,7 +421,7 @@ int SerializableList::deserializeImpl(SerializeBuffer *b){ break; } switch((*it).ptype){ - case TUSHORT: + case Tu2: if (b->decodeShort(*(*it).ptr.pshort) != 0) return -1; break; case TULONG: diff --git a/src/serialize.h b/src/serialize.h index 829dc39..2bf1dfb 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -48,14 +48,14 @@ class SerializeBuffer { //always return != 0 on error int encodeLong(u4 data); int encodeLongLong(u8 data); - int encodeShort(USHORT data); + int encodeShort(u2 data); int encodeString(const char *data); int encodeByte(UCHAR data); int decodeLong(u4 & data); int decodeLong(int & data); int decodeLongLong(u8 & data); - int decodeShort(USHORT & data); + int decodeShort(u2 & data); int decodeString(u4 &len,char * &data); int decodeByte(UCHAR &data); @@ -90,7 +90,7 @@ class Serializable { int deserialize(SerializeBuffer *b); //or the received version after deserialize //can be queried with deserializeImpl - USHORT getVersion(); + u2 getVersion(); //helper static int getSerializedStringLen(const char *str); protected: @@ -100,7 +100,7 @@ class Serializable { virtual int getSerializedLenImpl()=0; virtual int serializeImpl(SerializeBuffer *b)=0; virtual int deserializeImpl(SerializeBuffer *b)=0; - USHORT version; + u2 version; }; /** @@ -109,14 +109,14 @@ class Serializable { * by correct usage. * usage example: * 1. version - * USHORT myP1=0; + * u2 myP1=0; * u4 myP2=0; * SerializableList myList(); * myList.addParam(&myP1); * myList.addParam(&myP2); * //now serialize/deserialize... * //later - second version: - * USHORT myP1=0; + * u2 myP1=0; * u4 myP2=0; * char *myString=NULL; * SerializableList myList(); @@ -144,11 +144,11 @@ class SerializableList : public Serializable{ * compatibility * will return !=0 if adding is not possible (e.g. adding with a smaller version) */ - int addParam(Serializable *p,USHORT version=1); - int addParam(USHORT *p,USHORT version=1); - int addParam(u4 *p,USHORT version=1); - int addParam(u8 *p,USHORT version=1); - int addParam(char **p,USHORT version=1); + int addParam(Serializable *p,u2 version=1); + int addParam(u2 *p,u2 version=1); + int addParam(u4 *p,u2 version=1); + int addParam(u8 *p,u2 version=1); + int addParam(char **p,u2 version=1); /** * for lists only intended for encoding also @@ -158,27 +158,27 @@ class SerializableList : public Serializable{ * the non-const * After having called one of this methods deserialize will always fail! */ - int addParam(const Serializable *p,USHORT vs=1){ + int addParam(const Serializable *p,u2 vs=1){ encodeOnly=true; return addParam(const_cast(p),vs); } - int addParam(const USHORT *p,USHORT vs=1){ + int addParam(const u2 *p,u2 vs=1){ encodeOnly=true; - return addParam(const_cast(p),vs); + return addParam(const_cast(p),vs); } - int addParam(const u4 *p,USHORT vs=1){ + int addParam(const u4 *p,u2 vs=1){ encodeOnly=true; return addParam(const_cast(p),vs); } - int addParam(const int *p,USHORT vs=1){ + int addParam(const int *p,u2 vs=1){ encodeOnly=true; return addParam(reinterpret_cast(const_cast(p)), vs); } - int addParam(const u8 *p,USHORT vs=1){ + int addParam(const u8 *p,u2 vs=1){ encodeOnly=true; return addParam(const_cast(p),vs); } - int addParam(const char **p,USHORT vs=1){ + int addParam(const char **p,u2 vs=1){ encodeOnly=true; return addParam(const_cast(p),vs); } @@ -189,7 +189,7 @@ class SerializableList : public Serializable{ * during deserialize */ bool isDeserialized(Serializable *p); - bool isDeserialized(USHORT *p); + bool isDeserialized(u2 *p); bool isDeserialized(u4 *p); bool isDeserialized(u8 *p); bool isDeserialized(char **p); @@ -207,17 +207,17 @@ class SerializableList : public Serializable{ typedef enum{ TUNKNOWN, TSER, - TUSHORT, + Tu2, TULONG, TULLONG, TCHAR } Ptypes; struct Pentry { Ptypes ptype; bool isDeserialized; - USHORT version; + u2 version; union { Serializable *pser; - USHORT *pshort; + u2 *pshort; u4 *plong; u8 *pllong; char **pchar; diff --git a/src/tcp.cc b/src/tcp.cc index c8d453b..90b00f8 100644 --- a/src/tcp.cc +++ b/src/tcp.cc @@ -115,7 +115,7 @@ bool TCP::connectSocket(const std::string& socketFile) } #endif -bool TCP::connect(const std::string& ip, USHORT port) +bool TCP::connect(const std::string& ip, u2 port) { if (connected) return false; diff --git a/src/tcp.h b/src/tcp.h index 6e611ba..2474552 100644 --- a/src/tcp.h +++ b/src/tcp.h @@ -43,7 +43,7 @@ class TCP void shutdown(); // Optional if this is to be deleted. Closes connection. Can call connect() next void abortCall(); // causes a read/connect call to immediately abort - bool connect(const std::string& ip, USHORT port); + bool connect(const std::string& ip, u2 port); #ifndef WIN32 bool connectSocket(const std::string& socketFile); #endif diff --git a/src/udp4.cc b/src/udp4.cc index 49c08d1..2aec13e 100644 --- a/src/udp4.cc +++ b/src/udp4.cc @@ -47,7 +47,7 @@ UDP4::~UDP4() if (initted) shutdown(); } -int UDP4::init(USHORT tport) +int UDP4::init(u2 tport) { if (initted) return 0; @@ -165,7 +165,7 @@ const void* UDP4::getData() const { return buf; } const char* UDP4::getFromIPA() const { return fromIPA; } short UDP4::getFromPort() const { return fromPort; } -bool UDP4::send(const char *ipa, USHORT port, char *message, int length) +bool UDP4::send(const char *ipa, u2 port, char *message, int length) { if (!initted) return false; diff --git a/src/udp4.h b/src/udp4.h index 856f3ea..1da2c64 100644 --- a/src/udp4.h +++ b/src/udp4.h @@ -37,7 +37,7 @@ class UDP4 { public: ~UDP4(); - int init(USHORT port); + int init(u2 port); void shutdown(); #ifdef WIN32 unsigned char waitforMessage(unsigned char, SOCKET quitPipe = 0); // uchar =0-block =1-new wait =2-continue wait @@ -48,14 +48,14 @@ class UDP4 const void* getData() const; // returns a pointer to the data const char* getFromIPA() const; // returns a pointer to from IP address short getFromPort() const; - bool send(const char *, USHORT, char *, int); // send wants: IP Address ddn style, port, data, length of data + bool send(const char *, u2, char *, int); // send wants: IP Address ddn style, port, data, length of data private: bool initted{}; u4 getIPNumber(u4 num); u4 iterate_ip{}; int socketnum; // Socket descriptor - USHORT myPort{}; // My port number + u2 myPort{}; // My port number struct sockaddr_in myAddr; // My address struct sockaddr_in theirAddr; // User address socklen_t addrlen; // length of sockaddr struct diff --git a/src/udp6.cc b/src/udp6.cc index 166015d..a2d0e77 100644 --- a/src/udp6.cc +++ b/src/udp6.cc @@ -49,7 +49,7 @@ UDP6::~UDP6() if (initted) shutdown(); } -int UDP6::init(USHORT tPort) +int UDP6::init(u2 tPort) { if (initted) return 0; myPort = tPort; @@ -165,7 +165,7 @@ const char* UDP6::getFromIPA() const { return fromIPA; } short UDP6::getFromPort() const { return fromPort; } bool UDP6::getFromIPisLL() const { return fromIPisLL; } -bool UDP6::send(const char *ipa, USHORT port, char *message, int length, bool mcast) +bool UDP6::send(const char *ipa, u2 port, char *message, int length, bool mcast) { if (!initted) return false; int sentLength = 0; diff --git a/src/udp6.h b/src/udp6.h index 0bb992e..5cb8e19 100644 --- a/src/udp6.h +++ b/src/udp6.h @@ -33,7 +33,7 @@ class UDP6 { public: ~UDP6(); - int init(USHORT port); + int init(u2 port); void shutdown(); #ifdef WIN32 unsigned char waitforMessage(unsigned char, SOCKET quitPipe = 0); // uchar =0-block =1-new wait =2-continue wait @@ -45,14 +45,14 @@ class UDP6 const char* getFromIPA() const; // returns a pointer to from IP address short getFromPort() const; bool getFromIPisLL() const; - bool send(const char *, USHORT, char *, int, bool mcast = false); // send wants: text IP, port, data, length of data, is_mcast + bool send(const char *, u2, char *, int, bool mcast = false); // send wants: text IP, port, data, length of data, is_mcast private: bool initted{}; u4 getIPNumber(u4 num); u4 iterate_ip{}; int socketnum; // Socket descriptor - USHORT myPort{}; // My port number + u2 myPort{}; // My port number struct sockaddr_in6 myAddr; // My address struct sockaddr_in6 theirAddr; // User address socklen_t addrlen; // length of sockaddr struct diff --git a/src/vconnect.cc b/src/vconnect.cc index 0755ccd..0468603 100644 --- a/src/vconnect.cc +++ b/src/vconnect.cc @@ -123,7 +123,7 @@ void VConnect::threadMethod() int newPort; // copy around because of type mismatch if (config->getInt("server", "port", newPort)) { - serverFromConfig.port = static_cast(newPort); + serverFromConfig.port = static_cast(newPort); logger->debug(TAG, "Port read fron config: {}", serverFromConfig.port); } diff --git a/src/vdpc.cc b/src/vdpc.cc index dbb99bb..a54c862 100644 --- a/src/vdpc.cc +++ b/src/vdpc.cc @@ -38,7 +38,7 @@ bool VDPC::init() { logger = LogNT::getInstance(); - AddServerCallback addFunc( [this] (int ipVersion, const char* ip, const char* name, USHORT port, u4 version) + AddServerCallback addFunc( [this] (int ipVersion, const char* ip, const char* name, u2 port, u4 version) { std::lock_guard lg(serversLock); @@ -268,7 +268,7 @@ void VDPC::VDPC4::threadMethod() { // FIXME upgrade this to look for a return IP in the reply packet - USHORT newServerPort; + u2 newServerPort; memcpy(&newServerPort, &vdpreply[26], 2); u4 newServerVersion; @@ -383,7 +383,7 @@ void VDPC::VDPC6::threadMethod() { // FIXME upgrade this to look for a return IP in the reply packet - USHORT newServerPort; + u2 newServerPort; memcpy(&newServerPort, &vdpreply[26], 2); u4 newServerVersion; diff --git a/src/vdpc.h b/src/vdpc.h index 20c1bb0..ca243ab 100644 --- a/src/vdpc.h +++ b/src/vdpc.h @@ -47,12 +47,12 @@ struct VDRServer int ipVersion; std::string ip; std::string name; - USHORT port; + u2 port; u4 version; VDRServer() {} - VDRServer(int tipVersion, const std::string tip, const std::string tname, USHORT tport, u4 tversion) + VDRServer(int tipVersion, const std::string tip, const std::string tname, u2 tport, u4 tversion) : ipVersion(tipVersion), ip(tip), name(tname), port(tport), version(tversion) {} }; @@ -91,7 +91,7 @@ class VDPC { private: LogNT* logger{}; - typedef std::function AddServerCallback; + typedef std::function AddServerCallback; // Nested classes #ifdef IPV4 diff --git a/src/vdr.cc b/src/vdr.cc index 1cecf54..fb11e45 100644 --- a/src/vdr.cc +++ b/src/vdr.cc @@ -158,7 +158,7 @@ void VDR::setServerIP(const char* newIP) strcpy(serverIP, newIP); } -void VDR::setServerPort(USHORT newPort) +void VDR::setServerPort(u2 newPort) { serverPort = newPort; } diff --git a/src/vdr.h b/src/vdr.h index e0e1e5d..8a1a9b6 100644 --- a/src/vdr.h +++ b/src/vdr.h @@ -126,7 +126,7 @@ public ExternLogger */ void setServerIP(const char*); - void setServerPort(USHORT); + void setServerPort(u2); void setReceiveWindow(size_t size); bool connect(); void disconnect(); @@ -234,7 +234,7 @@ public ExternLogger int findingServer{}; TCP tcp; char serverIP[40]; - USHORT serverPort; + u2 serverPort; u4 maxChannelNumber{}; bool doVDRShutdown{}; int channelNumberWidth{1}; -- 2.39.5