From: Michael Tremer Date: Sat, 21 Jun 2025 11:44:58 +0000 (+0000) Subject: xfer: Add a function to URL escape any strings X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f1718dd83264e43d63517e57b27a3bb3009e8f93;p=pakfire.git xfer: Add a function to URL escape any strings Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/xfer.c b/src/pakfire/xfer.c index c9e90b05..d656c71a 100644 --- a/src/pakfire/xfer.c +++ b/src/pakfire/xfer.c @@ -558,6 +558,26 @@ int pakfire_xfer_verify_hashes(struct pakfire_xfer* self, const struct pakfire_h return pakfire_hashes_import(&self->expected_hashes, hashes); } +char* pakfire_xfer_escape(struct pakfire_xfer* self, const char* s) { + char* output = NULL; + char* result = NULL; + + // Return NULL if the input is NULL + if (!s) + return NULL; + + // Escape the output + output = curl_easy_escape(self->handle, s, 0); + if (!output) + return NULL; + + // Copy the string once more so that we don't have to call curl_free() outside of here. + result = strdup(output); + curl_free(output); + + return result; +} + int pakfire_xfer_add_query(struct pakfire_xfer* xfer, const char* key, const char* format, ...) { char* value = NULL; diff --git a/src/pakfire/xfer.h b/src/pakfire/xfer.h index 9f67e9a3..7ddb0100 100644 --- a/src/pakfire/xfer.h +++ b/src/pakfire/xfer.h @@ -111,6 +111,8 @@ int pakfire_xfer_set_size(struct pakfire_xfer* xfer, size_t size); int pakfire_xfer_verify_hashes(struct pakfire_xfer* self, const struct pakfire_hashes* hashes); +char* pakfire_xfer_escape(struct pakfire_xfer* self, const char* s); + int pakfire_xfer_add_query(struct pakfire_xfer* xfer, const char* key, const char* format, ...) __attribute__((format(printf, 3, 4))); int pakfire_xfer_add_param(struct pakfire_xfer* xfer,