Browse Source

Fix mingw and MSVC ci build (#1491)

Michael Jones 1 year ago
parent
commit
544382f313

+ 2 - 8
.github/workflows/msvc.yml

@@ -13,7 +13,6 @@ jobs:
       matrix:
         BUILD_TYPE: [Release, Debug]
         BUILD_SHARED_LIBS: [OFF, ON]
-        #VCPKG_PLATFORM_TOOLSET: [v143, v142, v141]
         CMAKE_GENERATOR_PLATFORM: [x64, Win32]
         os: [windows-latest]
         include:
@@ -30,12 +29,7 @@ jobs:
           - triplet: x86-windows
             VCPKG_PLATFORM_TOOLSET: v142
             CMAKE_GENERATOR_PLATFORM: Win32
- 
-          # MSVC 2017
-          - triplet: x86-windows
-            VCPKG_PLATFORM_TOOLSET: v141
-            CMAKE_GENERATOR_PLATFORM: Win32
- 
+
     runs-on: ${{matrix.os}}
 
     env:
@@ -91,7 +85,7 @@ jobs:
         7z a coturn_windows_msvc.zip ${{github.workspace}}\build\install\*
         cmake --build . --config ${{matrix.BUILD_TYPE}} --target package
 
-    - name: Update 
+    - name: Update
       if: ${{ matrix.BUILD_TYPE == 'Release' }}
       uses: actions/upload-artifact@v4
       with:

+ 26 - 22
src/apps/common/apputils.c

@@ -38,8 +38,12 @@
 #if defined(__unix__) || defined(unix) || defined(__APPLE__)
 #include <getopt.h>
 #include <ifaddrs.h>
+#endif
+
+#if defined(__unix__) || defined(unix) || defined(__APPLE__) || defined(__MINGW32__)
 #include <libgen.h>
 #endif
+
 #if defined(__unix__) || defined(unix)
 #include <pthread.h>
 #include <sys/resource.h>
@@ -106,7 +110,7 @@ int set_sock_buf_size(evutil_socket_t fd, int sz0) {
 
   sz = sz0;
   while (sz > 0) {
-    if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (const void *)(&sz), (socklen_t)sizeof(sz)) < 0) {
+    if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (const void *)&sz, (socklen_t)sizeof(sz)) < 0) {
       sz = sz / 2;
     } else {
       break;
@@ -120,7 +124,7 @@ int set_sock_buf_size(evutil_socket_t fd, int sz0) {
 
   sz = sz0;
   while (sz > 0) {
-    if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const void *)(&sz), (socklen_t)sizeof(sz)) < 0) {
+    if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const void *)&sz, (socklen_t)sizeof(sz)) < 0) {
       sz = sz / 2;
     } else {
       break;
@@ -239,7 +243,7 @@ int sock_bind_to_device(evutil_socket_t fd, const unsigned char *ifname) {
 
     strncpy(ifr.ifr_name, (const char *)ifname, sizeof(ifr.ifr_name));
 
-    if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0) {
+    if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (const void *)&ifr, sizeof(ifr)) < 0) {
       if (socket_eperm()) {
         perror("You must obtain superuser privileges to bind a socket to device");
       } else {
@@ -301,7 +305,7 @@ int addr_bind(evutil_socket_t fd, const ioa_addr *addr, int reusable, int debug,
       } while (ret < 0 && socket_eintr());
     } else if (addr->ss.sa_family == AF_INET6) {
       const int off = 0;
-      setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const char *)&off, sizeof(off));
+      setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&off, sizeof(off));
       do {
         ret = bind(fd, (const struct sockaddr *)addr, sizeof(struct sockaddr_in6));
       } while (ret < 0 && socket_eintr());
@@ -355,7 +359,7 @@ int get_raw_socket_ttl(evutil_socket_t fd, int family) {
     } while (0);
 #else
     socklen_t slen = (socklen_t)sizeof(ttl);
-    if (getsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, &slen) < 0) {
+    if (getsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (void *)&ttl, &slen) < 0) {
       perror("get HOPLIMIT on socket");
       return TTL_IGNORE;
     }
@@ -368,7 +372,7 @@ int get_raw_socket_ttl(evutil_socket_t fd, int family) {
     } while (0);
 #else
     socklen_t slen = (socklen_t)sizeof(ttl);
-    if (getsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, &slen) < 0) {
+    if (getsockopt(fd, IPPROTO_IP, IP_TTL, (void *)&ttl, &slen) < 0) {
       perror("get TTL on socket");
       return TTL_IGNORE;
     }
@@ -391,7 +395,7 @@ int get_raw_socket_tos(evutil_socket_t fd, int family) {
     } while (0);
 #else
     socklen_t slen = (socklen_t)sizeof(tos);
-    if (getsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &tos, &slen) < 0) {
+    if (getsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, (void *)&tos, &slen) < 0) {
       perror("get TCLASS on socket");
       return -1;
     }
@@ -404,7 +408,7 @@ int get_raw_socket_tos(evutil_socket_t fd, int family) {
     } while (0);
 #else
     socklen_t slen = (socklen_t)sizeof(tos);
-    if (getsockopt(fd, IPPROTO_IP, IP_TOS, &tos, &slen) < 0) {
+    if (getsockopt(fd, IPPROTO_IP, IP_TOS, (void *)&tos, &slen) < 0) {
       perror("get TOS on socket");
       return -1;
     }
@@ -424,7 +428,7 @@ int set_raw_socket_ttl(evutil_socket_t fd, int family, int ttl) {
     UNUSED_ARG(ttl);
 #else
     CORRECT_RAW_TTL(ttl);
-    if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)) < 0) {
+    if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (const void *)&ttl, sizeof(ttl)) < 0) {
       perror("set HOPLIMIT on socket");
       return -1;
     }
@@ -435,7 +439,7 @@ int set_raw_socket_ttl(evutil_socket_t fd, int family, int ttl) {
     UNUSED_ARG(ttl);
 #else
     CORRECT_RAW_TTL(ttl);
-    if (setsockopt(fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)) < 0) {
+    if (setsockopt(fd, IPPROTO_IP, IP_TTL, (const void *)&ttl, sizeof(ttl)) < 0) {
       perror("set TTL on socket");
       return -1;
     }
@@ -453,7 +457,7 @@ int set_raw_socket_tos(evutil_socket_t fd, int family, int tos) {
     UNUSED_ARG(tos);
 #else
     CORRECT_RAW_TOS(tos);
-    if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)) < 0) {
+    if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, (const void *)&tos, sizeof(tos)) < 0) {
       perror("set TCLASS on socket");
       return -1;
     }
@@ -463,7 +467,7 @@ int set_raw_socket_tos(evutil_socket_t fd, int family, int tos) {
     UNUSED_ARG(fd);
     UNUSED_ARG(tos);
 #else
-    if (setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) {
+    if (setsockopt(fd, IPPROTO_IP, IP_TOS, (const void *)&tos, sizeof(tos)) < 0) {
       perror("set TOS on socket");
       return -1;
     }
@@ -544,10 +548,10 @@ int set_socket_df(evutil_socket_t fd, int family, int value) {
     const int val = value;
     /* kernel sets DF bit on outgoing IP packets */
     if (family == AF_INET) {
-      ret = setsockopt(fd, IPPROTO_IP, IP_DONTFRAG, &val, sizeof(val));
+      ret = setsockopt(fd, IPPROTO_IP, IP_DONTFRAG, (const void *)&val, sizeof(val));
     } else {
 #if defined(IPV6_DONTFRAG) && defined(IPPROTO_IPV6)
-      ret = setsockopt(fd, IPPROTO_IPV6, IPV6_DONTFRAG, &val, sizeof(val));
+      ret = setsockopt(fd, IPPROTO_IPV6, IPV6_DONTFRAG, (const void *)&val, sizeof(val));
 #else
 #error CANNOT SET IPV6 SOCKET DF FLAG (1)
 #endif
@@ -567,14 +571,14 @@ int set_socket_df(evutil_socket_t fd, int family, int value) {
       if (!value) {
         val = IP_PMTUDISC_DONT;
       }
-      ret = setsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val));
+      ret = setsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER, (const void *)&val, sizeof(val));
     } else {
 #if defined(IPPROTO_IPV6) && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO) && defined(IPV6_PMTUDISC_DONT)
       int val = IPV6_PMTUDISC_DO;
       if (!value) {
         val = IPV6_PMTUDISC_DONT;
       }
-      ret = setsockopt(fd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, &val, sizeof(val));
+      ret = setsockopt(fd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, (const void *)&val, sizeof(val));
 #else
 #error CANNOT SET IPV6 SOCKET DF FLAG (2)
 #endif
@@ -704,10 +708,10 @@ int get_socket_mtu(evutil_socket_t fd, int family, int verbose) {
   int val = 0;
   socklen_t slen = sizeof(val);
   if (family == AF_INET) {
-    ret = getsockopt(fd, IPPROTO_IP, IP_MTU, &val, &slen);
+    ret = getsockopt(fd, IPPROTO_IP, IP_MTU, (void *)&val, &slen);
   } else {
 #if defined(IPPROTO_IPV6) && defined(IPV6_MTU)
-    ret = getsockopt(fd, IPPROTO_IPV6, IPV6_MTU, &val, &slen);
+    ret = getsockopt(fd, IPPROTO_IPV6, IPV6_MTU, (void *)&val, &slen);
 #endif
     ;
   }
@@ -981,14 +985,14 @@ wchar_t *_ATW(__in char *pszInBuf, __in int nInSize, __out wchar_t **pszOutBuf,
     return NULL;
   }
   // Get buffer size
-  *pnOutSize = MultiByteToWideChar(NULL, NULL, pszInBuf, nInSize, *pszOutBuf, 0);
+  *pnOutSize = MultiByteToWideChar((UINT)0, (DWORD)0, pszInBuf, nInSize, *pszOutBuf, 0);
   if (*pnOutSize == 0) {
     return NULL;
   }
   (*pnOutSize)++;
   *pszOutBuf = malloc((*pnOutSize) * sizeof(wchar_t));
   memset((void *)*pszOutBuf, 0, sizeof(wchar_t) * (*pnOutSize));
-  if (MultiByteToWideChar(NULL, NULL, pszInBuf, nInSize, *pszOutBuf, *pnOutSize) == 0) {
+  if (MultiByteToWideChar((UINT)0, (DWORD)0, pszInBuf, nInSize, *pszOutBuf, *pnOutSize) == 0) {
     free(*pszOutBuf);
     return NULL;
   } else {
@@ -1009,14 +1013,14 @@ char *_WTA(__in wchar_t *pszInBuf, __in int nInSize, __out char **pszOutBuf, __o
   if (!pszInBuf || !pszOutBuf || !pnOutSize || nInSize <= 0) {
     return NULL;
   }
-  *pnOutSize = WideCharToMultiByte(NULL, NULL, pszInBuf, nInSize, *pszOutBuf, 0, NULL, NULL);
+  *pnOutSize = WideCharToMultiByte((UINT)0, (DWORD)0, pszInBuf, nInSize, *pszOutBuf, 0, NULL, NULL);
   if (*pnOutSize == 0) {
     return NULL;
   }
   (*pnOutSize)++;
   *pszOutBuf = malloc(*pnOutSize * sizeof(char));
   memset((void *)*pszOutBuf, 0, sizeof(char) * (*pnOutSize));
-  if (WideCharToMultiByte(NULL, NULL, pszInBuf, nInSize, *pszOutBuf, *pnOutSize, NULL, NULL) == 0) {
+  if (WideCharToMultiByte((UINT)0, (DWORD)0, pszInBuf, nInSize, *pszOutBuf, *pnOutSize, NULL, NULL) == 0) {
     free(*pszOutBuf);
     return NULL;
   } else {

+ 2 - 2
src/apps/common/hiredis_libevent2.c

@@ -71,7 +71,7 @@ static int redis_le_valid(struct redisLibeventEvents *e) { return (e && !(e->inv
 
 /////////////////// Callbacks ////////////////////////////
 
-static void redisLibeventReadEvent(int fd, short event, void *arg) {
+static void redisLibeventReadEvent(evutil_socket_t fd, short event, void *arg) {
   ((void)fd);
   ((void)event);
   struct redisLibeventEvents *e = (struct redisLibeventEvents *)arg;
@@ -95,7 +95,7 @@ static void redisLibeventReadEvent(int fd, short event, void *arg) {
   }
 }
 
-static void redisLibeventWriteEvent(int fd, short event, void *arg) {
+static void redisLibeventWriteEvent(evutil_socket_t fd, short event, void *arg) {
   ((void)fd);
   ((void)event);
   struct redisLibeventEvents *e = (struct redisLibeventEvents *)arg;

+ 1 - 0
src/apps/natdiscovery/natdiscovery.c

@@ -41,6 +41,7 @@
 #endif
 
 #include "apputils.h"
+#include "ns_turn_ioalib.h"
 #include "ns_turn_utils.h"
 #include "stun_buffer.h"
 

+ 4 - 0
src/apps/relay/acme.c

@@ -8,6 +8,10 @@
 #include "acme.h"
 #include "ns_ioalib_impl.h"
 
+#if !defined(_MSC_VER)
+#include <unistd.h>
+#endif
+
 #define GET_ACME_PREFIX "GET /.well-known/acme-challenge/"
 #define GET_ACME_PREFIX_LEN 32
 

+ 2 - 0
src/apps/relay/netengine.c

@@ -30,6 +30,8 @@
 
 #include "mainrelay.h"
 
+#include "ns_turn_ioalib.h"
+
 //////////// Backward compatibility with OpenSSL 1.0.x //////////////
 #if (OPENSSL_VERSION_NUMBER < 0x10100001L ||                                                                           \
      (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER <= 0x3040000fL))

+ 17 - 17
src/apps/relay/ns_ioalib_engine_impl.c

@@ -759,7 +759,7 @@ int set_raw_socket_ttl_options(evutil_socket_t fd, int family) {
     UNUSED_ARG(fd);
 #else
     int recv_ttl_on = 1;
-    if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &recv_ttl_on, sizeof(recv_ttl_on)) < 0) {
+    if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, (const void *)&recv_ttl_on, sizeof(recv_ttl_on)) < 0) {
       perror("cannot set recvhoplimit\n");
     }
 #endif
@@ -768,7 +768,7 @@ int set_raw_socket_ttl_options(evutil_socket_t fd, int family) {
     UNUSED_ARG(fd);
 #else
     int recv_ttl_on = 1;
-    if (setsockopt(fd, IPPROTO_IP, IP_RECVTTL, &recv_ttl_on, sizeof(recv_ttl_on)) < 0) {
+    if (setsockopt(fd, IPPROTO_IP, IP_RECVTTL, (const void *)&recv_ttl_on, sizeof(recv_ttl_on)) < 0) {
       perror("cannot set recvttl\n");
     }
 #endif
@@ -783,7 +783,7 @@ int set_raw_socket_tos_options(evutil_socket_t fd, int family) {
     UNUSED_ARG(fd);
 #else
     int recv_tos_on = 1;
-    if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVTCLASS, &recv_tos_on, sizeof(recv_tos_on)) < 0) {
+    if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVTCLASS, (const void *)&recv_tos_on, sizeof(recv_tos_on)) < 0) {
       perror("cannot set recvtclass\n");
     }
 #endif
@@ -792,7 +792,7 @@ int set_raw_socket_tos_options(evutil_socket_t fd, int family) {
     UNUSED_ARG(fd);
 #else
     int recv_tos_on = 1;
-    if (setsockopt(fd, IPPROTO_IP, IP_RECVTOS, &recv_tos_on, sizeof(recv_tos_on)) < 0) {
+    if (setsockopt(fd, IPPROTO_IP, IP_RECVTOS, (const void *)&recv_tos_on, sizeof(recv_tos_on)) < 0) {
       perror("cannot set recvtos\n");
     }
 #endif
@@ -812,7 +812,7 @@ int set_socket_options_fd(evutil_socket_t fd, SOCKET_TYPE st, int family) {
     struct linger so_linger;
     so_linger.l_onoff = 1;
     so_linger.l_linger = 0;
-    if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof(so_linger)) < 1) {
+    if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (const void *)&so_linger, sizeof(so_linger)) < 1) {
       // perror("setsolinger")
       ;
     }
@@ -830,7 +830,7 @@ int set_socket_options_fd(evutil_socket_t fd, SOCKET_TYPE st, int family) {
 #ifdef TURN_IP_RECVERR
       on = 1;
 #endif
-      if (setsockopt(fd, IPPROTO_IP, IP_RECVERR, (void *)&on, sizeof(on)) < 0) {
+      if (setsockopt(fd, IPPROTO_IP, IP_RECVERR, (const void *)&on, sizeof(on)) < 0) {
         perror("IP_RECVERR");
       }
     }
@@ -842,7 +842,7 @@ int set_socket_options_fd(evutil_socket_t fd, SOCKET_TYPE st, int family) {
 #ifdef TURN_IP_RECVERR
       on = 1;
 #endif
-      if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVERR, (void *)&on, sizeof(on)) < 0) {
+      if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVERR, (const void *)&on, sizeof(on)) < 0) {
         perror("IPV6_RECVERR");
       }
     }
@@ -853,18 +853,18 @@ int set_socket_options_fd(evutil_socket_t fd, SOCKET_TYPE st, int family) {
     int flag = 1;
 
     if (is_tcp_socket(st)) {
-      setsockopt(fd,            /* socket affected */
-                 IPPROTO_TCP,   /* set option at TCP level */
-                 TCP_NODELAY,   /* name of option */
-                 (char *)&flag, /* value */
-                 sizeof(int));  /* length of option value */
+      setsockopt(fd,                  /* socket affected */
+                 IPPROTO_TCP,         /* set option at TCP level */
+                 TCP_NODELAY,         /* name of option */
+                 (const void *)&flag, /* value */
+                 sizeof(int));        /* length of option value */
     } else {
 #if defined(SCTP_NODELAY)
-      setsockopt(fd,            /* socket affected */
-                 IPPROTO_SCTP,  /* set option at SCTP level */
-                 SCTP_NODELAY,  /* name of option */
-                 (char *)&flag, /* value */
-                 sizeof(int));  /* length of option value */
+      setsockopt(fd,                  /* socket affected */
+                 IPPROTO_SCTP,        /* set option at SCTP level */
+                 SCTP_NODELAY,        /* name of option */
+                 (const void *)&flag, /* value */
+                 sizeof(int));        /* length of option value */
 #endif
     }
 

+ 6 - 0
src/apps/uclient/startuclient.c

@@ -39,6 +39,12 @@
 #include "startuclient.h"
 #include "uclient.h"
 
+#if defined(__MINGW32__)
+#ifndef usleep
+#define usleep Sleep
+#endif
+#endif
+
 /////////////////////////////////////////
 
 #define MAX_CONNECT_EFFORTS (77)

+ 7 - 0
src/apps/uclient/uclient.c

@@ -30,6 +30,7 @@
 
 #include "uclient.h"
 #include "apputils.h"
+#include "ns_turn_ioalib.h"
 #include "ns_turn_utils.h"
 #include "session.h"
 #include "startuclient.h"
@@ -40,6 +41,12 @@
 #endif
 #include <time.h>
 
+#if defined(__MINGW32__)
+#ifndef usleep
+#define usleep Sleep
+#endif
+#endif
+
 static int verbose_packets = 0;
 
 static size_t current_clients_number = 0;

+ 6 - 4
src/server/ns_turn_ioalib.h

@@ -54,10 +54,6 @@ typedef struct _tcp_connection tcp_connection;
 #define strtok_r strtok_s
 #endif
 
-#ifndef sleep
-#define sleep(t) Sleep(t * 1000)
-#endif
-
 #ifndef usleep
 #define usleep Sleep
 #endif
@@ -67,7 +63,13 @@ typedef struct _tcp_connection tcp_connection;
 typedef SSIZE_T ssize_t;
 #endif
 
+#endif // defined(_MSC_VER) || defined(__MINGW32__)
+
+#if defined(_MSC_VER) || defined(__MINGW32__)
+#ifndef sleep
+#define sleep(t) Sleep(t * 1000)
 #endif
+#endif // defined(_MSC_VER) || defined(__MINGW32__)
 
 ////////////// Mutexes /////////////////////
 

+ 1 - 1
src/server/ns_turn_server.c

@@ -409,7 +409,7 @@ void turn_session_info_add_peer(struct turn_session_info *tsi, ioa_addr *peer) {
     }
   }
 
-  addr_data* pTmp = (addr_data *)realloc(tsi->extra_peers_data, (tsi->extra_peers_size + 1) * sizeof(addr_data));
+  addr_data *pTmp = (addr_data *)realloc(tsi->extra_peers_data, (tsi->extra_peers_size + 1) * sizeof(addr_data));
   if (!pTmp) {
     return;
   }