]> git.ipfire.org Git - pakfire.git/commitdiff
packager: Add scaffolding
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Mar 2021 17:18:11 +0000 (17:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Mar 2021 17:18:11 +0000 (17:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/include/pakfire/packager.h [new file with mode: 0644]
src/libpakfire/libpakfire.sym
src/libpakfire/packager.c [new file with mode: 0644]

index 3e6cb8ce27cc436275f9da56b0c7a4432b88bda1..79a581b57854e7b27ef938a35f228a9676b2f669 100644 (file)
@@ -272,6 +272,7 @@ libpakfire_la_SOURCES = \
        src/libpakfire/key.c \
        src/libpakfire/logging.c \
        src/libpakfire/package.c \
+       src/libpakfire/packager.c \
        src/libpakfire/packagelist.c \
        src/libpakfire/pakfire.c \
        src/libpakfire/parser.c \
@@ -301,6 +302,7 @@ pkginclude_HEADERS += \
        src/libpakfire/include/pakfire/key.h \
        src/libpakfire/include/pakfire/logging.h \
        src/libpakfire/include/pakfire/package.h \
+       src/libpakfire/include/pakfire/packager.h \
        src/libpakfire/include/pakfire/packagelist.h \
        src/libpakfire/include/pakfire/pakfire.h \
        src/libpakfire/include/pakfire/parser.h \
diff --git a/src/libpakfire/include/pakfire/packager.h b/src/libpakfire/include/pakfire/packager.h
new file mode 100644 (file)
index 0000000..139b87b
--- /dev/null
@@ -0,0 +1,33 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2021 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PAKFIRE_PACKAGER_H
+#define PAKFIRE_PACKAGER_H
+
+#include <pakfire/types.h>
+
+struct pakfire_packager;
+
+int pakfire_packager_create(struct pakfire_packager** packager, PakfirePackage pkg);
+
+struct pakfire_packager* pakfire_packager_ref(struct pakfire_packager* packager);
+struct pakfire_packager* pakfire_packager_unref(struct pakfire_packager* packager);
+
+#endif /* PAKFIRE_PACKAGER_H */
index 40df6d12556c8d18400e566c61f871ad5c832f3f..9e9c73041f0cd41180e9b558fd0d3f557d03c8b9 100644 (file)
@@ -247,6 +247,12 @@ global:
        pakfire_packagelist_sort;
        pakfire_packagelist_unref;
 
+       # packager
+
+       pakfire_packager_create;
+       pakfire_packager_ref;
+       pakfire_packager_unref;
+
        # parser
        pakfire_parser_append;
        pakfire_parser_create;
diff --git a/src/libpakfire/packager.c b/src/libpakfire/packager.c
new file mode 100644 (file)
index 0000000..fd91f06
--- /dev/null
@@ -0,0 +1,77 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2021 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <pakfire/package.h>
+#include <pakfire/packager.h>
+#include <pakfire/pakfire.h>
+#include <pakfire/private.h>
+#include <pakfire/types.h>
+
+struct pakfire_packager {
+       Pakfire pakfire;
+       int nrefs;
+
+       PakfirePackage pkg;
+};
+
+PAKFIRE_EXPORT int pakfire_packager_create(struct pakfire_packager** packager,
+               PakfirePackage pkg) {
+       struct pakfire_packager* p = calloc(1, sizeof(*p));
+       if (!p)
+               return ENOMEM;
+
+       // Initialize reference counting
+       p->nrefs = 1;
+
+       // Store a reference to Pakfire
+       p->pakfire = pakfire_package_get_pakfire(pkg);
+
+       // Store a reference to the package
+       p->pkg = pakfire_package_ref(pkg);
+
+       *packager = p;
+
+       return 0;
+}
+
+static void pakfire_packager_free(struct pakfire_packager* packager) {
+       pakfire_package_unref(packager->pkg);
+       pakfire_unref(packager->pakfire);
+}
+
+PAKFIRE_EXPORT struct pakfire_packager* pakfire_packager_ref(
+               struct pakfire_packager* packager) {
+       ++packager->nrefs;
+
+       return packager;
+}
+
+PAKFIRE_EXPORT struct pakfire_packager* pakfire_packager_unref(
+               struct pakfire_packager* packager) {
+       if (--packager->nrefs > 0)
+               return packager;
+
+       pakfire_packager_free(packager);
+
+       return NULL;
+}