]> git.ipfire.org Git - pakfire.git/commitdiff
xfer: Compile even if cURL does not have support for WebSockets
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 9 Oct 2024 13:41:00 +0000 (13:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 9 Oct 2024 15:13:54 +0000 (15:13 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
configure.ac
src/cli/lib/daemon.c
src/cli/lib/daemon.h
src/libpakfire/daemon.c
src/libpakfire/include/pakfire/daemon.h
src/libpakfire/include/pakfire/job.h
src/libpakfire/include/pakfire/xfer.h
src/libpakfire/job.c
src/libpakfire/xfer.c

index c4d54570fcbc1e4cc0e84d2abfb9791a77d8f100..75feeb1a10ae77967157089a7b4d1823befd8ee6 100644 (file)
@@ -454,10 +454,12 @@ pakfire_client_LDADD = \
 
 # ------------------------------------------------------------------------------
 
+if CURL_HAS_WEBSOCKETS
 bin_PROGRAMS += \
        pakfire-daemon
+endif
 
-pakfire_daemon_SOURCES = \
+dist_pakfire_daemon_SOURCES = \
        src/cli/pakfire-daemon.c
 
 pakfire_daemon_CPPFLAGS = \
index 1e98a10466b6c99c0c8425218bfffdb676b9f1e8..2dbbd0aefc139afe8b185f96821b7f65400799b8 100644 (file)
@@ -316,6 +316,31 @@ AC_ARG_WITH([systemdsystemunitdir],
 AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
 AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir"])
 
+# Check if cURL has support for WebSockets
+AC_CHECK_PROG(CURL_CONFIG, curl-config, curl-config)
+if test "$CURL_CONFIG" != ""; then
+       # Check curl version
+       CURL_VERSION=$($CURL_CONFIG --version)
+
+       # Check for WebSocket support
+       AC_MSG_CHECKING([for curl WebSocket support])
+       CURL_FEATURES=$($CURL_CONFIG --features)
+
+       if echo "$CURL_FEATURES" | grep -q "websockets"; then
+               AC_MSG_RESULT([yes])
+               CURL_HAS_WEBSOCKETS=yes
+       else
+               AC_MSG_RESULT([no])
+               CURL_HAS_WEBSOCKETS=no
+       fi
+else
+       AC_MSG_ERROR([curl-config not found])
+fi
+
+# Set up a variable for later use
+AC_SUBST(CURL_HAS_WEBSOCKETS)
+AM_CONDITIONAL(CURL_HAS_WEBSOCKETS, [test "x$CURL_HAS_WEBSOCKETS" = "xyes"])
+
 AC_DEFINE_UNQUOTED([PAKFIRE_CONFIG_DIR], ["${sysconfdir}/${PACKAGE_NAME}"],
        [The path where Pakfire stores configuration files])
 AC_DEFINE_UNQUOTED([PAKFIRE_CACHE_DIR], ["/var/cache/${PACKAGE_NAME}"],
index d608457bcf7fd518044fed7d4c8c42d6a34118d6..d54e5e74b89035d5dcebda69eaa58b35e8059626 100644 (file)
@@ -18,6 +18,8 @@
 #                                                                             #
 #############################################################################*/
 
+#ifdef CURL_HAS_WEBSOCKETS
+
 #include <pakfire/ctx.h>
 #include <pakfire/daemon.h>
 
@@ -39,3 +41,5 @@ int cli_daemon_main(struct pakfire_ctx* ctx) {
 
        return r;
 }
+
+#endif /* CURL_HAS_WEBSOCKETS */
index 736c7625a00479b3033370d53a67924051666f13..a27ec39b2d851b4c07ec3633084fb281546ab4ae 100644 (file)
 #ifndef PAKFIRE_CLI_DAEMON_H
 #define PAKFIRE_CLI_DAEMON_H
 
+#ifdef CURL_HAS_WEBSOCKETS
+
 #include <pakfire/ctx.h>
 
 int cli_daemon_main(struct pakfire_ctx* ctx);
 
+#endif /* CURL_HAS_WEBSOCKETS */
 #endif /* PAKFIRE_CLI_DAEMON_H */
index ea9a05ac498b4e2ed688d722793decce2a3f1da9..087d1ee996ad63a9d5c9714542841df03fd1515c 100644 (file)
@@ -18,6 +18,8 @@
 #                                                                             #
 #############################################################################*/
 
+#ifdef CURL_HAS_WEBSOCKETS
+
 #include <errno.h>
 #include <stdlib.h>
 
@@ -762,3 +764,5 @@ int pakfire_daemon_job_finished(struct pakfire_daemon* daemon, struct pakfire_jo
 
        return 0;
 }
+
+#endif /* CURL_HAS_WEBSOCKETS */
index dd9ca597ec6a2333900a24abacf08afe514267d1..e332fc8df155e9664c3e3da37c61fd21619f4827 100644 (file)
@@ -22,6 +22,7 @@
 #define PAKFIRE_DAEMON_H
 
 #ifdef PAKFIRE_PRIVATE
+#ifdef CURL_HAS_WEBSOCKETS
 
 struct pakfire_daemon;
 
@@ -40,5 +41,6 @@ int pakfire_daemon_main(struct pakfire_daemon* daemon);
 
 int pakfire_daemon_job_finished(struct pakfire_daemon* daemon, struct pakfire_job* job);
 
+#endif /* CURL_HAS_WEBSOCKETS */
 #endif /* PAKFIRE_PRIVATE */
 #endif /* PAKFIRE_DAEMON_H */
index 0b9a5477f5d61fb396dba67b723b69513e65b09d..e131c7db9b94896cb20c097b8f47f9b207766bec 100644 (file)
@@ -22,6 +22,7 @@
 #define PAKFIRE_JOB_H
 
 #ifdef PAKFIRE_PRIVATE
+#ifdef CURL_HAS_WEBSOCKETS
 
 #include <pakfire/ctx.h>
 #include <pakfire/daemon.h>
@@ -39,5 +40,6 @@ int pakfire_job_terminate(struct pakfire_job* worker, int signal);
 
 int pakfire_job_exited(sd_event_source* s, const siginfo_t* si, void* data);
 
+#endif /* CURL_HAS_WEBSOCKETS */
 #endif /* PAKFIRE_PRIVATE */
 #endif /* PAKFIRE_JOB_H */
index 80effd06fe86d568e0a4e4d24d625c7d0f5e3d40..0e10ca00f6e01b2a0b01db089a74fac5e7fb8e37 100644 (file)
@@ -133,6 +133,7 @@ pakfire_xfer_error_code_t pakfire_xfer_run_api_request(
        struct pakfire_xfer* xfer, struct json_object** response);
 
 // WebSocket
+#ifdef CURL_HAS_WEBSOCKETS
 typedef int (*pakfire_xfer_open_callback)(struct pakfire_xfer* xfer, void* data);
 typedef int (*pakfire_xfer_recv_callback)(struct pakfire_xfer* xfer, const char* message, const size_t size, void* data);
 typedef int (*pakfire_xfer_send_callback)(struct pakfire_xfer* xfer, void* data);
@@ -142,6 +143,7 @@ int pakfire_xfer_socket(struct pakfire_xfer* xfer, pakfire_xfer_open_callback op
        pakfire_xfer_recv_callback recv, pakfire_xfer_send_callback send, pakfire_xfer_close_callback close, void* data);
 
 int pakfire_xfer_send_message(struct pakfire_xfer* xfer, const char* message, const size_t length);
+#endif /* CURL_HAS_WEBSOCKETS */
 
 #endif /* PAKFIRE_PRIVATE */
 #endif /* PAKFIRE_XFER_H */
index 1ae7d69e8bd86d388f30c87beb9cd4f1456a6b21..ad78d26cd3305167bd10cd098dee0e6d8f7e9a58 100644 (file)
@@ -18,6 +18,8 @@
 #                                                                             #
 #############################################################################*/
 
+#ifdef CURL_HAS_WEBSOCKETS
+
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
@@ -779,3 +781,5 @@ int pakfire_job_terminate(struct pakfire_job* job, int signal) {
 
        return 0;
 }
+
+#endif /* CURL_HAS_WEBSOCKETS */
index debcd0ee9785bafeb4d48d6324494088471b44ec..041f61b16ee807b0735b7751bb1f5a04e7fdd45b 100644 (file)
@@ -72,7 +72,9 @@ struct pakfire_xfer {
        enum {
                PAKFIRE_XFER_DOWNLOAD = 0,
                PAKFIRE_XFER_UPLOAD   = 1,
+#ifdef CURL_HAS_WEBSOCKETS
                PAKFIRE_XFER_SOCKET   = 2,
+#endif /* CURL_HAS_WEBSOCKETS */
        } direction;
 
        // Size
@@ -108,6 +110,7 @@ struct pakfire_xfer {
        // Event Loop
        sd_event_source* event;
 
+#ifdef CURL_HAS_WEBSOCKETS
        // Callbacks
        struct pakfire_xfer_callbacks {
                pakfire_xfer_open_callback open;
@@ -122,6 +125,7 @@ struct pakfire_xfer {
                char* data;
                size_t size;
        } buffer;
+#endif /* CURL_HAS_WEBSOCKETS */
 };
 
 static void pakfire_xfer_free(struct pakfire_xfer* xfer) {
@@ -141,9 +145,11 @@ static void pakfire_xfer_free(struct pakfire_xfer* xfer) {
        if (xfer->event)
                sd_event_source_unref(xfer->event);
 
+#ifdef CURL_HAS_WEBSOCKETS
        // Buffer
        if (xfer->buffer.data)
                free(xfer->buffer.data);
+#endif /* CURL_HAS_WEBSOCKETS */
 
        // cURL stuff
        if (xfer->handle)
@@ -856,6 +862,7 @@ static int pakfire_xfer_fail(struct pakfire_xfer* xfer, int code) {
                return -EAGAIN;
        }
 
+#ifdef CURL_HAS_WEBSOCKETS
        // Call the close callback for WebSockets
        if (xfer->direction == PAKFIRE_XFER_SOCKET) {
                if (xfer->callbacks.close) {
@@ -864,6 +871,7 @@ static int pakfire_xfer_fail(struct pakfire_xfer* xfer, int code) {
                                return r;
                }
        }
+#endif /* CURL_HAS_WEBSOCKETS */
 
        return code;
 }
@@ -916,6 +924,7 @@ static const char* curl_http_version(long v) {
        return "unknown";
 }
 
+#ifdef CURL_HAS_WEBSOCKETS
 static int pakfire_xfer_allocate(struct pakfire_xfer* xfer, size_t size) {
 
        // Otherwise, we resize the buffer
@@ -1079,6 +1088,7 @@ ERROR:
 
        return r;
 }
+#endif /* CURL_HAS_WEBSOCKETS */
 
 static int pakfire_xfer_save(struct pakfire_xfer* xfer) {
        int r;
@@ -1251,8 +1261,10 @@ pakfire_xfer_error_code_t pakfire_xfer_done(struct pakfire_xfer* xfer, int code)
                                        goto ERROR;
                                break;
 
+#ifdef CURL_HAS_WEBSOCKETS
                        case PAKFIRE_XFER_SOCKET:
                                return pakfire_xfer_done_socket(xfer, code);
+#endif /* CURL_HAS_WEBSOCKETS */
 
                        default:
                                break;
@@ -1298,8 +1310,10 @@ static int pakfire_xfer_update(void* data,
                        xfer->xferred = ulnow;
                        break;
 
+#ifdef CURL_HAS_WEBSOCKETS
                case PAKFIRE_XFER_SOCKET:
                        break;
+#endif /* CURL_HAS_WEBSOCKETS */
        }
 
        // Do nothing if no progress indicator has been set up
@@ -1407,6 +1421,7 @@ static int pakfire_xfer_prepare_url(struct pakfire_xfer* xfer) {
                goto ERROR;
        }
 
+#ifdef CURL_HAS_WEBSOCKETS
        // Replace the schema if we are using SOCKET
        if (xfer->direction == PAKFIRE_XFER_SOCKET) {
                r = curl_url_set(xfer->fullurl, CURLUPART_SCHEME, "wss", 0);
@@ -1415,6 +1430,7 @@ static int pakfire_xfer_prepare_url(struct pakfire_xfer* xfer) {
                        goto ERROR;
                }
        }
+#endif /* CURL_HAS_WEBSOCKETS */
 
        // Set the URL
        r = curl_easy_setopt(xfer->handle, CURLOPT_CURLU, xfer->fullurl);
@@ -1460,6 +1476,7 @@ int pakfire_xfer_prepare(struct pakfire_xfer* xfer, struct pakfire_progress* pro
                        xfer->headers = curl_slist_append(xfer->headers, "Transfer-Encoding: chunked");
                        break;
 
+#ifdef CURL_HAS_WEBSOCKETS
                case PAKFIRE_XFER_SOCKET:
                        // Ask cURL to connect and let us handle the rest
                        r = curl_easy_setopt(xfer->handle, CURLOPT_CONNECT_ONLY, 2L);
@@ -1469,6 +1486,7 @@ int pakfire_xfer_prepare(struct pakfire_xfer* xfer, struct pakfire_progress* pro
                        }
 
                        break;
+#endif /* CURL_HAS_WEBSOCKETS */
        }
 
        // Compose the URL
@@ -1544,6 +1562,7 @@ int pakfire_xfer_prepare(struct pakfire_xfer* xfer, struct pakfire_progress* pro
        return 0;
 }
 
+#ifdef CURL_HAS_WEBSOCKETS
 int pakfire_xfer_socket(struct pakfire_xfer* xfer, pakfire_xfer_open_callback open,
                pakfire_xfer_recv_callback recv, pakfire_xfer_send_callback send,
                pakfire_xfer_close_callback close, void* data) {
@@ -1581,6 +1600,7 @@ int pakfire_xfer_send_message(struct pakfire_xfer* xfer,
 
        return 0;
 }
+#endif /* CURL_HAS_WEBSOCKETS */
 
 pakfire_xfer_error_code_t pakfire_xfer_run(struct pakfire_xfer* xfer, int flags) {
        int r;