]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: add Linux CI job, fix pytest with cmake
authorViktor Szakats <commit@vsz.me>
Sun, 4 Aug 2024 15:18:39 +0000 (17:18 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 6 Aug 2024 00:40:32 +0000 (02:40 +0200)
- extend existing Linux workflow with CMake support.
  Including running pytest the first time with CMake.

- cmake: generate `tests/config` and `tests/http/config.ini`.
  Required for pytest tests.
  Uses basic detection logic. Feel free to take it from here.
  Also dump config files in a CI step for debugging purposes.

- cmake: build `tests/http/clients` programs.

- fix portability issues with `tests/http/clients` programs.
  Some of them use `getopt()`, which is not supported by MSVC.
  Fix the rest to compile in CI (old-mingw-w64, MSVC, Windows).

- GHA/linux: add CMake job matching an existing autotools one.

- GHA/linux: test `-DCURL_LIBCURL_VERSIONED_SYMBOLS=ON`
  in the new CMake job.

- reorder testdeps to build server, client tests first and then
  libtests and units, to catch errors in the more complex/unique
  sources earlier.

- sort list in `tests/http/clients/Makefile.inc`.

Closes #14382

15 files changed:
.github/workflows/linux.yml
tests/CMakeLists.txt
tests/http/CMakeLists.txt [new file with mode: 0644]
tests/http/Makefile.am
tests/http/clients/CMakeLists.txt [new file with mode: 0644]
tests/http/clients/Makefile.am
tests/http/clients/Makefile.inc
tests/http/clients/h2-download.c
tests/http/clients/h2-pausing.c
tests/http/clients/h2-serverpush.c
tests/http/clients/h2-upgrade-extreme.c
tests/http/clients/tls-session-reuse.c
tests/http/clients/upload-pausing.c
tests/http/clients/ws-data.c
tests/http/clients/ws-pingpong.c

index bde8fb60aae9964e5058d8dcb20901cb445a8412..bd5208c689d1bb9ce90ea4422b56c45c7fd4a392 100644 (file)
@@ -57,8 +57,8 @@ env:
   rustls-version: 0.13.0
 
 jobs:
-  autotools:
-    name: ${{ matrix.build.name }}
+  linux:
+    name: ${{ matrix.build.generate && 'CM' || 'AM' }} ${{ matrix.build.name }}
     runs-on: 'ubuntu-latest'
     container: ${{ matrix.build.container }}
     timeout-minutes: 90
@@ -84,6 +84,12 @@ jobs:
             configure: LDFLAGS="-Wl,-rpath,$HOME/libressl/lib" --with-openssl=$HOME/libressl --enable-debug
             singleuse: --unit
 
+          - name: libressl
+            install_packages: zlib1g-dev valgrind
+            install_steps: libressl pytest
+            generate: -DOPENSSL_ROOT_DIR=$HOME/libressl -DENABLE_DEBUG=ON -DCURL_LIBCURL_VERSIONED_SYMBOLS=ON
+            singleuse: --unit
+
           - name: libressl-clang
             install_packages: zlib1g-dev clang
             install_steps: libressl
@@ -412,29 +418,57 @@ jobs:
           sudo make install
 
       - run: autoreconf -fi
+        if: ${{ matrix.build.configure }}
         name: 'autoreconf'
 
       - run: ./configure --disable-dependency-tracking --enable-warnings --enable-werror ${{ matrix.build.configure }}
-        name: 'configure'
+        if: ${{ matrix.build.configure }}
+        name: 'configure (autotools)'
 
-      - run: make V=1
+      - run: |
+          cmake . \
+            -DCMAKE_C_COMPILER_TARGET=$(uname -m)-pc-linux-gnu -DBUILD_STATIC_LIBS=ON \
+            -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON \
+            -DBUILD_EXAMPLES=ON \
+            -DCURL_BROTLI=ON -DCURL_ZSTD=ON \
+            ${{ matrix.build.generate }}
+        if: ${{ matrix.build.generate }}
+        name: 'configure (cmake)'
+
+      - name: 'test configs'
+        run: |
+          cat tests/config || true
+          cat tests/http/config.ini || true
+
+      - run: make V=1 VERBOSE=1
         name: 'make'
 
       - run: |
           git config --global --add safe.directory "*"
-          ./scripts/singleuse.pl ${{ matrix.build.singleuse }} lib/.libs/libcurl.a
+          if [ -n '${{ matrix.build.generate }}' ]; then
+            libcurla=lib/libcurl.a
+          else
+            libcurla=lib/.libs/libcurl.a
+          fi
+          ./scripts/singleuse.pl ${{ matrix.build.singleuse }} ${libcurla}
         name: single-use function check
 
       - run: ./src/curl -V
         name: 'check curl -V output'
 
       - run: make V=1 examples
+        if: ${{ matrix.build.configure }}
         name: 'make examples'
 
       - run: make V=1 -C tests
-        name: 'make tests'
+        if: ${{ matrix.build.configure }}
+        name: 'make tests (autotools)'
+
+      - run: make VERBOSE=1 testdeps
+        if: ${{ matrix.build.generate }}
+        name: 'make tests (cmake)'
 
-      - run: make V=1 test-ci
+      - run: make V=1 VERBOSE=1 test-ci
         name: 'run tests'
         env:
           TFLAGS: "${{ matrix.build.tflags }}"
index dc75298efbc86635b4d0bdd4a20b939d7670bcdd..7df56918b149406b1a565e533eea3444c1ee9393 100644 (file)
 ###########################################################################
 set(CMAKE_UNITY_BUILD OFF)
 
+find_program(TEST_NGHTTPX "nghttpx")
+if(NOT TEST_NGHTTPX)
+  set(TEST_NGHTTPX "nghttpx")
+endif()
+# TEST_NGHTTPX
+configure_file("config.in" "${CMAKE_CURRENT_BINARY_DIR}/config" @ONLY)
+
 add_custom_target(testdeps)
-add_subdirectory(libtest)
+add_subdirectory(http)
+add_subdirectory(http/clients)
 add_subdirectory(server)
+add_subdirectory(libtest)
 add_subdirectory(unit)
 
 function(add_runtests targetname test_flags)
diff --git a/tests/http/CMakeLists.txt b/tests/http/CMakeLists.txt
new file mode 100644 (file)
index 0000000..2ccf4cf
--- /dev/null
@@ -0,0 +1,51 @@
+#***************************************************************************
+#                                  _   _ ____  _
+#  Project                     ___| | | |  _ \| |
+#                             / __| | | | |_) | |
+#                            | (__| |_| |  _ <| |___
+#                             \___|\___/|_| \_\_____|
+#
+# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at https://curl.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# SPDX-License-Identifier: curl
+#
+###########################################################################
+
+find_program(CADDY "caddy")  # /usr/bin/caddy
+if(NOT CADDY)
+  set(CADDY "")
+endif()
+find_program(VSFTPD "vsftpd")  # /usr/sbin/vsftpd
+if(NOT VSFTPD)
+  set(VSFTPD "")
+endif()
+find_program(HTTPD "apache2")  # /usr/sbin/apache2
+if(NOT HTTPD)
+  set(HTTPD "")
+endif()
+find_program(APACHECTL "apache2ctl")  # /usr/sbin/apache2ctl
+if(NOT APACHECTL)
+  set(APACHECTL "")
+endif()
+find_program(APXS "apxs")
+if(NOT APXS)
+  set(APXS "")
+endif()
+find_program(HTTPD_NGHTTPX "nghttpx" PATHS "/usr/bin" "/usr/local/bin")
+if(NOT HTTPD_NGHTTPX)
+  set(HTTPD_NGHTTPX "")
+endif()
+
+# APXS, HTTPD, APACHECTL, HTTPD_NGHTTPX, CADDY, VSFTPD
+configure_file("config.ini.in" "${CMAKE_CURRENT_BINARY_DIR}/config.ini" @ONLY)
index d9ab29686c08b45b05b3c82d4e74e015a7cca504..92652aa62290c1800c225f62b202a39c4ec460b8 100644 (file)
@@ -39,6 +39,7 @@ testenv/vsftpd.py                     \
 testenv/ws_echo_server.py
 
 EXTRA_DIST =           \
+CMakeLists.txt         \
 config.ini.in          \
 conftest.py            \
 requirements.txt       \
diff --git a/tests/http/clients/CMakeLists.txt b/tests/http/clients/CMakeLists.txt
new file mode 100644 (file)
index 0000000..46d887a
--- /dev/null
@@ -0,0 +1,44 @@
+#***************************************************************************
+#                                  _   _ ____  _
+#  Project                     ___| | | |  _ \| |
+#                             / __| | | | |_) | |
+#                            | (__| |_| |  _ <| |___
+#                             \___|\___/|_| \_\_____|
+#
+# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at https://curl.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# SPDX-License-Identifier: curl
+#
+###########################################################################
+
+# Get 'check_PROGRAMS' variable
+transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
+include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
+
+foreach(_client IN LISTS check_PROGRAMS)
+  set(_client_target "curl-test-client-${_client}")
+  add_executable(${_client_target} "${_client}.c")
+  add_dependencies(testdeps ${_client_target})
+  target_include_directories(${_client_target} PRIVATE
+    "${CURL_SOURCE_DIR}/lib"      # for "curl_setup_once.h"
+    "${CURL_BINARY_DIR}/lib"      # for "curl_config.h"
+    "${CURL_BINARY_DIR}/include"  # for "curl/curl.h"
+  )
+  target_link_libraries(${_client_target} ${LIB_SELECTED} ${CURL_LIBS})
+  target_compile_definitions(${_client_target} PRIVATE "CURL_NO_OLDIES")
+  if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32)
+    set_property(TARGET ${_client_target} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
+  endif()
+  set_target_properties(${_client_target} PROPERTIES OUTPUT_NAME "${_client}" UNITY_BUILD OFF)
+endforeach()
index 8fdc190b94eead5ec3b95781dc36fb6e62c3ab5c..5395b22bfb89dc91aaf6e67f215a956801650eec 100644 (file)
@@ -24,6 +24,7 @@
 
 AUTOMAKE_OPTIONS = foreign nostdinc
 
+EXTRA_DIST = CMakeLists.txt
 
 # Specify our include paths here, and do it relative to $(top_srcdir) and
 # $(top_builddir), to ensure that these paths which belong to the library
@@ -59,7 +60,7 @@ endif
 # This might hold -Werror
 CFLAGS += @CURL_CFLAG_EXTRAS@
 
-# Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines
+# Makefile.inc provides the check_PROGRAMS define
 include Makefile.inc
 
 all: $(check_PROGRAMS)
index 07b6ae4aaf2cf35f6e9512c7825c4c119c959bc1..e2ab2143b506b7a686410c3fa26f6e431479c787 100644 (file)
 
 # These are all libcurl example programs to be test compiled
 check_PROGRAMS = \
-  h2-serverpush \
   h2-download \
-  ws-data \
-  ws-pingpong \
+  h2-pausing \
+  h2-serverpush \
   h2-upgrade-extreme \
   tls-session-reuse \
-  h2-pausing \
-  upload-pausing
+  upload-pausing \
+  ws-data \
+  ws-pingpong
index 12af781de52abff895f76cdbddc1a0e05685ad28..29745311cbcc51a082348279540ebaef4ffb2006 100644 (file)
  * HTTP/2 server push
  * </DESC>
  */
-
 /* curl stuff */
 #include <curl/curl.h>
-#include <curl/mprintf.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#ifndef _MSC_VER
 /* somewhat Unix-specific */
-#include <sys/time.h>
-#include <unistd.h>
+#include <unistd.h>  /* getopt() */
+#endif
+
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
 
 #ifndef CURLPIPE_MULTIPLEX
 #error "too old libcurl, cannot do HTTP/2 server push!"
 #endif
 
+#ifndef _MSC_VER
 static int verbose = 1;
 
 static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
@@ -81,11 +85,10 @@ static int debug_cb(CURL *handle, curl_infotype type,
   if(!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
     if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
         conn_id >= 0) {
-      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2,
-                     xfer_id, conn_id);
+      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id, conn_id);
     }
     else {
-      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
     }
   }
   else
@@ -181,8 +184,7 @@ static size_t my_write_cb(char *buf, size_t nitems, size_t buflen,
   fprintf(stderr, "[t-%d] RECV %ld bytes, total=%ld, pause_at=%ld\n",
           t->idx, (long)blen, (long)t->recv_size, (long)t->pause_at);
   if(!t->out) {
-    curl_msnprintf(t->filename, sizeof(t->filename)-1, "download_%u.data",
-                   t->idx);
+    snprintf(t->filename, sizeof(t->filename)-1, "download_%u.data", t->idx);
     t->out = fopen(t->filename, "wb");
     if(!t->out)
       return 0;
@@ -272,12 +274,14 @@ static void usage(const char *msg)
     "  -V http_version (http/1.1, h2, h3) http version to use\n"
   );
 }
+#endif /* !_MSC_VER */
 
 /*
  * Download a file over HTTP/2, take care of server push.
  */
 int main(int argc, char *argv[])
 {
+#ifndef _MSC_VER
   CURLM *multi_handle;
   struct CURLMsg *m;
   const char *url;
@@ -477,4 +481,10 @@ int main(int argc, char *argv[])
   curl_multi_cleanup(multi_handle);
 
   return 0;
+#else
+  (void)argc;
+  (void)argv;
+  fprintf(stderr, "Not supported with this compiler.\n");
+  return 1;
+#endif /* !_MSC_VER */
 }
index c12e8fab0046342e024976029b146d437c20a3b9..dd27b2ff2e0193794e54d3e7add1752d88167bd6 100644 (file)
  * HTTP/2 download pausing
  * </DESC>
  */
-/* This is based on the poc client of issue #11982
+/* This is based on the PoC client of issue #11982
  */
+#include <curl/curl.h>
+
 #include <assert.h>
 #include <stdio.h>
 #include <string.h>
-#include <sys/time.h>
-#include <unistd.h>
 #include <stdlib.h>
-#include <curl/curl.h>
-#include <curl/mprintf.h>
 
+#ifndef _MSC_VER
+/* somewhat Unix-specific */
+#include <unistd.h>  /* getopt() */
+#endif
+
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
+
+#ifndef _MSC_VER
 #define HANDLECOUNT 2
 
 static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
@@ -75,11 +83,10 @@ static int debug_cb(CURL *handle, curl_infotype type,
   if(!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
     if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
         conn_id >= 0) {
-      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2,
-                     xfer_id, conn_id);
+      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id, conn_id);
     }
     else {
-      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
     }
   }
   else
@@ -192,9 +199,11 @@ static size_t cb(void *data, size_t size, size_t nmemb, void *clientp)
           handle->idx, (long)realsize);
   return realsize;
 }
+#endif /* !_MSC_VER */
 
 int main(int argc, char *argv[])
 {
+#ifndef _MSC_VER
   struct handle handles[HANDLECOUNT];
   CURLM *multi_handle;
   int i, still_running = 1, msgs_left, numfds;
@@ -263,8 +272,7 @@ int main(int argc, char *argv[])
     exit(1);
   }
   memset(&resolve, 0, sizeof(resolve));
-  curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1,
-                 "%s:%s:127.0.0.1", host, port);
+  snprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1", host, port);
   resolve = curl_slist_append(resolve, resolve_buf);
 
   for(i = 0; i<HANDLECOUNT; i++) {
@@ -339,7 +347,8 @@ int main(int argc, char *argv[])
     if(curl_multi_poll(multi_handle, NULL, 0, 100, &numfds) != CURLM_OK)
       err();
 
-    while((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
+    /* !checksrc! disable EQUALSNULL 1 */
+    while((msg = curl_multi_info_read(multi_handle, &msgs_left)) != NULL) {
       if(msg->msg == CURLMSG_DONE) {
         for(i = 0; i<HANDLECOUNT; i++) {
           if(msg->easy_handle == handles[i].h) {
@@ -394,4 +403,10 @@ out:
   curl_global_cleanup();
 
   return rc;
+#else
+  (void)argc;
+  (void)argv;
+  fprintf(stderr, "Not supported with this compiler.\n");
+  return 1;
+#endif /* !_MSC_VER */
 }
index a9b5537a5e80133ed980daa65e1055786e3f817a..0055add615a28817775854b6fae69b7294636fa3 100644 (file)
  * HTTP/2 server push
  * </DESC>
  */
-
 /* curl stuff */
 #include <curl/curl.h>
-#include <curl/mprintf.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-/* somewhat Unix-specific */
-#include <sys/time.h>
-#include <unistd.h>
-
 #ifndef CURLPIPE_MULTIPLEX
 #error "too old libcurl, cannot do HTTP/2 server push!"
 #endif
 
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
+
 static
 void dump(const char *text, unsigned char *ptr, size_t size,
           char nohex)
@@ -172,7 +170,7 @@ static int server_push_callback(CURL *parent,
   int rv;
 
   (void)parent; /* we have no use for this */
-  curl_msnprintf(filename, sizeof(filename)-1, "push%u", count++);
+  snprintf(filename, sizeof(filename)-1, "push%u", count++);
 
   /* here's a new stream, save it in a new file for each new push */
   out = fopen(filename, "wb");
index e15e34ce0a6d96468f2bb775c0b820bbf297a2ea..697362f974faaad9f2b46c7af98f0f962bf417b8 100644 (file)
  * HTTP/2 Upgrade test
  * </DESC>
  */
+#include <curl/curl.h>
+
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h>
-#include <inttypes.h>
 /* #include <error.h> */
 #include <errno.h>
-#include <curl/curl.h>
-#include <curl/mprintf.h>
 
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
 
 static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
 {
@@ -72,11 +73,10 @@ static int debug_cb(CURL *handle, curl_infotype type,
   if(!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
     if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
         conn_id >= 0) {
-      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2,
-                     xfer_id, conn_id);
+      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id, conn_id);
     }
     else {
-      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
     }
   }
   else
@@ -181,8 +181,7 @@ int main(int argc, char *argv[])
       curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
       curl_easy_setopt(easy, CURLOPT_WRITEDATA, NULL);
       curl_easy_setopt(easy, CURLOPT_HTTPGET, 1L);
-      curl_msnprintf(range, sizeof(range), "%" PRIu64 "-%" PRIu64,
-                     UINT64_C(0), UINT64_C(16384));
+      snprintf(range, sizeof(range), "%d-%d", 0, 16384);
       curl_easy_setopt(easy, CURLOPT_RANGE, range);
 
       mc = curl_multi_add_handle(multi, easy);
@@ -211,7 +210,8 @@ int main(int argc, char *argv[])
     }
 
     /* Check for finished handles and remove. */
-    while((msg = curl_multi_info_read(multi, &msgs_in_queue))) {
+    /* !checksrc! disable EQUALSNULL 1 */
+    while((msg = curl_multi_info_read(multi, &msgs_in_queue)) != NULL) {
       if(msg->msg == CURLMSG_DONE) {
         long status = 0;
         curl_off_t xfer_id;
index 2750ba77763b47fcad99a0edde742ec55939c572..97ec862c8b0ee1a7dd472c5a11edf9ec9b7e5c20 100644 (file)
  * TLS session reuse
  * </DESC>
  */
+#include <curl/curl.h>
+
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h>
 #include <string.h>
-#include <inttypes.h>
 /* #include <error.h> */
 #include <errno.h>
-#include <curl/curl.h>
-#include <curl/mprintf.h>
 
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
 
 static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
 {
@@ -73,11 +74,10 @@ static int debug_cb(CURL *handle, curl_infotype type,
   if(!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
     if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
         conn_id >= 0) {
-      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2,
-                     xfer_id, conn_id);
+      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id, conn_id);
     }
     else {
-      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
     }
   }
   else
@@ -222,9 +222,8 @@ int main(int argc, char *argv[])
     exit(1);
   }
 
-   memset(&resolve, 0, sizeof(resolve));
-   curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1,
-                  "%s:%s:127.0.0.1", host, port);
+  memset(&resolve, 0, sizeof(resolve));
+  snprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1", host, port);
   curl_slist_append(&resolve, resolve_buf);
 
   multi = curl_multi_init();
@@ -274,7 +273,8 @@ int main(int argc, char *argv[])
     }
 
     /* Check for finished handles and remove. */
-    while((msg = curl_multi_info_read(multi, &msgs_in_queue))) {
+    /* !checksrc! disable EQUALSNULL 1 */
+    while((msg = curl_multi_info_read(multi, &msgs_in_queue)) != NULL) {
       if(msg->msg == CURLMSG_DONE) {
         long status = 0;
         curl_off_t xfer_id;
index 58f3c9118f59e5bdeb1fe4c1d7060b6a04a7ccbf..80c030b89c366c7c3e5d014f0e98c303c0169f37 100644 (file)
  * upload pausing
  * </DESC>
  */
-/* This is based on the poc client of issue #11769
+/* This is based on the PoC client of issue #11769
  */
+#include <curl/curl.h>
+
 #include <stdio.h>
 #include <string.h>
-#include <sys/time.h>
-#include <unistd.h>
 #include <stdlib.h>
-#include <curl/curl.h>
-#include <curl/mprintf.h>
 
+#ifndef _MSC_VER
+/* somewhat Unix-specific */
+#include <unistd.h>  /* getopt() */
+#endif
+
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
+
+#ifndef _MSC_VER
 static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
 {
   /*
@@ -72,11 +80,10 @@ static int debug_cb(CURL *handle, curl_infotype type,
   if(!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
     if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
         conn_id >= 0) {
-      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2,
-                     xfer_id, conn_id);
+      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id, conn_id);
     }
     else {
-      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
     }
   }
   else
@@ -192,9 +199,11 @@ static void usage(const char *msg)
     "  -V http_version (http/1.1, h2, h3) http version to use\n"
   );
 }
+#endif /* !_MSC_VER */
 
 int main(int argc, char *argv[])
 {
+#ifndef _MSC_VER
   CURL *curl;
   CURLcode rc = CURLE_OK;
   CURLU *cu;
@@ -254,8 +263,7 @@ int main(int argc, char *argv[])
     exit(1);
   }
   memset(&resolve, 0, sizeof(resolve));
-  curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1,
-                 "%s:%s:127.0.0.1", host, port);
+  snprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1", host, port);
   resolve = curl_slist_append(resolve, resolve_buf);
 
   curl = curl_easy_init();
@@ -306,4 +314,10 @@ int main(int argc, char *argv[])
   curl_global_cleanup();
 
   return (int)rc;
+#else
+  (void)argc;
+  (void)argv;
+  fprintf(stderr, "Not supported with this compiler.\n");
+  return 1;
+#endif /* !_MSC_VER */
 }
index 183f982b166fdd92889b32dbfe9a51bdc56843b4..d045c5d2cb01bb88c91616463c6633fd354e2dde 100644 (file)
@@ -25,7 +25,6 @@
  * Websockets data echos
  * </DESC>
  */
-
 /* curl stuff */
 #include "curl_setup.h"
 #include <curl/curl.h>
 #include <stdlib.h>
 #include <string.h>
 
-/* somewhat Unix-specific */
-#include <sys/time.h>
-#include <unistd.h>
-
 #ifdef USE_WEBSOCKETS
 
+#ifdef _WIN32
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#else
+#include <sys/time.h>
+#endif
+
 static
 void dump(const char *text, unsigned char *ptr, size_t size,
           char nohex)
@@ -112,7 +116,11 @@ static CURLcode recv_binary(CURL *curl, char *exp_data, size_t exp_len)
     result = curl_ws_recv(curl, recvbuf, sizeof(recvbuf), &nread, &frame);
     if(result == CURLE_AGAIN) {
       fprintf(stderr, "EAGAIN, sleep, try again\n");
+#ifdef _WIN32
+      Sleep(100);
+#else
       usleep(100*1000);
+#endif
       continue;
     }
     fprintf(stderr, "ws: curl_ws_recv(offset=%ld, len=%ld) -> %d, %ld\n",
index 31904712ff2252fce43d33bcef1e7afa8ad1a6d7..c86d7daed88e72a9d5daa3e0434e3d977b956856 100644 (file)
@@ -25,7 +25,6 @@
  * Websockets pingpong
  * </DESC>
  */
-
 /* curl stuff */
 #include "curl_setup.h"
 #include <curl/curl.h>
 #include <stdlib.h>
 #include <string.h>
 
-/* somewhat Unix-specific */
+#ifdef _WIN32
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#else
 #include <sys/time.h>
-#include <unistd.h>
+#endif
 
 #ifdef USE_WEBSOCKETS
 
@@ -102,7 +106,11 @@ static CURLcode pingpong(CURL *curl, const char *payload)
     fprintf(stderr, "Receive pong\n");
     res = recv_pong(curl, payload);
     if(res == CURLE_AGAIN) {
+#ifdef _WIN32
+      Sleep(100);
+#else
       usleep(100*1000);
+#endif
       continue;
     }
     websocket_close(curl);