]> git.ipfire.org Git - pakfire.git/commitdiff
util: Don't require a reference to pakfire for the JSON functions
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Sep 2024 04:03:50 +0000 (04:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Sep 2024 04:03:50 +0000 (04:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/util.h
src/libpakfire/package.c
src/libpakfire/util.c

index ff552ed92792a7d49a89e7671624e0793ece3e56..2661fca2aca38932ca8a3c0d5d0cdcd041da44d1 100644 (file)
@@ -88,12 +88,9 @@ int pakfire_tty_is_noninteractive(void);
 struct json_object* pakfire_json_parse(struct pakfire_ctx* ctx,
        const char* buffer, const size_t length);
 struct json_object* pakfire_json_parse_from_file(struct pakfire_ctx* ctx, const char* path);
-int pakfire_json_add_string(struct pakfire* pakfire,
-       struct json_object* json, const char* name, const char* value);
-int pakfire_json_add_integer(struct pakfire* pakfire,
-       struct json_object* json, const char* name, int64_t value);
-int pakfire_json_add_string_array(struct pakfire* pakfire,
-       struct json_object* json, const char* name, char** array);
+int pakfire_json_add_string(struct json_object* json, const char* name, const char* value);
+int pakfire_json_add_integer(struct json_object* json, const char* name, int64_t value);
+int pakfire_json_add_string_array(struct json_object* json, const char* name, char** array);
 
 // Resource Limits
 
index e41f0a1a6c0a3d4fb41485d70bf65fc160288bff..ad5d0f3f4007e6928e6276c54eaf830119a609d2 100644 (file)
@@ -2024,7 +2024,7 @@ static int _pakfire_package_add_json_dependencies(
                return 1;
 
        // Add dependencies
-       int r = pakfire_json_add_string_array(pkg->pakfire, json, name, dependencies);
+       int r = pakfire_json_add_string_array(json, name, dependencies);
        if (r)
                goto ERROR;
 
@@ -2194,7 +2194,7 @@ static int __pakfire_package_add_build_packages(struct pakfire_ctx* ctx,
        }
 
        // Add package information to the list
-       r = pakfire_json_add_string(pkg->pakfire, object, name, evr);
+       r = pakfire_json_add_string(object, name, evr);
        if (r) {
                CTX_ERROR(ctx, "Could not add package to packages list: %m\n");
                return r;
@@ -2269,14 +2269,14 @@ static int pakfire_package_add_build_metadata(struct pakfire_package* pkg,
                return 1;
 
        // Add pakfire version that generated this metadata
-       r = pakfire_json_add_string(pkg->pakfire, object, "pakfire", PACKAGE_VERSION);
+       r = pakfire_json_add_string(object, "pakfire", PACKAGE_VERSION);
        if (r)
                goto ERROR;
 
        // Write build host
        const char* build_host = pakfire_package_get_string(pkg, PAKFIRE_PKG_BUILD_HOST);
        if (build_host) {
-               r = pakfire_json_add_string(pkg->pakfire, object, "host", build_host);
+               r = pakfire_json_add_string(object, "host", build_host);
                if (r)
                        goto ERROR;
        }
@@ -2284,7 +2284,7 @@ static int pakfire_package_add_build_metadata(struct pakfire_package* pkg,
        // Write build id
        const char* build_id = pakfire_package_get_string(pkg, PAKFIRE_PKG_BUILD_ID);
        if (build_id) {
-               r = pakfire_json_add_string(pkg->pakfire, object, "id", build_id);
+               r = pakfire_json_add_string(object, "id", build_id);
                if (r)
                        goto ERROR;
        }
@@ -2292,7 +2292,7 @@ static int pakfire_package_add_build_metadata(struct pakfire_package* pkg,
        // Write build host
        time_t build_time = pakfire_package_get_num(pkg, PAKFIRE_PKG_BUILD_TIME, 0);
        if (build_time) {
-               r = pakfire_json_add_integer(pkg->pakfire, object, "time", build_time);
+               r = pakfire_json_add_integer(object, "time", build_time);
                if (r)
                        goto ERROR;
        }
@@ -2300,7 +2300,7 @@ static int pakfire_package_add_build_metadata(struct pakfire_package* pkg,
        // Write build arches
        char** build_arches = pakfire_package_get_strings(pkg, PAKFIRE_PKG_BUILD_ARCHES);
        if (build_arches) {
-               r = pakfire_json_add_string_array(pkg->pakfire, object, "arches", build_arches);
+               r = pakfire_json_add_string_array(object, "arches", build_arches);
 
                // Cleanup
                pakfire_strings_free(build_arches);
@@ -2312,7 +2312,7 @@ static int pakfire_package_add_build_metadata(struct pakfire_package* pkg,
        // Source package name
        const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_SOURCE_NAME);
        if (name) {
-               r = pakfire_json_add_string(pkg->pakfire, object, "source-name", name);
+               r = pakfire_json_add_string(object, "source-name", name);
                if (r)
                        goto ERROR;
        }
@@ -2320,7 +2320,7 @@ static int pakfire_package_add_build_metadata(struct pakfire_package* pkg,
        // Source package EVR
        const char* evr = pakfire_package_get_string(pkg, PAKFIRE_PKG_SOURCE_EVR);
        if (evr) {
-               r = pakfire_json_add_string(pkg->pakfire, object, "source-evr", evr);
+               r = pakfire_json_add_string(object, "source-evr", evr);
                if (r)
                        goto ERROR;
        }
@@ -2328,7 +2328,7 @@ static int pakfire_package_add_build_metadata(struct pakfire_package* pkg,
        // Source package arch
        const char* arch = pakfire_package_get_string(pkg, PAKFIRE_PKG_SOURCE_ARCH);
        if (arch) {
-               r = pakfire_json_add_string(pkg->pakfire, object, "source-arch", arch);
+               r = pakfire_json_add_string(object, "source-arch", arch);
                if (r)
                        goto ERROR;
        }
@@ -2359,7 +2359,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // Name
        const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME);
        if (name) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "name", name);
+               r = pakfire_json_add_string(md, "name", name);
                if (r)
                        goto ERROR;
        }
@@ -2367,7 +2367,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // EVR
        const char* evr = pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR);
        if (evr) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "evr", evr);
+               r = pakfire_json_add_string(md, "evr", evr);
                if (r)
                        goto ERROR;
        }
@@ -2375,7 +2375,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // Arch
        const char* arch = pakfire_package_get_string(pkg, PAKFIRE_PKG_ARCH);
        if (arch) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "arch", arch);
+               r = pakfire_json_add_string(md, "arch", arch);
                if (r)
                        goto ERROR;
        }
@@ -2383,7 +2383,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // Vendor
        const char* vendor = pakfire_package_get_string(pkg, PAKFIRE_PKG_VENDOR);
        if (vendor) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "vendor", vendor);
+               r = pakfire_json_add_string(md, "vendor", vendor);
                if (r)
                        goto ERROR;
        }
@@ -2391,7 +2391,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // Distribution
        const char* distribution = pakfire_package_get_string(pkg, PAKFIRE_PKG_DISTRO);
        if (distribution) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "distribution", distribution);
+               r = pakfire_json_add_string(md, "distribution", distribution);
                if (r)
                        goto ERROR;
        }
@@ -2399,7 +2399,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // UUID
        const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID);
        if (uuid) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "uuid", uuid);
+               r = pakfire_json_add_string(md, "uuid", uuid);
                if (r)
                        goto ERROR;
        }
@@ -2407,7 +2407,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // Groups
        char** groups = pakfire_package_get_strings(pkg, PAKFIRE_PKG_GROUPS);
        if (groups) {
-               r = pakfire_json_add_string_array(pkg->pakfire, md, "groups", groups);
+               r = pakfire_json_add_string_array(md, "groups", groups);
 
                // Cleanup
                pakfire_strings_free(groups);
@@ -2419,7 +2419,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // Packager
        const char* packager = pakfire_package_get_string(pkg, PAKFIRE_PKG_PACKAGER);
        if (packager) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "packager", packager);
+               r = pakfire_json_add_string(md, "packager", packager);
                if (r)
                        goto ERROR;
        }
@@ -2427,7 +2427,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // URL
        const char* url = pakfire_package_get_string(pkg, PAKFIRE_PKG_URL);
        if (url) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "url", url);
+               r = pakfire_json_add_string(md, "url", url);
                if (r)
                        goto ERROR;
        }
@@ -2435,7 +2435,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // License
        const char* license = pakfire_package_get_string(pkg, PAKFIRE_PKG_LICENSE);
        if (license) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "license", license);
+               r = pakfire_json_add_string(md, "license", license);
                if (r)
                        goto ERROR;
        }
@@ -2443,7 +2443,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // Summary
        const char* summary = pakfire_package_get_string(pkg, PAKFIRE_PKG_SUMMARY);
        if (summary) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "summary", summary);
+               r = pakfire_json_add_string(md, "summary", summary);
                if (r)
                        goto ERROR;
        }
@@ -2451,7 +2451,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // Description
        const char* description = pakfire_package_get_string(pkg, PAKFIRE_PKG_DESCRIPTION);
        if (description) {
-               r = pakfire_json_add_string(pkg->pakfire, md, "description", description);
+               r = pakfire_json_add_string(md, "description", description);
                if (r)
                        goto ERROR;
        }
@@ -2459,7 +2459,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        // Installed package size
        unsigned long long installsize = pakfire_package_get_num(pkg, PAKFIRE_PKG_INSTALLSIZE, 0);
 
-       r = pakfire_json_add_integer(pkg->pakfire, md, "size", (uint64_t)installsize);
+       r = pakfire_json_add_integer(md, "size", (uint64_t)installsize);
        if (r)
                goto ERROR;
 
index baf421da0b8a3c3b37837c88c5933684d5baf98f..79962526b3dccb25cd007c53fb925da1dc5d978b 100644 (file)
@@ -713,7 +713,7 @@ struct json_object* pakfire_json_parse_from_file(struct pakfire_ctx* ctx, const
        return json;
 }
 
-int pakfire_json_add_string(struct pakfire* pakfire, struct json_object* json,
+int pakfire_json_add_string(struct json_object* json,
                const char* name, const char* value) {
        // No string? Nothing to do
        if (!value)
@@ -728,8 +728,7 @@ int pakfire_json_add_string(struct pakfire* pakfire, struct json_object* json,
        return json_object_object_add(json, name, object);
 }
 
-int pakfire_json_add_string_array(struct pakfire* pakfire, struct json_object* json,
-               const char* name, char** array) {
+int pakfire_json_add_string_array(struct json_object* json, const char* name, char** array) {
        int r = 1;
 
        // Allocate a new array
@@ -757,7 +756,7 @@ ERROR:
        return r;
 }
 
-int pakfire_json_add_integer(struct pakfire* pakfire, struct json_object* json,
+int pakfire_json_add_integer(struct json_object* json,
                const char* name, int64_t value) {
        // Convert integer to JSON object
        struct json_object* object = json_object_new_int64(value);