]> git.ipfire.org Git - pakfire.git/commitdiff
xfer: Add a function to URL escape any strings
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Jun 2025 11:44:58 +0000 (11:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Jun 2025 11:44:58 +0000 (11:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/xfer.c
src/pakfire/xfer.h

index c9e90b05bbd9bc6a450b48b66876a72a87ee392b..d656c71a82f5f849e73ae00caa931b5c2846d868 100644 (file)
@@ -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;
index 9f67e9a3d774ee204e079b2b77cb93ece370226d..7ddb01005e1c60736eb5cd97250486d6cc8e2fe7 100644 (file)
@@ -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,