]> git.vomp.tv Git - vompclient.git/commitdiff
Type change: USHORT -> u2
authorChris Tallon <chris@vomp.tv>
Sun, 14 Aug 2022 17:05:02 +0000 (17:05 +0000)
committerChris Tallon <chris@vomp.tv>
Sun, 14 Aug 2022 17:05:02 +0000 (17:05 +0000)
16 files changed:
src/defines.h
src/inputlirc.cc
src/inputudp.cc
src/serialize.cc
src/serialize.h
src/tcp.cc
src/tcp.h
src/udp4.cc
src/udp4.h
src/udp6.cc
src/udp6.h
src/vconnect.cc
src/vdpc.cc
src/vdpc.h
src/vdr.cc
src/vdr.h

index 210c57a5239f2573bf98e86989f740e584b0ada2..a835c968266345363e67a69768f64dcda5ffc25d 100644 (file)
@@ -21,7 +21,6 @@
 #define DEFINES_H
 
 typedef unsigned char UCHAR;
-typedef unsigned short USHORT;
 
 #include <stdint.h>
 
index ec13e7057976ecb43befd457d235b704f64b1c62..0c9e3c37bbd6643938c2f85e07dbd03c610c12c8 100644 (file)
@@ -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<USHORT>(lircPort));
+    tr = tcp.connect(lircIP, static_cast<u2>(lircPort));
   }
 
   if (!tr)
index 0ab47b032d8cfa7fa25bf5e34a53dd4ea4fe015c..11eff5b33c0e57586363cf45ac7743af8cabfb8f 100644 (file)
@@ -41,7 +41,7 @@ bool InputUDP::init()
 
   log->debug(TAG, "Starting InputUDP command server on port {}", port);
 
-  if (!udp6.init(static_cast<USHORT>(port)))
+  if (!udp6.init(static_cast<u2>(port)))
   {
     log->debug(TAG, "UDP6 init error");
     initted = false;
index 4e6cc5bfed5d8ce96a89d39894ba13a79313d04a..a303bc3a98a3ff02685d31f62062bc84f56a0f99 100644 (file)
@@ -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<Pentry>::iterator it=list.begin();it<list.end();it++) {
     switch((*it).ptype){
-      case TUSHORT:
-        rt+=sizeof(USHORT);
+      case Tu2:
+        rt+=sizeof(u2);
         break;
       case TULONG:
         rt+=sizeof(u4);
@@ -391,7 +391,7 @@ int SerializableList::getSerializedLenImpl(){
 int SerializableList::serializeImpl(SerializeBuffer *b){
   for (vector<Pentry>::iterator it=list.begin();it<list.end();it++) {
     switch((*it).ptype){
-      case TUSHORT:
+      case Tu2:
         if (b->encodeShort(*(*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:
index 829dc396573592868e54ed953d80cbe8c460eac7..2bf1dfbd24007b5c0b9518f5d4310ddb7da0f7ec 100644 (file)
@@ -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<Serializable*>(p),vs);
     }
-    int addParam(const USHORT *p,USHORT vs=1){
+    int addParam(const u2 *p,u2 vs=1){
       encodeOnly=true;
-      return addParam(const_cast<USHORT*>(p),vs);
+      return addParam(const_cast<u2*>(p),vs);
     }
-    int addParam(const u4 *p,USHORT vs=1){
+    int addParam(const u4 *p,u2 vs=1){
       encodeOnly=true;
       return addParam(const_cast<u4*>(p),vs);
     }
-    int addParam(const int *p,USHORT vs=1){
+    int addParam(const int *p,u2 vs=1){
       encodeOnly=true;
       return addParam(reinterpret_cast<u4*>(const_cast<int*>(p)), vs);
     }
-    int addParam(const u8 *p,USHORT vs=1){
+    int addParam(const u8 *p,u2 vs=1){
       encodeOnly=true;
       return addParam(const_cast<u8*>(p),vs);
     }
-    int addParam(const char **p,USHORT vs=1){
+    int addParam(const char **p,u2 vs=1){
       encodeOnly=true;
       return addParam(const_cast<char**>(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;
index c8d453bcd9ff2c175d60deec8e2b6084a238075a..90b00f8db8c69d1ce0fd86668355c4ed448417ba 100644 (file)
@@ -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;
 
index 6e611ba86266fdb5529d9d53180e2a89fa644bbf..24745529d81bb4526cd3ef8c74e2ec1fa549a911 100644 (file)
--- 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
index 49c08d1e2f86225736f6bc23b359d944bb058582..2aec13e9cf497b5dfbecc7eeab7f061d2ebb2e1d 100644 (file)
@@ -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;
 
index 856f3eaad5aa95dcb2df4d06703783b140551527..1da2c6454d38c477c03b15cc203445fc6e77beea 100644 (file)
@@ -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
index 166015d80a679ab501d3ba7c7920f6e250c1ebf7..a2d0e778d1ddce8df1db50612793097583630c23 100644 (file)
@@ -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;
index 0bb992ef703ab5757b25608ed9daee555b1fbae4..5cb8e19cc4d5973b42a18835f1e79818ebbf81a8 100644 (file)
@@ -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
index 0755ccd21235d1db643ae99a7da19d76c7d6c112..046860316a6bbb3f7fcffe3c922263c96ce3991d 100644 (file)
@@ -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<USHORT>(newPort);
+      serverFromConfig.port = static_cast<u2>(newPort);
       logger->debug(TAG, "Port read fron config: {}", serverFromConfig.port);
     }
 
index dbb99bbb46e7e520d3ede074d67499076e0c83ab..a54c86272aafdc4ae73f0577709bd8bc64957a4e 100644 (file)
@@ -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<std::mutex> 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;
index 20c1bb0f296d31df918f81522234a7de833020f1..ca243ab5b103e6992499c0505224ba3c2288efe5 100644 (file)
@@ -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<void(int, const char*, const char*, USHORT, u4)> AddServerCallback;
+    typedef std::function<void(int, const char*, const char*, u2, u4)> AddServerCallback;
 
   // Nested classes
 #ifdef IPV4
index 1cecf54513d40628609ebe4ac812f2686688247e..fb11e45716c3b9c879e2a8030d153bcf98c2be9d 100644 (file)
@@ -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;
 }
index e0e1e5d7c2c739c0011842f10909ba7d2e1f2f76..8a1a9b630bef2fe457cfc7acc40664128158b7c4 100644 (file)
--- 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};